Life of the IT-Drummer

A web log from Tobias Rusås Olsen.

Code Golf - Fun programming site.

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

RSS 2.0 | Trackback | Comment

One Response to “Code Golf - Fun programming site.”


  1. [...] here: Code Golf - Fun programming site. Related ArticlesBookmarksTags Functions 5.2 and earlier Functions are not first-class [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">