-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElixir.exs
More file actions
37 lines (30 loc) · 851 Bytes
/
Elixir.exs
File metadata and controls
37 lines (30 loc) · 851 Bytes
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
defmodule HelloWorld do
def run do
target = "hello world"
chars = String.codepoints("abcdefghijklmnopqrstuvwxyz")
loop(target, chars, "", 0, 0)
end
defp loop(target, chars, ans, index, pointer) do
cur = Enum.at(chars, index)
targetIndex = String.at(target, pointer)
{ans, pointer} =
cond do
targetIndex == " " -> {ans <> " ", pointer + 1}
cur == String.at(target, pointer) -> {ans <> cur, pointer + 1}
true -> {ans, pointer}
end
toLog = ans <> cur
IO.puts(
if String.ends_with?(toLog, "dd"),
do: String.slice(toLog, 0..-2),
else: toLog
)
if ans == target do
IO.puts("Successfully logged Hello World!")
System.halt(0)
end
index = rem(index + 1, 26)
loop(target, chars, ans, index, pointer)
end
end
HelloWorld.run()