Added a new List.sortFast()
method that you can use to sort a list containing primitives that is an order of magnitude faster than List.sort()
. Updated the solution to use that instead.
Am tackling Day 2 now…
BTW: If you need to sort some complex data type in Xojo, the (fast) trick is to:
- Put it into an array
- Create a second array of integers, into which you put ordering value based on the first array (e.g. if you want to sort strings by their length, put the lengths into the second array).
- Use secondArray.SortWith (firstArray)
Also: Still waiting on your update on github
After my antisocial-media comment in last year’s AOC discussion, Thomas shamed me into getting a Github account.
So, I’ve now done days 1 & 2 for this year’s version. I was lazy with the day 1 puzzle, and just did it in Excel. I did Day 2 in Xojo.
Join my leaderboard!
(Go to Leaderboard → Private Leaderboard and enter the code from the post above.)
Wow, so it was worth my belated comment
Welcome to the team!
Ah, I had previously not realized that the code you posted was for the leaderboard
And to everyone who is using the private leaderboard: There’s a great Chrome & FF extension that automatically shows a lot of extra information, including the time one needs for part 2. Get it here:
Sadly, it provides no stats for the initial puzzle, yet (see my FR).
Also, I only realized today that I had been logged in with the wrong account (“Thomas Tempelmann”) for the first 2 days. I’ve now switched to my “@tempelorg” account that I also used in 2021. So I re-did the first two days on the correct account, with amazing speeds for solving part 2
I had not even thought of using Excel for this. Amazing, what one can do with all the various “programming” options.
The most impressive ones to me are the solutions made with APL.
For example, for the first day, they looked like this:
x←<input>
s←(+/⍎¨)¨(' ' (≠⊆⊢)¨(∊1 (' ' ⍷ x))⊂x)
⌈/s
+/s[(⍒s)[1 2 3]]
(by @codehag@mastodon.social)
and:
(⊂1 3)⌷+⍀(⊂∘⍒⌷⊢)(+/⍎¨)¨((×≢)¨⊆⊢)⊃⎕nget'day1.txt'1
(https://iosdev.space/@xavier@hachyderm.io)
Crazy, huh?
Just joined as RSW0000.
A few years ago, I started doing the Project Euler puzzles. I used Xojo for most of them, but for a couple of them, using either Excel or Filemaker was much faster.
Guess I’m not the only one who stayed up tonight.
It’s still early where I am.
I’m falling behind here only because I keep having to add new language features!
I’ve updated my day 1 code to use a faster iterative QuickSort algorithm.
Many thanks to @Kem_Tekinay and @Björn_Eiríksson for their help and suggestions.
Wouldn’t have been cognitive if I had stayed up that long. Set my alarm to get up, puzzle, back to bed
With the browser extension, I can see that the time to solve puzzle two was very close for the first 3 contenders. All between 8 and less than 10 minutes. I had to re-read the instructions probably 3 times before I understood them. If there were no examples given, I wouldn’t be able to even solve half of them, probably.
Moving this off-topic stuff to the ObjoScript-thread
You’re quite mad, you know…
My thoughts exactly. I realized later that I was wasting my time trying to understand the explanation, and should have gone directly to the example. I would have saved ten minutes on each puzzle.
Why did everyone but Kem take over 5 min to solve the second puzzle? It was just about switching the boundary comparisons. Kem understood that immediately, but us other three all too a lot longer.
In my case it was because I actually confused the comparisons and got a wrong result, which made me have to redo the conditions very carefully. (Also, I stayed up until 6am for this last night - I thought I was still thinking well, but apparently didn’t ). BTW, my code is near-identical to Kem’s. We both did the “includes” and “intersects” checks the same way. While coding, I had been considering to find my “Ranges” class from other projects which had this already nicely wrapped (and been tested) but thought this is so easy I just write it out myself. Had I picked up my functional class I might have gotten this right the first time
Meh, I admit it’s just a lame attempt at justifying my losing to Kem. (I’m a very competitive person)
I find that working through these puzzles helps me to solve similar problems in my professional life, but the reverse is true too. In this case, I had worked through this exact scenario for work some time ago.
And if I had to pick between us for an important project @Thomas_Tempelmann , I’d choose you, so let me have Advent at least.