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
FalseNegative
Jul 24, 2007

2>/dev/null

the talent deficit posted:

the 2019 one wasn't bad. you could write the emulator in like 30 minutes; it was very simple. you also didn't need to use sdl or any kind of graphics. the breakout puzzle was easier to solve analytically than by actually playing the game

I can see it being simple if you are already familiar with that domain, otherwise that was quite a steep curve.

Adbot
ADBOT LOVES YOU

Cybernetic Vermin
Apr 18, 2005

FalseNegative posted:

Please do, j k, etc fascinate me.

honestly the bigger issue is that it doesn't turn out that interesting, in that it is some splits and sums with fewer characters.

code:
l:{+/`I$"\n"\x}'"\n\n"\1:"in"   / split on double newline, then, for each: split each on newline, cast to int, sum
(+\l@>l)@0 2                    / cumulative sum of l sorted, pick first and third sum

Cybernetic Vermin
Apr 18, 2005

FalseNegative posted:

I can see it being simple if you are already familiar with that domain, otherwise that was quite a steep curve.

also it was kind of unfriendly for some of the more fun aspects of aoc, i.e. trying something new or weird or simply shaking off some rust. if your approach didn't do it very well (e.g. running it in excel at great effort) it got annoying to have it resurface, and it had a tinge of doing real work when you found yourself refactoring your thing a second time.

didn't mind it too much, but probably as well to steer a bit clear of it.

e: otoh every year aoc winds up having that pain point where you go "huh, this is just work isn't it?", but it is usually only a couple of the days.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

did it in swift, spent more time finding out you can't statically link a swift package into a command-line tool in xcode because i got tired of opening the schemes dialog to change the command line parameters and wanted to run from the terminal but it could never find the framework dynamically that way. this is how all my side projects end up, by the way.

Archduke Frantz Fanon
Sep 7, 2004

spankmeister posted:

did day1 in python in like 5 minutes but gonna try rust now

lol yeah i feel like im cheating by not writing my own sort :negative:

MrQueasy
Nov 15, 2005

Probiot-ICK

Archduke Frantz Fanon posted:

lol yeah i feel like im cheating by not writing my own sort :negative:

why are you sorting? you can do both parts in a single pass through your input.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

MrQueasy posted:

why are you sorting? you can do both parts in a single pass through your input.

manually accumulating top-k is usually pretty grody code compared to "sort, take elements in order".

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
i guess if your language has an easy priority queue implementation then it's not so bad though

Archduke Frantz Fanon
Sep 7, 2004

MrQueasy posted:

why are you sorting? you can do both parts in a single pass through your input.

oh i guess i could have just extended what i was doing for part one but list.sort() is so easy

MrQueasy
Nov 15, 2005

Probiot-ICK

Archduke Frantz Fanon posted:

oh i guess i could have just extended what i was doing for part one but list.sort() is so easy

amen to that, I think the # of elves was an order of magnitude smaller than the total number of lines in my input. what’s a couple nanoseconds between friends?

Petanque
Apr 14, 2008

Ca va bien aller
after doing day 1 last midnight in python, i just got finished trying it in haskell, a language i have squinted at on occasion. it took me an hour and i could feel my brain operating differently

PIZZA.BAT
Nov 12, 2016


:cheers:


yeah if anything these puzzles are great for highlighting just how great python is for stuff like this

The Chairman
Jun 30, 2003

But you forget, mon ami, that there is evil everywhere under the sun
I am doing it in Racket this year because I refuse to learn any employable job skills from the elf puzzle game

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

Jabor posted:

i guess if your language has an easy priority queue implementation then it's not so bad though

i felt like a dope because i did the manual one-pass accumulation thing and then only after submitting did i realize i could replace my whole part 2 solution with one function call to python's heapq
...not that doing it in linear time actually matters with how small the data size is

LanceHunter
Nov 12, 2016

Beautiful People Club


Yeah I felt bad about doing a sort instead of a single pass on the second part of day 1, then remembered that I was calling the file read separately for each part (I keep the day’s input in a separate text file to keep down on clutter), so the sort was the least of my optimization crimes.

MrQueasy
Nov 15, 2005

Probiot-ICK

PIZZA.BAT posted:

yeah if anything these puzzles are great for highlighting just how great python is for stuff like this

Python is ok.

But Kotlin is still the best balance of expressive/type safety I've used in a while.

code:
fun part2(input: String) = input.split("\n\n")
                                .map { it.lines().sumOf(String::toInt) }
                                .sorted()
                                .takeLast(3)
                                .sum()

LanceHunter
Nov 12, 2016

Beautiful People Club


I feel a bit bad about all the switches and if statements in my code for day 2. But at least I only read the input file once, so that's a huge improvement from day 1...

MrQueasy
Nov 15, 2005

Probiot-ICK

LanceHunter posted:

I feel a bit bad about all the switches and if statements in my code for day 2. But at least I only read the input file once, so that's a huge improvement from day 1...

You think you feel bad, mine was using ridiculously overengineered enum/sealed classes.

Petanque
Apr 14, 2008

Ca va bien aller
i did some major mind math to think about array indices and reverse dictionary lookups. not sure where my head was tbh

Athas
Aug 6, 2007

fuck that joker
I'm having fun coming up with parallel algorithms for these, even if the inputs are too small for that to be sensible. Going well so far. In 2018 I got a bit tired of the later problems that were more about fiddly details than problem-solving (I remember having to encode some RPG combat ruleset).

Cybernetic Vermin
Apr 18, 2005

day 2 is one of those where aoc philosophy becomes a real question, i.e. deciding if one thinks it is a pure programming exercise and therefore we should try to make a nice program that has all the logic to solve the thing directly embedded, or is it problem solving so just do what solves the problem the most conveniently.


i.e., whether one thinks it is in the spirit to just write the scoring as dictionaries covering the 9 cases
code:
sc1:`AY`BZ`CX`AX`BY`CZ`AZ`BX`CY!8 9 7 4 5 6 3 1 2
sc2:`AY`BZ`CX`AX`BY`CZ`AZ`BX`CY!4 9 2 3 5 7 8 1 6

in:{`$x^" "}'0:"in"
(+/sc1@in;+/sc2@in)


