aboutsummaryrefslogtreecommitdiff
path: root/2023/1-Trebuchet
diff options
context:
space:
mode:
Diffstat (limited to '2023/1-Trebuchet')
-rw-r--r--2023/1-Trebuchet/example4
-rw-r--r--2023/1-Trebuchet/example27
-rw-r--r--2023/1-Trebuchet/first.hs44
-rw-r--r--2023/1-Trebuchet/input1000
-rw-r--r--2023/1-Trebuchet/second.hs78
5 files changed, 1133 insertions, 0 deletions
diff --git a/2023/1-Trebuchet/example b/2023/1-Trebuchet/example
new file mode 100644
index 0000000..7bbc69a
--- /dev/null
+++ b/2023/1-Trebuchet/example
@@ -0,0 +1,4 @@
+1abc2
+pqr3stu8vwx
+a1b2c3d4e5f
+treb7uchet
diff --git a/2023/1-Trebuchet/example2 b/2023/1-Trebuchet/example2
new file mode 100644
index 0000000..41aa89c
--- /dev/null
+++ b/2023/1-Trebuchet/example2
@@ -0,0 +1,7 @@
+two1nine
+eightwothree
+abcone2threexyz
+xtwone3four
+4nineeightseven2
+zoneight234
+7pqrstsixteen
diff --git a/2023/1-Trebuchet/first.hs b/2023/1-Trebuchet/first.hs
new file mode 100644
index 0000000..366d28e
--- /dev/null
+++ b/2023/1-Trebuchet/first.hs
@@ -0,0 +1,44 @@
+-- requires cabal install --lib megaparsec parser-combinators
+module Main (main) where
+import Control.Monad (void, when)
+import Data.Char qualified as C
+import Data.List qualified as L
+import Data.Map qualified as M
+import Data.Maybe
+import Data.Set qualified as S
+import Data.Void (Void)
+import Text.Megaparsec
+import Text.Megaparsec.Char
+
+exampleExpectedOutput = 142
+
+type Input = [String]
+
+type Parser = Parsec Void String
+
+parseInput' :: Parser Input
+parseInput' = some (some alphaNumChar <* eol) <* eof
+
+parseInput :: String -> IO Input
+parseInput filename = do
+ input <- readFile filename
+ case runParser parseInput' filename input of
+ Left bundle -> error $ errorBundlePretty bundle
+ Right input' -> return input'
+
+process :: Int -> String -> Int
+process acc str = acc + f * 10 + l
+ where
+ f = C.digitToInt . head $ dropWhile C.isLetter str
+ l = C.digitToInt . head . dropWhile C.isLetter $ reverse str
+
+compute :: Input -> Int
+compute = L.foldl' process 0
+
+main :: IO ()
+main = do
+ example <- parseInput "example"
+ let exampleOutput = compute example
+ when (exampleOutput /= exampleExpectedOutput) (error $ "example failed: got " ++ show exampleOutput ++ " instead of " ++ show exampleExpectedOutput)
+ input <- parseInput "input"
+ print $ compute input
diff --git a/2023/1-Trebuchet/input b/2023/1-Trebuchet/input
new file mode 100644
index 0000000..6deebe0
--- /dev/null
+++ b/2023/1-Trebuchet/input
@@ -0,0 +1,1000 @@
+jjfvnnlfivejj1
+6fourfour
+ninevbmltwo69
+pcg91vqrfpxxzzzoneightzt
+jpprthxgjfive3one1qckhrptpqdc
+mxphxfnffninethreetdj5jgknqfrxmhxfivexcxqv
+three7pktwo4279z
+1qcbszfgonedjcqj66929
+fivesixthreeptcqjnkzgdfgzspmlvmmhn3
+vm2sixseven
+1nine6oneeightnine5lfrzmzh7
+7onevsffj78ninejcnnvgn65
+qstwonepcd3twosixrmcnxhfzv
+3bnjfrfourseventwo
+zpcdmvmktlrrq8sixgjtxxjpt8fcstt1
+nine1gkmptbfsix87
+9ldmlbchvnvgfivesixnine7zrt
+45mjmblfqjvf9
+onehcpgmvd837sgzgsqqrtseven
+rhjfvkznjdvlgv9one8
+22xkkdsvfvfourhdpchs
+sixzjx5kvjbcfgcsrjndznkrtf6
+1fourmk8three3seven
+4716lpzhdcbone6seventwo
+443two27
+9sgtwoseven6
+pjtbhxchqfseven18tznxpbsppk
+9eightwonkt
+htsgxmrfsevenone8qjxhjsixnbsvcf5
+5jmnjnnfsfoursevenprtjzdxmxj7six
+dthreenrzonefourcxfrzsvtfz9xb
+6kvfn
+vlfbzpbpseven8tspgqfdzkmfivefourzjzdbxgtvx
+2rfqtfttqzkkzdjbjxnx51xrzczxmfmc2two
+3fnncmsdz1bnxvlfxng
+seven789bgzpszjd3
+6four8gjsmbztmp
+sjvmmb9h
+6jqttjkpjc145
+9threedzjjqnhrngktscfmc
+5onesix
+nine2onelpzhtrbninexkgtjqg
+6nined
+29xzfour7seven9pcvdbcgvtv
+hjdtscdc6twotwosixsevensix9six
+stmpvhnssixtwoffnhpn25
+45fourbpsghkqxqm9fmvhssbntdtwo64
+nine835four
+leightwothreesevenlhlmqcgcpfour9
+fgsfsqgkcctzcltpvpjhlb5eight4one
+four9four184five9
+67seven7twobdcltwonenh
+nsdbone5two16
+sixsix3jxfctsrsvfcrpbxtthmspdlqqrnckxtngnx
+fxftk3svcczpknmfourhlndmg
+eight4sevenmrlkcqx4three
+7ninerpcrqt46gtnlzlmknine
+hppggtwohcckscs5eighttwo
+phzdqznlbkthreephllsb32eighttwo9six
+6four8fxcmngbnine3
+seven6five23seven
+9seven6bfqkxsjvcpninehmprgsldb
+tffjstchhs3rnjsmlnr3sevenlkjzkrdg3mmlgbgnnjzoneightm
+913
+lvsqbjjsonethreeone864ncrlpdghgkfive
+fvlmhpxcrktwo3ninejm6eightxmc
+sevenjbnc2zvxnr4
+mqjztddmfmnskhlvvp2
+six1fivesixsevenninenine
+vpbpbsixsqvxfvf6
+6jjqln83one
+3dbone3
+ssczbsgp2fourdknjszzbvtlgtdplgplrnznmhdfivefdd
+threesevenqctdslt457
+eightthree9eightfiveninetzhmhg
+bsmzhmrm1eight5
+pzhpleighttbhhfxfdgprfjsxrzl7sixsixjgghqbr
+one5onecfdbpvxbdlmmdbxqdlbldjbz8
+qxsbz4rjdgcfsvmqthreeone3mtwo
+13zls3
+zpjlgbjrkl6four5
+264sevenfive
+413vhsevennpbnine
+gn9sevenhhhnblflxkeightnine
+hgdfdsdb5seven
+eightczrstqtcjmrpbhhdxrflkcjpsdjbskfvzdglt6nine
+jrgr15mzkpt5
+lxzlvmrdcvglcjsjzxm3748hjlvtgz
+ninekxcqcpztqfoureightsrdhtmnbpsqkc5
+vxfdkmp4fourtwopdpfmcqnrqkmvf
+prkkmcccpone4qthree
+lxxqfourkrttdqlhkjhp5
+five7three
+sixmljbdl2seven8six3ffrfc
+6threexgtvlxthree5fiveseven
+three86pztxhlcfour
+eightfiveeight79
+5ljzqvbgknk4
+seven4cnrxrv9
+brtwone8jsvbpstpmlbrxrjfivehhhqbvk
+three69two3dhvzj9
+fourfoursevenninelpjs5threevnc3
+42nine441xbc
+sevenfour2tqb42one
+btccgptzllfivesixtwo6
+hdbzgcmznbnrq8cvzrqtpqm
+jqzmone5threehrqhbdnfxhkqnvm
+98nrcvftzpslxnine
+five58one8snpvggzjbqthree79
+lkccfpfn37onenine6
+css9four2
+jbtffive6mtfzvkdpjnthreeeight
+224fourtwojc4
+spceightwolbrcfkbrtwo8dkfmvrmrglmrsxlseven9nine
+threeckdrrznbbhnpsrmbrxlmfjz1twothree2
+3twokcfivetwosix4
+k12mqeighthgdtthxjtwo
+coneightqtpgsjseven5dzqpvgtjm
+dpkjqkx22llklllblknine4
+svjmxbq8hfzjsbtccjdmqvbjcpklmqbseven665
+8rbfzjxlqx
+onefive3nineeight5
+eightqrlkf4two
+931
+41cvfivebfsxdkljjjkjhm8ftfdtnpsdmtkln
+sixjcnbeightnjtbck72dg
+tworvqfjdlr545lbpmlxknsd
+kgnt7fiveone3
+twofourrxmcmj894stppprqjf
+qcqpxnztmntwok34three28
+four1sevennlqvbk
+6fkjkbc
+2htpxbqvtg3one
+2threezhxzfslfxhvzdbfour15
+nrfdrzdjtlthreeonennzfbone9one
+sixtwosevenqplrqvxreight6
+djmzrfq3eight7five5
+jthreeeight51sixqlvgvm
+foureighteight4vvg98
+tttrnk2ctfpk7692mbccxhmpnl2
+bbsix2
+1two3five89zjrjnbpt6
+29787jbhkhtbnbgfoursixfour
+vpzmcqcvfour58
+9eightfcvfeight4one
+cdbdlseven6zvzl3tshhdtlczsstdbksthree
+three78
+hdmmprbbk9hvkpb
+vfivencslcc974
+6jthreesevenstksbsxttctjkdnxgjseven
+sixeight38sevenfive
+7sixnzcfgfjpzmcdsprgcnvspfive
+tttcfpm9sevennine
+x7dfxhgtqmeightveightfgrqj
+zktxptkzztwobztnfqvgxlkrsdhqhntqcnfknine6
+9kthreenglrnrxn8sixzlfdmfcdvnd
+xjznine3332jtrfnkf
+688k3eightone
+4four2chz
+1zpbmzvgxmhqdkr3four89four
+nqbthreeztjmkdgtwo53
+qvfjzclkrkslfmtpdhjeight4fivefour
+964eight91qhghxjxhcdslsnfour
+45twojrbjxb
+292sixthreekgzpzxxxk
+6dgmmtwotwo
+1msixthree4sixeighttwoeight
+sixfourt9k
+one1five6fourthreetwo7two
+fourjmbfrhltwosix42
+frgfnk8
+138
+4nn79fourfour28
+7zs5eightonenineqnzpsf6
+bqjndhdtqqhpmltzfv27bqvgklpmfvhgvplbpnxhjvprpldpg
+48tcrntjbninesbkkbbd
+nineeight5nineljhnxhqbpkbbkttwo
+scbbhqpcxthree1three1
+vlczgnrlz38threekjone
+nine7ckxh
+hpgvrtkpqpbjdlkpj2
+ninetwo63hhnsmoneightjtl
+zkhrcrb743fhjpfvdcxq9three
+nineeight5pfour9sixsqjnkpg3
+sixthreectddzgzrh9
+xjdgplninetfcldlnzftcv63four
+fivefourmrrb1three
+2mqxhngvb8
+5njfgllzxnjlqdgn
+five34fourfive1cddmdhrbmrjpz
+fiveg6seven1
+eightggzxtddx8mgl7seven9five
+6tlmlfrsixbtznxhhpclb
+twospsjtmnfnmfv36
+tcnmlsljtwo9onekcksj
+6onenine9mhznxmoneightnvq
+4seven6jxtknddnkfivefivenine
+qxpcxrxstwoninekvlsmtckcd1cxqccqss2
+8pk3xjbsevengfcseveneighteight
+7sevenstsmqcthreexqdh
+three6sevenmeightjeight5four
+958eightvg9bjrfpjfq6
+9zninegdmqrtxtlnfiveeight3twotwo
+989pdblcmkxhn
+sixvvkvjlndtqjlcqsixktmhpzs9d
+4threepzgdjvsqhseven
+fzfmnine5eight
+sevenvv78threexpfxxktwo5
+8pgjdzvb1
+vj7
+sevennine3eightfzpxdxpmseightwozvb
+gxftsptzcm1jcnmkqxnxr5five9onefour
+2fiveclxxnxmsevenzmz6rfvhkrseven3
+fqqdlnkb45lgjjnk5seventwo
+six5dhrkkxr
+kmrddmfpzsfmkthreeonefour1xxhshbxd8
+gdthree3fivefour
+sixsixj772four
+eight53
+sixfoursix333
+one8twothreeseven766
+bpnvgxjtwohmlgqpx3nineeightvnine
+95one88six
+4onefrlccksvfcc7
+xbjh67
+vzrgvrkzthreesix2
+five8eighttjxphqzstx
+fiveone3sixseven
+nine44eight66
+eighttwogndjkpdxqjvjmd7kgxvjfkltv
+mdpxgkxvfheightt41onefoursix
+vqnzsgmgbglqmjmhmqqlpjjhkszprjc184eightczzbrpxh
+jncvmkbone7vttpdnone
+bvsmnz7hctzgcfkk
+bssqrbzsixqx7
+nhtfvdnrtqqvjnzdgc4fvlzkm
+zhvdbthreeeight61dp
+24pv
+onesjjdct1zcknmfjfjvmfivepxzfds7
+3six7one5seventwo2
+twosixonemjsc2vg8lzvjrpnnhq
+rftwoneqjbq5hcssbxbtvcdsevenfournxhfkrrgjqmzmpmvrvnj
+58five5
+43nineseven3293three
+48sixsevenmgsr23
+eight1eight
+5hkbzntwo1lplgmfsevengrnhbhg
+1dqbbgjfvmfive7sevenninenhkspxbrxm
+srtwoneeight1jeightoneeightthree
+4cvhfbnine
+vsm56
+5onev2csngkll7
+6six5fivefourzbjkdppp
+gdjtp5onehqrngxqd
+4fvltc7ninezmpnbzv4twoone
+39sevenfxlcsfnkmjninesevennineoneseven
+cvfqkvfzx887sgzdpvxvhoneseven
+rvrhpssvkgzbbrgbgcvqbvdkfplsvk41bblsvtbqsk29
+9ninervjgsjrrtwo1twonbxcvd
+8g9one
+njznrrcshcpn9rbvbsgpdpv13ninefour
+8eightfflllbgkmdh44onenine
+9onetwo9two6
+hdfmvs6hjtjbzjth7ninefn
+dfzgrfivesix67
+7l9
+onecjeight88hk
+hgm2
+qt5nine7d8fivevlqjmhsix
+nqsix7onennmln2five
+6sevensevenmnxnbpmprd6
+five2seventhree2nineksczcl
+twotwokcmkzgkf9vfcmfqhzvseven
+4six2blsfjgmllblxnlfnspxbvvzjnninesevenfour
+836
+beightwosixonefxlthreepjddrthq9five
+22zhppjvmbfszrkrqt
+7ljpvtkrmgkfc5pxqpd
+xqrtsbzpjxhfn58three362
+2fiveqqdptvjxxnrnsrsixbeightfive
+gsgfvsfp1mfbrt3dnzttnine44mgmsjmkgv
+sixfive4sgxxgsix
+3nv3dsevensixmsqfdc5
+two66six
+ptz4qhkzftvxp4bfnnone
+five1five2rjftfiveseven
+kvdttwozhzcjk685fourtwolrbmnknp
+33srljnsfsxhfninensjh
+lkc4
+twotgnddfivefourcbfive35
+eight4qgthmpptkn
+7pqdkhhxqmtkcspmlc59991
+lvpbhlpdnvbqdzfmfktvn552
+fivefoursixdrscznhfivefive49
+439nlvnine
+qqxfoursix4xlslqdjvpx3l
+bpknbhdtgst7
+6four4fourddkk7cdhmdjx53
+3sevenseven8two4eightfive9
+zj6vmnq1pqrstfkznf6
+7lxjzsevensixtddveightp
+vbzrnzmcgvqkdrznhtblp8vjnxvs57five
+six6eightzmhqvsjzseven
+9three4nnhqsstptwo3
+twofiverdjfc96dqzeight
+six8bgmrplfeightonek93four
+sevennine4vzmf
+54five6gfour73jpkgt
+eight9288threeeight
+gjkrnbtseven6618vktqpmhmnine
+onejmlgzhpzdfmmkkt3fourpjkjglsd
+xqxkqjcsnine6eightxclnthree2
+hmthhjbfivesix4gdxjbg
+sevenkpjrscqhmfone3zjhxgptlgknine
+onerzbfive354
+9sldh38nine
+twonine9vqdzneight
+7one24
+2fivesixtnhssqnrhbcxtchjbxspnvkcxbsfrf
+kjpjqsnkrqnqpn99fpxfgmttxpxrd4twonebp
+hhfrz8zbdjtjjjngcccctwo
+mjhvbhrmpmmmbzcmr9four9dczbrfg
+mnhbcdc99
+11fivedpgmrxptconebdvhfbvfvxfive17
+fivegthreesixtwo9k5
+ninefourtwo7zjcsfhcfnine
+652
+five135eight4v
+eight6hsjpkf13mhmkggqqvqdmrpcttvs
+fourxndjxvpgpthree6vjs8pkt
+lvkeight5nthreeskjqc24one
+5vmqth
+1lmjpflgsix91fourlfldlgmn7
+jlpnxblthreebzztvrfg3done
+rrnxmsnptwoeight24threedqssix
+nfdcrtlb7eightsvhstfourcmrsix3
+nbslbqkmmfonellrfpmvjnsix944
+seven2pcstwoqfg
+six9nineninedpsixpqcl
+two53mgfcbhmlpr1bl1x
+bdzvksix8mlhvvscvvc
+seven1three9two
+4ninegvzqzbhckptwo8
+5zspmjkssghgtgpdpg3threeseven
+6fournineeight
+eight7jsxmdsix4jcnmzhxnrczslgclj
+xjlmqfgd9sjvvhmxbnrpztrgtvgklzt3two
+3gkfgrz71
+sevenfsix4
+one84532vkhbvfzpbthree4
+46zhdmrrh3
+eight7tdfbjnzqhs
+rfqfl6nine7
+nkpztmkbpqzn7
+8mzprpmn6
+2threebntdqxfdonettbgnbx7cp3
+5two77
+eight7three
+rhcbnrfslm8dqdthddqckonerclsshqhxpjdmgnmvsixgmqxt
+9five2
+jkzntwo5fiveonetwonec
+48oneseven
+7fourlqptgfkone
+six2hnlbhzxjjfpdeightwod
+46onel
+przvrp3ninethreenine2
+tnine2chbvxbkbnq
+sixjnbsrtrhg9twob
+knkdb5852fourfiveone6
+6onevndbhone
+4thqp
+xdnbtxgtjrgffourseven4threehzqxzqfourseven
+cpkbtl2
+three6psqmcxphvtfhn
+two42ninevndsevenmljgncshctnjrvszhnkt
+threefrvxonesqkcjdlk2mrztrlttjvs
+knvgqtqvn22jkjnxbxpkdfourfour9
+24oneqnnnztsshx6
+eighttbxsheight2phksevenptwo8
+seven8bvsnjhrl4hllmzbtlmone1
+three1626jvfqthree
+bspdn9rfgnztqgkrkk964
+9kprlqsmxnine
+6fourfourninethreesixfourfive1
+vkkggjljfxthreeeightseven6
+threefiverdvrtwo9tztjmghsz
+65rpk2six7six3
+bfgmtntc83
+3four5gtdsnljslceightnmtfbktwojnvqfour
+78ctscpstjtcdrqnskhrzsddhrsthreesix4btxv
+lmrscztwoxsgphp2five9
+eight4one
+tktpzntsffnpptpgmbndxhxskjlltpvbsvjrpmgbmdvjlqklnl1
+8hdhqmskvpdppnthvdlctthreelxvssgqzzcql
+eight6bjd3jbscchfnpqnine1
+r51three
+dpgscvm8eight
+6sbgzk
+two5rflnshkn
+zrplqqseven2ones
+fiveeightsevenfive6onetwo
+crjtrkcl8five592mkddrseven
+fiveone1qgrdzkgnv
+3svvtjmq8
+fivethreeninenine1skhctbxcckztkq
+threeppn71threelfourvpqfour
+ninetwoseven9
+5x6gqfsjqbrtr1slnlhhpq
+1xb
+xspkbeight9
+9onesixthreexjlscbx
+fj38vxpmlccfivemsmdqfour
+6twonvpxtkhlcpfvsgjonethree
+fivefiveninesixninethree3
+26four2
+d8hhbbgfoursixfour
+hdkqlhzs9hqcffcnzgsmhninegzhxthfivev
+onefourone9eight1sixdftmmzmj8
+qpnxmtl125eightsix9four
+ninefourvnxlmjp2fhdhzbcncs
+ninerhqpddslsh22sevennine9
+33vdj12
+2vqeight
+vbkfgbgflskxcfivefourzxvcbdj6
+6gssbzzgvb1
+6hmnkjfksrdmjhnqfv6five8
+92fouronefivebs96
+2twofive8
+mkkplqtjmfive45ddh
+fgtf933lgbxcnjv
+tsmbtnst65fpcsxcljbc6
+4dthreetpbqbjvlrnineseventwo
+3334
+85five
+62twomcnnj6fourhj
+fiveeight4
+sevenstxmqfdlp9threeeight
+55jnkhjh2hnqf
+xvrrqtr7onefouroneeightseven
+66btjrmvsfiveqpx
+1jbzjcsevenninerpdhfvjrrg
+1tsixsixdxqfdhpbsixthree
+h9twobfmqltwo
+eightrqlgqbmdcj7fourjbfourptdprg4
+6c8gbxxdhtxcxxgdntgsfninetwoqm
+67foursixgshpnxpsb
+gxfnbbrrfour4hdnzznc6five1threermh
+eight3fpqnbfbghshhkqmzmtkseven5
+g5threenine
+fivedseven3three469vjzmbklbm
+gxpktrpseven9kqbgvgqnqs6
+one64
+5threerxbfive5
+9ghdszvpbbldztqb1
+1xkzdblrpcjtwo
+smcnpxg3one58ttdsstwo8
+fourjhqxgjrms9oneone78four1
+9two6rxrrxlzc6tmzmxs5lq2
+onebnfnc9fqgczzdxczheightfrvrsixjcxhntbmk
+8twofivezmnssevenlfxzcqmqtt2
+threepnp3hdvphnthree8seventhree
+three441seven7fourthree
+99rvhgrxfsixfive
+zvtwone4three8
+5nine84eight
+crtztqjdmninesevennflskqgzrvsixqrthzhmnxsjzstj8
+sevenntxmdvhb931sevenninethree
+kxfk91fivehqgntfdhrj9897
+seven5p
+three1nh3
+gjdv22two1twoq
+2twonnjthree
+dlhmbplgqthreeonergqmxbbzzlvvmn4
+6twohldcs9
+6fourpjnztmqt
+threephjblksrhk1mzcfpvqx2mdlprtg52
+fmg5
+bgxd2dvlnstwo3six1
+gg64onerksrfour7four
+eight47ppeightsevengpzkn
+92mzfive2jh
+sevenjrnine8fivesixfivefour
+zmzxq869
+rjpgzqmsixninebvjkmb25seven
+9dfxrrfbqpr
+five2nine2rzps7twozkdjmbnc
+hsrpc9
+vsqfourgdkrzkf87four2seven
+two9eighteight42four3
+eight9threefive37
+twobpdzktzm892
+3lldqhone1six
+six84nineseven7
+nine7xtjqzqbxvx
+48twoeightthreepbjdmblzt
+5rzczxmeight
+seven85seven1
+threezfjzttheight9
+7fourthreenine3qfchk7eightone
+9h157ggstjh
+lxmhllvjxzsevenntnzrnkdjfive2
+64dzxxpgjcvhqkpzfivecjg
+3hfllvslrdgfiveckxgkzstqseven2seven
+four3fiveone
+two9eight26
+lsix9two
+two8sjvpnn2dpqhpfzgmthree4sevenblsmlfppg
+t9fdsgpmsghlp6ninesixsix
+9twonezk
+53fthcvkktx8eight1vkhrp
+fmslbnseven53four
+kjtwone486onefqdklnpdgone
+5threeqvkz
+ftwone5sthreegcdfivefour
+nine5sixhjconesix
+454eight5vsggjtjcxttndvg4
+six83hk
+5eightfourpzv8bjbbeightwopp
+79nine5eight
+1sixsqcpdmpqbg137ll3
+fsdbv64sixlpdd
+nine59
+vvnmt32
+eightsevennxcvvnqsix63four1eight
+sixcgtlvnmvjmcqkkxxbtjv6
+ninenine6
+5fhrsbvdjggnine
+twodkgtdghmjthree7
+zqkgbnqsixlqlbbhpdkvfourfive71
+nine5four3twoneg
+lxdpz971nfdsevensevenkjrzf
+2rkpbfphxjnnjkcpcphdpkkqbpjrbtqzmd5
+pqftnsixjrxqf7six2threeone
+six8d145twoqcgkllqmkxmqphoneightt
+seven25
+5sevenonednlhseven
+nkkfsl58xpdbqtptponethreempcxbkqqfbbml
+4fgk2
+9bxtjskxkhfmz4seven
+one78lpplzpbxcxseventwotwo3eight
+fbmqtp8one1gqmc3tzdqlnn3eightwoddf
+j2
+5sixsixnineonesixddpvf
+8xdnpczh
+7nfmgjjlonesixbfpmxvvcvf2
+4mnc
+7qjbl8
+c7fhtx
+lntmsfrbxtbbg7threexrd6
+fiveseven4two3
+hmmdbzp3three4five
+seven5rdkcdh3sixtwo6tql
+nine1xglps5zzpztmcm6six
+6fourfhxqkhqxeightonejcstpxklkbmk1two
+jreightgbpl8mmglzxjz88ztfnlhgvrz
+5dcfive1ninenine
+twoxkgjbqrmzj8
+one3kkxhrgskh6
+seven1mhkseven1zdlvnnxxk
+sevenonehpkqqxpshttrqcctsxp7
+43hdvhgconethreetsbjrkf
+xsmvfpnzpthreeqlpnf3
+rjhpbsz21six6
+onesix4271xgvsbd
+4gqnine
+516twoseven16vmbl
+twosixnine8mnmdjthree
+nine7twonine58
+4hnslsrxnslrmvmlninethreejcjxn
+knsnrdzbcmonetwo4nine8ghzndvjqdxgbzlq
+dkpnfpnpp6pqfclgqhsq1rjmsjcbdxxxxvff9
+pxnkbkvfiveltvnrpmdg5eightthree9
+91vbnvfmdjjt
+vpqxgzqlknttwo341
+5jlpdhzronetwonevvh
+6rhkxqjsznjhspm
+nmzsevenkgtb2cptrfhjfd
+ds75sixthreethree
+bone49ddv
+hhhnptkcx9bpvkjlzpm
+ctptntzjfive84
+cpxb94one3threeclrnsix
+ninedtjmdsmcg5eight78
+74rbrvt
+2four41
+sixgpqmtkfdhz7sevenkcnonetwonemcp
+lshcphmjvcqdtzbh35rvvsphj7twok
+clqbqvtdjpzgkqpfour4plkpsxkcnscnx2
+nflseventhreembkbnclftn4ksdc
+lljjndhone4
+krcthreeseventwofour7oneone
+dpjhm2three76
+npqtwone31tsgfbbtjtnshhtjvvnfb7
+5sixthreesix
+6cjzsix17onehbgdftzmxc
+tpmkqthreesxhzsfqfjv5five6
+9eightkxkpqtoneffxseven8jfdbcsmclxjbr
+threelz7zdcqlntmtlstbx
+nine3mtwotvmsctzlhtgcgxrmxkseven
+prtwone86seven
+nb2eight62zff
+fourfourmmlqjczfour6foureight
+3gjjsppmmjrtrseven
+3vcbjsmpbgfttczrseven6bsngjeightseventwo
+1dbhsix5sixtbxccqqvsvjttm
+csbsthreethreeone7
+spt8
+five521
+eighttwo5three369eight9
+53ck8
+569fdxfvtninesdbnvtwo4
+sevenvvctrsjpvgzphgxblm6sixfourfive
+seven6xtcdkmqf15
+twothree8233eightqhhpkrcjq
+bpmmvdqtvqsfqqdzmjl8six7four
+8twodktpzlvmqpgrfbbsix5
+bqfmkthreeseventwo87125
+qbdttlgc2onehtf749skzfslflbt
+seven79jbrh8threefivetwovgqphzpq
+skxcbtvbcll27fprcg
+dtknkdx1
+twozqjbmhmjoneeight2five
+5mzscs4twonineeight8four4
+698f
+twothree3eightklssg
+two1kchxfqsixdrc853
+9one4dzpqnineonexnzsvpplqgmtclfqfour
+hskt1twozqvkxeight
+6fkpgsdchnrkgthreetwotwo8
+hvnczltjleight4eight1mjsix
+ltwo7bmbdjlmlpvjxlttmb
+9sixninermdsjhg22
+rtgnjpbxtfznt1
+btdtnhtdkc4
+87eight2htsvgvzxqvhsevenvk
+6sixsix1dgszxseven9
+1rljjnxckl9bdlptqnqcmnine92
+three3two28fivevsevenb
+6ksfhxqndcccg66nmmbnz
+ktqskd4five
+pcvlhhz6
+three6three3onesfjvkrjt
+fourfour74
+txeightwo6gcc8seven44sixg
+79hphfdplrsgonefour
+nine9twothreeeight
+5h2eightwosmd
+8threeb7nine5cr
+eight528two
+fsfzrmlz2nine
+8vspddjbhlfn
+64ljd4rtnbtwo5vnine
+onesixninezggthree4
+one8sevenseven47
+three238eight45
+one251onextjqxztm
+lsqrvsgnxh1bxxchgjeight
+eight4gdfvltlmn1sixllsbcqpnx
+five7smrlbtbk
+djnshxnrcrtkk6two9
+frcpffjkhp3
+ninesix2f2smlspljlqseven8jtfml
+1gsvrpkjl
+5ninethreejpnbm
+4vdmjth6735
+eightmnlvzszqtjfour1rphtmntlk355
+joneight6six8qgtlffcpbvrcf9xsnvgt9
+gfqtnbbzrkfivelmmnmztdgeighthzfbzmpfnztwoxzzpjcsvfive3
+threevpgmhleightsevenfive1
+ninevmdknklvgbbmsdcmvjzcfcbeightrfmv14
+98cb
+8one85jpdlsmdpzskjz8two
+6three6
+fpnine1
+5threelonemfbqvssxkbmglt
+1zkxhjh5fournine
+twoxbczzqhcthree3sixeight
+4gdktpzlxzkxnine
+ninefivenineplttv8seventwoggsmztd6
+onepr3qpzf7seveneightfour7
+tdfpsssrczgzgmxlpmqb2zjjllrqstnine3threemqtzz1
+sevenninetwohsztwomvzdrdtsz4seventwo
+2lgsljspp1kpjpjh6six
+hz8four5lkcxzr
+hgcmhgftpspbhcj8four
+three2bdstsvsskx6hjhmxlhnonefour7eight
+3175cxbsg9eight
+one89twoone7
+cjjztqb7two
+7fzkbxrvseven6fbvgmckvjrlklqhlnsevenone8
+dfctz4
+cpbfshrsixhjnfcbfmd7gdhhzx
+seven1pbrzmtflvh
+fdchrzgzdsix63three7
+three4dckqnone2two1eightwoq
+two9khrvjmvg47hsn
+cdgpvclmngsixfshzlm15jsnrths
+jqztnseven6
+seven55seveneightwodc
+sevenff9onernhzsix9eightjdcc
+threeeightps9
+six9threevmgplqhzrncgkmqjnine1one
+three6six
+419zzsjzqvkkzrpnszbvg
+8fourthree7two
+sixfivefmhrttsqfz2eight6two
+286
+xvxhrfiveftnlkmcv2
+fourfour6eightninedkgxbkninexgncmkfqp
+ninekqjc1dvxtxdvzfgcph3
+8hnnqm
+gkzzmhbdqfour849
+95fjtrfourseven
+seven5rh
+five2bbqmnkkq7sixchcgslsevenvkmpfg
+knlfive1fpsevenmbcnqb
+qpjxzbninejrgmvxpslk5rlfmrdmfbh2
+9sixgqxdlcx
+19sqlbrngnvfqmzd
+tjdg3
+cmkpfivekzfhone1hxpbb
+fiveseven3
+dxthreethreeninetwoeight4three2
+6j
+nine59
+7seven8one22knqdsixone
+sixtzbkscdt5
+nine4gfxtrlzcd4twoone
+2seven7nine7
+fourpksdzztmll5
+2dgqoneoneone
+khzx1seven1cpkzvjtmv
+fiveseven8three6
+rrxkljtthreefoureight8hpxmmnjctthree
+2sixzcchvknspqdjthree1
+nnl1rnrhxprnlctwoone
+qsbgz28nfive
+clqtchqnvrvv11eight
+tvhrpxkbvpfiveonesix5
+qhjqmqpm37
+1748
+23sevenhnrvlvjhbfrxvhfthree
+1sixdnrnkb88fbrndqcphxrzlgjvf4
+8qlhmjsqzms9two1ffourcdlpssq
+5573
+eight76
+7qxcrrldb
+5zseven35
+nxkqrsmth1tmrvszjcceightlnzgfdnine
+fourqrkrsrzltnqcgnmnpptwo2zmgnlthreeeightxnxgmgd
+gnlqqtwo16xsxhrxthdltpxssnvfjqtrkfm
+njlpbqsixfour51eightpnzzfmfksevenvpgnmkqd
+two7xbhhbjrrp
+41two6
+sevenseven9xnlrnzlrnxfourjzsjfds
+frfdzkxhckdxtp8twokfour
+42ctfq5
+gxjmvxdprr5
+sixsixeightvvplxddrdnngdxj1
+989ffgvq4vpv
+ninecgtlfts9g5onebssmzsbnf
+3sixfourxltwopmdsrjscrh7dggvqhfour
+5jktwo98jksfqbdbbt
+fivemrrctsj7csqspbbnk2vtvlmnbdksfour
+832nine1sixzbtkxzqthreetwo
+1jbrv1rzhgtwo4c
+eight79
+3meightseventwo8one8
+qtkzxf9gmdqkgqcc
+vllkztxsjqsg8fivetwo
+5twohjzgcrhgpkfour7zkpngbbpj3
+7nggrljjllnineeight
+sixone17nine84
+5fourbnrpsnk5
+eightnghj7threethreeeight9
+956
+eight2grdnqrvhlt5ptlqjqzbsixseven
+4bgzdpbnmcone7rxdqjbmbsix
+9ninenine195
+cflqvgs4six9kjhkmqhnn3rqmpc
+25sbdjjnphsr1112
+two7jxxzxronesix
+gnzzkvjcxzonen7
+ninextxskkggr5nine3ckkfd
+pmkxbttdbllqqxfeightsix6fmmbltphngpmzbtsbbcq2
+4eightvthfour5
+eightksbjldxg7sixfour
+sixghvhqmthree7nine7
+zzjblxhvmltjqs1
+tslmgqfdt5eight53hmhlfzsvszthqmhxkmfhbxlm
+5sixzbczjtjg4nine811
+fourtgpmfourthree8ninecfd
+hqnpxjtpnsxqpfzvgmshfmntwothreetwovzgphgfsix5
+qjbdronetwo7five1hnf3
+3xmvlpkvqcctwo
+cgkninefoursixtwosix8eight
+csvnsvtshrpdpkxqeightcsl4cmpn
+hzoneightthreefour8threekppfivezl61
+327onenineseventwosix6
+eightone66
+71oneddkhbdfourrjmskvdslx
+dbv12ctlrgxbbmsix
+one5five3fourtwozgnhseven
+sz4kljvrjf3sixxfivefivefive
+tlvl6jttfznmthree9ljbqfdgfdhd
+gbdeightsevenninenine84ltblttwo
+fourjrbs5fiveonejhvzsl9nsxnmlnmjt
+4three2spkj
+fourbvmblbpkqjsfbssevensixsgrqnfpmj9vtx
+xgtzdmdgflmtdjvmqkbsvdxvbrcpdlmbptmljl2
+fourlcbxq95sevenr
+2sixfcqfgbtz3nine763
+one14
+l4six
+3tjxghncvg9qcrzsbzccvfhsvzcseven4
+seven9spzeightsix
+xzbeightwozvp7six3sqsxdhnm8
+75stwofivefvnjtktztwo
+1msqj8ninepnsjbjxmzpdgcd8ttcnlzk
+fvmxntfmxxf8fivepcqn9
+fkjkszt1seven
+3xkjvbjz8htrzhzkzmr
+2jktmfjbzdkpvzkpcqv9cpprlghqzdfive2five2
+ltmhdxkscptwo87
+hxhkjeight5seven6c67rj
+sbzvthree891ztc5four8
+one4ngsvv7nfblcrjzjsgkknrx
+jrb8one4qjjbvvcxrhfsslvq1
+6two5one5
+threesonecheightnine61
+fzppx9sixgonefour
+6fvnrr4five1fivejxxcmc
+sseven5threesevenfourr
+fcbnms5vctwo
+829three8gvqknllg
+qcmf9
+sixthreeeight4dxmsbb4
+two5fouronetwo
+33foureight
+sevenxjmkfgtseventhreefdtvn9two1
+18qseven
+8141mfxlzkgvonebhddp
+3fnmdmvrjktseven
+hgcnjmxchfive9
+sfvcmptk81
+vsfrpfzvdgxfjzxmpsdeight36four
+hjglvnvcmnine7fourtnxllcdksixnm
+4four912ctx
+8nineeightsqfhsevenninezfseven
+threemjq79tgzsevenone
+twofktsbghzzmbfzfd1
+5rsdninetwoneqp
+nrfztxghtl8qx8one8sixnine
+2lmhlkdvjjv4bbgnckvxpdtwothreebzqqdgmtfvsvqjj
+63fivemzqvkbftqxtg
+214three5fivedmskgjtdbbv
+jvxh8two
+kmnflrsfngone5zs6l7
+pmcqtzdvqkcnfbzgtqscfour5one
+sfcdttxpblbsevenseven2
+355
+5ninetctrhrqteight6three
+ninesevenls6nqqtfninehjdb
+hpdxptb9seventhree12
+85vqbhpqrzpcsnfive2oneseven
+79twothree
+8eight3vzxsixoneeightzzcdkhgtpz
+fivenine3hm3
+fourfthree7
+qkqgptwotvjkctgsbmsxvmssdpteightlxlkfqv46
+84kqtnsjplhp1
+3qk51
+two7gjdrxxjlg6
+7qbrhzdljnvthreefour8dc8qctqhnlfzdshvz
+pfcninefourjzqnmmmxhqsix49
+gfbzhslvjrl1sixsevenvnpcrlhfdttmfourzr
+3fourtwo636three
+qnxrzp7gxcfoursixoneightqmn
+fourhfstrgmmdvvlnq5rrb7
+348tdcztqxksixfiveseven3
+ninetnkhspprkmtljdfcbtwo2three7
+qgpfzngtntdsdjvlvmxnmgtbthree5bnkthree
+9vhthree
+six1four57sxcdzk97seven
+6mnhhjtfbcpeightwozj
+nploneight9
+6kpzgz5mtq7
+csflt33ninekmgc
+jcpntrdsjnkzpmgtdxk4
+plbvmzc3sixfourfoureightkrxbzsdnbj
+seven7ql74
+bknbt7eightcbpxzkhtfrgcvhksrr2kxhvqthtsg
+tcdcvqkknhxp9fivenlphrppfivenine
+8tgvvvsjl2ql5vjbsbrzvtjpkb
+51vtffpfzk1two
+58threellgc74three2
+zrrlzzpcq2c31four
+xcpksgthreerfdjldvfteightnine2npztqh
+dtonefourqpss7
+rzmx8
+2eight47
+nine593hsvgtghjqc
+five6gnkcxrvkvpone742mxsdpnxqkrcqzrmglxq
+onevtfour8eightfive
+vhnhqvsfm8qqgmsjkhsqeight
+2foureightsix8lhzplrtnpttznkt2
+cztjsixsix96xljqqfhtmd
+6four6mtvvxdbvninepjkfqlhhrhcqrddmghrlvkkphzvvb
+clshpcdb7bthreenine821
+lcbbcnn74xcpdspkqdphdvdtrkfqfoursix3
+2ssgn7mjtzrblgr229seven
+qtjzd5poneztdhvtdzt8svdfpv
+91fivetwo
+two41qctlttbcsevenjxczz5
+fourbsklkgltwolvdgvjxcxpvclxqbqxjhbz7
+vncsclbf8cbkmzone
+dfn349six34five
+one65kzsspzjhcsln
+bmnfzmhptzgmgjk1sevenfive824
+3zthjdsix9geightsixeightfour
+jvhhrkrnhfivenineonethree3sixninegplzthbxj
+boneightthreeqdglvf74
+13dmktbhp
+8ninetwo
+8eight87l
+six5xhrtbhdmhpbpqqsfjjninesix8seven
+lznlvseventd819qkq9
+55
+onevqgp3six
+8gc8
+seveneight8fivesixczbqpjdhxnschd1
+9hvpqtcsevenfctzrxtgj6rjzgfpm8
+ppcmhlccprnmpndzkkjvbrptfour5fivefivefcdqvf6
+sevenhsqnkhhcfonethreezdrjvqsmlvjrdbppjcj8eightwovn
+3mxqxlqsvfjpbclmqdrg1one
+zmxnftxklqqd8one
+2k2onesixthree
+1twofivetwozxqhjqjbzgzsslgd
+3mblcpmlmg8seven
+twoeight626snine
+p8onegjssix
+ninelkjbgsqtrx9fiveeighthljnlrdb
+x21six2cqfqbsmhxsbngstp
+2gcmhhtxpzsfive4sixmvrqzkfnv
+8ninethree7bbjmcnm8
+sixzqpl6three
+b7zfivebmlfvcdg1
+2fivetwo8
+zdkznnkonetsstchvtxsvpfone1sjmqndvbhfg
+ggrvbl2one
+1m
+7eightggfvfrsrfive77sxxrshdrfive
+12lkgxnfqd
+9znqtwo2three5three75
+seven8six
+four138six7six1four
+8vmpqprxdgj
+8zckvmtmbjtdqprvfxtkmgmmtgck
+8vlzthree49
+onesddbmbeightfive523sixtwo
+9jcfjq3
+5qlhxfour
+3five4
+2kvfourseven7vdh
+seven1one7
+7v
+fourdnh568oneninehqftnfninetwonejjn
+dpvcxz21seven
+4threeslnfhfskntz8kqmh
+58eight3
+fivetwo16sixfour
+fnxmrmcjsixninethreekbf5one
+1seven6fourfournjsdvhlkhp1
+five8339
+1fgmrleighteightdzxh
+eight5nine
+eight4fdnx
+sqfklfbkjvbghbgmszzzpeightfive2fiveonefive
+xcveight6zlfkpxrzsnq3gzjseven
+fkeightniner4fourfour2eight
+nine87lphjt
+3twombcfour
+dpn7688eighteightdjl8
+5tvplhtfrmlv3zjcgvfivenl
+2fiveztwo4
+fjbbtgone5
+bjrgnzzpsixnine4three
+kkqpcmvjnine18
+zhzkslnd1twonpqxtwoninefiveone
+fiveckknnzhdtm793
+seven2cbtkqzs861cbfgssfqtd
+sixvdtzsixthree4lchxtdkv
+1vvssfvlfbg2eightmxbqbvgsixnine
+nineeightjlngjz94t7
+lpncsfkn7fsgvkl
+583sevenhjxlqzjgbzxhkcl5
+81s
+2four3threesxxvlfqfive4
+nine6eightsevenzx9twoxc
+hmbfjdfnp989mfivefiverpzrjs
diff --git a/2023/1-Trebuchet/second.hs b/2023/1-Trebuchet/second.hs
new file mode 100644
index 0000000..3bcfa06
--- /dev/null
+++ b/2023/1-Trebuchet/second.hs
@@ -0,0 +1,78 @@
+-- requires cabal install --lib megaparsec parser-combinators
+module Main (main) where
+import Control.Monad (void, when)
+import Data.Char qualified as C
+import Data.Functor
+import Data.List qualified as L
+import Data.Map qualified as M
+import Data.Maybe
+import Data.Set qualified as S
+import Data.Void (Void)
+import Text.Megaparsec
+import Text.Megaparsec.Char
+
+exampleExpectedOutput = 281
+
+type Input = [(Int, Int)]
+
+type Parser = Parsec Void String
+
+parseDigit :: Parser Int
+parseDigit = (C.digitToInt <$> digitChar)
+ <|> (string "one" $> 1)
+ <|> (string "two" $> 2)
+ <|> (string "three" $> 3)
+ <|> (string "four" $> 4)
+ <|> (string "five" $> 5)
+ <|> (string "six" $> 6)
+ <|> (string "seven" $> 7)
+ <|> (string "eight" $> 8)
+ <|> (string "nine" $> 9)
+ <|> (letterChar *> parseDigit)
+
+parseDigitReversed :: Parser Int
+parseDigitReversed = (C.digitToInt <$> digitChar)
+ <|> (string "eno" $> 1)
+ <|> (string "owt" $> 2)
+ <|> (string "eerht" $> 3)
+ <|> (string "ruof" $> 4)
+ <|> (string "evif" $> 5)
+ <|> (string "xis" $> 6)
+ <|> (string "neves" $> 7)
+ <|> (string "thgie" $> 8)
+ <|> (string "enin" $> 9)
+ <|> (letterChar *> parseDigitReversed)
+
+parseFirstAndLast :: String -> (Int, Int)
+parseFirstAndLast str = (f, l)
+ where
+ f = case runParser parseDigit "parseDigit" str of
+ Left bundle -> error $ errorBundlePretty bundle
+ Right input' -> input'
+ l = case runParser parseDigitReversed "parseDigit" (reverse str) of
+ Left bundle -> error $ errorBundlePretty bundle
+ Right input' -> input'
+
+parseInput' :: Parser Input
+parseInput' = fmap parseFirstAndLast <$> some (some alphaNumChar <* eol) <* eof
+
+parseInput :: String -> IO Input
+parseInput filename = do
+ input <- readFile filename
+ case runParser parseInput' filename input of
+ Left bundle -> error $ errorBundlePretty bundle
+ Right input' -> return input'
+
+process :: Int -> (Int, Int) -> Int
+process acc l = acc + fst l * 10 + snd l
+
+compute :: Input -> Int
+compute = L.foldl' process 0
+
+main :: IO ()
+main = do
+ example <- parseInput "example2"
+ let exampleOutput = compute example
+ when (exampleOutput /= exampleExpectedOutput) (error $ "example failed: got " ++ show exampleOutput ++ " instead of " ++ show exampleExpectedOutput)
+ input <- parseInput "input"
+ print $ compute input