ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Advent of Code 2023

Tue Nov 21, 2023 4:40 am

The American Thanksgiving holiday is this week. That means Advent will be next and that means Advent of Code.

https://adventofcode.com/

Interesting, this year comes with the request in which
Eric Wastl wrote: Please don't use AI / LLMs (like GPT) to automatically solve a day's puzzles until that day's global leaderboards are full. By "automatically", I mean using AI to do most or all of the puzzle solving, like handing the puzzle text directly to an LLM. The leaderboards are for human competitors; if you want to compare the speed of your AI solver with others, please do so elsewhere. (If you want to use AI to help you solve puzzles, I can't really stop you, but I feel like it's harder to get better at programming if you ask an AI to do the programming for you.)
What's clear from the above is that these puzzles are meant to help people get better at programming. That's why I'm posting this in the Teaching and Learning Resources forum. Hopefully, the good news about Advent will reach anyone wanting to learn more about programming.

Note the puzzles start out relatively easy with a difficulty that is generally increasing.

For reference Raspberry Pi forum threads from previous seasons are at

viewtopic.php?t=343515

viewtopic.php?t=293084

viewtopic.php?t=325236

I haven't decided what languages to use this year, but I think Julia will play a major role since I'm trying to use it for real work and more practice helps. Though possible

viewtopic.php?p=1937981#p1937981

Julia doesn't run fast on a Raspberry Pi Zero. Therefore, I'm expecting to do most of my Julia programming using a Raspberry Pi 3 or 4 running in 64-bit mode. It seems I won't have a Pi 5 in time for Advent.

There is an official Redit at

https://www.reddit.com/r/adventofcode/wiki/index/

That's a great resource when stuck on a problem. At the same time, I find the smaller Pi-focused community discussion here enjoyable. According to Fido the difference between Raspberry Pi and Redit is comparable to the difference between NASCAR and IndyCar racing. One is slower the other faster, but it's a matter of preference what each person prefers.

I'm looking forward to the first puzzle and finding out what the theme will be.

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Wed Nov 22, 2023 11:35 pm

ejolson wrote:
Tue Nov 21, 2023 4:40 am
Julia doesn't run fast on a Raspberry Pi Zero. Therefore, I'm expecting to do most of my Julia programming using a Raspberry Pi 3 or 4 running in 64-bit mode. It seems I won't have a Pi 5 in time for Advent.
Even though Julia doesn't run fast on a Zero, the dog developer insists that it should at least run. Unfortunately, since the old binary was built the Void Linux distribution has rolled on.

Code: Select all

$ julia
julia: symbol lookup error: /usr/local/julia-1.6.3/bin/../lib/julia/libpthread.so.0: undefined symbol: __pthread_cond_destroy, version GLIBC_PRIVATE
Last night I downloaded Julia 1.6.7 the latest long-term supported version and began a build using a 32-bit ARMv6 chroot on a Pi 4.

To Fido's dismay the build keeps halting since the new version of gcc generates warnings in cases where the old one didn't. This interacts with someone's idea of setting -Werror as one of the default build flags.

As a result I find myself changing things like

Code: Select all

MBEDTLS_FATAL_WARNINGS:BOOL=ON
to

Code: Select all

MBEDTLS_FATAL_WARNINGS:BOOL=OFF
amidst too much barking.

I'm starting to suspect this is a scheme to force me to upgrade the dog house with new Pi 5 kit. Is there a way to prevent the build system from setting -Werror and halting at every warning?

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Thu Nov 23, 2023 7:51 am

ejolson wrote:
Wed Nov 22, 2023 11:35 pm
I'm starting to suspect this is a scheme to force me to upgrade the dog house with new Pi 5 kit. Is there a way to prevent the build system from setting -Werror and halting at every warning?
I now have a Julia 1.6.7 binary that compiles the base library but then chokes at the very end on a malformed platform string. I vaguely remember something similar happening with version 1.6.3.

I've already applied the patches from

viewtopic.php?p=1850234#p1850234