e: sort debate falls in this as well, as it is unlikely you'd ever manage to make the extra log n factor matter in an aoc problem, so a matter of the standard we hold ourselves to.

Cybernetic Vermin fucked around with this message at 11:11 on Dec 2, 2022

Athas
Aug 6, 2007

fuck that joker

Cybernetic Vermin posted:

e: sort debate falls in this as well, as it is unlikely you'd ever manage to make the extra log n factor matter in an aoc problem, so a matter of the standard we hold ourselves to.

You can do that sort in linear time, so it's only a constant factor that matters.

Cybernetic Vermin
Apr 18, 2005

Athas posted:

You can do that sort in linear time, so it's only a constant factor that matters.

if we're to *actually* "actually" this though every aoc solution is in constant time since the input is a given constant ;)

Peewi
Nov 8, 2012

Cybernetic Vermin posted:

if we're to *actually* "actually" this though every aoc solution is in constant time since the input is a given constant ;)

I usually run my solution on the small sample input to see that I've got it right before running on my real input.

Athas
Aug 6, 2007

fuck that joker

Cybernetic Vermin posted:

if we're to *actually* "actually" this though every aoc solution is in constant time since the input is a given constant ;)

OK sure, but the context was scaling up to hypothetical larger problem sizes, and you can sort this sequence using a radix sort. Although I suppose if you truly don't put any bounds on the input, that ends up being O(log(k)n), where 'k' is largest sum.

Cybernetic Vermin
Apr 18, 2005

Athas posted:

OK sure, but the context was scaling up to hypothetical larger problem sizes, and you can sort this sequence using a radix sort. Although I suppose if you truly don't put any bounds on the input, that ends up being O(log(k)n), where 'k' is largest sum.

