Skip to content

Instantly share code, notes, and snippets.

View joncol's full-sized avatar

Jonas Collberg joncol

View GitHub Profile
main :: IO ()
main = do
evalContT $ do
a <- ContT $ withFile "a.txt" ReadMode
b <- ContT $ withFile "b.txt" ReadMode
aContents <- liftIO $ hGetContents a
bContents <- liftIO $ hGetContents b
liftIO . putStrLn $ "contents of a: " <> show aContents
liftIO . putStrLn $ "contents of b: " <> show bContents
@joncol
joncol / Main.hs
Last active December 30, 2024 19:57
ImGui + SDL z-order
module Main (main) where
import Control.Exception (bracket, bracket_)
import Control.Monad (unless, when)
import Control.Monad.IO.Class ()
import Control.Monad.Managed
import DearImGui
import DearImGui.OpenGL3
import DearImGui.SDL
import DearImGui.SDL.Renderer
@joncol
joncol / day17.py
Created December 20, 2024 09:44
Day 17, part 2
import itertools
program = [2, 4, 1, 3, 7, 5, 0, 3, 1, 5, 4, 1, 5, 5, 3, 0]
rp = list(reversed(program))
def calc(ta):
b = (ta & 0b111) ^ 0b011 # Look at the 3 rightmost bits of "ta"
c = (
@joncol
joncol / Day11.hs
Created December 11, 2024 20:19
AoC 2024, day 11, part 2
type HashTable s k v = C.HashTable s k v
type Stone = Int
type Memo s = HashTable s (Stone, Int) Int
solvePart2 :: BS.ByteString -> Result
solvePart2 contents =
Result $ runST $ do
memo :: Memo s <- H.new
@joncol
joncol / ModKeys.hs
Created November 3, 2022 10:37
ModKeys
module ModKeys where
import Data.Aeson
import Data.Text (Text)
import GHC.Generics (Generic)
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Text.Encoding as E
import qualified Data.Text.IO as TIO
@joncol
joncol / arbitrary_trees.hs
Last active January 24, 2022 07:59
Arbitrary trees
import Data.Sequence (Seq((:|>)))
import Data.Tree (Tree(..))
import qualified Data.Sequence as Seq
foobar_test :: TestEnv ()
foobar_test = do
tree :: Tree () <- liftIO . generate $ treeGen 50 `suchThat` ((>= 5) . length . flatten)
ugids <- createUserGroupTree tree
building the system configuration...
warning: Git tree '/home/jco/nixos-flake' is dirty
error: The ‘gnome.vte’ alias was removed on 2022-01-13. Please use ‘pkgs.vte’ directly.
… while evaluating the attribute 'vte'
at /nix/store/yjs0c0h8nwqjjsy4zdg0nmj611rpjypa-source/pkgs/desktops/gnome/default.nix:362:3:
361| libgnomekbd = throw "The ‘gnome.libgnomekbd’ alias was removed on 2022-01-13. Please use ‘pkgs.libgnomekbd’ directly."; # added 2019-02-08
362| vte = throw "The ‘gnome.vte’ alias was removed on 2022-01-13. Please use ‘pkgs.vte’ directly."; # added 2019-02-08
from collections import deque
import fileinput
import itertools
nums = list(itertools.repeat(list(range(9, 0, -1)), 14))
def main():
i = 0
for n in itertools.product(*nums):
num = ''.join(map(str, n))
@joncol
joncol / day24.py
Created January 5, 2022 19:10
day24.py
from collections import deque
import fileinput
def main():
x = y = z = w = 0
for line in fileinput.input():
inp = deque(line)
w = int(inp.popleft())
x *= 0
@joncol
joncol / input24.txt
Created January 3, 2022 22:52
AoC-2021, day 24
inp w
mul x 0
add x z
mod x 26
div z 1
add x 12
eql x w
eql x 0
mul y 0
add y 25