#Advent of Code 2022

1 messages Β· Page 1 of 1 (latest)

trail hemlock
#

The Advent of Code 2022 is happening in just a few days!
https://adventofcode.com

@red pelican created a private leaderboard for this server.
Private advent of code 2022 leaderboard code:

2265237-0f8ae43d

You can join if you log in here https://adventofcode.com/2022/leaderboard and click the private leaderboard joining option!

Tell everyone in what language you're gonna do it! Personally I think I'm still gonna go with Rust, like I did in 2020 :)
Or maybe you have a different gimmick, like focusing on some kind of pretty visualisation of the problem after solving it ? πŸ‘€

nova mango
#

I'm gonna go with Kotlin, I think it has a lot of things that would be useful here

mental owl
#

i'll try to do it with rust i think

#

this time around there are no exams to distract me from it

tardy barn
#

I'm doing last year's with Rust, it's so much fun

red pelican
#

I havent done advent of code before, 100% doing it with rust

#

might be partially busy with school work but I know im going to have some time for it regardless

tardy barn
#

^^

modern delta
#

I was thinking of doing it for the first time, and use rust as a training exercise !

red pelican
#

aw this is in the advent of code HTML head ```Oh, hello! Funny seeing you here.

I appreciate your enthusiasm, but you aren't going to find much down here.
There certainly aren't clues to any of the puzzles. The best surprises don't
even appear in the source until you unlock them for real.

Please be careful with automated requests; I'm not a massive company, and I can
only take so much traffic. Please be considerate so that everyone gets to play.

If you're curious about how Advent of Code works, it's running on some custom
Perl code. Other than a few integrations (auth, analytics, social media), I
built the whole thing myself, including the design, animations, prose, and all
of the puzzles.

The puzzles are most of the work; preparing a new calendar and a new set of
puzzles each year takes all of my free time for 4-5 months. A lot of effort
went into building this thing - I hope you're enjoying playing it as much as I
enjoyed making it for you!

If you'd like to hang out, I'm @ericwastl on Twitter.

  • Eric Wastl```
trail hemlock
#

yeah :D

tardy barn
#

That's so cool
This whole event is so nice, I'm glad it exists

near steppe
#

I do AoC in javascript typically because I'm strong with the lang, and its dynamic nature helps with quick typing since I try to compete fr. This year I resolve to do a Rust rewrite each day, so I can practice rust without having to worry about understanding the problem at the same time

delicate basalt
#

i'll prob do it in python since i'm not really familiar with rust

trail hemlock
delicate basalt
#

too scared to leave my comfort zone sunglasses_crying

trail hemlock
#

