Posts

Showing posts with the label ruby

FizzBuzz in ruby in one line

Some days back I came accross this blog which says about writing the classic fizzbuzz program in one line using Haskell. So that inspired me about writing a single line FizzBuzz program in Ruby. So here you go. This is the code that I came out with. puts (1..100).map{|i|i%3*i%5==0?(i%3==0?"Fizz":"")+(i%5==0?"Buzz":""):i.to_s}.join(",") Do let me know if you can come out with something even smaller

A Simple introduction to Ruby

Image
A Simple introduction to Ruby Hi in this simple introduction i want to give you some very brief idea on Ruby. I am going to write some very simple program here and give the description of them. The peoples who are new to ruby or just want to learn something about ruby they will get the feel of this dynamic language in here. Simple Hello (first.rb) Lets start with a simple hello world program. The code is given bellow puts "Hello World" Now this is the very simple typical hello world program in ruby. Write this lines into a text file using your favourite editor. And then save it. Run this program by typing the following command in your command prompt ruby first.rb Now fig 1 show the screenshot of the ruby program Fig 1 : The screenshot showing the execution of our typical hello world program Make it a bit interactive (second.rb) Now let us write a bit more interactive program out of ruby. Lets say a program which will take you...