We can't do much without logic. The following tasks are a couple of computing problems that you may have seen before.
Start to get familiar with some of the conditional expressions in Ruby.
Write three functions that compute the sum of the numbers in a given list using a for-loop, a while-loop, and recursion.
Write a function that combines two lists by alternatingly taking elements.
For example:
# Given the two lists...
list_one = [a, b, c]
lsit_two = [1, 2, 3]
# The end result should be...
[a, 1, b, 2, c, 3]
Write a function that computes the list of the first 100 Fibonacci numbers.
By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two.
As an example, here are the first 10 Fibonnaci numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, and 34
.
Note: If you want to define a method or two during this exercise, you can do this by:
def your_method_name(arg_one, arg_two)
# some
# code
# here
return_value # this is returned from your method
end
What does the and
keyword do? Is there anything special about it?