There's more than one way to do things PerlMonks

### Re^2: Code Golf: Four is magic

by Haarg (Chaplain)
 on Jul 13, 2010 at 17:25 UTC ( #849325=note: print w/replies, xml ) Need Help??

in reply to Re: Code Golf: Four is magic
in thread Code Golf: Four is magic

A couple small improvements:
```perl -E'@x=split//,"0335443554366887798866555766";\$_+=<>;print;while(\$
+_!=4){split//,"99aabb87780";\$_?do{\$x=0;\$x+=hex(pop)*!!\$&+(\$1&&\$x[\$1]+
+7)+(\$2>1?\$x[\$2+18]+\$x[\$3]:\$x[\$2.\$3])while s/(.??)(.?)(.)\$//}:(\$x=4);s
+ay" is \$x.";print\$_=\$x}say" is magic."'

Replies are listed 'Best First'.
Re^3: Code Golf: Four is magic
by thundergnat (Deacon) on Jul 14, 2010 at 00:28 UTC

That actually has problems with large numbers (> native integer ?) Once it gets over 64 bits on my machine it converts to scientific notation... which throws off the conversion.

Never mind. Broken

Here's my whack at it - 232 strokes

```perl -E'@x=split//,"4335443554366887798866555766";\$_=<>;chop;print;whi
+le(\$_-4){split//,"99aabb87780";\$x=0;\$x+=hex(pop)*!!\$&+(\$1&&\$x[\$1]+7)+
+(\$2>1?\$x[\$2+18]+\$x[\$3]:\$x[\$2.\$3])while s/(.??)(.?)(.)\$//;say" is \$x."
+;print\$_=\$x}say" is magic."'

__END__
999999999999999999999999999999999
999999999999999999999999999999999 is 231.
231 is 19.
19 is 8.
8 is 5.
5 is 4.
4 is magic.

Doesn't seem to work right -- (\$1&&\$x[\$1]+7) adds 7 too often and !!\$& has issues with "000".

```# 123456789_123456789_1
# onemilliontwentyfour
# onethousandtwentyfour

echo 1000024 | perl duelafn.pl
1000024 is 20.
20 is 6.
6 is 3.
3 is 5.
5 is 4.
4 is magic.

echo 1024 | perl duelafn.pl
1024 is 21.
21 is 9.
9 is 4.
4 is magic.

echo 1000024 | haarg.pl
1000024 is 13.
13 is 8.
8 is 5.
5 is 4.
4 is magic.

echo 1024 | haarg.pl
1024 is 13.
13 is 8.
8 is 5.
5 is 4.
4 is magic.

echo 1000024 | perl thundergnat.pl
1000024 is 17.
17 is 9.
9 is 4.
4 is magic.

echo 1024 | perl thundergnat.pl
1024 is 13.
13 is 8.
8 is 5.
5 is 4.
4 is magic.

Update tracked doiwn more details of the bugs.

Good Day,
Dean

I did miss some things there. You should still be able to eliminate the @_ from the pop though.

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-02-22 01:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When it is dark outside I am happiest to see ...

Results (288 votes). Check out past polls.

Notices?