cancel
Showing results for
Did you mean:

Community Manager

It's that time of year again! (the most wonderful time of the year? 🎄 )

Tomorrow kicks off Advent of Code 2023, and if you know the KX community you'll know we love to take part the annual series of challenges set by the brilliant Eric Wastl.

If you want to join in, learn from your peers and partake in a bit of friendly competition, join the KX leaderboard by going to Private Leaderboard - Advent of Code 2023 and using code 1526329-bb0915a5.

Feel free to use your KX Community to ask questions, post suggestions or solutions so we can use this opportunity to improve our coding skills.

Remember, it's just a bit of fun!

Happy Coding 🤶

3 REPLIES 3
New Contributor II

I came up with the following for day 1 / part two:

``````/ Part Two
wordNumMap: ("*" ,' ((string 1 + til 9), ("one"; "two"; "three"; "four"; "five"; "six"; "seven"; "eight"; "nine")) ,' "*") ! raze flip 2#' 1 + til 9;
ansTwo: sum "I"\$(raze') (raze') string wordNumMap flip ({key[wordNumMap] (where') m @' first each (where') any each' m: x (like/:\:)\: key[wordNumMap]}') ((::; neg) @\: 1 + (til') (count') txt) (#\:')\: txt;
show "Part Two: ", string ansTwo;``````

The idea was for every line of input, to turn it into a cumulative list from the left and right hand sides e.g.

zlmlk1 ->

z, zl, zlm, zlml, zlmlk, zlmlk1

and

1, 1k, 1kl, 1klm, 1klml, 1klmlz

Cross compare this with "*1*", "*2*", ..., "*one*", "*two*".

For the first of the cumulative lists (both left and right) that has a match, find which number-string it matched against. Map this string back to its numeric form, before concatenating the left and right matches, and summing.

I'd be interested to see other solutions (or any ways to improve the above!) 🙂

New Contributor

Here's a solution to Day 1!

Part 1

Spoiler
``````p: read0 `:problem.txt;
is:where'[p within 48 58];
sum "J"\$p @' flip (min'[is];max'[is])``````

Part 2

Spoiler
``````p: read0 `:problem.txt;
numbers: ("one";"two";"three";"four";"five";"six";"seven";"eight";"nine");
is: where'[p within 48 58];
e:(count'[p])#\:0N;
e:@[;;:;]'[e;is;"J"\$/:/:p @' is];
e: e{@'[;;:;y 0][x;y 1]}/ (1+til 9),'enlist each p ss\:/: numbers;
e: except[;0N]'[e];
sum 10 sv (first'[e];last'[e]);``````
New Contributor

Day Two, too!

Spoiler
``````p: read0 `:problem.txt
rules: `red`green`blue!12 13 14
p:@'[p;where'[p=";"];:;","];
s:" " vs/:/: ", " vs/: (": " vs/: p)[;1]
game:"J" \$ s[;;0] @' group'[`\$s[;;1]]
sum 1+where all'[all''[rules >=/: game]]``````
Spoiler
``````p: read0 `:problem.txt
p:@'[p;where'[p=";"];:;","];
s:" " vs/:/: ", " vs/: (": " vs/: p)[;1]
game:"J" \$ s[;;0] @' group'[`\$s[;;1]]
sum prd'[max''[game]]``````