The goal of this challenge is to take a radical and convert it to a reduced and entire radical, and a real number. You do not have to convert it to all 3, however, you will get bonus points for converting it to 2 or 3 of them. You will also get bonus points if your code works not just with square roots. How the input works is your choice. You don't have to parse the input so you could just have it as a function. If your unable to output the root symbol (√) then you could output it as sqrt(x) or cuberoot(x). You could also use a superscript (²√) for the index of the radical.


  • If you just output one of the 3 options, then you can't just output it without converting it (ie: if the input is √125 then you can't just output √125 back).
  • The entire radical must have no co-efficient.
  • The mixed radical must have a coefficient (if there is no coefficient, then it should be 1).
  • The real number (or result of the radical) should have as many decimals as possible.


Here's an example output for the square root of 125 (√125):

Entire radical: √125
Mixed radical: 5√5
Real number: 11.18033988749895


  • 10% off your score for outputting 2 of either an entire radical, mixed radical, or real number.
  • 30% off your score for outputting all 3 (entire radical, mixed radical, and real number).
  • 30% off your score for working with a radical with any index


The person with the shortest code length wins. Good luck!


closed as unclear what you're asking by Mego, Rɪᴋᴇʀ, Emigna, FryAmTheEggman, NoOneIsHere May 26 '16 at 16:26

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    \$\begingroup\$ What is the first enumerated rule supposed to mean? Specifically: 1. Does it imply that the solution must accept input in the form of an entire radical? 2. Is that the only input form which must be supported? 3. If a program only outputs entire radicals, and an entire radical is supplied as input, what should the program do? Not output anything? \$\endgroup\$ – Peter Taylor Jan 15 '14 at 8:42
  • \$\begingroup\$ You may also want to specify, that the coefficient for mixed radicals is not always 1 but the maximum integer value. \$\endgroup\$ – Howard Jan 15 '14 at 9:30

APL, 77 × .7² = 37.7

{(a b)←×⌿(∪p)*[1]c,⍪e-⍺×c←⌊⍺÷⍨e←∪⍦p←π⍵⋄q←⍺/⍨⍺≠2⋄∊¨⍕¨¨⍪(q'√'⍵)(a'×'q'√'b),⍺√⍵}

Nars2000. Could be golfed some more, for instance by printing worse output, but I'm being lazy.
Also, pretty output is pretty.


  p←π⍵                       ⍝ prime factors of the radical argument ⍵
  u←∪p                       ⍝ unique prime factors
  e←∪⍦u                      ⍝ exponents of those factors (so that ⍵=u*e)
  r←⌊e÷⍺                     ⍝ u's exponents for the reduced radical factor
  f←×/u*r                    ⍝ reduced radical factor
  a←×/u*e-⍺×r                ⍝ reduced radical argument
  i←⍺/⍨⍺≠2                   ⍝ index, unless it's 2 (AH THE DECADENCE, I CAN WASTE SO MUCH)
  o←(i'√'⍵)(f'×'i'√'a),⍺√⍵   ⍝ the three expressions to output
  ∊¨⍕¨¨⍪o                    ⍝ return them as a table without spaces


     2 f 125
     2 f 1440
     3 f 1440
     2 f 987654321
  • \$\begingroup\$ Would it not cost fewer bytes to only do two tasks? \$\endgroup\$ – Leaky Nun May 25 '16 at 23:20

C (314)

n,d;main(i){scanf("%d %d",&n,&d);int val[d];for(;pow(i,n)<=d;i++)val[i]=pow(i,n);printf("Entire radical: %drt(%d)\n",n,d);for(i--;i>0;i--)if(d%val[i]==0){printf("Mixed radical: %d*%drt(%d)\n",i,n,d/val[i]);break;}double v,x=1.5,a=d;do{v=(a/pow(x,n-1)-x)/n;x+=v;}while(abs(v)>=1E-9);printf("Real number: %lf\n",x);}

Here it is with whitespace.

    scanf("%d %d",&n,&d);
    int val[d];


    printf("Entire Radical: %d*rt(%d)\n",n,d);

    for (i--;i>0;i--)
        if (d%val[i]==0){
            printf("Mixed Radical: %d*%drt(%d)\n", i, n, d/val[i]);

    double v,x=1.5,a=d;

    printf("Real number: %lf\n", x);


2 125


Entire radical: 2rt(125)
Mixed radical: 5*2rt(5)
Real number: 11.180340


3 125


Entire radical: 3rt(125)
Mixed radical: 5*3rt(1)
Real number: 5.000000

This isn't perfect, the root calculation will not work for all input values, and the chosen guess value is not random. It takes the whole value of the radical as input (see above).


C - 222 × 70% × 70% ≆ 108.78

p,c=1,i,n=2,t;main(){scanf("%d %d",&i,&p);printf("Entire radical: rt%d(%d)\nReal number: %.16
intf("Mixed root: %drt%d(%d)",c,i,p);}

Has some problems with rounding, but is otherwise fine.


Ruby, 199 chars * 70% * 70% = 97.51

I'm not good at mathstuffs. :P

a,b=gets.split.map &:to_i
[*2..o=b].map{|x|x**a}.map{|x|o=c/=x if c%x==0}until o==b
puts"Entire radical: #{a}rt#{b}
Mixed radical: #{((b/c)**(1.0/a)).round}*#{a}rt#{c}
Real number: #{b**(1.0/a)}"

I particularly like line 3. It's supposed to keep dividing out squares until it can't divide anymore. How I did it is that o is set to b in the beginning (conveniently tucking it into the range expression), and if a square can be divided out, o is set to the result (also conveniently only adding 2 more characters). Then, I used until o==b, so that it keeps going until o didn't change (meaning no squares could be divided out).

More explanations coming soon....

Sample runs:

2 100
Entire radical: 2rt100
Mixed radical: 10.0*2rt1
Real number: 10.0

2 125
Entire radical: 2rt125
Mixed radical: 5*2rt5
Real number: 11.180339887498949

2 100
Entire radical: 2rt100
Mixed radical: 10*2rt1
Real number: 10.0

5 32
Entire radical: 5rt32
Mixed radical: 2*5rt1
Real number: 2.0

3 27
Entire radical: 3rt27
Mixed radical: 3*3rt1
Real number: 3.0

2 99
Entire radical: 2rt99
Mixed radical: 3*2rt11
Real number: 9.9498743710662

2 98
Entire radical: 2rt98
Mixed radical: 7*2rt2
Real number: 9.899494936611665

Julia, 19*0.9 = 17.1

julia> f(n)="$(sqrt(n)) √$n"

julia> f(125)
"11.180339887498949 √125"

I feel like I must not have understood the challenge. As far as I could tell there is only a small bonus for bothering to reduce the radical.


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