Switch from markdown comments to hidden fences

This commit is contained in:
Nathan McCarty 2025-01-27 04:55:07 -05:00
parent 32a8c6bd43
commit 24285db686
17 changed files with 94 additions and 94 deletions

View file

@ -12,9 +12,9 @@ import Decidable.Equality
import Control.WellFounded import Control.WellFounded
``` ```
<!-- idris ```idris hide
import System import System
--> ```
```idris ```idris
%default total %default total
@ -89,9 +89,9 @@ Iterable (LazyList a) a where
## Immutable arrays ## Immutable arrays
<!-- idris ```idris hide
namespace Immutable namespace Immutable
--> ```
Immutable arrays created from vectors that provide constant time indexing and Immutable arrays created from vectors that provide constant time indexing and
slicing operations. slicing operations.

View file

@ -76,7 +76,7 @@ data Error : Type where
A `Show` implementation for `Error` is provided, hidden in this document for A `Show` implementation for `Error` is provided, hidden in this document for
brevity. brevity.
<!-- idris ```idris hide
Show Error where Show Error where
show (OptionsError errs) = show (OptionsError errs) =
let errs = unlines . map (" " ++) . lines . joinBy "\n" $ errs let errs = unlines . map (" " ++) . lines . joinBy "\n" $ errs
@ -98,7 +98,7 @@ Show Error where
show (SolveError year day part err) = show (SolveError year day part err) =
let err = unlines . map (" " ++) . lines . show $ err let err = unlines . map (" " ++) . lines . show $ err
in "Error solving day \{show day} part \{show part} of year \{show year}: \n" ++ err in "Error solving day \{show day} part \{show part} of year \{show year}: \n" ++ err
--> ```
## Extract the year and day ## Extract the year and day

View file

