Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
LanceHunter
Nov 12, 2016

Beautiful People Club


Cybernetic Vermin posted:

not like we're doing code golf, for problem solving size doesn't matter a whole lot. especially my k nonsense will stop at all being a good idea before the end.

nothing very interesting today, set intersections and a bit of ascii math, so having gotten properly into the mood for this i almost feel a bit cheated on the first weekend day of playing.

Today was a good lesson in typing time vs computer time for overall efficiency. I did another hash table for the scores for each letter, rather than doing the ascii math (since upper-case and lower-case letters would have needed different arithmetic). Of course, the time I took typing that was ages in comparison to the zillionth of a second saved avoiding the one extra comparison.

Adbot
ADBOT LOVES YOU

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
You can cast your input character into a u8, and then compare it against byte literals like b'a'. I just wrote the obvious code with one if statement checking if it was between a and z, and a second one for A and Z - but since those are the only two ranges in the problem you could instead just check if it's greater than Z and assume lowercase if so.

Cybernetic Vermin
Apr 18, 2005

part of the reason im excessively invested in aoc this year (and to some extent last) is i am teaching a competition-coding based course. over the years the first year of cs has been taken up with more and more theory, collaboration, documentation, and communication skills. which is very good, but students have gotten noticeably worse at just knocking out a program that does a thing independently.

which gives me the luxury to just push problem-solving where you just quickly do something sufficient. which was like 90% of the program when i was a kid, and i think is fun, but is actually kind of needed now.

not like you can be dumb doing it, but it is very much core to ignore small inefficiencies if it is good enough to get a thing done.

e: to be clear i am 100% a scrub noob at this stuff, struggling to make it through. and everyone working primarily to pay bills and live should be. but it is good to do a bit of an exercise to make sure you can still make the computer do what you need it to without it being too major a undertaking.

Cybernetic Vermin fucked around with this message at 18:10 on Dec 3, 2022

burning swine
May 26, 2004



I like writing code that doesn't have to come out looking professional for a change

code:
Character thingsWeHaveInCommon = threeway(elf1, elf2, elf3);

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Cybernetic Vermin posted:

part of the reason im excessively invested in aoc this year (and to some extent last) is i am teaching a competition-coding based course. over the years the first year of cs has been taken up with more and more theory, collaboration, documentation, and communication skills. which is very good, but students have gotten noticeably worse at just knocking out a program that does a thing independently.
This sounds super-cool; is the material available publicly anywhere?

A couple of years ago I got assigned to teach a weird vestigal "unix scripting" course and it was pretty awesome to see the students who totally floundered at the start by not being able to deal with an empty editor finish the class being able to be all "oh, sure, a program that does X? Ok, bing bang boom"

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

not sure whether this belongs here or in the cyberpunk thread, but: https://www.reddit.com/r/adventofcode/comments/zb98pn/2022_day_3_something_weird_with_copypasting/ :what:

quote:

I wasn't aware that "input corruption due to cryptocurrency malware" was an option on my AoC 2022 Moderation Topics bingo card... wow.

PIZZA.BAT
Nov 12, 2016


:cheers:



oh wow

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
more neat day3 news
https://twitter.com/ostwilkens/status/1599026699999404033

this guy used GPT-3 ML model and managed to submit an ai-generated solution to the silver-star problem in 10 seconds.
seems like he is just using OpenAI's api so he didn't train it himself or anything
only second place for the gold star though


is that in the spirit of competition? :iiam:

RPATDO_LAMD fucked around with this message at 20:44 on Dec 3, 2022

Asleep Style
Oct 20, 2010

got caught up on these this morning. I've been using python but I'm tempted to give it a shot with rust or zig depending on if I feel like learning something impractical or very impractical

Athas
Aug 6, 2007

fuck that joker
Three days down and haven't encountered any compiler bugs yet. Don't remember how far I got in 2018, but I remember finding plenty of bugs then.

Cybernetic Vermin
Apr 18, 2005

Athas posted:

Three days down and haven't encountered any compiler bugs yet. Don't remember how far I got in 2018, but I remember finding plenty of bugs then.

futhark is real good in my experience. gl, i fear a smaller part than is realistic will turn out amenable to the optimizations relevant.

Cybernetic Vermin fucked around with this message at 10:31 on Dec 4, 2022

LanceHunter
Nov 12, 2016

Beautiful People Club



That's a hell of a way to discover that your system was compromised.

echinopsis
Apr 13, 2004

by Fluffdaddy

DrPossum posted:

more like advent of chode

Cybernetic Vermin
Apr 18, 2005

