[Israel.pm] My First Io Program
Shlomi Fish
shlomif at iglu.org.il
Sun Dec 17 09:10:41 PST 2006
Yesterday I finished my first Io program, with some help from the good people
at #io on Freenode. Here it is in all its glory:
<<<<
digits_sum := method(n, if(n == 0, 0, n%10 + digits_sum(n / 10)))
a := BigNum with(1)
for(i, 0, 299,
writeln(digits_sum(a))
a := a << 1
)
>>>>
My main problem in writing it was the fact that I wrote "a:= BigNum 1" instead
of "a := BigNum with(1)". Without the previous version I'm getting:
<<<<<
Exception: Number does not respond to '<<'
>>>>>
As an exercise I also wrote this program in Haskell, and Lisp. I also have the
following Perl Golf version which I wrote:
<<<<<<
#!perl -l
use bigint;map{$_=1<<$_;s/./1x$&/ge;print y/1//}0..299
>>>>>>
The people on #codegolf (also on Freenode) came up with the following Ruby
golf version:
<<<<<<<
300.times{|i|p(($_="#{2**i}").sum-48*~/$/)}
>>>>>>>
Regards,
Shlomi Fish
---------------------------------------------------------------------
Shlomi Fish shlomif at iglu.org.il
Homepage: http://www.shlomifish.org/
Chuck Norris wrote a complete Perl 6 implementation in a day but then
destroyed all evidence with his bare hands, so no one will know his secrets.
More information about the Perl
mailing list