Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
def mod1(num,m): return num % m or m | |
cache = {} | |
def play_round(player,pos1,score1,pos2,score2): | |
if (pos1,score1,pos2,score2) in cache: | |
return cache[(pos1,score1,pos2,score2)] | |
# swap 0/1 below to get the other player wins | |
if score1 >= 21: | |
return 1 | |
if score2 >= 21: |
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
(ns aoc-clj-2021.day1 | |
(:require [clojure.string :as str] | |
[clojure.set :as set] | |
[clojure.java.io :as io])) | |
(def data | |
(->> (io/resource "day1.txt") | |
slurp | |
str/split-lines | |
(map parse-long))) |
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
(ns aoc-clj-2021.day2 | |
(:require [clojure.string :as str] | |
[clojure.set :as set] | |
[clojure.java.io :as io])) | |
(def data | |
(->> (io/resource "day2.txt") | |
slurp | |
str/split-lines | |
(map #(str/split % #" ")) |
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
(ns aoc-clj-2021.day3 | |
(:require [clojure.string :as str] | |
[clojure.set :as set] | |
[clojure.java.io :as io])) | |
(def data | |
(->> (io/resource "day3.txt") | |
slurp | |
str/split-lines)) |
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
(ns aoc-clj-2021.day4 | |
(:require [clojure.string :as str] | |
[clojure.set :as set] | |
[clojure.java.io :as io])) | |
(def data | |
(->> (io/resource "day4.txt") | |
slurp | |
str/split-lines | |
(remove #(= "" %)))) |
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 re | |
data = open('day4.txt').read().split('\n\n') | |
hand, *boards = data | |
boards = " ".join(boards) | |
hands = [int(n) for n in hand.split(',')] | |
nums = [int(n) for n in re.findall("(\d+)",boards)] | |
fives = [nums[i:i+5] for i in range(0,len(nums),5)] | |
boards = [fives[i:i+5] for i in range(0,len(fives),5)] |
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
from collections import Counter | |
data = open('day3.txt').read().splitlines() | |
def common_bits(bits,most=True): | |
data = list(zip(*bits)) | |
mc = [Counter(d).most_common() for d in data] | |
mc = [d[0] if most else d[-1] for d in mc] | |
mc = [d[0] for d in mc] | |
return int("".join(mc),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
data = open('day2.txt').read().splitlines() | |
depth, horizontal = 0,0 | |
for line in data: | |
dir,amt = line.split() | |
amt = int(amt) | |
if dir == 'forward': | |
horizontal += amt | |
elif dir == 'down': | |
depth += amt |
NewerOlder