General Discussions

Discuss any topics that are not product-specific here.

Advent of Code 2022 Day 2 (BaseA Style)

AlteryxCommunityTeam
Alteryx Community Team
Alteryx Community Team

Discussion thread for day 2 of the Advent of Code - https://adventofcode.com/2022/day/2

45 REPLIES 45
Jeff_Neklason
8 - Asteroid

Such a fun way to get the brain going in the morning!

Spoiler
Jeff_Neklason_0-1669997062551.png

 

MeganDibble
Alteryx Community Team
Alteryx Community Team

If Statement for the win! There are more clever ways to do this but this got the job done relatively fast for me:

Spoiler
Screen Shot 2022-12-02 at 9.48.11 AM.png
mceleavey
17 - Castor
17 - Castor

Fairly simple once I'd actually read the second question.

Turns out that's quite important.

 

Spoiler
mceleavey_0-1670003426620.png

 


 



So, I created a mapping table as follows:

mceleavey_2-1669999627498.png

this allowed me to simply join the first and second columns. Then for the first answer I simply built an IF to calculate the points then sum them:
(if [Outcome]= "Win" then 6 elseif [Outcome]="Draw" then 3 else 0 endif)+ (if [2]="Y" then 2 elseif [2]="X" then 1 else 3 endif).

The second part was a couple of IFs to determine the required play given the Required Outcome, then the associated points.

Noice.






Bulien

SeanAdams
17 - Castor
17 - Castor

Reply number 1: This is the raw solution - refactor to follow.

this is part of the practice of Red-Green-Refactor (TDD)

  • Red: get your test harness running and fail your first test
  • Green: Write code (even if SUPER messy) to get the test cases to pass
  • Refactor: Update your code to code that you would be proud of, while still passing your tests.

 

So here's the first post - my messy solution (Red & Green) - refactor to follow.

 

Spoiler
SeanAdams_0-1670000604962.png

 

 

 

 

kelsey_kincaid
12 - Quasar

Not super happy with my solve on this one - it feels clunky. I might give this some thought and come back to it when I'm not trying to move as fast!

 

Spoiler
kelsey_kincaid_0-1670005230949.png

 

JoshuaB
Alteryx Product Evangelist
Alteryx Product Evangelist

Really fun looking at all the responses. I think @grossal and @DavidP trying to go for tool golf is entertaining too! 

 

Here's mine:

Spoiler
JoshuaB_0-1670006084818.png

 

Joshua Burkhow | Chief Evangelist @ Alteryx | Follow me on LinkedIn and Twitter
grossal
15 - Aurora
15 - Aurora

@DavidP it doesn't count. As discussed in the WhatsApp group earlier: For tool golf, both answers have to be provided in a single cell output. Therefore you'd need two Summarize tools :-)

starkey
7 - Meteor

Lots of find replacing going on here, but gets the job done haha. I opted to build out the selection / results and points mapping in tables rather then messing with long if statements. I could have reduced the tool count if I combined the points mapping into the results mapping, but would have taken more manual effort than I cared for.

 

Spoiler
day 2 solution.png  

 

starkey
7 - Meteor

@AkimasaKajitani I love the simplicity of the formula you came up with! well done

aiahwieder
8 - Asteroid

I know there was a prettier way to do this, but this was my Day 2 solution:

Labels