2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,13 +1,14 @@
defmodule RC do
require Integer
def zigzag(n) do
indices = for x <- 1..n, y <- 1..n, do: {x,y}
sorted = Enum.sort_by(indices, fn{x,y}->{x+y, if(Integer.is_even(x+y), do: y, else: x)} end)
sorted2 = Enum.sort(Enum.with_index(sorted))
Enum.each(sorted2, fn {{_x,y},i} ->
IO.write "#{i} "
if y==n, do: IO.puts ""
end)
fmt = "~#{to_char_list(n*n-1) |> length}w "
(for x <- 1..n, y <- 1..n, do: {x,y})
|> Enum.sort_by(fn{x,y}->{x+y, if(Integer.is_even(x+y), do: y, else: x)} end)
|> Enum.with_index |> Enum.sort
|> Enum.each(fn {{_x,y},i} ->
:io.format fmt, [i]
if y==n, do: IO.puts ""
end)
end
end