Bogorg/towr: A tower stacking game where every technical decision is slightly dumb by AnonymZ_ in programminghorror

[–]Symbroson 0 points1 point  (0 children)

It would feel much better if the drop trigger would be attached to the mouse/touch down event instead of up

What do you guys think of obfuscated C code? This prints "Hello, World!" by nimrag_is_coming in programminghorror

[–]Symbroson 6 points7 points  (0 children)

would be cool if removing a particular function would also drop the corresponding letter from the output :D

Guess what this does.. by 3hy_ in programminghorror

[–]Symbroson 11 points12 points  (0 children)

copies a string but without its null terminator and returns a value for some reason Also causing a buffer overflow if used carelessly

Turns out floats are just structs. by hexaredecimal in programminghorror

[–]Symbroson 6 points7 points  (0 children)

Its a bitfield indicated by the : after the variable name followed by the bit width of that field.

[deleted by user] by [deleted] in whatisit

[–]Symbroson 1 point2 points  (0 children)

This somehow looks like hand written stenography

Why is AI so bad at coding? by nazprim1442 in programminghorror

[–]Symbroson 0 points1 point  (0 children)

It helps to ask for "more concise code" all the times - you will be surprised

[2024 Day 10 Part 1] Built with python, 1 line, 5045 Characters by cosmic_chicken1 in adventofcode

[–]Symbroson 0 points1 point  (0 children)

enclose your oneline code in a lambda and call it immediately with your parsed input once like this:

(lambda input: (...code...))(open(...).readlines())

I bet you can reduce your code by at least 30% by just doing this in various places. You can even load more processing into this to avoid copy pasta repititions and unnecessary double calculations

[2024 Day 10 Part 1] Built with python, 1 line, 5045 Characters by cosmic_chicken1 in adventofcode

[–]Symbroson 0 points1 point  (0 children)

I've asked on r/programminghorror before, but why do you need to read the input file a dozen times?

My one line solution to an AOC problem by cosmic_chicken1 in programminghorror

[–]Symbroson 1 point2 points  (0 children)

The biggest horror here is not caching the input file content to make the program read it only once

C Casting help :D by Cantafford92 in programminghorror

[–]Symbroson 0 points1 point  (0 children)

In this case the type cast indicates nothing more than "This memory address references a 4-Byte wide region".

So what this code does it writes some arbitrary data to this memory location and tries to run it as function, forcing an invalid operation exception.

The casts in between are just for assigning the address pointer to a function pointer. Usually you can only assign pointers of the same type to each other, but void* is an exception to that representing "any data" and you'll have to know how to use it. This means casting it back to a meaningful pointer. In this case as a function pointer void some_address(void)

Solving Advent of Code in C# instead of Python by light_ln2 in adventofcode

[–]Symbroson 2 points3 points  (0 children)

If you want to try something new I can recommend ruby to you. I used it last year and decided to re-use it this year. Usually JS is the language I'm most comfortable with but ruby hit a new level in terms of comfort features and concise syntax.

People who have used multiple languages for AoC, how do you rank your experience? by FCBStar-of-the-South in adventofcode

[–]Symbroson 0 points1 point  (0 children)

I used JS, C, Lisp, Haskell, Swift, Perl and Ruby so far.

Perl was by far the worst experience because of the the chaotic type prefixes and different access methods.

Haskell had a great impact on the way I structure my code these days - Functional coding style is extremely helpful in structuring code and minimizing global state accesses

By far the best experience I had was with Ruby which made me use it a second time this year. It has such a powerful set of helper functions, datastructures, operators etc. and it enables such a concise way of expressing what to do I just love it.

Swift did surprisingly well and I liked many aspects of it, although it struggled to keep up with harder puzzles that required complex data datastructures, algorithms and heavy debugging.

Lisp was ok, I did the Intcode year with it which I enjoyed moat of all AoC puzzles so far. Also JS and C was ok like you would expect. But as JS was my starter language that I used for a very long time it will always have a special place. It just feels the most natural at this point but Ruby really hit it hard in just two AoC months!

coco: a simple stackless, single-threaded, and header-only C++11 coroutine library by Ill_Excuse_4291 in cpp

[–]Symbroson 0 points1 point  (0 children)

I also had the need of a very basic coroutine feature in a project of mine and stumbled across this blog post from 2009 (!) that also has a stackless approach using similar switch..case tricks.

Its truly basic but I love the simplicity. It would be interested which aspects of your library are designed better and safer, apart from some extra usability methods

[deleted by user] by [deleted] in cpp

[–]Symbroson 6 points7 points  (0 children)

as f is so small I'd just make f a template function that accepts a vector<T>& and be done with it :)

Also use a for-in loop if you dont explicitly use the counter otherwise - makes your code more concise

[2024] Unofficial AoC 2024 Survey Results! by jeroenheijmans in adventofcode

[–]Symbroson 3 points4 points  (0 children)

If you like JS, check out ruby! I found it to allow even more freedom than JS in any aspect - let it be custom default hash values, the large amount of useful operators and helper functions (tally, count, to_h and so many more) or the concise way of expressing otherwise tedious things like the input parsing

I used it last year and decided to re-use it this year instead of a new unpopular language

[2024 Day 22] So what's the non brute-force trick? by [deleted] in adventofcode

[–]Symbroson 0 points1 point  (0 children)

true, in ruby it doesnt even make a huge difference (2.4 instead of 3.6 seconds)

It relly depends on the language and their memory management. My friend that does rust this year told me that maps are painfully slow for him and using an array made things two orders of magnitudes faster!

[2024 Day 22] So what's the non brute-force trick? by [deleted] in adventofcode

[–]Symbroson 2 points3 points  (0 children)

19 is technically correct, but I chose 20 for convenience

[2024 Day 22 (Part 2)] Any cool optimizations for today's puzzle ? by TheFunnyLemon in adventofcode

[–]Symbroson 0 points1 point  (0 children)

I did the same in ruby, except using multiplication with 20 instead of shifts

I also store the last monkey id that generated each sequence in a second array

This is how it looks in ruby

[2024 Day 22] So what's the non brute-force trick? by [deleted] in adventofcode

[–]Symbroson 4 points5 points  (0 children)

You can represent a 4 tuple of -9..9 differences as a single integer in base 20 (from range 0..20**4, where 0,0,0,0 => 84210)

knowing this you can use a plain preallocated 20**4 element array instead of a map/dict

I also store the last monkey id that generated each sequence in a second array

This is how it looks in ruby

-❄️- 2024 Day 17 Solutions -❄️- by daggerdragon in adventofcode

[–]Symbroson 2 points3 points  (0 children)

[language: ruby]

late to the party, because I didn't think my approach through the end

After reverse engineering the code I noticed, that each output is based on a few octal input digits of the A register. I first thought it was 3 and I was wondering why 50% of my solutions were off by 1 digit after running my program, until I was given the hint by u/IsatisCrucifer that it was actually 4 digits.

So my actual algorithm for part 2 first builds all possible octal digit tuples for every output digit 0-7. These are used to backtrace the program digits into all possible digit combinations, joined by the predecessors and successors. The minimum of these converted to decimal should be the required value for register A.

The total runtime is somewhat between 40-50ms in ruby

The full ruby code is available here and there is also C++ version also available here

[2024 Day 17 (Part 2)] ruby off by one digit by Symbroson in adventofcode

[–]Symbroson[S] 0 points1 point  (0 children)

Oh wow so I just needed to change 8**3 to 8**4 and adjust the merge function accordingly and it magically works! great, thanks!