ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests Early 2026. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. Learn more here
Start Free Trial

General Discussions

Discuss any topics that are not product-specific here.

Euleryx Project 19 – Counting Sundays

Pilsner
13 - Pulsar

Euleryx Problem 19 – Counting Sundays

 

Pilsner_1-1766064233141.png

 


My workflow and macro:


 

Spoiler

Workflow:

 

Pilsner_0-1766064223605.png

 



Answer: 171



 

Last Week's Favourite Solution:

Yes, I am aware that it was over a week ago since the last post, but changing the name of the award just didn’t seem right!  The winner of last week's favourite solution is @AkimasaKajitani . @AkimasaKajitani  took it one step further and provided two separate solutions, one generating all possible routes, and the other calculating the optimal path to each end location, keeping only the optimal steps, each iteration. Please find their solutions on page one of last week's post or click here.

 

Mathematical Theory:

After a tough couple of weeks with the Advent of Code, we are starting back with a relatively kind project. This weeks problem could be easily solved using Alteryx date time capabilities, to easily convert the dates into days of the week. However, I believe this alone is a little too easy, so I decided to tackle this problem using numbers and string values only.

 

ThatSoundsLikeAChallengeWilliamZabkaGIF.gif

 

The essence of this challenge is spotting patterns. Based on the information provided, the only day of the week we currently know is Monday, 1st Jan 1900. So lets calculate how many days later, the subsequent months are:

  • 1st Feb 1900 = 31days later
  • 1st Mar 1900 = 59 days later
  • 1st Apr 1900 = 90 days later
  • 1st May 1900 = 120 days later exc….

Another fact we can use to help, is that each week contains only 7 days. So that means, after every multiple of 7 days, we arrive back on a Monday. If we then divide the “days later” value, by 7, then keep only the remainder, we can figure out, how many days after Monday, the 1st of the month is:

  • 1st Feb 1900 = 31/7 = 4 remainder 3
  • 1st Mar 1900 = 59/7 = 8 remainder 3
  • 1st Apr 1900 = 90 = 12 remainder 6
  • 1st May 1900 = 120/7 = 17 remainder 1

Looking at the remainders, we know that 1 day after Monday is Tuesday, 3 days after Monday is Thursday, and 6 days after Monday is Sunday. This means that April 1st 1900 was a Sunday.

 

If we extend the list out, so we have a running total for “days later” than 1900-01-01, we can then use this same divide by 7 logic to easily identify all the Sundays.

 

Method:


1) Generate one row per year, starting at 1900, and ending at 2000

Pilsner_3-1766064313653.png

 



2) Append the months on to the list of years

Pilsner_4-1766064319792.png

 

 

 

3) Update the days in the month to 29, for the relevant Februarys.

Pilsner_5-1766064324566.png

 



4) Calculate a running total for the number of days after 1900-01-01

Pilsner_6-1766064330285.png

 



5) Find the modulus of the days since 1900-01-01, when divided by 7. (I also had to adjust the running total slightly so it represented the days to the start of the month not the end)

Pilsner_7-1766064335051.png

 



6) Filter to days where the modulus equalled 6, as we know these to all be Sundays, then count the number of these records. (Make sure to filter to the correct dates too)

Pilsner_8-1766064339589.png

 

 

 

7) Submit your answer to the Project Euler Website!

NailedItTheOfficeGIF.gif

 



Summary:

Creating the running total gave us the number of days since the 1st Jan 1900. By then exploiting the repetitive sequence formed by the days of the week, we were able to easily figure out which day of the week a date was on, by simply dividing the running total by 7.

 

Want to find out more, follow this link to our introduction post - Euleryx: Let The Games Begin.

 

2 REPLIES 2
Qiu
21 - Polaris
21 - Polaris

With completeness of AoC, the Euler Projec is back! 👍


I simple generate all the days between 1 Jan 1901 to 31 Dec 2000 then count all the Sundays using DateTimeFormat as the first day of the month.

Spoiler
Euleryx Project 19A.png

 

Hub119
12 - Quasar
12 - Quasar

I guess I went the easy route... hard to resist when Designer has so many handy functions built right in 😀

Spoiler
PE-19.png
Labels
Top Solution Authors