Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2022-12-02 05:33:17 +05:30
commit 5fe3ea5567
6 changed files with 2337 additions and 0 deletions

4
Day1/1.hs Normal file
View File

@@ -0,0 +1,4 @@
import Lib (calories)
main :: IO ()
main = print . maximum . calories =<< readFile "input"

6
Day1/2.hs Normal file
View File

@@ -0,0 +1,6 @@
import Data.List (sortOn)
import Data.Ord (Down (Down))
import Lib (calories)
main :: IO ()
main = print . sum . take 3 . sortOn Down . calories =<< readFile "input"

16
Day1/Lib.hs Normal file
View File

@@ -0,0 +1,16 @@
module Lib (calories) where
calories :: String -> [Integer]
calories input =
map (sum . map read) $
filter (not . null) $ split "" $ split '\n' input
split :: Eq a => a -> [a] -> [[a]]
split del =
foldr
( \c (x : xs) ->
if c == del
then [] : x : xs
else (c : x) : xs
)
[[]]

2237
Day1/input Normal file

File diff suppressed because it is too large Load Diff

43
flake.lock generated Normal file
View File

@@ -0,0 +1,43 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1669926181,
"narHash": "sha256-9UvqeOzNeVj1k3SmsRThcArP/IDos4OA4V38utDx7m8=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "60d042d7e30f35b598d244e2009d4bfc15052e04",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "release-22.05",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"utils": "utils"
}
},
"utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

31
flake.nix Normal file
View File

@@ -0,0 +1,31 @@
{
description = "AoC 2022 in Haskell";
inputs = {
nixpkgs.url = github:nixos/nixpkgs/release-22.05;
utils.url = github:numtide/flake-utils;
};
outputs = { self, nixpkgs, utils }:
utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
};
in
{
devShells = with pkgs; rec {
default = mkShell {
buildInputs = [ ghc ];
};
withLsp = mkShell {
buildInputs = [
ghc
haskell-language-server
];
};
};
}
);
}