day 4: first off-by-one of the year. also wrote a real dumb program, in that i realized the ranges, speculatively guessing that it'd be needed for part 2.

Dijkstracula posted:

This sounds super-cool; is the material available publicly anywhere?

A couple of years ago I got assigned to teach a weird vestigal "unix scripting" course and it was pretty awesome to see the students who totally floundered at the start by not being able to deal with an empty editor finish the class being able to be all "oh, sure, a program that does X? Ok, bing bang boom"

not yet, first year had a lot of flaws (as it always goes), but hopefully down the line!

Athas
Aug 6, 2007

fuck that joker

Cybernetic Vermin posted:

futhark is real good in my experience. gl, i fear a smaller part than is realistic will turn out amenable to the optimizations relevant.

Thanks for the kind words. It's getting more tricky to do the input parsing, but not so bad yet:

pre:
def parse (s: string[]) =
  let (get,ls) = lines.lines s
  in map (\l -> let (a,b) = span (==',') (get l)
                let (a0,a1) = span (=='-') a
                let (b0,b1) = span (=='-') (tail b)
                in ((atoi a0, atoi (tail a1)),
                    (atoi b0, atoi (tail b1)))) ls
That's not too unlike what I would write in common languages like Haskell.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

day 4 status: inclusive intervals :argh:

Athas posted:

Thanks for the kind words. It's getting more tricky to do the input parsing, but not so bad yet:
yeah, I feel like this is probably one of the last days where I'll be able to get away with doing the "straightforward" thing:


