Introduction
Introduction Statistics Contact Development Disclaimer Help
taoc5b - aoc22 - advent of code 2022 solutions
git clone git://src.adamsgaard.dk/aoc22
Log
Files
Refs
README
---
taoc5b (697B)
---
1 #!/bin/awk -f
2
3 function addstart(i, char) {
4 pile[i] = sprintf("%s%s", char, pile[i])
5 }
6
7 function append(i, char) {
8 pile[i] = sprintf("%s%s", pile[i], char)
9 }
10
11 function pop(i, n) {
12 len = length(pile[i])
13 if (len && len - n >= 0) {
14 char = substr(pile[i], len - (n-1), len+1)
15 pile[i] = substr(pile[i], 1, len - n)
16 return char
17 }
18 }
19
20 NR == 1 { n = (length+1)/4 }
21
22 $1 ~ /1/ { move=1; getline }
23
24 move == 0 {
25 for (i=1; i<=n; i++) {
26 field = substr($0, (i-1)*4 + 2, 1)
27 if (sub(/ /, "", field) == 0)
28 addstart(i, field)
29 }
30 }
31
32 move == 1 {
33 nmove = $2
34 from = $4
35 to = $6
36 append(to, pop(from, nmove))
37 }
38
39 END{
40 for (i=1; i<=n; i++)
41 printf("%s", substr(pile[i], length(pile[i]), 1))
42 print
43 }
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.