From e7c9108b95e39d7ea5a29ae06d619c4727f11027 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 29 Oct 2021 23:02:39 +0200 Subject: Initial commit --- 2015/03/input | 1 + 2015/03/puzzle-1.awk | 6 ++++++ 2015/03/puzzle-2.awk | 11 +++++++++++ 2015/03/puzzles.sh | 4 ++++ 4 files changed, 22 insertions(+) create mode 100644 2015/03/input create mode 100644 2015/03/puzzle-1.awk create mode 100644 2015/03/puzzle-2.awk create mode 100755 2015/03/puzzles.sh (limited to '2015/03') diff --git a/2015/03/input b/2015/03/input new file mode 100644 index 0000000..6e8d40e --- /dev/null +++ b/2015/03/input @@ -0,0 +1 @@ +^^<<>^^>^^^><^>v^>v><><><^^v>v^v>>>^<>v<^<^>>>>><>^>>^>v^>><<^>v>v<>^v^v^vvv><>^^>v><>^><^^^v>>^v^>v><>v^^><vv^<<>v>>><<<>>^^^vv>>>^><<<>><><^>v<>^>v<^v^><<<<>^<>v>^v>vv<^<<>>>>^^v>vv^^<>^<>^^^^<^^^vv<^^v^^>v>^v^^^^>><v<>^v^><>^^><<^^<^^>vv<>v^<^v^>^^>^<>v^^vv<>>v><<<>vvv<>v<>><^<^v<>^vv>^^v<^<>>vv<^>>^>>vv^v>^v^<>^>>>>vv>^^>v>vv>v><^vv^<^<<^^vv^^v>^>>v><^<>v<><>^^<>v>><>^^>^^>>vvv^><<<<<^<^vv<^<>^^^<<<^>^^^vv<>^<>v<^v>^<<>^v<>>v<<^<^<<<><><>^>>>>^>v^v<>vv<^vvv^^^^vv>^v^^v^<^vv<^vv>v<^>vv<>>^>^><^>v>^v>vvv<>^>^v<><>vv>><^v^<><>>v^v^><^<^>vv>v<^>vvv>v<<<<<^>^vv>^><><>^<v^>^><><>>^>^>><^^^>^^>^^v^^<^v^^>v^^>>><<><><>^^<<^^v^>v>><>^^^><^vvv<^^^^^v><<><><>>^>vv>>^vv^^><v<^^>^<^^<^>>>^v<>v<^^^>vvv^v<<^><>>>>v>>>^^vvv^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^^v^vvv^>><>>v<>^<^vvv<<^^>vv^^<<>>><^^vvv<<<^>^<><^>vv^><^<<>vv<>vv>v>v^<<>^^^^v^^^^^<<^><><^^v^>v>^>><^><<>v^>>^vvv>>^<^<>^^v^vv^^v><>>v<<<>v>^<>v<<>v^>^<<><<>v^>v<><^^>^<^v^^><^>vv>^>vvvv>^^><<>vv^>^v<<^<<^<<>vv>>^>>>>>v^v<^v>v>^^^vv^v<^<>v><>>vv>v><>v>^v<><<<<<>v^vv<<<<^<>^>><>^^vv>^<^<<>vv>>vv><>><^^><^<>^><>v^^^^v^^vv<>v<>v>^vv^>^<>^^^>v^>>>v><<^>>v<^v<>^^v<><<>v<^<^>v<>v^>v>^^<<<^^vv^<><<<>>v>^^<>v>>>><<>v^v<>v>><<<<^<<^>^>v^vv^><^v^^<>^^><>vv>^>vvv<^v^>>^>^>^^<<^>^>^v><>>^<^^v>^>>^^<><>>>^^>^^vvv>v<^^<>v^v^^v^v>><<^^^>>v>^vv>^>^^v<>^^<>v^^<>v^><<>vv<<^vvvv><<v>v^>v^<>v^>^^<>^>^^v<>><<<>^v^^v^v<<<^v^<>^<>v>^^>vv>^^<<<><<^>v<^^<^<<>^>>>>>^v^v<vvv<<>v>v>>^v^v^>><<<<>v^<<>>>^>>^>>< \ No newline at end of file diff --git a/2015/03/puzzle-1.awk b/2015/03/puzzle-1.awk new file mode 100644 index 0000000..13b1209 --- /dev/null +++ b/2015/03/puzzle-1.awk @@ -0,0 +1,6 @@ +BEGIN { x = y = 1; homes[x][y] = 1; acc = 1 } +$0 == "^" { if (!homes[x][++y]++) acc++; next } +$0 == ">" { if (!homes[++x][y]++) acc++; next } +$0 == "v" { if (!homes[x][--y]++) acc++; next } +$0 == "<" { if (!homes[--x][y]++) acc++; next } +END { print acc } diff --git a/2015/03/puzzle-2.awk b/2015/03/puzzle-2.awk new file mode 100644 index 0000000..0857009 --- /dev/null +++ b/2015/03/puzzle-2.awk @@ -0,0 +1,11 @@ +BEGIN { sx = sy = rx = ry = 1; homes[sx][sy] = 1; acc = 1 } + { santa = santa ? 0 : 1 } +santa == 0 && $0 == "^" { if (!homes[rx][++ry]++) acc++; next } +santa == 0 && $0 == ">" { if (!homes[++rx][ry]++) acc++; next } +santa == 0 && $0 == "v" { if (!homes[rx][--ry]++) acc++; next } +santa == 0 && $0 == "<" { if (!homes[--rx][ry]++) acc++; next } +santa == 1 && $0 == "^" { if (!homes[sx][++sy]++) acc++; next } +santa == 1 && $0 == ">" { if (!homes[++sx][sy]++) acc++; next } +santa == 1 && $0 == "v" { if (!homes[sx][--sy]++) acc++; next } +santa == 1 && $0 == "<" { if (!homes[--sx][sy]++) acc++; next } +END { print acc } diff --git a/2015/03/puzzles.sh b/2015/03/puzzles.sh new file mode 100755 index 0000000..6007df1 --- /dev/null +++ b/2015/03/puzzles.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +fold -w1 input | awk -f puzzle-1.awk +fold -w1 input | awk -f puzzle-2.awk -- cgit v1.2.3