This file contains hidden or 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 Rule do | |
defstruct [:from, :to, :count] | |
end | |
defmodule Day7 do | |
def read_input do | |
File.read!("input/day7.txt") | |
|> String.split("\n", trim: true) | |
|> Enum.map(&(String.replace(&1, "bags", "bag"))) | |
|> Enum.map(&(String.trim(&1, "."))) |
This file contains hidden or 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 Day6 do | |
def read_input do | |
File.read!("input/day6.txt") | |
|> String.split("\n\n", trim: true) | |
end | |
def get_common_answers(str) do | |
answers = String.split(str, "\n", trim: true) | |
|> Enum.map(&String.graphemes/1) | |
|> Enum.map(&(MapSet.new(&1))) |
This file contains hidden or 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 Seat do | |
defstruct min_row: 0, max_row: 127, min_col: 0, max_col: 7 | |
def from_string(str) do | |
str | |
|> String.graphemes | |
|> Enum.reduce(%Seat{}, &Day5.process_letter/2) | |
end | |
def from_tuple({row, col}) do |
This file contains hidden or 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 Day4 do | |
def read_input do | |
File.read!("input/day4.txt") | |
|> String.split("\n\n", trim: true) | |
|> Enum.map(&to_passport/1) | |
end | |
def to_passport(str) do | |
str | |
|> String.split(~r{\s+}, trim: true) |
This file contains hidden or 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 Day3 do | |
def read_input do | |
File.read!("input/day3.txt") | |
|> String.split("\n", trim: true) | |
|> Enum.map(&String.graphemes/1) | |
|> Enum.map(&Enum.with_index/1) | |
|> Enum.with_index | |
|> Enum.flat_map(fn {line, row} -> Enum.map(line, fn {el, col} -> {{row, col}, (if el == "#", do: 1, else: 0) } end) end) | |
|> Enum.into(%{}) | |
end |
This file contains hidden or 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 Day2 do | |
def read_input do | |
File.read!("input/day2.txt") | |
|> String.split("\n", trim: true) | |
|> Enum.map(&(Regex.scan(~r/(\d+)-(\d+) (\w+): (.*)/, &1))) | |
|> Enum.map(fn [[_, min, max, char, text]] -> { | |
String.to_integer(min), | |
String.to_integer(max), | |
char, | |
text |
This file contains hidden or 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 Day1 do | |
def read_input do | |
File.read!("input/day1.txt") | |
|> String.split("\n", trim: true) | |
|> Enum.map(&String.to_integer/1) | |
end | |
def part1 do | |
values = read_input() | |
for a <- values, b <- values, a + b == 2020, do: a * b |
This file contains hidden or 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
text = "some string (with parentheses (and also inner parentheses)) (yay) hi" | |
stack = [] | |
for i in range(len(text)): | |
char = text[i] | |
if char == "(": | |
stack.append(char) | |
elif char == ")": | |
stack.pop() | |
if len(stack) == 0: |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'csv' | |
require 'json' | |
def print_as_json(data) | |
$/ = "\n" | |
csv = CSV.new(data, :headers => true, liberal_parsing: true) | |
puts csv.to_a.map {|row| row.to_hash }.to_json | |
$/ = "---===---" |
This file contains hidden or 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
from PyQt5.QtCore import * | |
from PyQt5.QtWidgets import * | |
from ui_mainwindow import Ui_MainWindow | |
from functools import partial | |
import sys | |
class MainWindow(QMainWindow): | |
def __init__(self): | |
super().__init__() |