Why do the advent of code then? :(

#

(I'm kidding, you don't need to get out of your comfort zone, but still, it's a great opportunity to do so)

#

Ok better phrasing: why are you scared to leave your comfort zone?

delicate basalt
#

not sure

tardy barn
#

Who isn't?

trail hemlock
#

I guess you've got a point :v

#

but like idk, I'd try if that's what I wanted to do at some point, AoC would be a perfect opportunity xd

mental owl
#

@amber siren 🐝

amber siren
marble stream
#

o/

red pelican
marble stream
#

ok

#

im just doing the 2015 one

#

cos ill probably just do 2 or 3 puzzles then give up

marble stream
#

ive done the first 4 days of 2015 in c

marble stream
#

im stuck on 2015 5.2

#

lol

marble stream
#

:w

#

om

#

omg

tardy barn
mental owl
#

😭

#

it won't let us leave

marble stream
#

lmao

#

i need to stop wroking on this puzzle because

#

im getting annoyed LOL

tranquil ether
trail hemlock
#

daaaaamn

tardy barn
#

Nice!

mental owl
#

i wonder if there'll be someone doing aoc in brainfuck

marble stream
#

I think it could be fun for like

#

The first day

mental owl
#

yeah

marble stream
#

I am a terrible programmer I am just on the sixth day of 2015 in C

mental owl
#

when this aoc starts we can horribly fail in parallel

marble stream
#

Lol ok

#

I love C Tbh

#

U just let it RIP

livid pier
#

I want to do it in Rust, but I kinda just want to do it quick and dirty in python like I usually do, then make it pretty in Rust

#

1-25 December is python, then 1-25 January is Rust πŸ˜„

I will venture to do it in Rust for as long as I can reasonable abide, if it feels dreadful then I might switch over midway

#

I've already started doing some re-writes for past years and have updated my repo.

So I have a nice filestructure already ready for it if I feel the need to switch back and forth but I'm going to give it an honest attempt at Rust from the start

near steppe
#

1-25 December is python, then 1-25 January is Rust πŸ˜„
yeah I'm feeling that too, but I know I won't end up doing 1-25 January in Rust :(

livid pier
#

OH man it starts at midnight US East. Tragic.

tardy barn
#

Starts <t:1669870740:R>!

mental owl
#

it's here

modern delta
#

Oh no it’s December already

mental owl
#

yeah this terrible year is coming to an end

crude juniper
#

I'm giving it a go in Rust! but will fall back to Python if my inexperience makes a particular day take too long

red pelican
#

time to do the first task

mental owl
#

mu first task went like this so far
#newbie-advice message

#

i want to do aoc in something that isn't my daily comfort language but life is fucking me over the second i want to step out :(

red pelican
#

both parts done

#

im also practicing/learning vim at the same time which is fun

#

im getting access to the input like thisrs static INPUT: &str = include_str!("input.txt");

mental owl
#

fuck it i'm doing it in c# unless/until i get other option fixed

#

better than not doing it

nova mango
#

I'm building a tool that automatically runs the code when a file changes and checks against the examples provided

#

with Kotlin

tardy barn
#

Help
I think I'm fundamentally misunderstanding the puzzle
(Part 2)

#

Neither one works

mental owl
#

that seems...wrong

red pelican
trail hemlock
#

aight time to start

tardy barn
#

Huh

#

That's so much easier

#

I don't understand why my very-backwards-and-dumb method doesn't work though

mental owl
#

iters are good shit

zealous tulip
#

Sigh I might do it in rust even though I have mock exams

mental owl
zealous tulip
#

I'm pretty happy with day one

livid pier
#

This was my solution in Rust

#

My friend made fun of me because I added error handling. 😦

tardy barn
#

Imagine doing error handling
Hah
bullies

zealous tulip
livid pier
#

Yeah I was going to do unwrap_or(0) or something like that, but I wanted to know WHEN an error happened as well rather than just kind of ignoring it. Which showed me that ||it didn't like the end of file area which was what lead me to adding the trim() on the initial split||

#

I appreciate the recommendation though!

zealous tulip
#

||ngl I thought the end of the file was my copying and pasting incorrectly so I removed it 😬 ||

zealous tulip
livid pier
#

||I wasn't sure if it was or wasn't but I thought "hey bit of serendipity, I now have an edgecase I have fixed"||

#

Highly respect your solution to that problem though

#

✍️ "look up split_terminator"

zealous tulip
#

Idk if my solution for the 2nd is that good of a idea due the fact I iterate a lot

#

I'd benchmark mark it versus ||vec.sort();vec.reverse();|| but eh

livid pier
#

I'd like to see the results.

zealous tulip
#

fine πŸ™„

zealous tulip
#

@livid pier it is only slightly faster

livid pier
#

Hahaha only a little bit

zealous tulip
#

though this gives me a idea...

#

||the idea was terrible (I was sorting the top_3 vector), .sort is REALLY slow huh||

zealous tulip
livid pier
#

I was goign to say

zealous tulip
#

that's really big, huh

livid pier
#

What are you using for benchmarking

zealous tulip
#

criterion

#

very good

livid pier
#

I figured

red pelican
zealous tulip
#

trueee

#

very good point

#

though that won't help me much since I want to replace the new lines

#

those were so annoying

#

technically for solving this EXACT input \r\n works

#

but i'd rather not

zealous tulip
#

which is handy

livid pier
# zealous tulip criterion

Going to do the same with my code. Current implementation and the first "just do it as fast as possible" and see if i did optimise it or if I just did the same thing but with more complex looking code

zealous tulip
#

If I had set up my stuff correctly I could have had criterion look at the change in performance over time as I try to improve a function

livid pier
#

Its insane how much the prints take.

I ran a bench with the println! and got 207.18 Β΅s
I ran a bench with removing and got 83.829 Β΅s

zealous tulip
#

it does a lot!

#

and we are talking microseconds here

zealous tulip
livid pier
zealous tulip
#

true

#

I wonder why mine is so much higher

#

I am not printing anything

livid pier
zealous tulip
#

oops

livid pier
#

I was like oh man you did yours in 530 nano seconds 😒

zealous tulip
#

I was benching these two things

livid pier
#

Ahhhhh

#

I removed the reverse (and just took the last 3 values at the end of the vector) and it took 82.579 Β΅s down to 73.326 Β΅s

zealous tulip
#

oh yeah

livid pier
#

So the reverse was worth about 9 microseconds

zealous tulip
#

let me bench that rq

#

517.98 ns vs 5.8426 Β΅s

#

hrm

#

maybe if I pass in a vector directly

#

actually let me test these two approaches in the scope of the whole thing

livid pier
#

Proud of that. Final implementation without the reverse vs the intial implementation (no prints for either)

zealous tulip
#

can you show source code?

#

now that I tweaked some things I am getting the result that sorting the vec is better

#

I am doing this

mental owl
#

(the benchmarking)

zealous tulip
mental owl
#

i mean, how are you benchmarking it?

zealous tulip
#

ah

mental owl
#

never bothered to benchmark before, was gonna see how mine was doing

zealous tulip
#

criterion

mental owl
#

can you share the setup?

#

im trying and feeling confused

#

or maybe i'm being stupid...

zealous tulip
#

you need to have a folder in the root of your project

#

then have

[[bench]]
name = "name of where your benchmarks will be inside /benches"
harness = false
#

wait nohrm

#

edited to fix

mental owl
#

yeah i got that bit

#

tbh what i can't figure out is how to access my crate

#

which seems stupid

zealous tulip
#

huh?

#

ohh

#

your crate needs to be a lib

#

well, I don't think so

#

but you can just import it with it's name

mental owl
zealous tulip
#

I use a separate project to put all my

#

benchmarks in

mental owl
#

is there a way to get criterion to just benchmark my tests? cargo bench does but it's not exactly, uh, detailed information

zealous tulip
#

no :(

mental owl
#

annoying

#

meh, whateer

zealous tulip
#

can you give me your function

mental owl
#

is on the gitlab i posted earlier but its a bit of a mess because im trying to keep both the first and second parts around

zealous tulip
#

ah

#

I am benchmarking both of them

mental owl
#

πŸ˜† looks like println! isn't really the problem in mine

#

its just slow in general

zealous tulip
mental owl
#

...
...
sed

zealous tulip
#

if only I was on linux

#

also does it really count if we are modifying the input

#

before testing

#

ignore how doing it at compile time technically also does that

mental owl
#

i was considering just changing the input to just be able to be include!ed by setting it up as an array

#

it didn't work but was a fun thought

livid pier
#

Deleted because I read it wrong

zealous tulip
livid pier
#

Thought you could spoiler code

zealous tulip
#

nope

#

weirdly

livid pier
#

Thats my final implementation with no reverse and prints included

zealous tulip
#

these are my final 2 with the performance improvement being from handling windows lines directly

#

to note the lines is slower then calling directly split_terminator("\r\n")

#

this is because what lines does under the hood is call split_terminator('\n') and then a map which removes all \r at the end of the function

#

this causes a 10 Β΅s difference for me

mental owl
#

is there a non-mutating sort() in std?

#

(as in, so that it can be chained)

zealous tulip
#

As far as I know, no

mental owl
#

or is there a way to sort a const vec

zealous tulip
#

doing things in constant is so frustrating

#

it's what I imagine working without standard feels like but probably much better in reality

#

Upon further realisation I think the reason why I went down this weird road for my code initially was because I thought that all my previous code for the first solution was pretty good and so did not think about how I could optimise both solutions together but instead just solution 1 and 2 separately

#

My first solution would be good if I wasn't measuring running both solutions at once

livid pier
zealous tulip
#

hmmm

livid pier
#

Ran it back to back like 7 times and it seems to be all around the 66 microseconds vs 69

red pelican
mental owl
#

yeah I'm trying to not use external crates

zealous tulip
#

Time to use the aoc_2022 crate /j

red pelican
mental owl
#

fun

zealous tulip
#

i was doing to use urq but then I realised authentication for it existed

mental owl
# red pelican Why?

i mean, the implementation is just

trait Sorted<T: Ord> {
   fn Sorted(self) -> Self
}

impl<T: Ord> Sorted<T> for Vec<T> {
   fn sorted(self) ->  Self {
       self.sort();
       self
   }
}

but yk

#

(written on phone might be wrong but my point stands)

delicate basalt
#

who's the one anon lol

#

i feel like being anon is pretty pointless because:
there's only 1
everyone on the board is likely following this thread

crude juniper
#

This was my go!

#

It's the first Rust program I've written from scratch (i.e. not a rustling) so any advice much appreciated πŸ™‚

zealous tulip
#

Especially since you are already sorting them

crude juniper
#

Thx πŸ™‚

zealous tulip
#

Do you have to reverse it πŸ€”

crude juniper
#

I suppose not

#

Is there a quick way to do indexes-from-the-end?

zealous tulip
#

I don't think so

crude juniper
#

I'm used to Python having negative indexes, but it doesn't seem to be a thing in Rust

#

So I guess I just need to grab the length, and use that

#

fn main() -> anyhow::Result<()> {

    let mut elf_calories_sum: Vec<i64> = include_str!("calories.txt")
        .split("\n\n")
        .map(|s| 
            s.split('\n')
            .map(|y| y.parse::<i64>().unwrap())
            .sum()
        )
        .collect();
    elf_calories_sum.sort();

    let final_index = elf_calories_sum.len() - 1;
    let part1: i64 = elf_calories_sum[final_index];
    dbg!(part1);
    let part2: i64 = elf_calories_sum[final_index] + elf_calories_sum[final_index-1] + elf_calories_sum[final_index-2];
    dbg!(part2);
    
    Ok(())
}

Like that!

zealous tulip
#

Hnmm

#

For part 2 I used a iterator over a range instead of getting them one by one

#

But maybe this one is faster (it probably is)

#

I'd bench it if I wasn't in my bed

crude juniper
#

Like so?

let part2: i64 = elf_calories_sum[..3].iter().sum();
zealous tulip
#

Yep

crude juniper
#

Oh that's makes a different number!

#

I'm at the wrong end of the array

zealous tulip
#

Ah yes the range is wrong

#

Yep

#

It'd need to be the length - 3

#

And the length not the final index

crude juniper
#
let part2: i64 = elf_calories_sum[final_index-2..].iter().sum();
zealous tulip
#

Hmmm

crude juniper
#

That does the trick!

zealous tulip
#

While it's cleaner it probably has some performance downside

crude juniper
#

I'd definitely use the iter if they wanted many more than the first 3!

#

What do you use to benchmark?

zealous tulip
#

Criterion

#

I am getting out of bed for this I NEED to know

crude juniper
#

I need to do a clothes wash before I hit the hay, but will try Criterion when back

zealous tulip
#

the possible TINIEST difference

#

I will rerun with a higher sample size

crude juniper
#

Wow that's close!

zealous tulip
#

newer results prove they are pretty much the same

crude juniper
#

That's good to know for the future

#

and Criterion looks cool! I'll be experimenting with that tomorrow

#

Also the getting_started page having a benchmark with values in picoseconds!! 0_o

zealous tulip
#

Well if the time was longer it'd need to be a more complicated example

zealous tulip
#

this is a sample size of 100 and a measurement time of 1 minute

#

I will now rest

zealous tulip
livid pier
zealous tulip
#

To me the final index variable is more intuitive

#

But it's not intuitive when you do it with ranges since it uses count not length

mental owl
#

I cheated in d1t2 by using .net Framework builtin types

red pelican
frank cairn
#

my solution is currently

use std::fs;

fn main() {
    let f = fs::read_to_string("aocinput").unwrap();
    let mut elves = Vec::new();
    for elf in f.split("\n\n") {
        let mut r = Elf { food_items: Vec::new() };
        for food_item in elf.split("\n") {
            if let Ok(x) = food_item.parse() {
                r.food_items.push(x);
            }
        }
        elves.push(r);
    }
    println!("{}", answer(elves));
}

struct Elf {
    food_items: Vec<u32>,
}

fn answer(elves: Vec<Elf>) -> u32 {
    most_calories(elves)
}

fn most_calories(elves: Vec<Elf>) -> u32 {
    let mut amount = 0;
    let mut best_three = [(0usize, 0u32); 3];
    let mut max = u32::MAX;
    for best in best_three.iter_mut() {
        let mut current_best = (0usize, 0u32);
        for (i, elf) in elves.iter().enumerate() {
            let mut count = 0;
            for food_item in &elf.food_items {
                count += food_item;
            }
            if count > current_best.1 && count < max {
                current_best = (i, count);
            }
        }
        *best = current_best;
        max = current_best.1;
        amount += current_best.1;
    }
    amount
}
#

it runs in linear time sunglas

trail hemlock
dapper abyss
#

iam done

#

--------Part 1--------- --------Part 2---------
Day Time Rank Score Time Rank Score
1 >24h 134535 0 >24h 129276 0

#

took like an hour in steep2learn :rust:

red pelican
modern delta
#

I kinda want bigger inputs for day 2 so I can MULTITHREAD IT

red pelican
#

and used let else once πŸ™‚

livid pier
#

Ah I see

#

--------Part 1-------- --------Part 2--------
Day Time Rank Score Time Rank Score
2 06:47:42 61256 0 06:59:11 56633 0
1 05:57:32 46160 0 06:18:57 45036 0

livid pier
#

Part 1: (Ugly)|| (This is the function to calculate the score for an individual line, the rest is just a loop and print lines to display the score)||

#

Part 2: || The same but have just updated the arms of the match statements ||

livid pier
#

Changed essentially 3 lines and got a 45% performance gain

#

||I moved the splitting string to a vector out of the functions and did it once in the loop and passed the vector as a parameter to the get_score functions||

red pelican
livid pier
#

Now that's hot

frank cairn
#

should probably show my result

#

its very idiomatic as in it makes invalid states unrepresentable by using enums for everything

#

one moment

frank cairn
#

this is for part 2

red pelican
#

cool, you did a lot differently to me but both are good

livid pier
undone creekBOT
#
Critical error:

You must provide a valid language or compiler!

;compile c++
```
int main() {}
```

frank cairn
livid pier
#

Ah

frank cairn
undone creekBOT
#
Critical error:

Unable to find compiler or language for target 'rs'.

livid pier
#

Does that code compile on your side?

frank cairn
#

;compile rust

undone creekBOT
#
Critical error:

You must attach a code-block containing code to your message or quote a message that has one.

frank cairn
frank cairn
undone creekBOT
#
Critical error:

Unable to find compiler or language for target 'rs'.

livid pier
frank cairn
#

Huh

#

just exchange the two score += lines

red pelican
frank cairn
#

not needed

#

just exchange the two lines

mental owl
#

groans yk when it works on the test input but not on the actual one?

#

yea i had that too

#

(i was stupid and mixed up int values for enums)

#

but like... how do i /debug/

#

as a c# pleb i get the benefits of breakpoints

#

uwu

red pelican
#

Ive gotten all 4 correct on the first go so far by just making sure my logic is right

zealous tulip
frank cairn
#

#1044250755953078312

zealous tulip
#

that is indeed the channel

mental owl
#

mmm yes the channel here is made out of channel

frank cairn
#

oh

#

i thought this was off topic because i am very stoopid

#

sorry

mental owl
#

u irl

frank cairn
#

this boi is so cute

mental owl
#

if only I allowed myself access to external crates :(

#

(for part two)

#

probably could do the same for part one (by that I mean absolutely i could) but this was easier because I don't have to deal with two options

zealous tulip
#

they are being unwrapped either way

#

and_then is also a thing if you wanted to handle at once

crude juniper
#

I'm not sure how I'd approach the problem if there were many more than 3 states for tool/game outcome each.

red pelican
frail slate
#

hi i joined

crude juniper
#

and I agree about id_to_tool

red pelican
#

my day 3 solution for both parts ||https://pastebin.com/zd98VVpM 52 lines of code when not including unit tests.||
steadily getting better at vim, this is very good practice

#

hmm let me test how fast it is

#

around 270 microseconds with file reading and printing not included

#

oh 75 microseconds by just removing my use of ||hashset||

#

not worth it for sets this small

frail slate
#

consider using || hashet::intersection || lol

#

|| its kinda funny that you used sets and then didn't use them at all ||

red pelican
red pelican
frail slate
#

tbf i just || collected back into a hashset and did another intersection lmao ||

#

ok well idc about speed

red pelican
#

it seems to me that use of ||HashSet|| isnt anywhere near worth it for this small scale stuff

frail slate
#

fair enough

#

but basically all of the functions i needed were implemented already

red pelican
zealous tulip
#

||Chunks was VERY useful for the 2nd one, though it requires I collect the lines into a vec :/||

frail slate
#

|| i used itertools so i didn't need to collect but that probably wasn't that beneficial anyway ||

zealous tulip
modern delta
zealous tulip
#

I have yet to use a for loop for advent of code

#

I think I will try to make all of them loopless

modern delta
#

That's a cool challenge

mental owl
#

yall doing some weird rust challenges adjacent to it and I'm just wondering when I'll drop dead with my c#

modern delta
#

my goal is only trying to complete the AOC in rust

#

I'm glad that it enables me to get some practice with day to day stuff I need to master

mental owl
#

did AoC with a splitting headache

#

look at me go

#

(and by that i mean it was some /shitty/ code)

#

you should return to bed

#

probably tbh

#

you should do the tired loafy NOW

#

be healthy or else πŸ”ͺ

zealous tulip
# zealous tulip ||Chunks was VERY useful for the 2nd one, though it requires I collect the lines...

when looking at what https://youtu.be/yBJJYkC5cdk did I found him using the nightly array_chunks which is actually better since it gives a array and not a slice over them which means you can deconstruct them in a map (and it also works on iterator)

red pelican
#

why does length 0 even need to be an error?

zealous tulip
#

well

#

x / 0 chunks....

red pelican
#

actually I was thinking of it in terms of array_windows instead for some reason, where it always advances by one so my bad

#

asking about it here in the rust community discord #818964227783262209 message

zealous tulip
#

let me just join that real quick

red pelican
#

I have almost 6k messages there

zealous tulip
#

I know of the discord I just do not like to stay in big ones

red pelican
#

Ok

livid pier
#

Are you all doing yours in one rust source folder? or are you doing cargo new day-01 / day-02 etc for each day?

#

If the former, are you using a lib or a binary?

zealous tulip
#

I'm doing it as a binary

livid pier
#

I knew my code editor looked weird. like no indication on types of things and i thought I broke something

#

Its because im in one folder, that has my folders of daily solutions in it

#

so there is no "workspace" for the rust analyzer to detect stuff from

zealous tulip
#

you can make a workspace if you want one

#

make a Cargo.toml in the root folder and then do something like

#

this will make your target folder be in the root too

tardy barn
#

I have an Advent-of-code folder with a default cargo project inside of it, then an alias that makes the day-x project

frail slate
livid pier
zealous tulip
#

damn

#

My manual effort has gone to waste!

livid pier
#

Saved me though

#

Unfortunately rust analyzer still unhappy

zealous tulip
#

what's the error?

livid pier
zealous tulip
#

hm, idk

#

maybe restart vscode

livid pier
#

Nah, I'll just do something else. Going to just put it all in one folder

#

I did the google trick and copy pasted and no solution worked for me so far and its like 1 am so really just going to sack it off haha

livid pier
#

(I didn't bin it off) I figured it out

#

Thank you for the help πŸ™‚

#

Now everythings a lot nicer

crude juniper
#

I much prefer how you found the priorities @zealous tulip, I was looking for a way to do that (char as u32) conversion but couldn't work it out!

zealous tulip
#

Yours is a bit more intuitive

livid pier
#

That is my solution for part 1, part 2 and the helper function I used

marble stream
#

im doing day 7 of 2015

#

i think my approach will work but holy moley i am bad at coding

tardy barn
#

Mooood

crude juniper
#

Converting a bool directly to int for a oneliner function feels bad...somehow? But altogether the code run in ~7micoseconds without prints, so I'm happy πŸ˜›

tardy barn
#

Here's my day 4 utter and absolute spaggheti

#

It's such trash

#

BUT

#

It works

frail slate
#

why do you || collect || so much 😭

zealous tulip
frail slate
#

shit i wanted to use || split_once|| but i didn't find that function 😭

zealous tulip
#

oooof

#

it's very nice apart from the ||tuple deconstruction hell, I was going to use ranges but then I realised that wasn't needed for challenge two (or well I couldn't find a helper function which does contains on two ranges)||

frail slate
#

|| i made one of the ranges an iterator, and found whether each value iterated is contained in the other range ||

zealous tulip
#

||yeah that was like what was happening last day so I wanted to not do it again||

zealous tulip
tardy barn
tardy barn
#

(Suggestions to de-spaghetti-fy are very welcome)

zealous tulip
tardy barn
#

Ohh
i forgot what it was called but I knew it existed
Thanks

modern delta
zealous tulip
#

Isn't from_str_radix(input, 10) the equivalent to from_str(input) πŸ€”

#

and thusly from_str(input) is the equivalent to input.parse()

modern delta
#

maybe

#

i'm still new to rust

zealous tulip
#

it seems like they do use from_str_radix(src, 10) to implement FromStr using a macro for all integer types

modern delta
#

I'm definitely using from_str_radix directly to save compile time /s

zealous tulip
#

mhuahaha

red pelican
#

runs in about 100 microseconds on my computer, without file reading and printing

#

I should have used ||RangeInclusive, not Range|| tbh

zealous tulip
#

I mean you don't need to use a range at all

red pelican
#

;compile rs fn main() { dbg!(std::mem::size_of::<std::ops::RangeInclusive<u32>>()); }

undone creekBOT
#
Compiler Output
[/app/example.rs:2] std::mem::size_of::<std::ops::RangeInclusive<u32>>() = 12
zealous tulip
#

huh

tardy barn
#

Wha

red pelican
#

its a shame, one of the worst rust std design decisions that made it to stable

#

ranges directly implement the Iterator trait. that makes them bad at being just ranges, they should be only IntoIterator

zealous tulip
#

;compile

fn main() {
    dbg!(std::mem::size_of::<std::ops::Range<u32>>());
}
undone creekBOT
#
Compiler Output
[/app/example.rs:2] std::mem::size_of::<std::ops::Range<u32>>() = 8
zealous tulip
#

an extra 4 πŸ€”

#

why

red pelican
#
pub struct RangeInclusive<Idx> {
    // Note that the fields here are not public to allow changing the
    // representation in the future; in particular, while we could plausibly
    // expose start/end, modifying them without changing (future/current)
    // private fields may lead to incorrect behavior, so we don't want to
    // support that mode.
    pub(crate) start: Idx,
    pub(crate) end: Idx,

    // This field is:
    //  - `false` upon construction
    //  - `false` when iteration has yielded an element and the iterator is not exhausted
    //  - `true` when iteration has been used to exhaust the iterator
    //
    // This is required to support PartialEq and Hash without a PartialOrd bound or specialization.
    pub(crate) exhausted: bool,
}```
zealous tulip
#

bruh

tardy barn
#

Lmao

red pelican
#

specialization would be great, even a limited version of it

#

specialization is basically the ability to have a blanket implementation and another implementation overlap

zealous tulip
red pelican
#

afaik my cpu is pretty good but gpu is not

zealous tulip
#

who even needs gpu

#

what am I going to do with a fancy gpu! run factorio at a slightly higher quality???

frail slate
#

for Range it makes no sense

#

for RangeInclusive i dont understand the extra field

zealous tulip
#

I made a alternative way to parse the input which is very funky

red pelican
#

how do you tell when to stop iterating

frail slate
#

hmm

#

fair enough then

frail slate
#

that's what i did lol

red pelican
#

what I did||rs fn parse_line(line: &str) -> Option<(Range<u32>, Range<u32>)> { let mut iter = line.split(['-', ',']).flat_map(|s| s.parse().ok()); let ranges = ( iter.next()?..iter.next()? + 1, iter.next()?..iter.next()? + 1, ); if iter.next().is_some() { return None; } Some(ranges) }||

zealous tulip
#

idk I like working with the tuples

#

repeatably calling .next feels a bit jank

frail slate
#

its only twice

zealous tulip
#

true, ||but you are flattening everything and then I assume chunking it back into pairs||

frail slate
#

yeah but || i used Itertools which chunks back into an iterator so i had to do .next() anyway lmao ||

zealous tulip
#

ahhh

#

dammit I need array_chunks in my life

zealous tulip
livid pier
#

Day 4 - Part 1 and 2 solutions

#

This is my string to int converter function that I threw together just to look a little nicer

frail slate
zealous tulip
#

nom nom nom

mental owl
#

CUTE

#

waa i didnt do yesterdays one

frail slate
#

today's puzzle was really fun

#

relevant to the discussion before

red pelican
#

nice, to switch to solving part 2 of day 5, I only had to ||remove a single .rev()||

zealous tulip
#

Tfw I get frustrated with nom and then ask openai to give me a clue

#

and it gives something more informative then 10 minutes of googling

zealous tulip
dapper abyss
#

i know i am late : rubberduck: but i think that a games is for 3 rounds does not matter for the overall score, does it?

#

day2

mental owl
#

.net standard library has Too Much Shit

#

week 1 gonna be autosolved by Framework Types for me

#

maybe i should have started doing this in netstandard

#

just to spice things up

mental owl
#

got to today's tasks

#

parsing input looks annoying, everything else not so much

zealous tulip
#

I am currently in nom hell

frail slate
#

nom was so good

#

some of the functions are weirdly named so I struggled to find them

zealous tulip
#

i like using it A LOT

#

it's just the learning curve is getting to me

frail slate
#

it's not too bad, it's just HOFs

zealous tulip
#

I messed up ||because I realised I actually needed to make the crate parsing function return a Option<char> so that the vector positions match the actual position||

frail slate
#

|| i just used the space character lol ||

zealous tulip
#

||hm, I think i'll keep it as a option for reasons||

red pelican
zealous tulip
#

indeed

#

I have so much aoc stuff to explore after this is done

red pelican
#

isnt reading those a good thing to do just after youre done with the one problem? you could use it to see how you can refactor and improve your code

zealous tulip
#

so now I got 2 of them to read

#

maybe at the same time

tardy barn
#

How'd you guys even || get the crates' order from the input||?

#

I just hard-coded them

#

Most cringe way to code it possible

zealous tulip
#

Pain

#

I am so close to finishing parsing

#

I forget what the actual challenge was

mental owl
#

stack strings are consistent in length

#

so like, you can dumb-index it

#

or are you all trying to do it in an inputerror prone way on top of doing it in rust

tardy barn
#

C#
shudders

mental owl
#

my rust compiler got fucked up okay

#

besides ive never done aoc before

red pelican
zealous tulip
red pelican
#

spend that time making sure your code is right or making a unit test maybe

zealous tulip
#

how dare you suggest a good solution

red pelican
#

ive been making unit tests for 3 days now, to cover at least most of the examples in the problem instructions

#

to make it easier to check it out if someone reading this doesnt know how to write tests in rust

mental owl
#

someone i know is doing this aoc in python oneliners

zealous tulip
#

so that's the issue

#

fuuuu that was the issue

mental owl
#

ratio me all you want

zealous tulip
#

What a nightmare

#

I'll publish the code soon

livid pier
#

Well slightly different but same same

red pelican
livid pier
#

That is what I did

tardy barn
mental owl
#

what's the mark after which AOC tasks usually get wacky?

#

i assume 1.5-2 weeks?

zealous tulip
#

Hopefully not in 5 days

#

I won't even be able to do the one on Saturday

#

So I'll have to do two on Sunday

crude juniper
zealous tulip
#

There is technically no time limit

#

But it actually unlocks the new one at 5 am ;)

#

Or well midnight for EST

crude juniper
mental owl
#

from last year

mental owl
red pelican
#

ok im not going to be doing advent of code at least today. It's just draining my energy that I currently need for other things

frail slate
#

Today's is pretty simple in Rust. Both parts took like 10 lines of code

livid pier
#

Hilariously, I find iterating over/parsing strings in Rust so infuriating.

frail slate
#

approximately

#

there isn't much to parse here lol

livid pier
#

I think I might just be too fond of the hack and slash capabilites of Python.

#

lol I'm going to give it a genuine go in a bit but right now I am just reading the instructions

zealous tulip
#

I really like how iterators make me think rather then making everything a for loop

livid pier
#

I finished part one. ||and the way I wrote my code for part one, means all I had to do was change one parameter and it worked for part 2 ||

#

Day 6 Part 1 and 2

zealous tulip
#

||VecDeques are pretty cool tbh, I like the idea of a cyclic vector, also the next_chunk function is amazing for giving me a straight array and not a slice, also hadn't used constant numbers before this but they are cool||

zealous tulip
#

oh god today is really hard

mental owl
#

ohhh this is exactly the thing i like doing i think

zealous tulip
#

I am going to try make my solution more generic because if I try to only solve this problem I would have to rewrite everything

mental owl
#

waaaa

#

i dont feel like doing this today

#

lazy ass wasp

zealous tulip
#

It's hurting my brain

mental owl
#

||i made a parser recently so it shouldn't be terribly hard... i just feel lazy overall||

zealous tulip
#

||I've been making parsers since the start of december! /s||

mental owl
#

nevermind i woke up somewhat

#

result shouldn't include root folder right

#

this could use some slightly clearer wording,,,

zealous tulip
#

i knowww

#

I am crying right

#

now

mental owl
#

just caught up with everything but todays... today's is too complicated and im still ill not gonna happen

zealous tulip
#

I have a bug and it is breaking everythinggggg

mental owl
#

i have a bug...it's making me cough a shit tonne

#

ba dum tss

zealous tulip
#

I am currently on 6 tabs of indentation

frail slate
#

cease

mental owl
#

part one done

#

||i went a very naive tree structure way but it works||

mental owl
frail slate
#

i did the parsing and gave up at the tree stuff

mental owl
#

i was three match statement and four if statements deep

frail slate
#

skill issue

zealous tulip
#

I am close to finishing

#

I think

#

||currently just trying to flatten my "tree" into all the directories but I don't think it's working||

#

OH IT'S AT MOSTTT

#

not at LEAST

mental owl
#

ooopsie daisies

zealous tulip
#

it did not cause that much pain

#

thankfully

#

thank god

#

I'M FREEE

mental owl
#

bruh, VSC official C# plugin doesn't have inference or hints for call chains like that

zealous tulip
#

yeah

#

I was surprised when I first saw it in rust

mental owl
#

fucking what

#

i'm discovering new things today

zealous tulip
#

tf

mental owl
#

if it means what i think it means that's

#

INCREDIBLY idiotic

#

and i hope it does not happen

zealous tulip
#

just change all of the dotnet standard library

#

it'd be easy!

mental owl
#

πŸ₯Ή

mental owl
# mental owl fucking what

meh, that's a lint i like. if it's idiomatic to do it otherwise and it might be a future conflict then why not add it to the linter

#

worse than bullshit naming conventions are enforced bullshit naming conventions

#

oh wait it's enforced?

#

i mean

#

sure sounds like it

zealous tulip
#

idk about that

mental owl
#

yellow line β‰  warning???

#

yellow line is warning yes

#

okay so it ain't enforced (unless Werror is a thing in C#?)

#

it's not as of now, but since "reserved" usually means "no one else is allowed to", i assume there's a proposal somewhere to make it enforced

#

maybe i assume wrong

#

all that reads to me is "don't bother being un-idiomatic here, we use this system to name keywords or std or whatever (im not a c# dev)"

zealous tulip
#

"we MIGHT use these in the future"

mental owl
#

i mean, rust reserves a few keywords for unimplemented features but it can never be exhaustive, i prefer c# here in that my code wont have a conflict ten years in the future than rust being like HOPE ITS OKAY

#

yeah probably

#

i just had a flash of paranoia i guess

livid pier
#

I'm fuming, all the tests work but my answer is too low

zealous tulip
#

||Well in general it's best to look at what is being done in your data that isn't being done in the sample||

#

||also a debugger can be a good idea but you need to learn how to use it a bit beforehand||

livid pier
#

||I am handling multiple cd .. properly ||

mental owl
#

actuallu no i'll move it

zealous tulip
#

There is so much that can be wrongggg

livid pier
#

I know

#

I am just in hell right now lol

#

I abandoned Rust after like an hour and a half

#

I have been in Python for the last 2 hours

#

and I am just staring at the void

mental owl
#

python moment

livid pier
#

I thought it would be easier since I've used it more but somehow I've gotten myself more twisted and its now 1 am

zealous tulip
#

😭

#

Drop it it's not worth it

mental owl
#

i wonder if i would be in as much pain as you folk if i wasn't using my comfort lang

zealous tulip
#

It would not say it was painful

#

Annoying and tedious? Maybe

#

Also I kind of don't know if I like C# iterators anymore

#

Though the borrow checker was actually kind of a pain for this one

#

||Since tree structure does that to a mfer, I tried to store a mutable reference to the parent and it did NOT WORK AT ALL||

#

Now I hope tomorrow it won't be as difficult

mental owl
#

yielders for life

livid pier
#

I am in hell. I checked everything. I have spent a while testing things. I ran my friends code. I got the same result. The same wrong result.

#

The test input gives me the correct value

#

||95437|| for the test on part 1

#

IDK why i blocked out the answer for the test lmao

zealous tulip
#

They are made for every user

#

So no

livid pier
#

Ah my god I am dying lmao

#

But wait

#

that infuriates me even more. His code and my code resolve to the same answer

zealous tulip
mental owl
zealous tulip
#

||we need rust yields 😭||

mental owl
#

||when making fs, i instinctively started overengineering and had to hold myself back like "hold on, full path cd is not in task spec, i probably should not add things that won't be used"||

amber siren
# mental owl i mean, rust reserves a few keywords for unimplemented features but it can never...

[pt] i'm pretty sure rust's approach is actually even more backwards compatible
new strong/reserved keywords that weren't previously strong/reserved can only be introduced in a new edition, which is the only time breaking changesΒΉ are allowed at all
code from different editions can be used together without anything being different at all (changing the edition of a library doesn't break its users in either direction)
anything can be used as an identifier by putting r# before it

#

ΒΉrust allows some things that are technically breaking in some circumstances to be minor, stuff like creating new things that are public, implementing a trait, making the signature of a function more general,
with the idea being that you should be able to work around minor changes just by adding extra annotations

frail slate
#

i have completed today's but im still crying at yesterday's

crude juniper
mental owl
zealous tulip
#

shit I cannot do part 2

#

I think my lack of experience with algorithms is starting to show

mental owl
#

haven't gotten to the tasks yet, but ||i think building a visibility cache grid should be good enough here||

zealous tulip
#

||I have no idea what you mean by that||

frail slate
#

My solution is very hacky lol

mental owl
# zealous tulip ||I have no idea what you mean by that||

||concept: for each row/column, in each direction (u/d/l/r), you can take a tree height and determine where is there a first tree that would shadow it. ie in the example||

30373
25512
65332
33549
35390

||for row 1 you'd remember: height 0-3 is shadowed starting with position 2, height 0-7 are shadowed starting with position 5. I'm going to cache these on one loop and do something with cache on another, whenever i get around to it||

zealous tulip
#

what the fukkkkk

mental owl
#

?

zealous tulip
#

It's just not something It'd have thought about

#

OH that gave me a interesting idea

mental owl
#

ughb my brain is not working right now

#

no aoc for a few hours

mental owl
#

✨

zealous tulip
#

Beyond COMPREHENSION!

mental owl
#

i will be slightly surprised if this clump of code works first try

#

huh, it almost worked

#

20 instead of 21

#

(probably something gone horribly wrong somewhere and it's an accident)

zealous tulip
#

20 + 1 boom fixed

#

I mean if that solution works for different inputs.... then is it a wrong solution?

mental owl
#

guh

#

i lost motivation again

zealous tulip
#

I am getting really concerned because I will not be able to do the aoc for the next 2 days so I will have a backlog that i probably won't be able to catch up on

visual spire
#

shouldda pinned this before, it's now pinned

livid pier
#

I am toasted TBH

#

I again am stuck. I thought I had all edge cases worked out. I have tests working perfectly and then I run the full input and it broke

mental owl
#

love it when that happens

livid pier
#

Honestly, i don't!

frank cairn
#

i think that was sarcasm

livid pier
#

I'm going to take a shower and give it a swing one last time but it's almost 1 am so I think this will be a RIP for me

mental owl
#

last time it did that i just switched to a solution with half as many iterators and twice as many LoC

livid pier
#

I switched programming languages

#

First time I ran the code it worked

#

I went from Python, to Rust.

livid pier
#

Progress so far

#

The pivot from trying python and struggling last night and having my rust solution work first try has got me back following the light of Ferris

zealous tulip
frail slate
#

lol

livid pier
#

Day 10 Part 1:

#

||Honestly was prepping for new commands in part 2 or additional signal checks or whatever and NOPE||

livid pier
#

Day 10 part 2 - Only thing slightly cut off is the print capability for the answer

crude juniper
#

Hey all! I'm catching up on AoC today/tomorrow and I'm hitting a Rust-related speed-bump. I'd like to visualise the current state of my knot-moving for Day 9 so I'm creating a Vec<Vec<&str>> to insert characters into at the 2d coordinates I know have a knot in. As part of the visualisation, I want to number the positions on the knots as per the problem spec. As I iterate over my Vec<_> of position object, I use a "usize" index to work out which number to put in that place. All that said, the issue I have is I can't find a way to convert that "usize" index into a "char" without going through "String", and that leads me to this error:

error[E0716]: temporary value dropped while borrowed
   --> src/main.rs:101:38
    |
101 |             let mut display_char = &*((self.sections.len() - 1) - ind).to_string().as_str();
    |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^         - temporary value is freed at the end of this statement
    |                                      |
    |                                      creates a temporary which is freed while still in use
...
105 |             output[(position.y - min_y) as usize][(position.x - min_x) as usize] = display_char
    |                                                                                    ------------ borrow later used here
    |
    = note: consider using a `let` binding to create a longer lived value

To the best of my understanding, it's the fact that I'm making a String for the "char" to reference which then gets freed afterwards that's the problem. But I can't find another way to go "usize"->"char"! Any advice much appreciated; code context for error in attached picture.

#

^and I just noticed the missing semicolon on 104 πŸ˜›

frail slate
#

is this what you want?

#

(i haven't done the last few days)

crude juniper
#

Yep, that's the one!

#

Looks like I was getting "char" and "&str" a but muddled up too

#

Thanks muchly!

#

Ah but also no, it seems - converting usize->u32->char like this doesn't quite do what I expected.

livid pier
#

I dont know what has happened but I am frozen. My computer is stuck on this:

cargo run -p day-11
Blocking waiting for file lock on package cache

#

I have ran cargo clean, I have removed cargo cache files, I have restarted the computer. I have no idea what could be causing it

#

I have even closed vscode and everything, tried to run from iterm2, default terminal, etc

#

I even killed and restarted the cargo process

livid pier
#

Took me forever but got it and finished Part 2.

||Did lowest common multiple to not have to use arbitrarily large numbers.||

livid pier
#

I had to tap out on Day 12.

#

I am officially going to be a day behind from now sadly

#

Going to try and finish it tomorrow

nova mango
#

I haven't done today's or yesterday's yet because I've been sick

modern delta
#

the way covid hit me

frail slate
#

😭

#

i got lazy/unmotivated

mental owl
#

same

#

laundmo destroyed me with minecraft

#

i can no longer do something that isn't minecraft

zealous tulip
#

the day of reckoning (day 8), though it was actually because I had to go on a 2 day long travelling session

mental owl
#

well

#

I'm not obsessing over Minecraft anymore but i also don't have the motivation to start aoc again

#

fuck

modern delta
#

Just did day 10 and I had such a hard time understanding the behaviour for step 2 😭

young knoll
#

ive tried getting into aoc multiple times but its like

#

my brain doesnt have the processing power to digest the walls of text into the actual problem at hand

red pelican
young knoll
#

no its like

#

my brain cannot process it it just processes it as background noise its like "oh the elves are staring at this pile of lava because the raindeers are stuck and-" and im like "what does any of this have to do with programming"

#

"just tell me what i need to do"

mental owl
mental owl
mental owl
#

back on day 8

#

my idea of how to do it is fine, but i'm struggling to come up with an implementation that wouldn't be a nightmare of flipping indices to write

livid urchin
#

What is Advent of Code?

zealous tulip
#

daily challenges with increasing difficulty during October and until christmas

frail slate
#

October? πŸ‘€

zealous tulip
#

very.

red pelican
#

Very daily very challenges with very increasing very difficulty during very october and until very christmas

#

Its only 1st of december to 25th of december (at least this year, idk if it has been different other years, I really doubt it considering its called advent of code)