http://www.perlmonks.org?node_id=1006294


in reply to Determining if a rational number terminates

Nicely obfuscated, but this is shorter:

$_=pop;$_/=2until$_%2;print/(5|^1)$/?Y:N,$/
$_=pop;for$.(2,5){$_/=$.until$_%$.}print/^1$/?Y:N,$/

Of course, neither of these works for the fraction 3/6 which of course terminates as 0.5. For that to work, you'd need to add an initial step to reduce the fraction to its lowest terms.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'