Ruby, Day 1
It’s funny because I never learned Ruby, I never wanted to because dynamic languages don’t move me much, but so far it’s been quite fun.
First, a link to http://ruby-doc.org/docs/ProgrammingRuby/ that is the main reference to every question on that language.
I’m not going to run through all the exercises, but I will put solutions of those I found interesting to solve.
Print “This is sentence number 1” where the number 1 changes from 1 to 10:
(1..10).each { |i| puts "This is sentence number #{i}" }
Bonus problem: write a program that picks a random number (I will do between 1 and 1024, how geeky!). Let the player guess a number, telling the player whether the guess is too low or too high:
max = 1024 guess = -1 number = rand(max) + 1 puts "Guess a number from 1 to #{max}" until guess == number guess = gets.to_i puts "Number is greater than #{guess}" if number > guess puts "Number is lesser than #{guess}" if number < guess end puts "Well done!"
Seven Languages in Seven Weeks
A recently bought the book titles “Seven Languages in Seven Weeks”. The book has excellent reviews, and I have to say that in the list of languages it covers, I only have vague notions for some of them (Prolog, Clojure, Haskell), but absolutely no experience with any of them.
So, what I’m going to do is write my answers to the exercises on this blog, day by day (the book is divided by “days”) to keep track of my progress and findings. I started out by writing all of this in a text file for private use, but I figured that, after all, why not make it public?
This will probably look boring if you know any of these languages, but mind you that I have no experience whatsoever with nearly all of them.
So, let’s start with the very trendy Ruby!
