[ create a new paste ] login | about

Link: http://codepad.org/b3shD4T2    [ raw code | output | fork ]

minitech - Ruby, pasted on Sep 22:
1
2
3
4
5
6
7
8
9
10
11
12
13
def factorial(x)
    if x <= 1 then
        1
    else
        x * factorial(x - 1)
    end
end

x = [1,2,3,4,5]
puts "Result:"
puts '[' + x.map {|y|
    factorial(y)
}.join(',') + ']'


Output:
1
2
Result:
[1,2,6,24,120]


Create a new paste based on this one


Comments: