[-] Ategon@programming.dev 1 points 2 years ago

Turns out I got really lucky and my location value is much lower than most peoples which is why it can be solved relatively quickly

[-] Ategon@programming.dev 1 points 2 years ago* (last edited 2 years ago)

Stretch mode scale should do that, its what it was made for. The only things I changed are the two you can see on the right there

[-] Ategon@programming.dev 1 points 2 years ago* (last edited 2 years ago)

Improvement I found afterwards:

  • Could have done a reduce on the amount array instead of the lines array since I don't use the line value at all
[-] Ategon@programming.dev 1 points 2 years ago* (last edited 2 years ago)

[JavaScript] Swapped over to javascript from rust since I want to also practice some js. Managed to get part 1 in 4 minutes and got top 400 on the global leaderboard. Second part took a bit longer and took me 13 mins since I messed up by originally trying to append to the card array. (eventually swapped to keeping track of amounts in a separate array)

Part 1

// Part 1
// ======

function part1(input) {
  const lines = input.split("\n");
  let sum = 0;

  for (const line of lines) {
    const content = line.split(":")[1];
    const winningNums = content.split("|")[0].match(/\d+/g);
    const myNums = content.split("|")[1].match(/\d+/g);

    let cardSum = 0;

    for (const num of winningNums) {
      if (myNums.includes(num)) {
        if (cardSum == 0) {
          cardSum = 1;
        } else {
          cardSum = cardSum * 2;
        }
      }
    }

    sum = sum + cardSum;
  }

  return sum;
}

Part 2

// Part 2
// ======

function part2(input) {
  let lines = input.split("\n");
  let amount = Array(lines.length).fill(1);

  for (const [i, line] of lines.entries()) {
    const content = line.split(":")[1];
    const winningNums = content.split("|")[0].match(/\d+/g);
    const myNums = content.split("|")[1].match(/\d+/g);

    let cardSum = 0;

    for (const num of winningNums) {
      if (myNums.includes(num)) {
        cardSum += 1;
      }
    }

    for (let j = 1; j <= cardSum; j++) {
      if (i + j >= lines.length) {
        break;
      }
      amount[i + j] += amount[i];
    }
  }

  return lines.reduce((acc, line, i) => {
    return acc + amount[i];
  }, 0);
}

Code Link

[-] Ategon@programming.dev 1 points 2 years ago

Yeah tried to golf it a bit so its not very readable

Seems like the site doesn't track characters though so won't do that for future days

It basically just loops through every character on a line, if it's a number it sets last to that and if its not a number it checks if theres a substring starting on that point that equals one of the 10 strings that are numbers

[-] Ategon@programming.dev 1 points 2 years ago* (last edited 2 years ago)

Ive been paying attention which is why I dont see the communities youre talking about (especially after ive tweaked things). If youre quoting the instance rules with that theres the rule #5 exception which can make bots transition to be opt out instead of opt in. If you want it removed from c++ node and cloud I can do that (I assume you do considering what youve been saying so will remove the three communities from the bots sight)

[-] Ategon@programming.dev 1 points 2 years ago* (last edited 2 years ago)

for node.js it seems like it was triggering on the .js which I just went through and removed so it should get barely any triggers now unless you explicitly mention something

for that community message it sent you posted an article about graphql and about performance

I made it not crosspost by default so I can tweak things and so people are guided for future posts. (and to prevent false positives while im tweaking things). Im purposely tweaking it to fire less and less and like I said im aiming to get it to fire on 2% of the posts

again, block the bot if you dont want it

[-] Ategon@programming.dev 1 points 2 years ago* (last edited 2 years ago)

dont think thats supported in it currently

all of the editor color settings though can be found by going to editor in the top bar->editor settings->text editor category->theme

[-] Ategon@programming.dev 1 points 2 years ago

starts december 1st

[-] Ategon@programming.dev 1 points 2 years ago

lol rip guess someone broke the modlog again. If a mod enters too large of a time lemmy cant handle it and just crashes the page

[-] Ategon@programming.dev 1 points 3 years ago
view more: โ€น prev next โ€บ

Ategon

0 post score
0 comment score
joined 3 years ago
MODERATOR OF