code:
fn parse(s: &str) -> ((u32, u32), (u32, u32))
{
    let mut it = s.split(",")
        .map(|r| {
            let mut it = r.split("-").map(|i| i.parse::<u32>().unwrap()).into_iter();
            (it.next().unwrap(), it.next().unwrap())
        })
        .into_iter();
    (it.next().unwrap(), it.next().unwrap())

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
I'm finding itertools::collect_tuple and array_init::from_iter to be pretty handy for writing this sort of code with less actual writing.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

As it happens I learned about itertools::from_tuple today, and used for part 2 of today's! A habit I've been getting into is to solve the problem and look at fasterthanlime's solution, and I usually learn at least one useful idiom from it even if his solutions are a lot more "built-out" than mine.

ToxicFrog
Apr 26, 2008


Like a bunch of other people ITT I like to use Advent as an excuse to learn new languages. This year it's Factor. I'm pretty happy with this day 4 solution:

code:
: as-range ( str -- range ) "-" split [ parse-number ] map first2 [a..b] ;
"4.data" utf8 file-lines [ "," split [ as-range ] map ] map

! part 1
: fully-contained? ( ranges -- bool ) dup first2 subset? swap first2 swap subset? or ;
dup [ fully-contained? ] filter length .

! part 2
: overlaps? ( ranges -- bool ) first2 intersect null? not ;
[ overlaps? ] filter length .


It's taking me a bit to get my head back into the concatenative programming groove, I haven't used Postscript in over a decade and Factor has a shitload of libraries, many of which are conceptually similar to stuff I'm already familiar with from Rust or Clojure but often with different names.

i vomit kittens
Apr 25, 2019


i found it kind of odd how easy today's part 2 was in comparison to others, all i had to do was swap out a couple variables from what i did for part 1.

i'm doing c++ this year. i've been wanting to learn how to write vst audio plugins for years but i've always been working in plangs/Java (other than loving around with Rust a bit in my spare time for the past year or so) so the task of learning c++ has always kind of put me off from that. so far at least it hasn't been as bad as i'd thought it would be

PIZZA.BAT
Nov 12, 2016


:cheers:


c++ isn’t and won’t be that bad for any advent of code stuff you do. once the code base starts growing larger than toy project though it gets hairy quick

MrQueasy
Nov 15, 2005

Probiot-ICK
Another kinda underwhelming part 2 on day 5.

The Chairman
Jun 30, 2003

But you forget, mon ami, that there is evil everywhere under the sun

MrQueasy posted:

Another kinda underwhelming part 2 on day 5.

maybe they're harder to implement in other languages but for my day 4 and day 5 I was able to get the second star in about 10 seconds by just changing one predicate

LanceHunter
Nov 12, 2016

Beautiful People Club


I will say that today’s exercise was another chance to consider the philosophy of how to handle the input. I ended up just typing up the 2d array for the crate stacks, then only saved the moves to the input file that the program parsed. Taking all of it as a single input file and properly parsing it into the two different types of data within would have been an interesting exercise, and I may do that later today if work is slow.

As far as the second stars being easy, it does kids feel that way. I’m sure something will come along in the next week or so that makes me regret saying that, though.

MrQueasy
Nov 15, 2005

Probiot-ICK

LanceHunter posted:

I will say that today’s exercise was another chance to consider the philosophy of how to handle the input. I ended up just typing up the 2d array for the crate stacks, then only saved the moves to the input file that the program parsed. Taking all of it as a single input file and properly parsing it into the two different types of data within would have been an interesting exercise, and I may do that later today if work is slow.

As far as the second stars being easy, it does kids feel that way. I’m sure something will come along in the next week or so that makes me regret saying that, though.

It just feels like an unusually non-twist of a twist compared to previous years' week 1 part 2s.

Cybernetic Vermin
Apr 18, 2005

it was enough of a non-twist that reading sloppily i wound up writing part 2 first.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
It feels like that in past years part 1 was a "parse this input and here's a trivial challenge to see if you've parsed it correctly", and part 2 was an actual problem that needed you to do something with that parsed input.
This year they feel like two trivial challenges that just happen to have the same input.

Hopefully it picks up at some point.

Athas
Aug 6, 2007

fuck that joker
Today was the first mindlessly sequential implementation (except the input parsing I guess). I have a hunch that the second part can be parallelised by characterising a movement as a linear operation and then taking their composition, but these are supposed to be simple challenges and I have a real job too.

Cybernetic Vermin
Apr 18, 2005

Jabor posted:

It feels like that in past years part 1 was a "parse this input and here's a trivial challenge to see if you've parsed it correctly", and part 2 was an actual problem that needed you to do something with that parsed input.
This year they feel like two trivial challenges that just happen to have the same input.

Hopefully it picks up at some point.

real early days yet, so pretty hopeful. i kind of expected something more substantial sunday (as the weekends are traditionally larger), but day 4 might have been a bit too early to do that.

not going to lie though, it has been a *bit* flat so far. compare e.g. day 5 of last year which was this (somewhat annoying, but a bit different) thing:


but then it was a weekend problem.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
i don't think day five last year was particularly twistier than today. i looked up my answers and the difference was changing the inner bit like this
code:
if(y1 == y2)
  for(i = x1; i < x2; i++)
    v[i][y1] += 1
if(x1 == x2)
  for(i = y1; i < y2; i++)
    v[x1][i] += 1
to something like this
code:
xs = x1 < x2 ? 1 : x2 < x1 : -1 : 0
ys = y1 < y2 ? 1 : y2 < y1 : -1 : 0
v[x1][y1] += 1
while(x1 != x2 && y1 != y2) {
  x1 += xs
  y1 += ys
  v[x1][y1] += 1
}
i think when they start requiring more than a running total or a simple 2d array between different lines of input is when the twists start getting you, because how you model a graph or whatever has a lot more assumptions in it

LanceHunter
Nov 12, 2016

Beautiful People Club


Destroyenator posted:

i don't think day five last year was particularly twistier than today. i looked up my answers and the difference was changing the inner bit like this
code:
if(y1 == y2)
  for(i = x1; i < x2; i++)
    v[i][y1] += 1
if(x1 == x2)
  for(i = y1; i < y2; i++)
    v[x1][i] += 1
to something like this
code:
xs = x1 < x2 ? 1 : x2 < x1 : -1 : 0
ys = y1 < y2 ? 1 : y2 < y1 : -1 : 0
v[x1][y1] += 1
while(x1 != x2 && y1 != y2) {
  x1 += xs
  y1 += ys
  v[x1][y1] += 1
}
i think when they start requiring more than a running total or a simple 2d array between different lines of input is when the twists start getting you, because how you model a graph or whatever has a lot more assumptions in it

That's a good point. The actual code updates needed to handle the way Part 2 changes the problem can be quite small, because figuring out the change you need to implement is more important than doing a lot of separate work.

Hell, maybe the problem just feels easier for some folks this year because they've gotten better at computer?

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

I wondered if some data scientist at Advent Of Code, LLC looked at the dropoff and decided they needed to make it gentler so 90% of people don't quit in the first week

The Chairman
Jun 30, 2003

But you forget, mon ami, that there is evil everywhere under the sun
it's also just hard to write puzzles that target a specific difficulty/experience level, like for day 5 I bet the puzzle writer thought people would want to simulate each individual crate's movement instead, which would make implementing part 2 a little more complex

ToxicFrog
Apr 26, 2008


I does feel easier than previous years, but:
(a) I'm probably comparing the current point to whatever point I dropped out at in previous years
(b) I have, hopefully, gotten at least slightly better at computer, and
(c) the last three years have been incredibly stressful, the last three months at work have piled more stress on top of that, I'm staring down the barrel of a holiday where I'll be expected to travel for hours on icy country roads so that I can pretend to be normal around my dysfunctional in-laws, and if AoC wants to take it easy on me this year so I can relax with a new language I am a-ok with that.

MrQueasy
Nov 15, 2005

Probiot-ICK

Dijkstracula posted:

I wondered if some data scientist at Advent Of Code, LLC looked at the dropoff and decided they needed to make it gentler so 90% of people don't quit in the first week

Lol this is a labor of love by one dude (Eric Wastl), 5 beta testers, and 2 community managers.

Cybernetic Vermin
Apr 18, 2005

still, no doubt a lot of tuning with such things in mind. which is v. good, id hate them tuning it for the true tryhards.

it is absolutely fine so far this year. not looking for higher difficulty, but would enjoy a bit more of a curveball theme next. i cited day 5 last year not because it was hard or had a twist, but because it is one of those you absolutely can ponder a moment and do in several different ways (would have worked even better this year with the preceding overlapping ranges one).

PIZZA.BAT
Nov 12, 2016


:cheers:


man i am still struggling with types in rust

i have an array of vectors that i hand instantiate from the puzzle input because parsing all that in code will be a huge pita

i then have a loop for each line that pulls out the number of crates to move, the source and target stacks, and then i just push into the target vector what i pop from the source. it then does that x times

however i'm getting an error that it can't infer the type and after an hour of googling around i still can't figure out how it actually wants me to specify this for the compiler

code:
use std::fs::File;
use std::io::{BufReader, BufRead};

fn main() {
    println!("Day 05");
	let f = File::open("1.txt").expect("1.txt should be accessible");
	let f = BufReader::new(f);
	
	// Puzzle input
	let mut stacks = [
		vec!['X'], // Keep this just to make later parsing easier
		vec!['R', 'S', 'L', 'F', 'Q'], // 1
		vec!['N', 'Z', 'Q', 'G', 'P', 'T'], //2
		vec!['S', 'M', 'Q', 'B'], //3
		vec!['T', 'G', 'Z', 'J', 'H', 'C', 'B', 'Q'], //4
		vec!['P', 'H', 'M', 'B', 'N', 'F', 'S'], //5
		vec!['P', 'C', 'Q', 'N', 'S', 'L', 'V', 'G'], //6
		vec!['W', 'C', 'F'], //7
		vec!['Q', 'H', 'G', 'Z', 'W', 'V', 'P', 'M'], //8
		vec!['G', 'Z', 'D', 'L', 'C', 'N', 'R']
	];
	
	for line in f.lines() {
		let line = line.expect("We should be able to read strings from the file");
		
		// Extract the line's source, target, and # of crates to be moved
		let move_vector: Vec<&str> = line.split(",").collect();
		let move_count : i32 = move_vector[0].parse().unwrap();
		let source = move_vector[1].parse().unwrap();
		let target = move_vector[2].parse().unwrap();
		
		for count in 1..move_count {
			stacks[target].push(stacks[source].pop());
		}
	}
	
	println!("done");
}


halp

edit: oh i'm dumb it was complaining about the index type, not the pop/push

PIZZA.BAT fucked around with this message at 21:43 on Dec 5, 2022

PIZZA.BAT
Nov 12, 2016


:cheers:


it's sloppy but i solved part two by just creating a temp vector to pop the source stack into and then turning around and popping them all into the target stack afterwards. i definitely could have done this with an elegant slice somehow but i'm struggling enough just with rust's enum/typing system for now so f it

edit: maybe someone can help me understand this because these are the lines that i was struggling with

code:
		while temp_vec.len() > 0 {
			let crate_char : char = temp_vec.pop().unwrap();
			stacks[target].push(crate_char);
		}


i originally had the pop and push in the same line. everything to the right of the assignment was inside the next line's push. rust wasn't liking this because i guess it allowed for ambiguity but i just couldn't figure out how to tell it 'hey whatever is here should be a char'. i eventually gave up and split it into the two lines you see above but i'd like to know how to get this down to a single line

PIZZA.BAT fucked around with this message at 22:42 on Dec 5, 2022

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆
that sounds like an issue with lifetimes and not types to me cus the types there are pretty dang trivial, but usually rust compiler errors are very detailed about what the problem is

Adbot
ADBOT LOVES YOU

Frozen Peach
Aug 25, 2004

garbage man from a garbage can
This is the first year I've done advent of code, and so far I'm having an absolute blast.

Parsing today's input was really fun, and people are REALLY mad about it in some circles.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply