sln_2021_16
Copyright(c) Eric Mertens 2021
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Main

Description

https://adventofcode.com/2021/day/16

Decode an expression from a bit stream.

This solution uses the ReadP parser combinator module. Since ReadP only operates on String parsing bits is simulated by parsing strings of the characters '0' and '1'. ReadP's gather operation is useful for computing the bit size of a packet which comes up in some of the operator packets.

Examples

>>> vers <$> parse (decodeHex "8A004A801A8002F478")
Just 16
>>> vers <$> parse (decodeHex "620080001611562C8802118E34")
Just 12
>>> vers <$> parse (decodeHex "C0015000016115A2E0802F182340")
Just 23
>>> vers <$> parse (decodeHex "A0016C880162017C3686B18A3D4780")
Just 31
>>> eval <$> parse (decodeHex "C200B40A82")
Just 3
>>> eval <$> parse (decodeHex "04005AC33890")
Just 54
>>> eval <$> parse (decodeHex "880086C3E88112")
Just 7
>>> eval <$> parse (decodeHex "CE00C43D881120")
Just 9
>>> eval <$> parse (decodeHex "D8005AC2A8F0")
Just 1
>>> eval <$> parse (decodeHex "F600BC2D8F")
Just 0
>>> eval <$> parse (decodeHex "9C005AC2F8F0")
Just 0
>>> eval <$> parse (decodeHex "9C0141080250320F1802104A08")
Just 1
Synopsis

Documentation

main :: IO () Source #

>>> :main
843
5390807940351