-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrefix Compression.ex
More file actions
22 lines (18 loc) · 927 Bytes
/
Copy pathPrefix Compression.ex
File metadata and controls
22 lines (18 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
defmodule Solution do
def start do
s1 = IO.gets("") |> String.trim |> String.codepoints
s2 = IO.gets("") |> String.trim |> String.codepoints
s3 = Enum.zip(s1, s2) # https://hexdocs.pm/elixir/Enum.html#zip/2
s4 = Enum.reduce_while(s3, 0, fn({a, b}, cnt) ->
if a === b,
do: {:cont, cnt+1},
else: {:halt, cnt}
end) # https://hexdocs.pm/elixir/Enum.html#reduce_while/3
a = length(s1) - s4
b = length(s2) - s4
IO.puts "#{s4} #{Enum.take(s1, s4)}" # https://hexdocs.pm/elixir/Enum.html#take/2
IO.puts "#{a} #{Enum.take(s1, -a)}" # https://hexdocs.pm/elixir/Enum.html#take/2
IO.puts "#{b} #{Enum.take(s2, -b)}" # https://hexdocs.pm/elixir/Enum.html#take/2
end
end
Solution.start