kanouk
unread,May 20, 2008, 12:12:19 AM5/20/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to SICP eXtreme Reading の会
だめだー。これ以上、短くならない。意地で答え見なかったw
CとかJavaだったらもっと長くなりそうなのでダメっぽい。
エラー処理はまったくなしです。
-- pascal.rb
#! /usr/bin/env ruby
def pascal(depth, order)
return 1 if (order == 1 or order == depth)
return pascal(depth - 1, order - 1) + pascal(depth - 1, order)
end
def test
# unit test
puts pascal(1, 1) == 1
puts pascal(2, 2) == 1
puts pascal(4, 3) == 3
puts pascal(6, 2) == 5
puts pascal(100, 100) == 1
end
test
__END__