hi @vaporeon_ want to read some disgusting golfy javascript code i just wrote
@wallhackio Yes
Advent of Code Day 1, Part 1 spoiler
@vaporeon_
There is a round safe lock with the numbers 0-99. I have a text file called "inputs.txt" that has a bunch of instructions separated by line terminators. The instructions are like "L38" or "R15" and tell you turn the safe lock left or right by the given number. The safe lock starts at 50, I need to find how many times the safe lock hits the number 0.
let bound = 100, t = 50, hits = 0;
Deno.readTextFileSync("input.txt").split("\r\n").map(s => s.replace("L", "-").replace("R", "")).forEach(n => {
if ((t +=+ n) < 0 ? t = -(-t % bound) : t %= bound); else ++hits;
});
console.log("password:", hits);
re: Advent of Code Day 1, Part 1 spoiler
@vaporeon_ in javascript the negative numbers do result in negative results with the % operator because the language is bad
re: Advent of Code Day 1, Part 1 spoiler
@vaporeon_ oh i didn't read it right
uh, you might be right? although the inputs the question give you have turns greater than 100 if im not mistaken, so maybe this wouldn't work
re: Advent of Code Day 1, Part 1 spoiler
@wallhackio Good point... For part 2, the division with modulus fixes that, but for part 1? Actually I'm now surprised that my solution works...
re: Advent of Code Day 1, Part 1 spoiler
@wallhackio OK, my solution works because in Sun OpenBoot, -90 100 mod and 10 100 mod both produce the same result
So if I wrote that in C, my solution would indeed be broken
Truly, I am fake programmer :(
re: Advent of Code Day 1, Part 1 spoiler
@vaporeon_ reported for lies
re: Advent of Code Day 1, Part 1 spoiler
@wallhackio That's why the
+boundpartE.g. assume t is currently at 5, you want to rotate L95
(5 + -95 + 100) % 100 = 10 % 100 = 10The left part never gets negative if
abs(n)is always less than 100Meanwhile, if you just did
(5 + -95) % 100 = -90 % 100, that would indeed be a problem