Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Determining if a rational number terminates

by blackle (Beadle)
on Nov 29, 2012 at 18:12 UTC ( #1006314=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Determining if a rational number terminates
in thread Determining if a rational number terminates

Thanks for that, I didn't even consider that it wouldn't be in lowest form.

It's really clever to take advantage of the fact that powers of five always end with five, I suppose then it's better to divide out the powers of two first than the powers of five. Tomorrow I will ++ both of these :D


Comment on Re^3: Determining if a rational number terminates
Re^4: Determining if a rational number terminates
by tobyink (Abbot) on Nov 29, 2012 at 20:13 UTC

    Meh... I was actually only checking multiples of five. D'oh! 1/15 was reporting "Y".

    Fixed...

    @ARGV = (15, 40); sub _{@i=sort{$b-$a}@_;return$i[1]if$i[0]==$i[1];@i=($i[1],$i[0]%$i[1 ])while$i[1];$i[0]}sub __{$j=_@_;$_/=$j for@_;$_[1]<0and do{$_*=-1for @_}}__(($k,$l)=@ARGV);for(2,5){$l/=$_ until$l%$_}print$l eq 1?Y:N,$/#
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006314]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2014-10-20 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (93 votes), past polls