🏡 index : ~doyle/aoc.git

author Jordan Doyle <jordan@doyle.la> 2023-12-11 21:48:53.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-12-11 21:48:53.0 +00:00:00
commit
425176c84de4e1d6ce160a99933e8de19adad78f [patch]
tree
8b1d7c395af395bb2985717538e1ddfbf403e35f
parent
49c83a4f856ff6d3f4a0089e999b9b3a8dda8e7a
download
425176c84de4e1d6ce160a99933e8de19adad78f.tar.gz

Add 2022 day 6



Diff

 README              |   4 ++--
 2022/6/.gitignore   |   2 ++
 2022/6/apache2.conf | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2022/6/read.sh      |   9 +++++++++
 4 files changed, 169 insertions(+), 2 deletions(-)

diff --git a/README b/README
index fa3f42f..afc2a1c 100644
--- a/README
+++ a/README
@@ -19,8 +19,8 @@
|        3 | Haskell  | |        3 | Clojure  |
|        4 | Haskell  | |        4 | Jsonnet  |
|        5 | Rust     | |        5 | HCL/TF   |
|        6 | Haskell  | +---------------------+
|        7 | Haskell  |
|        6 | Haskell  | |        6 | Apache2  |
|        7 | Haskell  | +---------------------+
|        8 | Haskell  |
|        9 | Haskell  |
|       10 | Haskell  |
diff --git a/2022/6/.gitignore b/2022/6/.gitignore
new file mode 100644
index 0000000..f5efcb4 100644
--- /dev/null
+++ a/2022/6/.gitignore
@@ -1,0 +1,2 @@
httpd.pid
logs
diff --git a/2022/6/apache2.conf b/2022/6/apache2.conf
new file mode 100644
index 0000000..fd4ad0e 100644
--- /dev/null
+++ a/2022/6/apache2.conf
@@ -1,0 +1,156 @@
LoadModule mpm_prefork_module libexec/apache2/mod_mpm_prefork.so
LoadModule alias_module libexec/apache2/mod_alias.so
LoadModule unixd_module libexec/apache2/mod_unixd.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule headers_module libexec/apache2/mod_headers.so

ServerRoot .
PidFile ./httpd.pid
RewriteEngine On

Listen 8888