as well as

viewtopic.php?p=1937929#p1937929

However, that wasn't enough and I can't find any more notes. Fido's been quietly growling about the inefficiency all afternoon.

Hopefully Julia will be ready by December 1.

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Sat Nov 25, 2023 6:31 am

ejolson wrote:
Thu Nov 23, 2023 7:51 am
Hopefully Julia will be ready by December 1.
Tails are wagging! Julia 1.6.7 is now working under Void Linux on a Pi Zero.

viewtopic.php?p=2161149#p2161149

As far as I know this may be the only build of Julia 1.6.7 for ARMv6.

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Tue Nov 28, 2023 5:40 pm

ejolson wrote:
Sat Nov 25, 2023 6:31 am
ejolson wrote:
Thu Nov 23, 2023 7:51 am
Hopefully Julia will be ready by December 1.
Tails are wagging! Julia 1.6.7 is now working under Void Linux on a Pi Zero.

viewtopic.php?p=2161149#p2161149

As far as I know this may be the only build of Julia 1.6.7 for ARMv6.
More happiness! Julia 1.6.7 now runs under the Bookworm release of Raspberry Pi OS on a Pi Zero.

viewtopic.php?p=2162018#p2162018

Is anyone else preparing for the start of Advent?

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Fri Dec 01, 2023 7:03 am

ejolson wrote:
Tue Nov 28, 2023 5:40 pm
ejolson wrote:
Sat Nov 25, 2023 6:31 am
ejolson wrote:
Thu Nov 23, 2023 7:51 am
Hopefully Julia will be ready by December 1.
Tails are wagging! Julia 1.6.7 is now working under Void Linux on a Pi Zero.

viewtopic.php?p=2161149#p2161149

As far as I know this may be the only build of Julia 1.6.7 for ARMv6.
More happiness! Julia 1.6.7 now runs under the Bookworm release of Raspberry Pi OS on a Pi Zero.

viewtopic.php?p=2162018#p2162018

Is anyone else preparing for the start of Advent?
Fido read the first puzzle and went to sleep. It looks like I'm on my own.

https://adventofcode.com/2023/day/1

The theme is about increasing the supply of snow. Maybe this can wait until tomorrow.

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Fri Dec 01, 2023 4:31 pm

ejolson wrote:
Fri Dec 01, 2023 7:03 am
The theme is about increasing the supply of snow. Maybe this can wait until tomorrow.
In the morning I had a discussion with the dog developer about the first star needed to increase the amount snow. My data looks like

Code: Select all

3fiveone
eightnineseventwo1seven
9h1xcrcggtwo38
nine4pvtl
seven7rsbqpgxtjzsgxssix
twofivethreepqgsvrszczrthree7
...omitted...
which is notable compared to the sample data because it contains English words for numbers.

Fido wants to create a general digit recognizer using deep learning that decodes numbers for all languages in anticipation of part 2. It's not working. As far as I can tell, the main difficulty is half the training data looks like someone typed bark into a file thousands of times. I mentioned that dog language is still too difficult for a large language model to understand, but the reply sounded like barking and I didn't understand either.

As a compromise, I've decided to ask ChatGPT to write the code which solves the problem, even though that was explicitly discouraged by the author of the puzzles.

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Fri Dec 01, 2023 4:49 pm

ejolson wrote:
Fri Dec 01, 2023 4:31 pm
As a compromise, I've decided to ask ChatGPT to write the code which solves the problem, even though that was explicitly discouraged by the author of the puzzles.
Upon asking ChatGPT 3.5 the question
Could you please write code in the Julia programming language that reads a text file. Each line consists of a string that encodes a calibration value. This value is obtained by combining the first digit and the last digit (in that order) to form a single two-digit number. For example, the string "1abc2" encodes to the value 12 while "pqr3stu8vwx" encodes the value 38. If only one digit appears in the string such as "treb7uchet" then the value is 77. The program should decode each line in the file and sum all the calibration values, then print the sum.
I received the output
ChatGPT wrote: Certainly! Below is an example Julia code that reads a text file, decodes each line based on the specified rules, calculates the sum of the calibration values, and prints the result:

