Simplifying Radicals

2

Given integers a and b in the format a√b (a on the square root of b), make a program that will reduce b and increase a until the radical statement is fully simplified.

Example

input  
a = 1
b = 16

output
4 root 1

In this instance, 1√16 = 4√1

Bonus - 25 chars for the ability to simplify radicals other than square root using another variable, c.

Jake1130

Posted 2014-01-30T17:24:14.470

Reputation: 31

Question was closed 2014-01-30T21:46:17.657

4

Isn't this question a special case of http://codegolf.stackexchange.com/questions/18535/convert-radicals-to-mixed-entire-radicals-and-to-real-numbers ?

– Howard – 2014-01-30T17:30:00.977

Answers

0

Python, 71-25=46 63-25=38 chars

f=lambda a,b:max((a*i,b/i/i)for i in range(1,b)if b%(i*i)==0)

g=lambda a,b,c:max((a*i,b/i**c)for i in range(1,b)if b%i**c==0)

f is 61, chars. g is 63 but gets a 25 char bonus.

Keith Randall

Posted 2014-01-30T17:24:14.470

Reputation: 19 865

You can make it a lot shorter by using the ** operator and getting rid of unnecessary parens: f=lambda a,b,c:max((a*i,b/i**c)for i in range(1,b)if b%i**c==0) – Josh – 2014-01-30T18:01:04.640

@Josh: thanks.. – Keith Randall – 2014-01-30T18:12:11.493