@ -29,9 +29,9 @@ repeatN (S times') f seed = repeatN times' f (f seed)
## Either ## Either
<!-- idris ```idris hide
namespace Either namespace Either
--> ```
### mapLeft ### mapLeft
@ -47,9 +47,9 @@ Applies a function to the contents of a `Left` if the value of the given
## List ## List
<!-- idris ```idris hide
namespace List namespace List
--> ```
### contains ### contains
@ -94,12 +94,12 @@ Define some operations for pairs of numbers, treating them roughly like vectors
### Addition and Subtraction ### Addition and Subtraction
<!-- idris ```idris hide
export infixl 8 >+< export infixl 8 >+<
export infixl 8 >-< export infixl 8 >-<
namespace Pair namespace Pair
--> ```
```idris ```idris
public export public export
@ -115,9 +115,9 @@ namespace Pair
Extend `Data.SortedSet` Extend `Data.SortedSet`
<!-- idris ```idris hide
namespace Set namespace Set
--> ```
### length ### length
@ -133,9 +133,9 @@ Count the number of elements in a sorted set
Extend `Data.String` Extend `Data.String`
<!-- idris ```idris hide
namespace String namespace String
--> ```
### isSubstr ### isSubstr

View file

@ -6,11 +6,11 @@ module Util.Digits
import Data.Monoid.Exponentiation import Data.Monoid.Exponentiation
``` ```
<!-- idris ```idris hide
import System import System
%default total %default total
--> ```
This module provides views and associated functionality for treating `Integers` This module provides views and associated functionality for treating `Integers`
as if they were lists of numbers. as if they were lists of numbers.
@ -22,10 +22,10 @@ teaching purposes, we'll do it here, but please consider a library like
[prim](https://github.com/stefan-hoeck/idris2-prim) if you find yourself needing [prim](https://github.com/stefan-hoeck/idris2-prim) if you find yourself needing
to prove properties about primitive types. to prove properties about primitive types.
<!-- idris ```idris hide
-- This mutual block isn't strictly required, but is useful for literate purposes -- This mutual block isn't strictly required, but is useful for literate purposes
mutual mutual
--> ```
## Primitive functionality ## Primitive functionality
@ -50,14 +50,14 @@ most significant digit.
For a clarifying example: For a clarifying example:
<!-- idris ```idris hide
-- @@test Ascending Digits Example -- @@test Ascending Digits Example
ascendingExample : IO Bool ascendingExample : IO Bool
ascendingExample = do ascendingExample = do
putStrLn "Expecting: \{show [5, 4, 3, 2, 1]}" putStrLn "Expecting: \{show [5, 4, 3, 2, 1]}"
putStrLn "Got: \{show . ascList $ ascending 12345}" putStrLn "Got: \{show . ascList $ ascending 12345}"
pure $ pure $
--> ```
```idris ```idris
ascList (ascending 12345) == [5, 4, 3, 2, 1] ascList (ascending 12345) == [5, 4, 3, 2, 1]
@ -121,14 +121,14 @@ least significant digit.
For a clarifying example: For a clarifying example:
<!-- idris ```idris hide
-- @@test Descending Digits Example -- @@test Descending Digits Example
descendingExample : IO Bool descendingExample : IO Bool
descendingExample = do descendingExample = do
putStrLn "Expecting: \{show [1, 2, 3, 4, 5]}" putStrLn "Expecting: \{show [1, 2, 3, 4, 5]}"
putStrLn "Got: \{show . decList $ descending 12345}" putStrLn "Got: \{show . decList $ descending 12345}"
pure $ pure $
--> ```
```idris ```idris
decList (descending 12345) == [1, 2, 3, 4, 5] decList (descending 12345) == [1, 2, 3, 4, 5]

View file

@ -36,7 +36,7 @@ data Level : Type where
Other : (n : Nat) -> {auto _ : n `GT` 4} -> Level Other : (n : Nat) -> {auto _ : n `GT` 4} -> Level
``` ```
<!-- idris ```idris hide
export export
levelToNat : Level -> Nat levelToNat : Level -> Nat
levelToNat Err = 0 levelToNat Err = 0
@ -67,7 +67,7 @@ export infixl 8 >+
export export
(>+) : Level -> Nat -> Level (>+) : Level -> Nat -> Level
(>+) x k = natToLevel (k + levelToNat x) (>+) x k = natToLevel (k + levelToNat x)
--> ```
Convert a `Level` into a colorized tag Convert a `Level` into a colorized tag

View file

@ -6,7 +6,7 @@ import Structures.Dependent.FreshList
import Runner import Runner
``` ```
<!-- idris ```idris hide
import Years.Y2015.Day1 import Years.Y2015.Day1
import Years.Y2015.Day2 import Years.Y2015.Day2
import Years.Y2015.Day3 import Years.Y2015.Day3
@ -18,7 +18,7 @@ import Years.Y2015.Day8
import Years.Y2015.Day9 import Years.Y2015.Day9
import Years.Y2015.Day10 import Years.Y2015.Day10
import Years.Y2015.Day11 import Years.Y2015.Day11
--> ```
# Days # Days

View file

@ -3,7 +3,7 @@
Pretty simple, basic warmup problem, nothing really novel is on display here Pretty simple, basic warmup problem, nothing really novel is on display here
except the effectful part computations. except the effectful part computations.
<!-- idris ```idris hide
module Years.Y2015.Day1 module Years.Y2015.Day1
import Control.Eff import Control.Eff
@ -11,7 +11,7 @@ import Control.Eff
import Runner import Runner
%default total %default total
--> ```
## Solver Functions ## Solver Functions
@ -76,8 +76,8 @@ part2 x = do
pure $ findBasement 1 0 input pure $ findBasement 1 0 input
``` ```
<!-- idris ```idris hide
public export public export
day1 : Day day1 : Day
day1 = Both 1 part1 part2 day1 = Both 1 part1 part2
--> ```

View file

@ -3,13 +3,13 @@
This day doesn't really add anything new, but we will show off our new views for This day doesn't really add anything new, but we will show off our new views for
viewing integers as lists of digits. viewing integers as lists of digits.
<!-- idris ```idris hide
module Years.Y2015.Day10 module Years.Y2015.Day10
import Control.Eff import Control.Eff
import Runner import Runner
--> ```
```idris ```idris
import Data.String import Data.String
@ -22,9 +22,9 @@ import Util
import Util.Digits import Util.Digits
``` ```
<!-- idris ```idris hide
%default total %default total
--> ```
# Solver Functions # Solver Functions
@ -118,8 +118,8 @@ part2 digits = do
pure $ count (const True) output pure $ count (const True) output
``` ```
<!-- idris ```idris hide
public export public export
day10 : Day day10 : Day
day10 = Both 10 part1 part2 day10 = Both 10 part1 part2
--> ```

View file

@ -10,13 +10,13 @@ implement the one we need for today's task as a throw away data structure just
for this module, we will be using the `refined`[^1] library's implementation for for this module, we will be using the `refined`[^1] library's implementation for
the sake of getting on with it. the sake of getting on with it.
<!-- idris ```idris hide
module Years.Y2015.Day11 module Years.Y2015.Day11
import Control.Eff import Control.Eff
import Runner import Runner
--> ```
```idris ```idris
import Data.Vect import Data.Vect
@ -55,13 +55,13 @@ record PasswordChar where
%name PasswordChar pc %name PasswordChar pc
``` ```
<!-- idris ```idris hide
Show PasswordChar where Show PasswordChar where
show (MkPC char) = singleton char show (MkPC char) = singleton char
Eq PasswordChar where Eq PasswordChar where
x == y = x.char == y.char x == y = x.char == y.char
--> ```
A function to fallible convert `Char`s into refined `PasswordChar`s, this will A function to fallible convert `Char`s into refined `PasswordChar`s, this will
return `Just` if the `Char` satisfies the predicate, and `Nothing` otherwise, return `Just` if the `Char` satisfies the predicate, and `Nothing` otherwise,
@ -227,11 +227,11 @@ part2 password = do
pure $ passwordToString next_password pure $ passwordToString next_password
``` ```
<!-- idris ```idris hide
public export public export
day11 : Day day11 : Day
day11 = Both 11 part1 part2 day11 = Both 11 part1 part2
--> ```
## References ## References

View file

@ -2,13 +2,13 @@
This day provides us our first little taste of effectful parsing This day provides us our first little taste of effectful parsing
<!-- idris ```idris hide
module Years.Y2015.Day2 module Years.Y2015.Day2
import Control.Eff import Control.Eff
import Runner import Runner
--> ```
```idris ```idris
import Data.List import Data.List
@ -16,9 +16,9 @@ import Data.List1
import Data.String import Data.String
``` ```
<!-- idris ```idris hide
%default total %default total
--> ```
## Box structure ## Box structure
@ -130,8 +130,8 @@ part2 : (boxes : List Box) -> Eff (PartEff String) Integer
part2 boxes = pure . sum . map totalRibbon $ boxes part2 boxes = pure . sum . map totalRibbon $ boxes
``` ```
<!-- idris ```idris hide
public export public export
day2 : Day day2 : Day
day2 = Both 2 part1 part2 day2 = Both 2 part1 part2
--> ```

View file

@ -3,13 +3,13 @@
This day provides a gentle introduction to `mutual` blocks and mutually This day provides a gentle introduction to `mutual` blocks and mutually
recursive functions. recursive functions.
<!-- idris ```idris hide
module Years.Y2015.Day3 module Years.Y2015.Day3
import Control.Eff import Control.Eff
import Runner import Runner
--> ```
```idris ```idris
import Data.SortedSet import Data.SortedSet
@ -18,9 +18,9 @@ import Data.String
import Util import Util
``` ```
<!-- idris ```idris hide
%default total %default total
--> ```
## Parsing and data structures ## Parsing and data structures
@ -152,8 +152,8 @@ part2 movements = do
pure . length $ locations pure . length $ locations
``` ```
<!-- idris ```idris hide
public export public export
day3 : Day day3 : Day
day3 = Both 3 part1 part2 day3 = Both 3 part1 part2
--> ```

View file

@ -3,13 +3,13 @@
This day introduces us to a little bit of FFI, linking to openssl to use it's This day introduces us to a little bit of FFI, linking to openssl to use it's
`MD5` functionality. `MD5` functionality.
<!-- idris ```idris hide
module Years.Y2015.Day4 module Years.Y2015.Day4
import Control.Eff import Control.Eff
import Runner import Runner
--> ```
```idris ```idris
import Data.String import Data.String
@ -196,8 +196,8 @@ part2 seed = do
pure number pure number
``` ```
<!-- idris ```idris hide
public export public export
day4 : Day day4 : Day
day4 = Both 4 part1 part2 day4 = Both 4 part1 part2
--> ```

View file

@ -6,13 +6,13 @@ specifically `String`'s
[`AsList`](https://www.idris-lang.org/docs/idris2/current/base_docs/docs/Data.String.html#Data.String.AsList) [`AsList`](https://www.idris-lang.org/docs/idris2/current/base_docs/docs/Data.String.html#Data.String.AsList)
view, which lets us treat `String`s as if they were lazy lists or iterators. view, which lets us treat `String`s as if they were lazy lists or iterators.
<!-- idris ```idris hide
module Years.Y2015.Day5 module Years.Y2015.Day5
import Control.Eff import Control.Eff
import Runner import Runner
--> ```
```idris ```idris
import Data.String import Data.String
@ -20,9 +20,9 @@ import Data.String
import Util import Util
``` ```
<!-- idris ```idris hide
%default total %default total
--> ```
## Nice Strings ## Nice Strings
@ -213,8 +213,8 @@ part2 _ = do
pure x pure x
``` ```
<!-- idris ```idris hide
public export public export
day5 : Day day5 : Day
day5 = Both 5 part1 part2 day5 = Both 5 part1 part2
--> ```

View file

@ -2,13 +2,13 @@
Introduction to the advent of code classic 2d grid problem. Introduction to the advent of code classic 2d grid problem.
<!-- idris ```idris hide
module Years.Y2015.Day6 module Years.Y2015.Day6
import Control.Eff import Control.Eff
import Runner import Runner
--> ```
```idris ```idris
import Util import Util
@ -21,9 +21,9 @@ import Data.String
import Data.IORef import Data.IORef
``` ```
<!-- idris ```idris hide
%default total %default total
--> ```
## Parsing and data structures ## Parsing and data structures
@ -75,12 +75,12 @@ The three types of action that can be performed on a light.
data Action = On | Off | Toggle data Action = On | Off | Toggle
``` ```
<!-- idris ```idris hide
Show Action where Show Action where
show On = "on" show On = "on"
show Off = "off" show Off = "off"
show Toggle = "toggle" show Toggle = "toggle"
--> ```
The range of coordinates that a command affects The range of coordinates that a command affects
@ -90,11 +90,11 @@ record Range (rows, cols : Nat) where
top_left, bottom_right : Coord rows cols top_left, bottom_right : Coord rows cols
``` ```
<!-- idris ```idris hide
Show (Range rows cols) where Show (Range rows cols) where
show (MkRange top_left bottom_right) = show (MkRange top_left bottom_right) =
"\{show top_left} -> \{show bottom_right}" "\{show top_left} -> \{show bottom_right}"
--> ```
Helper function to extract a range of values from our Grid. Helper function to extract a range of values from our Grid.
@ -119,11 +119,11 @@ record Command (rows, cols : Nat) where
range : Range rows cols range : Range rows cols
``` ```
<!-- idris ```idris hide
Show (Command rows cols) where Show (Command rows cols) where
show (MkCmd action range) = show (MkCmd action range) =
"{\{show action}: \{show range}}" "{\{show action}: \{show range}}"
--> ```
### Parsing ### Parsing
@ -334,8 +334,8 @@ part2 commands = do
pure brightness pure brightness
``` ```
<!-- idris ```idris hide
public export public export
day6 : Day day6 : Day
day6 = Both 6 part1 part2 day6 = Both 6 part1 part2
--> ```

View file

@ -13,13 +13,13 @@ Ensuring that the input contains only one gate outputting for each wire is done
through throwing a runtime error in the parsing function if a second gate through throwing a runtime error in the parsing function if a second gate
outputting to a given wire is found in the input. outputting to a given wire is found in the input.
<!-- idris ```idris hide
module Years.Y2015.Day7 module Years.Y2015.Day7
import Control.Eff import Control.Eff
import Runner import Runner
--> ```
```idris ```idris
import Data.Bits import Data.Bits
@ -31,9 +31,9 @@ import Data.SortedMap.Dependent
import Decidable.Equality import Decidable.Equality
``` ```
<!-- idris ```idris hide
%default total %default total
--> ```
## Parsing and data structures ## Parsing and data structures
@ -252,8 +252,8 @@ part2 (circut, value) = do
pure value pure value
``` ```
<!-- idris ```idris hide
public export covering public export covering
day7 : Day day7 : Day
day7 = Both 7 part1 part2 day7 = Both 7 part1 part2
--> ```

View file

@ -3,7 +3,7 @@
This day provides a more in depth introduction to writing effectful parsers, This day provides a more in depth introduction to writing effectful parsers,
making use of state and non-determinism in our parsers. making use of state and non-determinism in our parsers.
<!-- idris ```idris hide
module Years.Y2015.Day8 module Years.Y2015.Day8
import Control.Eff import Control.Eff
@ -11,7 +11,7 @@ import Control.Eff
import Data.Primitives.Interpolation import Data.Primitives.Interpolation
import Runner import Runner
--> ```
```idris ```idris
import Data.String import Data.String
@ -344,8 +344,8 @@ part2 inputs = do
pure difference pure difference
``` ```
<!-- idris ```idris hide
public export public export
day8 : Day day8 : Day
day8 = Both 8 part1 part2 day8 = Both 8 part1 part2
--> ```

View file

@ -6,13 +6,13 @@ meeting the problem criteria, and then figure out the length in a separate step.
This isn't a particularly efficient solution, but its good enough for this small This isn't a particularly efficient solution, but its good enough for this small
problem size. problem size.
<!-- idris ```idris hide
module Years.Y2015.Day9 module Years.Y2015.Day9
import Control.Eff import Control.Eff
import Runner import Runner
--> ```
```idris ```idris
import Data.String import Data.String
@ -70,10 +70,10 @@ DistanceMap : Type
DistanceMap = SortedMap Location (List LP) DistanceMap = SortedMap Location (List LP)
``` ```
<!-- idris ```idris hide
Show l => Show (LocationPair l) where Show l => Show (LocationPair l) where
show (MkLP [x, y] distance) = "\{show x} <-> \{show y}: \{show distance}" show (MkLP [x, y] distance) = "\{show x} <-> \{show y}: \{show distance}"
--> ```
Perform simple, pattern matching based parsing of a location pair. Perform simple, pattern matching based parsing of a location pair.
@ -287,8 +287,8 @@ part2 (distance_map, pairs) = do
pure len pure len
``` ```
<!-- idris ```idris hide
public export public export
day9 : Day day9 : Day
day9 = Both 9 part1 part2 day9 = Both 9 part1 part2
--> ```