The stupid question is the question not asked PerlMonks

### Re^3: Determining if a rational number terminates

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

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

Replies are listed 'Best First'.
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'

Create A New User
Node Status?
node history
Node Type: note [id://1006314]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2017-08-24 09:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (367 votes). Check out past polls.

Notices?