-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.yml
78 lines (66 loc) · 2.37 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
- name: Split input into the two parts
ansible.builtin.set_fact:
boxes_view: "{{ day5_input | split('\n\n') | first }}"
procedure: "{{ day5_input | split('\n\n') | last }}"
- name: Split procedure into instructions
ansible.builtin.set_fact:
instructions: "{{ procedure | split('\n') | reject('equalto', '') | list}}"
- name: Split boxes view into boxes and instructions
ansible.builtin.set_fact:
# Boxes should be all rows except the lsat
boxes: "{{ boxes_view | split('\n') | json_query('[:-1]') }}"
indexes: "{{ boxes_view | split('\n') | last }}"
- name: Get the box indexes
ansible.builtin.set_fact:
box_index: "{{ indexes | trim | split(' ') | map('int') | list }}"
- name: Split boxes into arrays
ansible.builtin.set_fact:
box_rows: "{{ box_rows | default([]) + [item | replace(' ', '[|] ') | split(']') | map('trim') | map('replace', '[', '') | list | json_query('[:-1]')] }}"
loop: "{{ boxes }}"
- name: Create stacks
tags: part1
ansible.builtin.include_tasks: "stacks.yml"
- name: Loop over all instructions
tags: part1
ansible.builtin.include_tasks: "inner.yml"
vars:
instruction_full: "{{ item }}"
nums: "{{ instruction | regex_findall('[0-9]+') | map('int') }}"
amount: "{{ nums[0] }}"
move_from: "{{ nums[1] | int - 1 }}"
move_to: "{{ nums[2] | int - 1 }}"
reverse: true
loop: "{{ instructions }}"
loop_control:
loop_var: instruction
index_var: instruction_index
- name: ANSWER TO PART 1 | Get the top box of every stack
tags: part1
ansible.builtin.debug:
msg: "{% for i in stacks %}{{ i[0] }}{% endfor %}"
- name: Reset stacks variable
tags: part2
ansible.builtin.set_fact:
stacks: []
- name: Recreate stacks
tags: part2
ansible.builtin.include_tasks: "stacks.yml"
- name: Loop over all instructions but don't reverse new boxes
tags: part2
ansible.builtin.include_tasks: "inner.yml"
vars:
instruction_full: "{{ item }}"
nums: "{{ instruction | regex_findall('[0-9]+') | map('int') }}"
amount: "{{ nums[0] }}"
move_from: "{{ nums[1] | int - 1 }}"
move_to: "{{ nums[2] | int - 1 }}"
reverse: false
loop: "{{ instructions }}"
loop_control:
loop_var: instruction
index_var: instruction_index
- name: ANSWER TO PART 2 | Get the top box of every stack
tags: part2
ansible.builtin.debug:
msg: "{% for i in stacks %}{{ i[0] }}{% endfor %}"