~rootmos/AoC

74599e09e08de7095b251cf15547edb7b4706132 — Gustav Behm 11 days ago 237d3c1
Extend the Haskell runner and Qulude to render input and call run-c
8 files changed, 1492 insertions(+), 7 deletions(-)

M .gitignore
A 2023/13.example
A 2023/13.hs
A 2023/13.hs.c
A 2023/13.input
M aoc
M lib/Qulude.hs
M run/run-c
M .gitignore => .gitignore +2 -0
@@ 1,5 1,7 @@
*.so
.event
.suffix
.target

*.exe
*.hi

A 2023/13.example => 2023/13.example +15 -0
@@ 0,0 1,15 @@
#.##..##.
..#.##.#.
##......#
##......#
..#.##.#.
..##..##.
#.#.##.#.

#...##..#
#....#..#
..##..###
#####.##.
#####.##.
..##..###
#....#..#

A 2023/13.hs => 2023/13.hs +45 -0
@@ 0,0 1,45 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Main where

import Qulude

--import Data.Array ( (!) )
import qualified Data.Array as Array
import qualified Data.Array.ST as STArray
import qualified Data.Either as Either
import qualified Data.List as List
--import Data.Map ( (!) )
import qualified Data.Map as Map
import qualified Data.Maybe as Maybe
import qualified Data.Sequence as Seq
import qualified Data.Set as Set

type Pattern = [[Bool]]

type Parse = [Pattern]
parser :: Parser Parse
parser = pattern `sepBy1` newline
  where pattern = many1 $ many1 m <* newline
        m = try $ (char '.' $> False) <|> (char '#' $> True)

renderC :: [Pattern] -> String
renderC ps = printf "int N = %d;\nint size[][2] = %s;\nint mirror[][%d][%d] = %s;\n" (length ps) sizes my mx mirrors
  where sizes = toArray $ s <$> ps
        my = maximum $ length <$> ps
        mx = maximum $ (length . head) <$> ps
        mirrors = toArray $ fmap p ps
        p ls = toArray $ fmap l ls
        l ms = toArray $ fmap m ms
        m True = "1"
        m False = "0"
        s ls = printf "{%d,%d}" (length $ head ls) (length ls)
        toArray = (\s -> printf "{%s}" s) . List.concat . List.intersperse ","

main :: IO ()
main = with parser $ do
  runC renderC "13.hs.c" "13.example" "a example"
  runC renderC "13.hs.c" "13.input" "a input"

A 2023/13.hs.c => 2023/13.hs.c +25 -0
@@ 0,0 1,25 @@
#include <stdio.h>

#include "input.h"

