```
data =: > ". each ,. > > ('-'&cut) L:0 (','&cut) each LF cut freads '04.txt'
lte =: > +. =
gte =: < +. =
test =: ((0&{ gte 2&{) *. (1&{ lte 3&{)) +. ((0&{ lte 2&{) *. (1&{ gte 3&{))
solution =: +/ test"1 data
first =: 0&{ + [: i. [: >: 1&{ - 0&{
second =: 2&{ + [: i. [: >: 3&{ - 2&{
test2 =: first ([ -. -.) second
solution2 =: +/ 0&< >./"1 test2"1 data
```
Day 3 solution.
```
data =: LF cut freads '03.txt'
lines =: - @: -: @: # [\ ]
intersection =: ~. @: ([ -. -.)/
doubled =: intersection/ @: lines
priority_lookup =: (26 {. 'a' dropto a.) , (26 {. 'A' dropto a.)
priority =: 1 + (priority_lookup&i.)
answer =: +/ > (priority @: doubled) each data
common =: (intersection @: >)"1
answer2 =: +/ , priority common _3 [\ data
```
Day 3 solution.
```
data =: LF cut freads '03.txt'
lines =: - @: -: @: # [\ ]
intersection =: ~. @: ([ -. -.)/
doubled =: intersection/ @: lines
priority_lookup =: (26 {. 'a' dropto a.) , (26 {. 'A' dropto a.)
priority =: 1 + (priority_lookup&i.)
answer =: +/ > (priority @: doubled) each data
common =: (intersection @: >)"1
answer2 =: +/ , priority common _3 [\ data
```
Day 2 solution.
```
data =: freads '02.txt'
parse =: {{ ". each LF&cut rplc&('A';'0';'B';'1';'C';'2';'X';'0';'Y';'1';'Z';'2') y }}
data =: parse data
ind =: {: @: [ { ({. @:[ { ])
s =: 3 3 $ 3 6 0 0 3 6 6 0 3
score =: > ind&s each data
pscore =: > >:@:{: each data
answer =: +/ pscore , score
p =: 3 3 $ 3 1 2 1 2 3 2 3 1
pscore2 =: > ind&p each data
score2 =: > 3&*@:{: each data
answer2 =: +/ score2 , pscore2
```
So, Tag 1 des #AdventOfCode ist fertig -- die erste Hälfte in Ada (eigentlich sollte es #SPARKAda werden, aber da habe ich mich in der I/O verheddert), und dann nochmal beide Teile schön kompakt in #Jsoftware :sweat_smile: https://adventofcode.com/2022/day/1
#adventofcode #sparkada #jsoftware
Day 1 solution. Parsing text in #J is painful.
```
parse =: (". @: ((LF,' ')&charsub)) each @: (([: 2&= (1&|. + [) @: (LF&=)) <;.2 ])
calories =: +/"1 > parse data
highest =: >. / calories
sum_three_heighest =: +/ 3 {. |. (/: { ]) calories
```
#AOC in #J #jsoftware
input =: 1!:1 <'aoc01.txt'
input =: ".;._2 input
echo >./ +/;._2 input , 0
input =: +/;._2 input , 0
echo +/ 0 1 2 { input \: input
J, that concise, it fits easily into a toot. :)
@okflo @ldbeth is #jsoftware the hashtag to use to find other J developers / users? or is it #jlang? or just #j ?