2
\$\begingroup\$

This question already has an answer here:

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.

\$\endgroup\$

marked as duplicate by Howard, Peter Taylor, Justin, Doorknob, ace Jan 30 '14 at 21:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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) \$\endgroup\$ – Josh Jan 30 '14 at 18:01
  • \$\begingroup\$ @Josh: thanks.. \$\endgroup\$ – Keith Randall Jan 30 '14 at 18:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.