Code: Select all

function decode_calibration_value(line::AbstractString)
    digits = [c for c in line if isdigit(c)]
    
    if length(digits) == 1
        return parse(Int, digits[1])*10 + parse(Int, digits[1])
    elseif length(digits) >= 2
        return parse(Int, digits[1])*10 + parse(Int, digits[end])
    else
        return 0  # No digits found
    end
end

function main(filename::AbstractString)
    sum_calibration_values = 0

    try
        open(filename, "r") do file
            for line in eachline(file)
                calibration_value = decode_calibration_value(line)
                sum_calibration_values += calibration_value
            end
        end

        println("Sum of calibration values: $sum_calibration_values")

    catch err
        println("Error: $err")
    end
end

# Replace "your_file.txt" with the actual file path you want to read
main("your_file.txt")
Make sure to replace "your_file.txt" with the actual file path you want to read. This code defines a function decode_calibration_value to extract and decode the calibration value from a given line, and a main function to read the file, decode each line, calculate the sum, and print the result. The program also handles potential errors, such as file not found or other IO-related issues.
Pasting the code into my Pi resulted in

Code: Select all

julia> include("gpt01.jl")
main (generic function with 1 method)

julia> main("day01.txt")
Sum of calibration values: 54968
and then
Advent of Code wrote: That's the right answer! You are one gold star closer to restoring snow operations.
Fido's tail is wagging, but somehow I'm in tears. ChatGPT solved the puzzle correctly in one try.

lurk101
Posts: 2552
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Advent of Code 2023

Fri Dec 01, 2023 7:50 pm

Have you tried it with part 2?

User avatar
DougieLawson
Posts: 42847
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: Advent of Code 2023

Fri Dec 01, 2023 8:06 pm

I found a couple of python solutions for day1 parts 1 & 2.
I was almost there with my RYO python but the two python mongers I found each used a more elegant solution.

Roll on day 2.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

User avatar
DougieLawson
Posts: 42847
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: Advent of Code 2023

Fri Dec 01, 2023 8:48 pm

ejolson wrote:
Fri Dec 01, 2023 4:31 pm

Fido wants to create a general digit recognizer using deep learning that decodes numbers for all languages in anticipation of part 2.
I found this for Fido

Image
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Fri Dec 01, 2023 10:52 pm

DougieLawson wrote:
Fri Dec 01, 2023 8:48 pm
ejolson wrote:
Fri Dec 01, 2023 4:31 pm

Fido wants to create a general digit recognizer using deep learning that decodes numbers for all languages in anticipation of part 2.
I found this for Fido

Image
Fido is whining that the image doesn't show. Fortunately, the link works when I paste it.

https://pbs.twimg.com/media/GASDF_HX0AAb_WY.jpg

I wonder why it didn't embed.

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Sat Dec 02, 2023 8:30 am

ejolson wrote:
Fri Dec 01, 2023 10:52 pm
DougieLawson wrote:
Fri Dec 01, 2023 8:48 pm
ejolson wrote:
Fri Dec 01, 2023 4:31 pm

Fido wants to create a general digit recognizer using deep learning that decodes numbers for all languages in anticipation of part 2.
I found this for Fido

Image
Fido is whining that the image doesn't show. Fortunately, the link works when I paste it.

https://pbs.twimg.com/media/GASDF_HX0AAb_WY.jpg

I wonder why it didn't embed.
Hm, it does embed on Chrome, just not Firefox. Maybe there is a missing certificate chain.

User avatar
RogerW
Posts: 412
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: Advent of Code 2023

Mon Dec 04, 2023 2:51 pm

Its very quiet in here. Is anyone else taking up the challenge?
I have only just cracked day 3 part 1nd am trying to get my head around part 2.

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Mon Dec 04, 2023 2:54 pm