right, and the problem gets bigger as the value k is exponential in the input, so log(k) is actually in O(n) (strictly speaking you can't get to O(n^2) from this i guess, as the the number of digits and number of numbers trades off, but the k is hiding some stuff). beyond that you need O(k) space. e.g. taking the input where one elf carries 1 gigasnacks, a second 1 terasnacks, and a third 1 petasnacks (which in input would be written as just '1125899906842624'; n i still small) you start by allocating 1 petabits of memory, and then you need to scan *most* of the petabits to figure out the actually three largest numbers.

one can probably get clever with encoding this sparsely, but i think one ultimately cycles back to this being a top-k extraction in that case.

(this only for entertainment purposes of course, not at all obvious that the generalization should have elfs carrying trillions of snacks)

Cybernetic Vermin fucked around with this message at 12:05 on Dec 2, 2022

echinopsis
Apr 13, 2004

by Fluffdaddy

DrPossum posted:

more like advent of chode

LanceHunter
Nov 12, 2016

Beautiful People Club


Cybernetic Vermin posted:


i.e., whether one thinks it is in the spirit to just write the scoring as dictionaries covering the 9 cases
code:
sc1:`AY`BZ`CX`AX`BY`CZ`AZ`BX`CY!8 9 7 4 5 6 3 1 2
sc2:`AY`BZ`CX`AX`BY`CZ`AZ`BX`CY!4 9 2 3 5 7 8 1 6

in:{`$x^" "}'0:"in"
(+/sc1@in;+/sc2@in)


This is so clearly the cleanest way to do this, given today's problems, that I'm kicking myself for missing it.

Dijkstracula
Mar 18, 2003

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

LanceHunter posted:

I feel a bit bad about all the switches and if statements in my code for day 2.
Yeah, I didn't approach it just by converting A,B,C and X,Y,Z to 0,1,2 and doing modular arithmetic on the results, which I think is probably the oneliner solution and quickly found myself in "ugh, modeling this many cases feels like I'm doing actual work territory". Luckily Rust's pattern matching makes it not too painful, but still.

I made a worse crime for part 2: couldn't be bothered to write another case analysis for the "what do I play such that the outcome matches what we're given" part so instead I brute forced it against all the three cases until I found the one that matched :v:

code:
#[derive(PartialEq, Debug)]
enum Outcome {
    Win, Lose, Draw
}
impl Outcome {
    fn decide(&self, them: &Choice) -> Choice {
        for us in [Choice::Rock, Choice::Paper, Choice::Scissors].into_iter() {
            if us.compute_outcome(them) == *self {
                return us;
            }
        }
        panic!();
    }
...

DrPossum
May 15, 2004

i am not a surgeon
let's write code about elf calories - a statement people itt support

MrQueasy
Nov 15, 2005

Probiot-ICK

DrPossum posted:

let's write code about elf calories - a statement people itt support

Advent of Code 2022.1 - We love our thicc elves

burning swine
May 26, 2004



well shart, I had been thinking about trying aoc again this year. guess I'll give it a go

signed up as pancake-tongs

LanceHunter
Nov 12, 2016

Beautiful People Club


Redid day 2 with the cleaner answer. Of course, then I post it here in spoilers and it still seems enormous compared to what everyone else is posting.


code:
const part1scores = {
  'A X' : 4,
  'A Y' : 8,
  'A Z' : 3,
  'B X' : 1,
  'B Y' : 5,
  'B Z' : 9,
  'C X' : 7,
  'C Y' : 2,
  'C Z' : 6
};

const part2scores = {
  'A X' : 3,
  'A Y' : 4,
  'A Z' : 8,
  'B X' : 1,
  'B Y' : 5,
  'B Z' : 9,
  'C X' : 2,
  'C Y' : 6,
  'C Z' : 7
};

async function parts1and2(inputFile) {
  try {
    const data = await fs.readFile(inputFile, 'utf8');
    let arr = data.split('\n');
    arr = arr.map(x => part1scores[x]);
    console.log(`Part 1 answer: ${arr.reduce((sum,acc) => sum + acc, 0)}`);
    arr = data.split('\n');
    arr = arr.map(x => part2scores[x]);
    console.log(`Part 2 answer: ${arr.reduce((sum,acc) => sum + acc, 0)}`);
  } catch (e) {
    console.log('Error - ', e);
  }
}

parts1and2('day02.txt');

Cybernetic Vermin
Apr 18, 2005

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.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
so after knocking out today's aoc i figured i'd do something about vs code's nagging "hey we replaced the rust extension with a new one" notice and installed the new one.
first thing i noticed was that it was flagging every use of text formatting macros as a missing-unsafe error. i looked around and saw something that suggested the fix was to update rust, so i did that.
now it completely fails to compile anything because of some missing msvc library.

very cool and easy-to-use language ecosystem!

MrQueasy
Nov 15, 2005

Probiot-ICK

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.

I haven’t even felt the need to write something tail-call recursive yet. what a rip off.

i vomit kittens
Apr 25, 2019


Jabor posted:

so after knocking out today's aoc i figured i'd do something about vs code's nagging "hey we replaced the rust extension with a new one" notice and installed the new one.
first thing i noticed was that it was flagging every use of text formatting macros as a missing-unsafe error. i looked around and saw something that suggested the fix was to update rust, so i did that.
now it completely fails to compile anything because of some missing msvc library.

very cool and easy-to-use language ecosystem!

are you using rustup? this sounds vaguely familiar to some issue I remember having a couple years ago and it was because i had tried to install rust directly instead of using that. rust-analyzer, which is the new LSP that it sounds like you switched to, is also dependent on rustup iirc

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
i was using rustup, yeah.

i fixed it by installing visual studio 2022, which i guess the version of rust i updated to requires the build tools from?

Dijkstracula
Mar 18, 2003

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

Rust enjoyers: as a newbie, can I ask if there's a better way to write

code:
fn score(c: char) -> u32 {
    if c.is_uppercase() {
        27 + (c as u32 - 'A' as u32)
    } else {
        1 + (c as u32 - 'a' as u32)
    }
}


All these casts suggest that the language would absolutely prefer that I not do this, but nothing more built-in lept out at me. (It feels like in general, in our new world of non-seven bit clean ASCII characters, this is a poor thing to do anyway, so maybe it's "fine" here and just "not fine" in a different context)

Adbot
ADBOT LOVES YOU

Cybernetic Vermin
Apr 18, 2005

Dijkstracula posted:

Rust enjoyers: as a newbie, can I ask if there's a better way to write

code:
fn score(c: char) -> u32 {
    if c.is_uppercase() {
        27 + (c as u32 - 'A' as u32)
    } else {
        1 + (c as u32 - 'a' as u32)
    }
}


All these casts suggest that the language would absolutely prefer that I not do this, but nothing more built-in lept out at me. (It feels like in general, in our new world of non-seven bit clean ASCII characters, this is a poor thing to do anyway, so maybe it's "fine" here and just "not fine" in a different context)

i think the language is right and this is a thing to do only because it is an artificial programming problem. looks good to me.

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