int main(int argc, char* argv[])
{
    printf("%s:\n", argv[1]);

    for(int n = 0; n < N; n++) {
        printf("%dx%d\n", size[n][0], size[n][1]);
        for(int y = 0; y < size[n][1]; y++) {
            for(int x = 0; x < size[n][0]; x++) {
                if(mirror[n][y][x]) {
                    printf("#");
                } else {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}

A 2023/13.input => 2023/13.input +1351 -0
@@ 0,0 1,1351 @@
...##.#
.##.###
.##.###
...##.#
#...###
.#..##.
##.##.#
...####
#.#.###
#....#.
..#.##.
..#.##.
#....#.
#.#.#.#
...####

###..##.######.##
..#..#.#......#.#
#.##.#..#.##.#..#
#.#.##.#..##..#.#
#..#...###..###..
#..#...###..###..
#.#.##.#..##..#.#
#.##.#..#.##.#..#
..#..#.#......#.#
###..##.######.##
...#.#..######..#
..###....#..#..#.
#.###....#..#....
##.#####.#..#.###
...#.....####....
..#...#.#.##.#.#.
...###.#......#.#

##.##.#####
#.####.#..#
#.####.#..#
##.##.###.#
########...
.#....#....
###..#####.

..#.#.#...####.
..#.#...#....##
##.##.#..##....
...#..#.....#..
##......#.##.#.
..####.#.#.#...
..####.#.###...

.#..#.##.
##..####.
.#..#..#.
..##....#
.#..#..#.
.#..#.###
........#
......#.#
##..##.##
##..##.#.
##..##...
##..##.##
......#.#
........#
.#..#.###

....###...#..##
#..####..##..##
.###..###.#.###
...####...#####
#..#..#..##..##
#.##..##.#.....
#........#.##..

.#.#.#.
.#.#.#.
##.#.##
#.#.###
..##...
..#....
###.###
..#..#.
#.####.
.##.###
.##.###
#.####.
..##.#.
###.###
..#....

#..#.###.##.#
....#...#..#.
....#..#.##.#
....##.......
.##.##.######
####....#..#.
.##..##.#....
.##.#.#..##..
####.#...##..
.##.#.#.#..#.
.....#.######
.##.....#..#.
#..##.###..##

#....#.#.
####.##.#
#.##..###
##..#.###
.#....#.#
...##..##
##..#....
##..#....
...##..##
.#....#.#
##..#.###
#.##..###
####.##.#
#....#.#.
.#...#...
.#...#...
#....#.##

..##....#.#.##.
.####..#.##.##.
##..##..#.#####
##..##.#.#.....
#######..######
.#....####.....
.......#.#.####

..#.....#
.###.#.##
##...##..
#......#.
#.###..##
#.#.#..##
#......#.
#.##..##.
#.###.###
#.###.###
#.##..##.
#......#.
#.#.#..##
#.###..##
#......#.

#####....####
..##..##..##.
###..#..#..##
##..##..##..#
##..#....#..#
###...#....##
..###.##.###.
####.####.###
..##.####.##.
###.##..##.##
##...#..#...#

#.###.###.#
#.###.###.#
...##.#..##
#..#.....#.
.....##...#
#..##.##...
...#.#.....
###.#...#.#
..#.#.##..#
#.#...#....
#.#...#....
..#.#.##..#
###.#...#.#
...#.#.....
#..##.#....
.....##...#
#..#.....#.

###.#..####..
###.#..#.##..
###.#..#.##..
###.#..####..
.#.#..#.#...#
.#....#..###.
#...##..#####

..#.###.#.####.
.....###.###.##
..#..#.#.######
##.#.....######
###.#..##......
##..#..##..##..
..##.#.########
..###..#..#..#.
...#####...##..

...##..##
.#.......
#####.#..
##..#..##
#..#.##..
##..#..##
.###..###
#.#..##..
#.....#..
.####..##
.##.#.###
.#....#..
.#.#..#..
.##.#.###
.####..##

..####.
#..#.##
.###.#.
#.##..#
###...#
.#.#...
.#.#...
###...#
#.##..#
.###.#.
#..####
..####.
..####.

#...##.####..##.#
###.##.###.##.#..
.#...#.#####..###
##...####.##.#..#
.##..#.#.#.#.####
#....#.#####..#..
#....#######..#..
.##..#.#.#.#.####
##...####.##.#..#
.#...#.#####..###
###.##.###.##.#..
#...##.####..##.#
....##...##.#..##
#.##....#.#.###..
#.##....#.#.###..

##..###.##.
.####.#..#.
.####.###.#
#.##.######
##..####.#.
..###..#.##
..##...#..#
########...
.#..#.##..#
..........#
.#..#.#..##
.####..###.
......##.#.
......##.#.
.####..###.

##.#.#..#.#
.#####..###
.##.#.##.#.
..##......#
.###.####.#
#####....##
..#.######.
##...####..
#.#########
.##.#.##.#.
.##.#.##.#.
#.#########
##...####..
..#.######.
##.##....##

.##.#.###.#....
..#...#####..##
#.##.##..##..##
..#..##........
.##..##.#.#..#.
#.........#..#.
#.#.###..######
...#...####..##
.#.#......####.
......####....#
#..####...####.
..##.##.###..##
...##.#####..##
....##..###..##
##.##...###..##
##.##...###..##
....##..###..##

#.###....
.###..###
#..#.#..#
##.#.....
##.##..##
.##.##.##
#..###...
.#...#.##
#.##.##..
#.#..#.##
#...#.###
#...#.###
#.#..#.##
#.##.##..
.#...#.##
#..###...
.##.##.##

.##.#....#.
....######.
.##........
####..##..#
#..########
#####.##.##
#..#..##..#
#..#..##.##
#..#......#
.##..####..
.##..####..
#..#.####.#
.....#..#..
......##...
####.####.#
.##........
#..#......#

.##.###.#######..
.##.###.#######..
.##.##....##..#..
#.#.####.###.####
..##.#.#.....###.
###.#..##.#.##..#
.##..#..#..#..#.#
...#.####..###.#.
...#.####..###.#.
.##..#..#..#..#.#
###.#..##...##..#

######..#####
###..#..#..##
###..####..##
######..#####
####......###
##..######...
..#..#..#..#.
..#.######.#.
..#........#.
..##......##.
###........##

.#..#.####.
#.##.#.##.#
..##...##..
.####..##.#
.#..#......
##..###..##
.####.####.

#####.#..###.
#####.#..###.
#...##.#..#..
.#....#.##.##
#..#.#.#...#.
.##..####.##.
.#...#.#.##..
.#...#.#.###.
.##..####.##.

##.##.##.##
########...
.######.#..
#.####.##..
#.####.#..#
#......#.##
.#.##.#..##
...##...#..
..#..#..#..

.#........#.#
###.####.###.
...##..##....
.....##.....#
#.##....##.##
#.##....##.##
.....##.....#
...##..##....
###.####.###.
.#........#.#
..###..###..#
##.#.##.#.#..
.#..#..#..#.#

##.#...#.
#...#...#
..##.....
.###.....
#...#...#
##.#...#.
#..#.#.##
####.####
####.#...
..#.#.###
..#.#.###

#..#..#..#.
#######.#.#
#######.#..
#..#..#..#.
####......#
....##.#..#
.......#.##

.#.#####.##..##..
#..####....#.....
#..##.#....#.....
.#.#####.##..##..
..##.......##.#.#
##...#.#.#..#..#.
#.#.##..#...##.##
#########.##..###
#.####.#..#.#....
#.#.#.#.####...#.
##.....###...#.##
..#...#.......###
...###.##.....###
#.##.##.###...#..
#.##.##.###...#..
...###.##.....###
..#...#.......###

..###.#....#.###.
##.###.####.###.#
..#.####..####.#.
..##.#......#.##.
.....##.##.##.#..
##...##....##...#
..#..##....##..#.
...##.##..##.##..
####.#.#..#.#.###
#######.##.######
###.#........#.##
.....###..###....
##.#..######..#.#
..#####....#####.
....#.##..##.#...
...#..#.##.#..#..
..#..########..#.

.###.##.#
#.###.#..
.#...#.##
##.#...##
###...#..
#.##..###
...#..#..
...#..#..
#.##..###
###...#..
##.#...##
.#...#.##
#.###.#..

#..#.##
.##..##
#..#...
####.##
#..#.##
#..####
....###
.....##
.....##
....###
#..#.##
#..##..
.##.##.
####.##
.##.###

##....###
#.#.##...
#..##.#.#
.###..###
###.#..##
###.#..##
.###..#.#
#..##.#.#
#.#.##...
##....###
###...##.
####.#.#.
####.#.#.

#..#....##....#
#####..####..##
..###..####..##
.###....##....#
....##########.
..###..####..##
#..............
#.#............
..##.##.##.##.#

######.#.#.##
..####..#.#.#
..####..#.#.#
######.#.#.##
.#..#.##.#.##
#######.##.#.
.#...#.######
#...##..###..
......###.###
##..#......##
###..##...#..
###..##...#..
##..#......##
.....####.###
#...##..###..

..#######
#.#......
..##.##.#
###......
###.####.
##.##..##
####.##.#

#.###..
#.###..
.#....#
##.#.##
##.#..#
#.#..#.
.#..#.#
.#..#.#
#.#..#.
##.#..#
##.#.##
.##...#
#.###..

#....##...###
.####.#....##
#######.##.##
..##..#......
##..####.####
#....#..#..##
#######......
.####.##.....
#....###...##
#.##.#.#.##..
#....##.#.###
##..##.#..###
#.##.#.#...##
#....##.#....
.#..#...#.###
......##.#...
#....#.#.#.#.

#######.#..#.##
.#..#....##....
......#.#..#.#.
#.##.#.#.##.#.#
##..##.#.##.#.#
..##..###..###.
##..###.#..#.##
#.##.#........#
#....##.#..#.#.

..#....##
..#....##
##...##..
#####....
..#.#...#
..#.#..##
...#...##
...##.#..
####..#..
.....####
##.###.#.
..#.#.###
##.##.#..
......##.
#.####..#

#...#####
#....####
#....####
#...##..#
.#.##....
......##.
..##.#..#

#......######..
#..##..#.##.#..
...##...#..#...
#.#..#.##..####
########.##.###
##....##....##.
##.##.###..###.
#.#..#.#....#.#
#......#....#..

.#..#..####
.#.....####
##..##..##.
..#.#.#..##
..####.##.#
.##.######.
.##.######.
..####.##.#
..#.#.#..##
##..##..##.
.#.....####
.#..#..####
...####..#.

###.#...#......#.
#..####.##....##.
..######..####..#
#.#...#.#..##..#.
...#.#..#..##..#.
....###..##..#...
#.#.#.#..##..##..
.#.##..#..####..#
.##.##...#....#..
........##.##.##.
.#..####..#..#..#
.#..##.#.##..##.#
##.#..#..######..
##.#..#..######..
.#..##.#.##..##.#
.#..####..#..#..#
........##.##.##.

...##..
#.#..#.
#.#..#.
##.##.#
.###.##
.##..##
#.#..#.
...##..
...##..
#.#..#.
.##..##

#.#..#...
##.####.#
...#...##
...#...##
##.####.#
#.#..#...
#..#..##.
##....###
##.#..###
....##...
##..##...
##......#
##....#.#

..#..##...#..#...
..#....##....#...
#####..##..######
####........#####
##.###.##.###.###
....#.#..#.#.....
#...#..##..#...##
#..##.#..#.##..##
.####......####..
#..#..#..#..#..##
.#.#..#..#..#.#..
.#.#..#..#..#.#..
.#.###....###.#..
#.###..##..###.##
#.#..#....#..#.##

....##.
##..#.#
##..#.#
....#..
.#.#...
.##..##
#...#.#
.###.#.
.###.#.
#...#.#
.##..##

#.#...###..#.
..###...##..#
..###...##..#
#.#....##..#.
#...##.#####.
#...##.#####.
#.#....##..#.
..###...##..#
..###...##..#
#.#...###..#.
.#.#..#..##.#
...#..##.#.#.
##..##..###.#
.###..####.##
##..####.##.#
..#.#.#...#..
#.##....##.#.

###.#.##.#...#.
###.#.##.#...#.
.#.#.#.#..#....
..##.##..#.##.#
#.#.###.#.###.#
.####.....#.#..
#.#..###.###...
#.#..###.###...
.####.....#.#..
#.#.###.#.###.#
..#####..#.##.#

......#...#.##...
####..##.#.#..#..
.......##.##..#.#
.......#.###...#.
......###.##.#.##
#..#.###.#.##..##
....###...#..##.#
..........#.###.#
####.###...#..#.#
#######.#..##...#
.....###...##.###
.....###.#####...
####..#.#.#.#.#..
....####.#.##....
####.##.###.#....

.##.#..#.
##.......
#.##.##.#
#.##.##.#
###......
.##.#..#.
#........

###.#..#.##
###..###...
.#####.##..
#.##..#####
.####..##..
...##.#.###
#....#..#..
.#..#.##.##
#.#.#..#...
#..##.#.#..
#..#.######
.#.##...###
##....#####
##.#.#.##..
#.##.###...
...####.###
...#.##.###

.#.##..#..###
##.#.####....
#.#.#.#.#.#..
#.#...##.##..
#.#.#.#....##
.###.....##..
.###.....##..
#.#.#.#....##
#.#...##.##..
#.#.#.#.#.#..
.#.#.####....

.#.##.#.##.
.######.##.
#......####
.#.##.#.##.
#..##..####
##.##.#####
#.####.#..#
.######.##.
########..#
.#.##.#..#.
#......#..#
#.#..#.#..#
###..######
#.#..#.#..#
##....#####

#..##..#.......
###..###..####.
.#....#..#.##.#
.######...#..#.
.#.##.#.#.#..#.
...##......##..
##.##.####....#
.#.##.#...####.
.#....#..#....#
..####.....##..
#########..##..
##....##..####.
..........#..#.
#..##..#.######
.........##..#.
..#..#..#######
.######.#######

..#.#.##.
..#.#.##.
#######..
.##.#.#.#
....#..##
..#######
##...##.#
##...##.#
###.....#
#####..#.
####.##.#
##.....#.
..#.##..#
###..###.
..##.#.#.
...#...##
..#.#.#..

.....###.
####.###.
####...#.
####..##.
####.###.
.....###.
.##.#..#.
.....#..#
....###.#
####..##.
#..#.#.##
#..##...#
#..#.....
#..###..#
.##.##..#

..#...#.#######
...####.#...##.
.####.#.#.##..#
...#.#.###..##.
..##.#.##..#..#
.....#.#..#....
.#####..###....
.....#####.....
#..##.#..#.#..#
#..##.#..#.#..#
..#..#####.....

.#..#..####.#
.#..#...###.#
#....#.#..###
.####.#..###.
#.##.##...#..
######..##.#.
#.##.##.....#
..##..#..##.#
.####.#.##.##
.#..#....##..
#....##.###.#
#.##.#...##..
.####.....#.#

##..#.#.##..#
##.###.##....
.##.#####.##.
#.####.##....
.##.#....#..#
.####....#..#
#......#.####
#......#.####
.####....#..#
.##.#....#..#
#.####.##....
.##.#####.##.
.#.###.##....
##..#.#.##..#
..#.##.######

##.#..#.##.####
#..####..#.#...
###########...#
##.#..#.###.###
####..####...##
##......###...#
..######.....#.
###.##.####.###
##..##..###.##.
####..#######..
#.#....#.#...#.
.#..##..#.#..##
.#..##..#.#.###

##.##......##.###
###.#.####.#.####
#..##..##..##..##
##..########..###
..###..##..###...
..#.##.##.##.#...
.#....#..#....#..
##.#.##..##.#.###
.#.....##.....#..
##.###....###.###
#.#..##..##..#.##
#...##....#....##
###.##....##.####
##.###....###.###
.#..#..##..#..#..
.#.###....###.#..
..#.##....##.#...

#....###.
######.#.
#.#..#...
#....#.#.
#######.#
#....#.#.
..##...#.
.......#.
.#..#...#
#.##.###.
#.##.###.

######.
##...#.
##..##.
..#.#..
###.##.
.#.##.#
.#....#
.#....#
.#.##.#
###.##.
..#.#..
##..##.
##...#.

.#.#.#.####
.#....#....
....##....#
...##..####
.#...#.#..#
..##..##..#
#######....
#######....
..##..##..#

#####.#..#.######
###.########.####
.#.####..####.#..
#.#...#..#...#.##
..#.#.#..#.#.#...
.##.#......#.##..
.....##.###......
.###.######.###..
.##.#......#.##..
#.####....####.##
.###..#..#..###..
...#...##...#....
#.#..........#.##

#.##.######.#
..##...##...#
.####..##..##
..##...###..#
.#..#......#.
.####..##..##
######.##.###
#.##.#.##.#.#
.......##....
......#..#...
#######..####

..#.#.##.
..#...###
#.#..#.##
...#.####
...##.#.#
###....#.
####.#..#
.....#.##
..##..#.#
..##..#.#
.....#.##

##.##...###......
########...#..#..
#....##.#.#.#....
###.#.#.##...#..#
##...##..###.#..#
##.####...#...##.
#.#####..##..#..#
.#...####..#..##.
.#...####..#..##.
#.#####..##..#..#
##.####...#...##.
##...##..###.#..#
###.#.#.##...#..#

####.#.#.#..#..
.#.##.######.#.
.#.##.#.....###
.#.##.#.....###
.#.##.######.#.
####.#.#.#..#..
.##.#.#.##.##.#
.##..###..#.##.
#.#######.#.##.
#.#######.#.##.
.##..###..#.##.
.##.#.#.##.##.#
####.#.#.#..#..
.#.##.######.#.
.####.#.....###

#..##..###..#
..#..#....#.#
#.####.##.#..
#.#..#.####.#
...##.....#.#
###..###.....
##.##.######.
..####.....##
##.##.#######
.##..##.##..#
.######......
.######......
.##..##.##...

.##..##
.######
##.##.#
##.##.#
..#..#.
#.####.
#.####.
.#...##
...##..
...##..
#......
...##..
...##..
#......
...##..

......#.##.##....
.####..##........
.####..##........
......#.##.##....
##..####.#...#...
.####......######
##..##..#.##..#.#
#.##.##..####.#..
##..##.#.##.##.##
..##..#.###.#.##.
#....#####...####
##..##.....##...#
..##...####.#...#
#.##.##.##..#####
#####.....##..#..
......##.###.####
#....####.####...

#..##...##.#.
.###...#.#...
####...#.#...
#..##...##.#.
..#.......##.
###....#.#.##
...####..##.#
##...#.#.##..
##...#.#.##..

.##..##
##.....
.##....
..##...
###....
.####..
.#.##..
.#.##..
#####..

####..####....#
####...#.#.##.#
.#....#########
##..#..#.######
..#..#.#.......
..#..#..##.##.#
..#..#..##....#
..#..#.#.......
##..#..#.######

#.#.##.
..#.##.
..#.##.
#.#.##.
#...##.
##.....
..#####
#.##.##
#.##...

...#.####.###
#.#.##..##.##
.#.#..###.#..
#######.#..##
#######.#..##
.#.#..###.#..
#.#.##..##.##
...#.####.###
####.#..#....
.#.##.######.
#.#####..#...

....###...#
..###...##.
..###...##.
....###...#
####.###.#.
#...##..#.#
##...###...

.#..#..#.
.########
#.##.##.#
..#.####.
..#.####.
#.##.##.#
.########
.#..#..#.
#..######
..##...##
...#.##.#
##..#..#.
..#######

.#.##...###...##.
.#.##...###...##.
..###.##.###.##..
##..##.....###..#
#.##.......#.###.
###..###########.
#...##...##.#.##.
##....#...#..#..#
##....#...#..#..#
#...##...##.#.##.
###..###########.
#.##.......#.###.
##..##.....####.#
..###.##.###.##..
.#.##...###...##.

#.#..###.#..#.#
#.#..###....#.#
#.#.##.###.#..#
#######......#.
####.#.#.##...#
#.###....#.##.#
.#####...###...
##.#####.##.#..
##...#..#...###
#..####.....#.#
####.#..##.#..#
####.#..##.#..#
#..####.....#.#

#....#....#..
#.##.#....#.#
.#..#..##..#.
#.##.#....#.#
##..##....##.
..##..#..#..#
.####......##
#.##.#....#.#
#.##.#..#.#.#
.#..#..##..#.
#.##.######.#
######.##.###
##..########.
.####......##
.#..#..##..#.

.#.....######
#..##########
#.###..##....
...##..#.....
###.#..###..#
...####......
..###.#######
...#...######
.##...#.#####

.#..#.####.#.
.###........#
.###........#
.#..#.####.#.
#.#....#.....
###.##....##.
#.#...#..#...

......#..##..
.#..#........
#.####..#....
#.##.####...#
#######.##.#.
.####.#..####
.####.#..####
#######.##.#.
#.##.####...#

#.##...
#..####
.##.##.
.######
.#.####
#......
..#####
###.##.
.######
.#.....
..##..#
.###..#
.###..#

#..##...##...
####.#...#.##
....##..#..##
######.###...
..#..##..####
####.#..#..#.
....#.#..####
.##.#..###..#
.##...###....
####.#.#.#.#.
####.#.#.#.#.
.##...###....
.##.#..###..#
....#.#..####
####.#..#..#.

###..##.##..#
##.##.######.
######.##.#..
##...#.#####.
##..###..#.##
..#....##.###
###.#.##.##..
##.#..#...##.
##.#..#....#.

.###.....#.
.#...#.#...
#..##.##..#
....###.###
###..#..#.#
####...##..
#...##..#.#
#...##..#.#
####...##..
###..#..#.#
....###.###
#...#.##..#
.#...#.#...
.###.....#.
.###.....#.

##....##.#.....
#..##..#######.
#########.....#
.######.###..##
#......##....##
#......##....##
.######.####.##

#..##....
###.#.##.
...#.#..#
..#.#....
...#..##.
..#######
#.#..####
###..#..#
#..#..##.
##.#.#..#
.....#..#
##.##.##.
...#.####
##..##..#
##..##..#
.#.#.####
##.##.##.

#####.#.##..#..
#####.#.##..#..
..##.##..#..#..
#####......#..#
#..##.##.###.##
#.#....###...##
#.....###.#####
###.###..#..###
...#..##.#.###.
#...####...##.#
##.#.#..#.#####
##.#.#....#####
#...####...##.#
...#..##.#.###.
###.###..#..###
#.....###.#####
#.#....###...##

#..#.##.#.####.
.#.#.#...##..##
.#.#.#...##..##
#..#.##.#.####.
###..##.#.#..#.
###.#..#.##...#
#...#.####....#

##..####.##
.##.#..#.#.
..###.###..
###.#.#.#.#
.##.#.#.#.#
..###.###..
.##.#..#.#.
##..####.##
.###..##..#
.###..##..#
##..####.##
.##.#..#.#.
..###.###..

##.....#.#.
#...##...##
..#####.###
..#####.#.#
#...##...##
##...#..#..
#...##.....
#.##.###...
#.##.###...
#...##.....
##...#..#..
#...##...##
..#####.#.#
..#####.###
#...##...##

M aoc => aoc +18 -4
@@ 3,7 3,7 @@
set -o nounset -o pipefail -o errexit

SCRIPT_DIR=$(readlink -f "$0" | xargs dirname)
RUNNERS_DIR=$SCRIPT_DIR/run
export RUNNERS_DIR=$SCRIPT_DIR/run
TEMPLATES_DIR=$SCRIPT_DIR/templates
ROOT=${ROOT-$SCRIPT_DIR}



@@ 16,7 16,15 @@ if [ -z "$EVENT" ]; then
     fi
fi

DEFAULT_SUFFIX=${DEFAULT_SUFFIX-hs}
DEFAULT_SUFFIX=${DEFAULT_SUFFIX-}
if [ -z "$DEFAULT_SUFFIX" ]; then
     if [ -f "$ROOT/.suffix" ]; then
          DEFAULT_SUFFIX=$(<"$DEFAULT_SUFFIX")
     else
          DEFAULT_SUFFIX=hs
     fi
fi

SUFFIX=${SUFFIX-$DEFAULT_SUFFIX}
ACTION=edit
CLIPBOARD=


@@ 36,13 44,19 @@ while getopts "reixcE:R:s:-" OPT; do
done
shift $((OPTIND-1))

if [ $# -lt 1 ]; then
     TARGET=$(date +%d)
if [ $# -eq 0 ]; then
     if [ -f "$ROOT/.target" ]; then
          TARGET=$(<"$ROOT/.target")
     else
          TARGET=$(date +%d)
     fi
else
     TARGET=$1
     shift
fi

echo "$TARGET" >"$ROOT/.target"

EVENT_ROOT=$ROOT/$EVENT
if [ ! -d "$EVENT_ROOT" ]; then
     mkdir "$EVENT_ROOT"

M lib/Qulude.hs => lib/Qulude.hs +22 -2
@@ 41,7 41,10 @@ module Qulude ( module Prelude
              , with
              , run, run'
              , runIO
              , runC

              , render
              , renderT

              , (\\), (&)
              , (><), (<|), (|>), Seq ( (:<|), (:|>) )


@@ 103,6 106,10 @@ import Data.STRef
import System.Directory ( doesFileExist )
import System.IO ( hPutStrLn, stderr )
import System.IO.Unsafe ( unsafePerformIO )
import System.Environment ( getEnv )
import System.FilePath ( (</>) )
import System.Process ( callProcess )
import System.IO.Temp ( withSystemTempDirectory )

import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as TIO


@@ 198,7 205,20 @@ run_ fn t mb f = ask >>= \p -> lift (parseFile p fn) >>= \case
      Just b' | otherwise -> lift $ printf "%s: %s != %s\n" t (show b) (show b')
  Nothing -> return ()

render :: String -> String -> (a -> T.Text) -> ReaderT (Parser a) IO ()
render input output f = ask >>= \p -> lift $ parseFile p input >>= \case
renderT :: FilePath -> FilePath -> (a -> T.Text) -> ReaderT (Parser a) IO ()
renderT input output f = ask >>= \p -> lift $ parseFile p input >>= \case
  Just x -> TIO.writeFile output (f x)
  Nothing -> return ()

render :: FilePath -> FilePath -> (a -> String) -> ReaderT (Parser a) IO ()
render input output f = renderT input output (T.pack . f)

runRunC :: [String] -> ReaderT (Parser a) IO ()
runRunC args = liftIO $ do
  runner <- flip (</>) "run-c" <$> getEnv "RUNNERS_DIR"
  callProcess runner args

runC :: (a -> String) -> FilePath -> FilePath -> String -> ReaderT (Parser a) IO ()
runC r cfn input t = withSystemTempDirectory "aoc" $ \tmp -> do
  render input (tmp </> "input.h") r
  runRunC ["-I" ++ tmp, cfn, t]

M run/run-c => run/run-c +14 -1
@@ 5,4 5,17 @@ set -o nounset -o pipefail -o errexit
SCRIPT_DIR=$(readlink -f "$0" | xargs dirname)
LIB=${LIB-$SCRIPT_DIR/../lib}

exec tcc -run -DLOG_LEVEL="LOG_${LOG_LEVEL-INFO}" -I"$LIB" "$1"
ARGS=(-DLOG_LEVEL="LOG_${LOG_LEVEL-INFO}" -I"$LIB")
while getopts "I:-" OPT; do
    case $OPT in
        I) ARGS+=("-I$OPTARG") ;;
        -) break ;;
        ?) exit 2 ;;
    esac
done
shift $((OPTIND-1))

INFILE=$1
shift

exec tcc "${ARGS[@]}" -run "$INFILE" "$@"