RogerW wrote:
Mon Dec 04, 2023 2:51 pm
Its very quiet in here. Is anyone else taking up the challenge?
I have only just cracked day 3 part 1nd am trying to get my head around part 2.
I'm still here--just haven't had the time to work on the puzzles as other years.

lurk101
Posts: 2552
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Advent of Code 2023

Mon Dec 04, 2023 3:11 pm

RogerW wrote:
Mon Dec 04, 2023 2:51 pm
Its very quiet in here. Is anyone else taking up the challenge?
I have only just cracked day 3 part 1nd am trying to get my head around part 2.
I just enjoy solving the puzzles. Not really learning anything so I don't see the point of posting my code here since it's undocumented and usually fairly opaque. If anyone is interested I've been storing my solutions here. So far the problems this year have been more challenging than previous years.

Interestingly the Pi5 has performed slightly better than the more powerful rock5b and orange pi5 with these single threaded tasks!

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Mon Dec 04, 2023 5:05 pm

ejolson wrote:
Fri Dec 01, 2023 10:52 pm
Fido is whining that the image doesn't show. Fortunately, the link works when I paste it.

https://pbs.twimg.com/media/GASDF_HX0AAb_WY.jpg

I wonder why it didn't embed.
It seems the data dog graphic is targeted by the automatic add-blocking routine built into Firefox on Android. On desktop versions of Firefox without that feature enabled the graphic is displayed. Does anyone know where the setting is to turn it on and off?

Enquiring canines want to know.
Last edited by ejolson on Mon Dec 04, 2023 9:27 pm, edited 5 times in total.

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Mon Dec 04, 2023 5:24 pm

lurk101 wrote:
Mon Dec 04, 2023 3:11 pm
RogerW wrote:
Mon Dec 04, 2023 2:51 pm
Its very quiet in here. Is anyone else taking up the challenge?
I have only just cracked day 3 part 1nd am trying to get my head around part 2.
I just enjoy solving the puzzles. Not really learning anything so I don't see the point of posting my code here since it's undocumented and usually fairly opaque. If anyone is interested I've been storing my solutions here. So far the problems this year have been more challenging than previous years.
From ChatGPT's Julia solution to the first puzzle I learned the end keyword normally used to delimit a block of code can also be used as an array index.

I wouldn't have used a conditioned iterator as

Code: Select all

    digits = [c for c in line if isdigit(c)]
to build an array of digits. However, I like it.

Since Julia supports multiple programming paradigms, I suspect it compiles just-in-time down to something quite similar to a bunch of append operations inside a loop. Even so, being able to conveniently mix functional and procedural styles has tails wagging around here.

While I'm still surprised that ChatGPT solved the puzzle, I'm further impressed how the solution was factored into a decode_calibration_value routine called from a main routine. It was also nice to see error checking for the open function.

lurk101
Posts: 2552
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Advent of Code 2023

Tue Dec 05, 2023 5:59 pm

Hmm... Day 5 was as difficult as last year's most! Brute force approach is simple enough but takes 3 minutes to run. Not acceptable. Optimal algorithm runs under 1 ms. on Pi5.

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Wed Dec 06, 2023 6:39 am

lurk101 wrote:
Fri Dec 01, 2023 7:50 pm
Have you tried it with part 2?
I've now tried five times to tell ChatGPT how to modify part 1 to do part 2 but failed. Maybe I should have started a new session and explained how to do part 2 from the beginning. Interestingly, one time the AI indicated it had changed the code to remedy a difficulty I brought up but then produced the exact same code as before.
Last edited by ejolson on Wed Dec 06, 2023 10:13 pm, edited 1 time in total.

User avatar
bensimmo
Posts: 6812
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Advent of Code 2023

Wed Dec 06, 2023 6:49 am

