Inital commit

This commit is contained in:
Natty 2023-12-01 14:32:30 +01:00
commit 2104ab5b46
27 changed files with 2392 additions and 0 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
*.txt linguist-generated

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/.vscode
/*/dist-newstyle
/*/target

24
LICENSE Normal file
View File

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# aoc23
My solutions for Advent of Code 2023

2
day01a/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.stack-work/
*~

30
day01a/day01a.cabal Normal file
View File

@ -0,0 +1,30 @@
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.35.2.
--
-- see: https://github.com/sol/hpack
name: day01a
version: 0.1.0.0
description: Please see the README at <https://git.astolfo.cool/natty/aoc23#readme>
author: Natty
maintainer: natty.sh.git@gmail.com
copyright: 2023 Natty
build-type: Simple
extra-source-files:
README.md
CHANGELOG.md
executable day01a
main-is: Main.hs
other-modules:
Paths_day01a
hs-source-dirs:
src
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, containers
, megaparsec
, text
default-language: Haskell2010

1000
day01a/input.txt generated Normal file

File diff suppressed because it is too large Load Diff

37
day01a/package.yaml Normal file
View File

@ -0,0 +1,37 @@
name: day01a
version: 0.1.0.0
author: "Natty"
maintainer: "natty.sh.git@gmail.com"
copyright: "2023 Natty"
extra-source-files:
- README.md
- CHANGELOG.md
description: Please see the README at <https://git.astolfo.cool/natty/aoc23#readme>
dependencies:
- base >= 4.7 && < 5
- megaparsec
- containers
- text
ghc-options:
- -Wall
- -Wcompat
- -Widentities
- -Wincomplete-record-updates
- -Wincomplete-uni-patterns
- -Wmissing-export-lists
- -Wmissing-home-modules
- -Wpartial-fields
- -Wredundant-constraints
executables:
day01a:
main: Main.hs
source-dirs: src
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N

10
day01a/src/Main.hs Normal file
View File

@ -0,0 +1,10 @@
module Main (main) where
import Data.Char (isDigit)
import qualified Data.Text as T
import Data.Maybe (maybeToList)
main :: IO ()
main = do
lns <- (T.pack <$>) . lines <$> getContents
let values = read . (\x -> maybeToList (T.find isDigit x) ++ maybeToList (T.find isDigit $ T.reverse x)) <$> lns :: [Integer]
print $ sum values

6
day01a/stack.yaml Normal file
View File

@ -0,0 +1,6 @@
resolver: lts-21.21
packages:
- .
extra-deps: []

12
day01a/stack.yaml.lock Normal file
View File

@ -0,0 +1,12 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files
packages: []
snapshots:
- completed:
sha256: 7d4b649cf368f9076d8aa049aa44efe58950971d105892734e9957b2a26a2186
size: 640060
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/21.yaml
original: lts-21.21

4
day01a/test.txt generated Normal file
View File

@ -0,0 +1,4 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet

2
day01b/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.stack-work/
*~

30
day01b/day01b.cabal Normal file
View File

@ -0,0 +1,30 @@
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.35.2.
--
-- see: https://github.com/sol/hpack
name: day01b
version: 0.1.0.0
description: Please see the README at <https://git.astolfo.cool/natty/aoc23#readme>
author: Natty
maintainer: natty.sh.git@gmail.com
copyright: 2023 Natty
build-type: Simple
extra-source-files:
README.md
CHANGELOG.md
executable day01b
main-is: Main.hs
other-modules:
Paths_day01b
hs-source-dirs:
src
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, containers
, megaparsec
, text
default-language: Haskell2010

1000
day01b/input.txt generated Normal file

File diff suppressed because it is too large Load Diff

37
day01b/package.yaml Normal file
View File

@ -0,0 +1,37 @@
name: day01b
version: 0.1.0.0
author: "Natty"
maintainer: "natty.sh.git@gmail.com"
copyright: "2023 Natty"
extra-source-files:
- README.md
- CHANGELOG.md
description: Please see the README at <https://git.astolfo.cool/natty/aoc23#readme>
dependencies:
- base >= 4.7 && < 5
- megaparsec
- containers
- text
ghc-options:
- -Wall
- -Wcompat
- -Widentities
- -Wincomplete-record-updates
- -Wincomplete-uni-patterns
- -Wmissing-export-lists
- -Wmissing-home-modules
- -Wpartial-fields
- -Wredundant-constraints
executables:
day01b:
main: Main.hs
source-dirs: src
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N

41
day01b/src/Main.hs Normal file
View File

