-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.yml
31 lines (25 loc) · 946 Bytes
/
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
---
- name: Split input into separate elves
ansible.builtin.set_fact:
elfs: "{{ day1_input | split('\n\n') }}"
- name: Split the calories from each elf
ansible.builtin.set_fact:
elf_calories: "{{ elf_calories | default([]) + [item | split('\n') | map('int') ] }}"
loop: "{{ elfs }}"
- name: Add all calories of each elf together
ansible.builtin.set_fact:
elf_total_calories: "{{ elf_total_calories | default([]) + [item | sum] }}"
loop: "{{ elf_calories }}"
- name: ANSWER TO PART 1 | Return the highest total calories
tags: part1
ansible.builtin.debug:
msg: "{{ elf_total_calories | max }}"
- name: Sort the list by size
tags: part2
ansible.builtin.set_fact:
sorted_elfs: "{{ elf_total_calories | sort(reverse=True) }}"
- name: ANSWER TO PART 2 | Return the calories of the top 3 elves
tags: part2
ansible.builtin.debug:
msg: "{{ [sorted_elfs[0], sorted_elfs[1], sorted_elfs[2]] | sum }}"
...