According to Wikipedia, "Code golf is a type of recreational computer programming competition in which participants strive to achieve the shortest possible source code that implements a certain algorithm". "Shortest possible source code" will be the least number of characters, as determined by ruby -e 'p File.read(ARGV[0]).split(//).size' file.rb
(same as wc -c file.rb
).
Tonight we'll be doing four short code golf challenges in Ruby, aiming for about 15-20 minutes of coding per challenge, and 10-15 minutes of review and discussion. Seeing other people's code golf submissions is a often good way to learn some lesser known Ruby features.
Some rules:
- No spawning external programs.
- No use of libraries not included in the default install of Ruby.
- No looking up answers to specific problems on the internet (general internet research is OK)