Merge: doc: fixed some typos and other misc. corrections
[nit.git] / examples / rosettacode / ethiopian_multiplication.nit
1 #!/usr/bin/env nit
2 #
3 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # This program is public domain
5
6 # Task: Ethiopian Multiplication
7 # SEE: <http://rosettacode.org/wiki/ethiopian_multiplication>
8 #
9 # Generic non-robust version.
10 module ethiopian_multiplication
11
12 fun ethiopian(x, y: Int): Int
13 do
14 print "{x}; {0}"
15 var sum: Int
16 if x.is_even then
17 sum = 0
18 else
19 sum = y
20 end
21
22 while x>1 do
23 x /= 2
24 y *= 2
25 print "{x}; {y}"
26 if not x.is_even then sum += y
27 end
28
29 return sum
30 end
31
32 var words = gets.split(" ")
33 print ethiopian(words[0].to_i, words[1].to_i)