This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num :: Char -> Int | |
num '(' = 1 | |
num ')' = -1 | |
main = readFile "input" >>= putStrLn . show . sum . map num | |
f :: (Int, Int) -> Int -> (Int, Int) | |
f (a, b) c = (a + c, b + 1) | |
cellar :: (Int, Int) -> Bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Example extends App { | |
def DynamicOption(value: DynamicType) = Option(value) | |
val a = DynamicOption(1) | |
val b = DynamicOption("hello") | |
val result: Option[DynamicType] = | |
for { | |
aa <- a | |
bb <- b | |
} yield { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inputs = ["turn on 499,499 through 500,500"] | |
res = inputs |> Enum.reduce(%{}, fn (input, acc) -> | |
[[_, cmd, x1, y1, x2, y2]] = Regex.scan(~r/(turn (?:on|off)|toggle) (\d+),(\d+) through (\d+),(\d+)/, input) | |
x1 = String.to_integer(x1) | |
x2 = String.to_integer(x2) | |
y1 = String.to_integer(y1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Day24 extends App { | |
val test = List(1,2,3,4,5,7,8,9,10,11).mkString("\n") | |
val input = | |
""" | |
|1 | |
|3 | |
|5 | |
|11 | |
|13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Day18 do | |
def neighbor_index(x, y) do | |
Enum.flat_map((x - 1)..(x + 1), fn xx -> | |
Enum.flat_map((y - 1)..(y + 1), fn yy -> | |
if x == xx && y == yy, do: [], else: [{xx, yy}] | |
end) | |
end) | |
end | |
def solve(input, iterations, part_2 \\ false) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Day_17 do | |
def solve(input, target) do | |
Regex.scan(~r/-?\d+/, input) | |
|> Enum.map(&hd/1) | |
|> Enum.map(&Integer.parse/1) | |
|> Enum.map(&(elem(&1, 0))) | |
|> process([], target) | |
end | |
defp process([], acc, target) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Day12 do | |
def run do | |
"/Users/anton/Desktop/input" | |
|> File.read! | |
|> Poison.decode! | |
|> process | |
end | |
def process(item) when is_map(item) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val input = """Tristram to AlphaCentauri = 34 | |
Tristram to Snowdin = 100 | |
Tristram to Tambi = 63 | |
Tristram to Faerun = 108 | |
Tristram to Norrath = 111 | |
Tristram to Straylight = 89 | |
Tristram to Arbre = 132 | |
AlphaCentauri to Snowdin = 4 | |
AlphaCentauri to Tambi = 79 | |
AlphaCentauri to Faerun = 44 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input = File.read!("/Users/anton/Desktop/input") |> String.split("\n") | |
a = input |> Enum.map(&String.length/1) |> Enum.sum | |
b = input |> Enum.map(fn a -> Regex.scan(~r/(\\x[a-f0-9]{2}|\\\"|\\\\|\")/, a) |> length end) |> Enum.map(&(&1 - 2)) |> Enum.sum | |
c = input |> Enum.map(fn a -> Regex.split(~r/(\\x[a-f0-9]{2}|\\\"|\\\\|\")/, a, trim: true) |> Enum.map(&String.length/1) |> Enum.sum end) |> Enum.sum | |
a - b - c | |
## Part 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Bitwise | |
# inputs = [ | |
# "123 -> x", | |
# "456 -> y", | |
# "x AND y -> d", | |
# "x OR y -> e", | |
# "x LSHIFT 2 -> f", | |
# "y RSHIFT 2 -> g", | |
# "NOT x -> h", |
NewerOlder