Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8597

Teaching and learning resources • Re: Advent of Code 2025

$
0
0
To me Hare looks like Go with extra semicolons but no garbage collection. For that reason I'll use Purr's code as a basis for my program.
My Go solution for Day 3 runs as

Code:

$ ./day03-go # Pi 5Advent of Code 2025 Day 03 Lobby (go)Part 1 The 2-cell joltage is 17346Part 2 The 12-cell joltage is 172981362045136Total execution time 0.00029476 seconds.
from the code

Code:

/*  Advent of Code 2025 Day 03 Lobby (go)    Written December 2025 by Eric Olson */package mainimport("fmt"; "os"; "time"; "bufio")var tictime time.Timefunc tic(){    tictime=time.Now()}func toc() float64 {    now:=time.Now()    elapsed:=now.Sub(tictime)    return elapsed.Seconds()}func selectm(s []int,m int)int64 {    n:=0; r:=int64(0)    for l:=m-1;l>=0;l-=1 {        c:=-1        for i:=n;i<len(s)-l;i+=1 {            b:=s[i]            if c<b { c=b; n=i+1; }        }        r=r*10+int64(c)    }    return r}func dowork(){    fn:="day03.txt"    fd,err:=os.Open(fn)    if err!=nil {            fmt.Fprintf(os.Stderr,"Unable to open %s for input!\n",fn)        os.Exit(1)    }    defer fd.Close()    fp:=bufio.NewScanner(fd)    p1:=int64(0); p2:=int64(0)        ds:=make([]int,0,128)    for fp.Scan() {        s:=fp.Text()        ds=ds[0:len(s)]        for i:=range s {            ds[i]=int(s[i])-int('0')        }        p1 += selectm(ds,2)        p2 += selectm(ds,12)    }    fmt.Printf("Part 1 The 2-cell joltage is %d\n",p1)    fmt.Printf("Part 2 The 12-cell joltage is %d\n",p2)}func main(){    fmt.Printf("Advent of Code 2025 Day 03 Lobby (go)\n\n")    tic()    dowork()    t:=toc()    fmt.Printf("\nTotal execution time %.6g seconds.\n",t)    os.Exit(0)}
It's pretty much a literal translation of the Hare code.

Now that all the programs are written the kittens want a graph. I'd be surprised if it looked any different than the Day 1 results. At the same time, it shouldn't be difficult to make another graph.

Statistics: Posted by ejolson — Sun Dec 07, 2025 4:29 am



Viewing all articles
Browse latest Browse all 8597

Trending Articles