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 LambdaCase #-} | |
module Lib | |
( someFunc | |
) where | |
import Control.Applicative (Alternative (empty, (<|>))) | |
import Control.Monad (MonadPlus (..)) | |
import Data.Bifunctor (first) | |
import Data.Char (isDigit, isSpace, ord) |
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
regex = '([0-9]+)-([0-9]+) ([a-z]): ([a-z]+)', | |
sum([ | |
parts = grep(@, regex), | |
ct = count(grep(parts[3], parts[2])), | |
uint(parts[0]) <= ct && ct <= uint(parts[1]) | |
: @ | |
]) |
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 Day1 (part1, part2) where | |
import Data.SBV | |
import Data.Foldable (for_) | |
input = | |
[ 1977 | |
, 1515 | |
, 1857 | |
, 1800 |
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 OverloadedStrings #-} | |
module Main where | |
import qualified Data.Text as T | |
import qualified Data.Text.IO as TIO | |
import qualified Data.Set as S | |
import qualified Data.Map.Strict as M | |
import Data.List (sortOn) |
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
program at ./y2020d8.txt | |
with instructions | |
jmp {offset:num} means jump offset away | |
acc {amount:num} means set state to (state + amount) | |
nop {v:num} means noop | |
registers start at 0 | |
global register named state |
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
conway of 2 dimensions | |
initial state at ./y2020d11.txt | |
where '.' means 'floor' | |
and 'L' means 'empty' | |
and '#' means 'occupied' | |
cells transition | |
from empty to occupied if (neighbors occupied) = 0 | |
from occupied to empty if (neighbors occupied) >= 4 | |
otherwise a cell is unchanged |
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 Main where | |
import qualified Data.Set as S | |
paths n vs = do | |
next <- S.toList $ S.filter (`elem` [n+1, n+2, n+3]) vs | |
case paths next vs of | |
[] -> [[n, next]] | |
subpaths -> do | |
subpath <- subpaths |
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 Main where | |
import qualified Data.Map.Strict as M | |
import qualified Data.Set as S | |
data Inst | |
= Nop Int | |
| Acc Int | |
| Jmp Int |
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 OverloadedStrings #-} | |
module Main where | |
import qualified Data.Map.Strict as M | |
import qualified Data.Set as S | |
import Data.List (foldl') | |
import qualified Data.Text as T | |
import qualified Data.Text.IO as TIO | |
import Data.Bifunctor |
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 OverloadedStrings #-} | |
module Main where | |
import qualified Data.Text as T | |
import qualified Data.Text.IO as TIO | |
import Data.List.NonEmpty (groupAllWith) | |
groups = map (T.replace "\n" "") . T.splitOn "\n\n" |