From 0cfbc8f3e5a1360c87d567307cce7fcfb4afd422 Mon Sep 17 00:00:00 2001 From: kageru Date: Mon, 2 Dec 2019 14:57:01 +0100 Subject: [PATCH] Day 2 awk: minor refactoring --- 2019/02/day2.awk | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) mode change 100644 => 100755 2019/02/day2.awk diff --git a/2019/02/day2.awk b/2019/02/day2.awk old mode 100644 new mode 100755 index d213799..6d733a6 --- a/2019/02/day2.awk +++ b/2019/02/day2.awk @@ -1,3 +1,5 @@ +#!/usr/bin/awk -f + # There are no scopes, so we just write to `arr` here and use it later. # Returning the array does not seem to be legal either. Only scalars allowed. function prepareInput(raw) { @@ -31,12 +33,13 @@ function process(arr, len, first, second) { len = prepareInput($1); process(arr, len, 12, 2); printf("Part 1: %d\n", arr[0]); + part2_target = 19690720 for (x=0; x<100; x++) { for (y=0; y<100; y++) { len = prepareInput($1); process(arr, len, x, y); - if (arr[0] == 19690720) { - printf("Part 2: %d\n", 100* x + y); + if (arr[0] == part2_target) { + printf("Part 2: %d\n", 100 * x + y); } } }