ejolson wrote:
Wed Dec 06, 2023 6:39 am
lurk101 wrote:
Fri Dec 01, 2023 7:50 pm
Have you tried it with part 2?
I've now tried five times to tell ChatGPT how to modify part 1 to do part 2 but failed. Maybe I should have started a new session and explained how to do part 2 from the beginning. Interestingly, one time the AI indicated it had changed to code to remedy a difficulty I brought up but then produced the exact same code as before.
It's done that a few time for me as well, though asking for python code.

It is polite, says sorry and provides the 'corrected' but actually identical version as before. I guess it doesn't have a self-check for that, I think it needs to go away, meditate and reflect on its abilities and how it can improve and why it went wrong.

lurk101
Posts: 2552
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Advent of Code 2023

Wed Dec 06, 2023 5:30 pm

Day 6
Brute force - 80 ms.
Using a little calculus - 80us.

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Wed Dec 06, 2023 9:50 pm

ejolson wrote:
Wed Dec 06, 2023 6:39 am
lurk101 wrote:
Fri Dec 01, 2023 7:50 pm
Have you tried it with part 2?
I've now tried five times to tell ChatGPT how to modify part 1 to do part 2 but failed. Maybe I should have started a new session and explained how to do part 2 from the beginning. Interestingly, one time the AI indicated it had changed the code to remedy a difficulty I brought up but then produced the exact same code as before.
I gave in and finished day 1 myself.

Code: Select all

#=  Advent of Code 2023 Day 1 Trebuchet
    Written 2023 by Eric Olson =#

struct DoExit <: Exception
end

function english(a)
    ws=["zero","one","two","three","four",
        "five","six","seven","eight","nine"]
    for i=1:length(ws)
        w=ws[i]
        if length(a)>=length(w) &&
            a[1:length(ws[i])]==w
            return i-1
        end
    end
    return -1
end

function getdigits1(a)
    return [parse(Int,c) for c in a if isdigit(c)]
end

function getdigits2(a)
    d=[]
    for i=1:length(a)
        if isdigit(a[i])
            push!(d,parse(Int,a[i]))
        else
            r=english(a[i:end])
            if r>=0
                push!(d,r)
            end
        end
    end
    return d
end

function partn(data,getdigits)
    s=0
    for a in data
        d=getdigits(a)
        if length(d)>0
            s+=d[1]*10+d[end]
        else
            println("Error in $a: no digits found.")
            throw(DoExit())
        end
    end
    return s
end

function doinit()
    data=[]
    open("day01.txt","r") do fp
        data=readlines(fp)
    end
    p1=partn(data,getdigits1)
    p2=partn(data,getdigits2)
    println("Part 1 The sum of calibration values is ",p1)
    println("Part 2 The English calibration value is ",p2)
end

function main()
    t=@elapsed try
        println("Advent of Code 2023 Day 1 Trebuchet\n")
        doinit()
        throw(DoExit())
    catch r
        if !isa(r,DoExit)
            rethrow(r)
        end
    end
    println("\nTotal execution time ",t," seconds.")
end 

main()
Fido is barking mad and claims the style looks like Fortran. I pointed out the getdigits1 routine that I learned from ChatGPT, but there was more barking. The output on an Intel i3-550 was

Code: Select all

$ julia day01.jl
Advent of Code 2023 Day 1 Trebuchet

Part 1 The sum of calibration values is 54968
Part 2 The English calibration value is 54094

Total execution time 0.289618602 seconds.
which includes the just-in-time compilation.

lurk101
Posts: 2552
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Advent of Code 2023

Fri Dec 08, 2023 3:33 pm

For day 8 what would be more interesting than solving the problem would be figuring out the algorithm used to create the problem input data!

ejolson
Posts: 12155
Joined: Tue Mar 18, 2014 11:47 am

Re: Advent of Code 2023

Fri Dec 08, 2023 4:24 pm

lurk101 wrote:
Fri Dec 08, 2023 3:33 pm
For day 8 what would be more interesting than solving the problem would be figuring out the algorithm used to create the problem input data!
I'd like to generate more data and scale the problem up for lots of the puzzles so the computation is large enough a parallel algorithm could be efficient.

Return to “Teaching and learning resources”