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
module Day8 where | |
import Data.Map.Strict qualified as Map | |
import Data.List | |
import Data.Containers.ListUtils (nubOrd) | |
main :: IO () | |
main = do | |
input <- readFile "day8.txt" | |
let (width, height) = (length (head (lines input)), length (lines input)) |
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
module Day7 where | |
import Data.Bifunctor | |
import Data.List | |
import Data.Set qualified as Set | |
main :: IO () | |
main = do | |
input <- readFile "day7.txt" | |
let equations = fmap (bimap (read @Int) (fmap (read @Int) . split ' ' . drop 2) . break (== ':')) $ lines input |
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
module Day6 where | |
import Data.List | |
import Data.Map.Strict ((!?)) | |
import Data.Map.Strict qualified as Map | |
import Data.Set qualified as Set | |
import Debug.Trace | |
main :: IO () | |
main = 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
module Day5 where | |
import Control.Arrow | |
import Data.List qualified as List | |
import Data.Map.Strict ((!?)) | |
import Data.Map.Strict qualified as Map | |
import Data.Maybe | |
import Data.Set qualified as Set | |
import Data.Tuple | |
import Debug.Trace |
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
(defun substring2 (lists x1 y1 x2 y2) | |
(let ((i x1) | |
(j y1) | |
(res "")) | |
(while (and (or (/= i x2) (/= j y2)) | |
(>= i 0) | |
(>= j 0) | |
(< j (length lists)) | |
(< i (length (nth j lists)))) | |
(setq res (concat res (substring (nth j lists) i (1+ i)))) |
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 read_num(line, j): | |
num = "" | |
while line[j] in "0123456789": | |
num += line[j] | |
j += 1 | |
return j, int(num) | |
def check(line, j, s): | |
return line[j:j+len(s)] == s | |
file = open("day3.csv", "r") |
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 is_increasing(a, b): | |
return b - a > 0 and b - a <= 3 | |
def is_decreasing(a, b): | |
return b - a < 0 and b - a >= -3 | |
def is_unsafe(list, bad_level): | |
n1 = int(list[0]) | |
n2 = int(list[1]) | |
if is_increasing(n1, n2): | |
last_n = n2 | |
for n in list[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
def is_increasing(a, b): | |
return b - a > 0 and b - a <= 3 | |
def is_decreasing(a, b): | |
return b - a < 0 and b - a >= -3 | |
def is_unsafe(list, bad_level): | |
n1 = int(list[0]) | |
n2 = int(list[1]) | |
if is_increasing(n1, n2): | |
last_n = n2 | |
for n in list[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 collections | |
# import http.client | |
# | |
# conn = http.client.HTTPSConnection('adventofcode.com') | |
# conn.request('GET', '/2024/day/1/input') | |
# response = conn.getresponse() | |
# | |
# print(response.readlines()) | |
file = open("day1.csv", "r") |
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
{-# LANGUAGE DerivingStrategies #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE NumericUnderscores #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
module Text.Megaparsec.ParseNumWordsEn (parseNumWordsEn, showNumWordsEn, test) where | |
import Control.Exception hiding (try) | |
import Control.Monad | |
import Data.CaseInsensitive (FoldCase) |
NewerOlder