Code Golf - Fun programming site.
December 21st, 2008 at 8:53pm |
I recently discovered Code Golf, which is a web site with a collection of fairly simple programming challenges. You are free to choose from a set of languages (Ruby, Python, PHP, Perl) and the goal is not just to solve the challenge, but to solve it using as few characters as possible. It will not produce nice, readable code, but it’s pretty fun.
I’m not the best at these things, but I will show you my below average solution to the challenge “Choose”. I write in Ruby. You can read more about the problem here.
The solution:
1 2 3 | a,b=gets.split(",").map{|i|i.to_i} def f(n)n==0?1:n*f(n-1)end puts f(a)/(f(b)*f(a-b)) |
In short, this reads input and transform each number to an int, then we define a function for calculating faculty, and then we print the calculation.
More challenges here:
codegolf.com
Posted in Programming, ruby
[...] here: Code Golf - Fun programming site. Related ArticlesBookmarksTags Functions 5.2 and earlier Functions are not first-class [...]