Compare commits
2 Commits
2ac18fcb7e
...
def733add9
Author | SHA1 | Date | |
---|---|---|---|
|
def733add9 | ||
|
05460991c1 |
1
2022/.gitignore
vendored
Normal file
1
2022/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
dist-newstyle/
|
5
2022/CHANGELOG.md
Normal file
5
2022/CHANGELOG.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Revision history for x2022
|
||||
|
||||
## 0.1.0.0 -- YYYY-mm-dd
|
||||
|
||||
* First version. Released on an unsuspecting world.
|
35
2022/aoc2022.cabal
Normal file
35
2022/aoc2022.cabal
Normal file
@ -0,0 +1,35 @@
|
||||
cabal-version: 2.4
|
||||
name: aoc2022
|
||||
version: 0.1.0.0
|
||||
|
||||
-- A short (one-line) description of the package.
|
||||
-- synopsis:
|
||||
|
||||
-- A longer description of the package.
|
||||
-- description:
|
||||
|
||||
-- A URL where users can report bugs.
|
||||
-- bug-reports:
|
||||
|
||||
-- The license under which the package is released.
|
||||
-- license:
|
||||
author: Steph
|
||||
maintainer: noreply+steph@code.steph.tools
|
||||
|
||||
-- A copyright notice.
|
||||
-- copyright:
|
||||
-- category:
|
||||
extra-source-files: CHANGELOG.md
|
||||
|
||||
executable aoc2022
|
||||
main-is: Main.hs
|
||||
|
||||
-- Modules included in this executable, other than Main.
|
||||
-- other-modules:
|
||||
|
||||
-- LANGUAGE extensions used by modules in this package.
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.16.3.0
|
||||
hs-source-dirs: app
|
||||
default-language: Haskell2010
|
||||
other-modules: Day1.Main
|
32
2022/app/Day1/Main.hs
Normal file
32
2022/app/Day1/Main.hs
Normal file
@ -0,0 +1,32 @@
|
||||
module Day1.Main (main) where
|
||||
|
||||
import Data.List
|
||||
import System.IO
|
||||
import Control.Monad
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn "Day 1"
|
||||
|
||||
handle <- openFile "app/Day1/input" ReadMode
|
||||
contents <- hGetContents handle
|
||||
|
||||
let r1 = part1 contents
|
||||
putStrLn $ "part 1: " ++ show r1
|
||||
|
||||
let r2 = part2 contents
|
||||
putStrLn $ "part 2: " ++ show r2
|
||||
|
||||
parseInput :: String -> [Int]
|
||||
parseInput contents = map sum foodItems
|
||||
where
|
||||
input = lines contents
|
||||
elves = foldr (\a b -> if a == "" then [] : b else (a : head b) : tail b) [[]] input
|
||||
foodItems = (map . map) (read :: String -> Int) elves
|
||||
|
||||
part1 :: String -> Int
|
||||
part1 = maximum . parseInput
|
||||
|
||||
part2 :: String -> Int
|
||||
part2 = sum . (take 3) . reverse . sort . parseInput
|
||||
|
2249
2022/app/Day1/input
Normal file
2249
2022/app/Day1/input
Normal file
File diff suppressed because it is too large
Load Diff
7
2022/app/Main.hs
Normal file
7
2022/app/Main.hs
Normal file
@ -0,0 +1,7 @@
|
||||
module Main where
|
||||
|
||||
import qualified Day1.Main as Day1
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
Day1.main
|
13
2022/cabal.config
Normal file
13
2022/cabal.config
Normal file
@ -0,0 +1,13 @@
|
||||
remote-repo-cache: /build/.cabal/packages
|
||||
world-file: /build/.cabal/world
|
||||
extra-prog-path: /build/.cabal/bin
|
||||
build-summary: /build/.cabal/logs/build.log
|
||||
remote-build-reporting: none
|
||||
jobs: $ncpus
|
||||
installdir: /build/.cabal/bin
|
||||
haddock
|
||||
init
|
||||
install-dirs user
|
||||
install-dirs global
|
||||
program-locations
|
||||
program-default-options
|
36
2022/default.nix
Normal file
36
2022/default.nix
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
pkgs ? import <nixpkgs> {},
|
||||
hc ? "ghc924"
|
||||
}:
|
||||
|
||||
pkgs.stdenv.mkDerivation rec {
|
||||
name = "aoc-2022";
|
||||
buildInputs = [
|
||||
pkgs.haskell.compiler.${hc}
|
||||
pkgs.git
|
||||
pkgs.zlib
|
||||
pkgs.cabal-install
|
||||
pkgs.pkgconfig
|
||||
pkgs.which
|
||||
];
|
||||
shellHook = ''
|
||||
export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath buildInputs}:$LD_LIBRARY_PATH
|
||||
export LANG=en_US.UTF-8
|
||||
'';
|
||||
LOCALE_ARCHIVE =
|
||||
if pkgs.stdenv.isLinux
|
||||
then "${pkgs.glibcLocales}/lib/locale/locale-archive"
|
||||
else "";
|
||||
src = ./.;
|
||||
|
||||
# This currently doesn't work yet.
|
||||
buildPhase = ''
|
||||
export HOME=$TMP
|
||||
mkdir -p $TMP/.cabal $out/bin
|
||||
cp cabal.config $TMP/.cabal/config
|
||||
cabal build
|
||||
ln -s dist-newstyle/build/x86_64-linux/ghc-9.2.4/aoc2022-0.1.0.0/x/aoc2022/build/aoc2022/aoc2022 $out/bin/aoc2022
|
||||
'';
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user