-
Notifications
You must be signed in to change notification settings - Fork 0
/
reverse_list.ex
70 lines (55 loc) · 897 Bytes
/
reverse_list.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
defmodule ReverseList do
@doc """
You are given a list of elements.
Reverse the list without using the reverse function.
The input and output portions will be handled automatically.
You need to write a function with the recommended method signature.
Input Format
Each element, , of the list is displayed on a separate line.
Output Format
The output is the reverse of the input list.
Sample Input
19
22
3
28
26
17
18
4
28
0
Sample Output
0
28
4
18
17
26
28
3
22
19
"""
def solve([]) do
:ok
end
def solve(arr) do
[item | tail] = arr
IO.puts(item)
solve(tail)
end
def input_loop(elements \\ []) do
case IO.gets("") do
:eof -> elements
"\n" -> elements
data ->
{element, _} = Integer.parse(data)
input_loop([element] ++ elements)
end
end
def main() do
solve(input_loop())
end
end
ReverseList.main()