🏡 index : ~doyle/aoc.git

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>