diff --git a/intro/01_basics/family.rb b/intro/01_basics/family.rb index b20700e..aca4f21 100644 --- a/intro/01_basics/family.rb +++ b/intro/01_basics/family.rb @@ -6,3 +6,7 @@ # Your code goes here +age_sum = mom + dad + john + mary +result = (mom * dad)/(john - mary) +puts "Sum of ages = #{age_sum}" +puts "Result = #{result}" \ No newline at end of file diff --git a/intro/02_control_flow/names.rb b/intro/02_control_flow/names.rb index e360f0d..298567e 100644 --- a/intro/02_control_flow/names.rb +++ b/intro/02_control_flow/names.rb @@ -6,3 +6,12 @@ # Your code goes here +avg_length = (name1.length + name2.length + name3.length + name4.length)/ 4 +puts "What is your name" +my_name = gets + +if (my_name.length < avg_length.size) + puts "#{my_name} is shorter than average" +else + puts "#{my_name} is longer than average" +end diff --git a/intro/03_loops/fibonacci.rb b/intro/03_loops/fibonacci.rb index a81c6fa..4128557 100644 --- a/intro/03_loops/fibonacci.rb +++ b/intro/03_loops/fibonacci.rb @@ -2,3 +2,7 @@ # Your code goes here +def fibo(n) + n <= 2 ? 1 : fibo(n-1) + fibo(n-2) + end + p (1..10).map{|x| fibo(x)} \ No newline at end of file diff --git a/intro/04_data_structures/queen.rb b/intro/04_data_structures/queen.rb index 9d0ca4e..1cae3cf 100644 --- a/intro/04_data_structures/queen.rb +++ b/intro/04_data_structures/queen.rb @@ -1,9 +1,6 @@ # A little bit of classic rock -lyrics = "Is this the real life?"\ - "Is this just fantasy?"\ - "Caught in a landslide,"\ - "No escape from reality." +lyrics = "Is this the real life?\nIs this just fantasy?\nCaught in a landslide,\nNo escape from reality." # Your code goes here - +puts lyrics.each_char.tally #=> {"I"=>2, "s"=>8, " "=>13, "t"=>7, "h"=>4, "i"=>6, "e"=>7, "r"=>3, "a"=>8, "l"=>5, "f"=>3, "?"=>2, "\n"=>3, "j"=>1, "u"=>2, "n"=>3, "y"=>2, "C"=>1, "g"=>1, "d"=>2, ","=>1, "N"=>1, "o"=>2, "c"=>1, "p"=>1, "m"=>1, "."=>1}