@ -0,0 +1,41 @@
{-# LANGUAGE ViewPatterns #-}
module Main (main) where
import Data.Char (isDigit)
import Data.List (isPrefixOf)
import Data.Maybe (fromJust)
import Control.Applicative ((<|>))
findNumeral :: String -> Maybe Integer
findNumeral (isPrefixOf "one" -> True) = Just 1
findNumeral (isPrefixOf "two" -> True) = Just 2
findNumeral (isPrefixOf "three" -> True) = Just 3
findNumeral (isPrefixOf "four" -> True) = Just 4
findNumeral (isPrefixOf "five" -> True) = Just 5
findNumeral (isPrefixOf "six" -> True) = Just 6
findNumeral (isPrefixOf "seven" -> True) = Just 7
findNumeral (isPrefixOf "eight" -> True) = Just 8
findNumeral (isPrefixOf "nine" -> True) = Just 9
findNumeral (isPrefixOf "zero" -> True) = Just 0
findNumeral _ = Nothing
findDigit :: String -> Maybe Integer
findDigit (findNumeral -> Just d) = Just d
findDigit (digit@(isDigit -> True) : _) = Just (read [digit] :: Integer)
findDigit _ = Nothing
findDigitFirst :: String -> Maybe Integer
findDigitFirst (findDigit -> Just d) = Just d
findDigitFirst (_ : t) = findDigitFirst t
findDigitFirst _ = Nothing
findDigitLast :: String -> Maybe Integer
findDigitLast t@(findDigit -> Just d) = findDigitLast (tail t) <|> Just d
findDigitLast (_ : t) = findDigitLast t
findDigitLast [] = Nothing
main :: IO ()
main = do
lns <- lines <$> getContents
let values = (\x -> fromJust (findDigitFirst x) * 10 + fromJust (findDigitLast x)) <$> lns
print $ sum values

6
day01b/stack.yaml Normal file
View File

@ -0,0 +1,6 @@
resolver: lts-21.21
packages:
- .
extra-deps: []

12
day01b/stack.yaml.lock Normal file
View File

@ -0,0 +1,12 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files
packages: []
snapshots:
- completed:
sha256: 7d4b649cf368f9076d8aa049aa44efe58950971d105892734e9957b2a26a2186
size: 640060
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/21.yaml
original: lts-21.21

7
day01b/test.txt generated Normal file
View File

@ -0,0 +1,7 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen

24
new.sh Executable file
View File

@ -0,0 +1,24 @@
#! /bin/sh
set -e
if [ "$#" -ne 1 ]; then
echo "Parameter expected: <day>"
exit 1
fi
if [ "$1" == "--help" ]; then
echo "Usage: $0 <dayxx>"
exit 1
fi
if [ -d "$1" ]; then
echo "Error! Directory '$1' already exists! Refusing to recreate."
exit 1
fi
mkdir -p "$1/src"
cp "template00/src/Main.hs" "$1/src/Main.hs"
cp "template00/.gitignore" "$1/.gitignore"
cp "template00/stack.yaml" "$1/stack.yaml"
sed "s/template00/$1/g" "template00/package.yaml" > "$1/package.yaml"

26
run.sh Executable file
View File

@ -0,0 +1,26 @@
#! /bin/sh
set -e
if [ "$#" -ne 1 ]; then
echo "Parameter expected: <day>"
exit 1
fi
if [ "$1" == "--help" ]; then
echo "Usage: $0 <dayxx>"
exit 1
fi
if ! [ -d "$1" ]; then
echo "Not a directory: $1"
exit 1
fi
cd "$1"
case "$1" in
# Default solutions -- Haskell
*) stack run <input.txt
;;
esac

2
template00/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.stack-work/
*~

37
template00/package.yaml Normal file
View File

@ -0,0 +1,37 @@
name: template00
version: 0.1.0.0
author: "Natty"
maintainer: "natty.sh.git@gmail.com"
copyright: "2023 Natty"
extra-source-files:
- README.md
- CHANGELOG.md
description: Please see the README at <https://git.astolfo.cool/natty/aoc23#readme>
dependencies:
- base >= 4.7 && < 5
- megaparsec
- containers
- text
ghc-options:
- -Wall
- -Wcompat
- -Widentities
- -Wincomplete-record-updates
- -Wincomplete-uni-patterns
- -Wmissing-export-lists
- -Wmissing-home-modules
- -Wpartial-fields
- -Wredundant-constraints
executables:
template00:
main: Main.hs
source-dirs: src
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N

4
template00/src/Main.hs Normal file
View File

@ -0,0 +1,4 @@
module Main (main) where
main :: IO ()
main = putStrLn "Hello world!"

6
template00/stack.yaml Normal file
View File

@ -0,0 +1,6 @@
resolver: lts-21.21
packages:
- .
extra-deps: []

26
test.sh Executable file
View File

@ -0,0 +1,26 @@
#! /bin/sh
set -e
if [ "$#" -ne 1 ]; then
echo "Parameter expected: <day>"
exit 1
fi
if [ "$1" == "--help" ]; then
echo "Usage: $0 <dayxx>"
exit 1
fi
if ! [ -d "$1" ]; then
echo "Not a directory: $1"
exit 1
fi
cd "$1"
case "$1" in
# Default solutions -- Haskell
*) stack run <test.txt
;;
esac