Skip to content

Commit

Permalink
tweak and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Jan 3, 2025
1 parent 2c4ed00 commit d037eb9
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions examples/aoc2024/day21/part2.jou
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,12 @@ def apply_arrow_keypad_to_regex(orig_regex: byte*) -> byte*:
assert end[1] != '('
assert end[1] != '|'
assert end[1] != ')'
assert end[1] != '\0'

s = arrow_keypad_table[prev][end[1]]
assert s != NULL
result.append_str(s)
if end[1] != '\0':
s = arrow_keypad_table[prev][end[1]]
assert s != NULL
result.append_str(s)

result.append_str("|")

# Come back to earlier state
Expand All @@ -433,16 +434,21 @@ def apply_arrow_keypad_to_regex(orig_regex: byte*) -> byte*:


def do_the_thing(code: byte*) -> None:
regex1 = get_numpad_regex(code)
regex2 = preprocess_regex(regex1)
regex3 = apply_arrow_keypad_to_regex(regex2)
regex4 = preprocess_regex(regex3)
regex5 = apply_arrow_keypad_to_regex(regex4)
printf("%s %lld\n", code, shortest_instance_len(regex5))
free(regex2)
free(regex3)
free(regex4)
free(regex5)
numpad_array = get_numpad_regex(code)

regex: byte* = numpad_array
for i = 0; i < 2; i++:
regex2 = preprocess_regex(regex)
if regex != &numpad_array[0]:
free(regex)
regex = apply_arrow_keypad_to_regex(regex2)
free(regex2)

printf("%s --> %lld (%lld)\n", code, shortest_instance_len(regex), strlen(regex))
fflush(stdout)

if regex != &numpad_array[0]:
free(regex)


def main() -> int:
Expand Down

0 comments on commit d037eb9

Please sign in to comment.