<VirtualHost *:8888>
    LogLevel debug

    #########################
    #        PART 1         #
    #########################

    # entry point to part 1
    RedirectMatch 301 ^/part1/(.*)$ /part1-iter/$1/1

    # extract first 4 characters from string
    RewriteRule ^/part1-iter/(.)(.)(.)(.) - [E=C1:$1,E=C2:$2,E=C3:$3,E=C4:$4]

    # assert that all characters are distinct
    RewriteCond %{ENV:C1}#%{ENV:C2} !^([^#]+)#\1$
    RewriteCond %{ENV:C1}#%{ENV:C3} !^([^#]+)#\1$
    RewriteCond %{ENV:C1}#%{ENV:C4} !^([^#]+)#\1$
    RewriteCond %{ENV:C2}#%{ENV:C3} !^([^#]+)#\1$
    RewriteCond %{ENV:C2}#%{ENV:C4} !^([^#]+)#\1$
    RewriteCond %{ENV:C3}#%{ENV:C4} !^([^#]+)#\1$
    RewriteRule ^ - [E=ALL_PART1_CHARS_DISTINCT:1]

    # redirect to completion page if distinct
    RewriteCond %{ENV:ALL_PART1_CHARS_DISTINCT} =1
    RewriteRule ^/part1-iter/(.{4})[^/]*/(1+)$ /part1-complete/$1/111$2 [R=301,L]

    # remove the first character, increment the iterator and continue on
    RewriteCond %{ENV:ALL_PART1_CHARS_DISTINCT} !=1
    RewriteRule ^/part1-iter/.([^/]+)/(1+)$ /part1-iter/$1/1$2 [R=301,L]

    #########################
    #        PART 2         #
    #########################

    # entry point to part 2
    RedirectMatch 301 ^/part2/(.*)$ /part2-iter/$1/1

    # extract first 14 characters from string. this needs to be split into two capture
    # groups because apache reads $10 as $1 and a 0 literal. ask me how i know :)
    RewriteRule ^/part2-iter/(.)(.)(.)(.)(.)(.)(.)(.)(.) - [E=CC1:$1,E=CC2:$2,E=CC3:$3,E=CC4:$4,E=CC5:$5,E=CC6:$6,E=CC7:$7,E=CC8:$8,E=CC9:$9]
    RewriteRule ^/part2-iter/.{9}(.)(.)(.)(.)(.) - [E=CC10:$1,E=CC11:$2,E=CC12:$3,E=CC13:$4,E=CC14:$5]

    # assert that all characters are distinct
    RewriteCond %{ENV:CC1}#%{ENV:CC2} !^([^#]+)#\1$
    RewriteCond %{ENV:CC1}#%{ENV:CC3} !^([^#]+)#\1$
    RewriteCond %{ENV:CC1}#%{ENV:CC4} !^([^#]+)#\1$
    RewriteCond %{ENV:CC1}#%{ENV:CC5} !^([^#]+)#\1$
    RewriteCond %{ENV:CC1}#%{ENV:CC6} !^([^#]+)#\1$
    RewriteCond %{ENV:CC1}#%{ENV:CC7} !^([^#]+)#\1$
    RewriteCond %{ENV:CC1}#%{ENV:CC8} !^([^#]+)#\1$
    RewriteCond %{ENV:CC1}#%{ENV:CC9} !^([^#]+)#\1$
    RewriteCond %{ENV:CC1}#%{ENV:CC10} !^([^#]+)#\1$
    RewriteCond %{ENV:CC1}#%{ENV:CC11} !^([^#]+)#\1$
    RewriteCond %{ENV:CC1}#%{ENV:CC12} !^([^#]+)#\1$
    RewriteCond %{ENV:CC1}#%{ENV:CC13} !^([^#]+)#\1$
    RewriteCond %{ENV:CC1}#%{ENV:CC14} !^([^#]+)#\1$
    RewriteCond %{ENV:CC2}#%{ENV:CC3} !^([^#]+)#\1$
    RewriteCond %{ENV:CC2}#%{ENV:CC4} !^([^#]+)#\1$
    RewriteCond %{ENV:CC2}#%{ENV:CC5} !^([^#]+)#\1$
    RewriteCond %{ENV:CC2}#%{ENV:CC6} !^([^#]+)#\1$
    RewriteCond %{ENV:CC2}#%{ENV:CC7} !^([^#]+)#\1$
    RewriteCond %{ENV:CC2}#%{ENV:CC8} !^([^#]+)#\1$
    RewriteCond %{ENV:CC2}#%{ENV:CC9} !^([^#]+)#\1$
    RewriteCond %{ENV:CC2}#%{ENV:CC10} !^([^#]+)#\1$
    RewriteCond %{ENV:CC2}#%{ENV:CC11} !^([^#]+)#\1$
    RewriteCond %{ENV:CC2}#%{ENV:CC12} !^([^#]+)#\1$
    RewriteCond %{ENV:CC2}#%{ENV:CC13} !^([^#]+)#\1$
    RewriteCond %{ENV:CC2}#%{ENV:CC14} !^([^#]+)#\1$
    RewriteCond %{ENV:CC3}#%{ENV:CC4} !^([^#]+)#\1$
    RewriteCond %{ENV:CC3}#%{ENV:CC5} !^([^#]+)#\1$
    RewriteCond %{ENV:CC3}#%{ENV:CC6} !^([^#]+)#\1$
    RewriteCond %{ENV:CC3}#%{ENV:CC7} !^([^#]+)#\1$
    RewriteCond %{ENV:CC3}#%{ENV:CC8} !^([^#]+)#\1$
    RewriteCond %{ENV:CC3}#%{ENV:CC9} !^([^#]+)#\1$
    RewriteCond %{ENV:CC3}#%{ENV:CC10} !^([^#]+)#\1$
    RewriteCond %{ENV:CC3}#%{ENV:CC11} !^([^#]+)#\1$
    RewriteCond %{ENV:CC3}#%{ENV:CC12} !^([^#]+)#\1$
    RewriteCond %{ENV:CC3}#%{ENV:CC13} !^([^#]+)#\1$
    RewriteCond %{ENV:CC3}#%{ENV:CC14} !^([^#]+)#\1$
    RewriteCond %{ENV:CC4}#%{ENV:CC5} !^([^#]+)#\1$
    RewriteCond %{ENV:CC4}#%{ENV:CC6} !^([^#]+)#\1$
    RewriteCond %{ENV:CC4}#%{ENV:CC7} !^([^#]+)#\1$
    RewriteCond %{ENV:CC4}#%{ENV:CC8} !^([^#]+)#\1$
    RewriteCond %{ENV:CC4}#%{ENV:CC9} !^([^#]+)#\1$
    RewriteCond %{ENV:CC4}#%{ENV:CC10} !^([^#]+)#\1$
    RewriteCond %{ENV:CC4}#%{ENV:CC11} !^([^#]+)#\1$
    RewriteCond %{ENV:CC4}#%{ENV:CC12} !^([^#]+)#\1$
    RewriteCond %{ENV:CC4}#%{ENV:CC13} !^([^#]+)#\1$
    RewriteCond %{ENV:CC4}#%{ENV:CC14} !^([^#]+)#\1$
    RewriteCond %{ENV:CC5}#%{ENV:CC6} !^([^#]+)#\1$
    RewriteCond %{ENV:CC5}#%{ENV:CC7} !^([^#]+)#\1$
    RewriteCond %{ENV:CC5}#%{ENV:CC8} !^([^#]+)#\1$
    RewriteCond %{ENV:CC5}#%{ENV:CC9} !^([^#]+)#\1$
    RewriteCond %{ENV:CC5}#%{ENV:CC10} !^([^#]+)#\1$
    RewriteCond %{ENV:CC5}#%{ENV:CC11} !^([^#]+)#\1$
    RewriteCond %{ENV:CC5}#%{ENV:CC12} !^([^#]+)#\1$
    RewriteCond %{ENV:CC5}#%{ENV:CC13} !^([^#]+)#\1$
    RewriteCond %{ENV:CC5}#%{ENV:CC14} !^([^#]+)#\1$
    RewriteCond %{ENV:CC6}#%{ENV:CC7} !^([^#]+)#\1$
    RewriteCond %{ENV:CC6}#%{ENV:CC8} !^([^#]+)#\1$
    RewriteCond %{ENV:CC6}#%{ENV:CC9} !^([^#]+)#\1$
    RewriteCond %{ENV:CC6}#%{ENV:CC10} !^([^#]+)#\1$
    RewriteCond %{ENV:CC6}#%{ENV:CC11} !^([^#]+)#\1$
    RewriteCond %{ENV:CC6}#%{ENV:CC12} !^([^#]+)#\1$
    RewriteCond %{ENV:CC6}#%{ENV:CC13} !^([^#]+)#\1$
    RewriteCond %{ENV:CC6}#%{ENV:CC14} !^([^#]+)#\1$
    RewriteCond %{ENV:CC7}#%{ENV:CC8} !^([^#]+)#\1$
    RewriteCond %{ENV:CC7}#%{ENV:CC9} !^([^#]+)#\1$
    RewriteCond %{ENV:CC7}#%{ENV:CC10} !^([^#]+)#\1$
    RewriteCond %{ENV:CC7}#%{ENV:CC11} !^([^#]+)#\1$
    RewriteCond %{ENV:CC7}#%{ENV:CC12} !^([^#]+)#\1$
    RewriteCond %{ENV:CC7}#%{ENV:CC13} !^([^#]+)#\1$
    RewriteCond %{ENV:CC7}#%{ENV:CC14} !^([^#]+)#\1$
    RewriteCond %{ENV:CC8}#%{ENV:CC9} !^([^#]+)#\1$
    RewriteCond %{ENV:CC8}#%{ENV:CC10} !^([^#]+)#\1$
    RewriteCond %{ENV:CC8}#%{ENV:CC11} !^([^#]+)#\1$
    RewriteCond %{ENV:CC8}#%{ENV:CC12} !^([^#]+)#\1$
    RewriteCond %{ENV:CC8}#%{ENV:CC13} !^([^#]+)#\1$
    RewriteCond %{ENV:CC8}#%{ENV:CC14} !^([^#]+)#\1$
    RewriteCond %{ENV:CC9}#%{ENV:CC10} !^([^#]+)#\1$
    RewriteCond %{ENV:CC9}#%{ENV:CC11} !^([^#]+)#\1$
    RewriteCond %{ENV:CC9}#%{ENV:CC12} !^([^#]+)#\1$
    RewriteCond %{ENV:CC9}#%{ENV:CC13} !^([^#]+)#\1$
    RewriteCond %{ENV:CC9}#%{ENV:CC14} !^([^#]+)#\1$
    RewriteCond %{ENV:CC10}#%{ENV:CC11} !^([^#]+)#\1$
    RewriteCond %{ENV:CC10}#%{ENV:CC12} !^([^#]+)#\1$
    RewriteCond %{ENV:CC10}#%{ENV:CC13} !^([^#]+)#\1$
    RewriteCond %{ENV:CC10}#%{ENV:CC14} !^([^#]+)#\1$
    RewriteCond %{ENV:CC11}#%{ENV:CC12} !^([^#]+)#\1$
    RewriteCond %{ENV:CC11}#%{ENV:CC13} !^([^#]+)#\1$
    RewriteCond %{ENV:CC11}#%{ENV:CC14} !^([^#]+)#\1$
    RewriteCond %{ENV:CC12}#%{ENV:CC13} !^([^#]+)#\1$
    RewriteCond %{ENV:CC12}#%{ENV:CC14} !^([^#]+)#\1$
    RewriteCond %{ENV:CC13}#%{ENV:CC14} !^([^#]+)#\1$
    RewriteRule ^ - [E=ALL_PART2_CHARS_DISTINCT:1]

    # redirect to completion page if distinct
    RewriteCond %{ENV:ALL_PART2_CHARS_DISTINCT} =1
    RewriteRule ^/part2-iter/(.{14})[^/]*/(1+)$ /part2-complete/$1/1111111111111$2 [R=301,L]

    # remove the first character, increment the iterator and continue on
    RewriteCond %{ENV:ALL_PART2_CHARS_DISTINCT} !=1
    RewriteRule ^/part2-iter/.([^/]+)/(1+)$ /part2-iter/$1/1$2 [R=301,L]
</VirtualHost>
diff --git a/2022/6/read.sh b/2022/6/read.sh
new file mode 100755
index 0000000..68ca040 100755
--- /dev/null
+++ a/2022/6/read.sh
@@ -1,0 +1,9 @@
#!/usr/bin/env bash

STDIN=$(cat -)

PART1=$(curl --max-redirs 100000 -Ls "http://127.0.0.1:8888/part1/$STDIN" -o /dev/null -w %{url_effective})
echo $(echo $PART1 | gsed -E 's/.*\/([1]+)/\1/' | tr -d '\n' | wc -c)

PART2=$(curl --max-redirs 100000 -Ls "http://127.0.0.1:8888/part2/$STDIN" -o /dev/null -w %{url_effective})
echo $(echo $PART2 | gsed -E 's/.*\/([1]+)/\1/' | tr -d '\n' | wc -c)