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

servers been going down to update every so often. Usually you can get in after a bit when that happens and its up atm

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

JavaScript

Ended up misreading the instructions due to trying to go fast. Built up a system to compare hand values like its poker before I realized its not poker

Likely last day im going to be able to write code for due to exams coming up

Code Link

Code Block

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

function part1(input) {
  const lines = input.replaceAll("\r", "").split("\n");
  const hands = lines.map((line) => line.split(" "));

  const sortedHands = hands.sort((a, b) => {
    const handA = calculateHandValue(a[0]);
    const handB = calculateHandValue(b[0]);

    if (handA > handB) {
      return -1;
    } else if (handA < handB) {
      return 1;
    } else {
      for (let i = 0; i < 5; i++) {
        const handACard = convertToNumber(a[0].split("")[i]);
        const handBCard = convertToNumber(b[0].split("")[i]);
        if (handACard > handBCard) {
          return 1;
        } else if (handACard < handBCard) {
          return -1;
        }
      }
    }
  });

  return sortedHands
    .filter((hand) => hand[0] != "")
    .reduce((acc, hand, i) => {
      return acc + hand[1] * (i + 1);
    }, 0);
}

function convertToNumber(card) {
  switch (card) {
    case "A":
      return 14;
    case "K":
      return 13;
    case "Q":
      return 12;
    case "J":
      return 11;
    case "T":
      return 10;
    default:
      return parseInt(card);
  }
}

function calculateHandValue(hand) {
  const dict = {};

  hand.split("").forEach((card) => {
    if (dict[card]) {
      dict[card] += 1;
    } else {
      dict[card] = 1;
    }
  });

  // 5
  if (Object.keys(dict).length === 1) {
    return 1;
  }

  // 4
  if (Object.keys(dict).filter((key) => dict[key] === 4).length === 1) {
    return 2;
  }

  // 3 + 2
  if (
    Object.keys(dict).filter((key) => dict[key] === 3).length === 1 &&
    Object.keys(dict).filter((key) => dict[key] === 2).length === 1
  ) {
    return 3;
  }

  // 3
  if (Object.keys(dict).filter((key) => dict[key] === 3).length === 1) {
    return 4;
  }

  // 2 + 2
  if (Object.keys(dict).filter((key) => dict[key] === 2).length === 2) {
    return 5;
  }

  // 2
  if (Object.keys(dict).filter((key) => dict[key] === 2).length === 1) {
    return 6;
  }

  return 7;
}

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

function part2(input) {
  const lines = input.replaceAll("\r", "").split("\n");
  const hands = lines.map((line) => line.split(" "));

  const sortedHands = hands.sort((a, b) => {
    const handA = calculateHandValuePart2(a[0]);
    const handB = calculateHandValuePart2(b[0]);

    if (handA > handB) {
      return -1;
    } else if (handA < handB) {
      return 1;
    } else {
      for (let i = 0; i < 5; i++) {
        const handACard = convertToNumberPart2(a[0].split("")[i]);
        const handBCard = convertToNumberPart2(b[0].split("")[i]);
        if (handACard > handBCard) {
          return 1;
        } else if (handACard < handBCard) {
          return -1;
        }
      }
    }
  });

  return sortedHands
    .filter((hand) => hand[0] != "")
    .reduce((acc, hand, i) => {
      console.log(acc, hand, i + 1);
      return acc + hand[1] * (i + 1);
    }, 0);
}

function convertToNumberPart2(card) {
  switch (card) {
    case "A":
      return 14;
    case "K":
      return 13;
    case "Q":
      return 12;
    case "J":
      return 1;
    case "T":
      return 10;
    default:
      return parseInt(card);
  }
}

function calculateHandValuePart2(hand) {
  const dict = {};

  let jokers = 0;

  hand.split("").forEach((card) => {
    if (card === "J") {
      jokers += 1;
      return;
    }
    if (dict[card]) {
      dict[card] += 1;
    } else {
      dict[card] = 1;
    }
  });

  // 5
  if (jokers === 5 || Object.keys(dict).length === 1) {
    return 1;
  }

  // 4
  if (
    jokers === 4 ||
    (jokers === 3 &&
      Object.keys(dict).filter((key) => dict[key] === 1).length >= 1) ||
    (jokers === 2 &&
      Object.keys(dict).filter((key) => dict[key] === 2).length === 1) ||
    (jokers === 1 &&
      Object.keys(dict).filter((key) => dict[key] === 3).length === 1) ||
    Object.keys(dict).filter((key) => dict[key] === 4).length === 1
  ) {
    return 2;
  }

  // 3 + 2
  if (
    (Object.keys(dict).filter((key) => dict[key] === 3).length === 1 &&
      Object.keys(dict).filter((key) => dict[key] === 2).length === 1) ||
    (Object.keys(dict).filter((key) => dict[key] === 2).length === 2 &&
      jokers === 1)
  ) {
    return 3;
  }

  // 3
  if (
    Object.keys(dict).filter((key) => dict[key] === 3).length === 1 ||
    (Object.keys(dict).filter((key) => dict[key] === 2).length === 1 &&
      jokers === 1) ||
    (Object.keys(dict).filter((key) => dict[key] === 1).length >= 1 &&
      jokers === 2) ||
    jokers === 3
  ) {
    return 4;
  }

  // 2 + 2
  if (
    Object.keys(dict).filter((key) => dict[key] === 2).length === 2 ||
    (Object.keys(dict).filter((key) => dict[key] === 2).length === 1 &&
      jokers === 1)
  ) {
    return 5;
  }

  // 2
  if (
    Object.keys(dict).filter((key) => dict[key] === 2).length === 1 ||
    jokers
  ) {
    return 6;
  }

  return 7;
}

export default { part1, part2 };

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

yeah its our end and thats why. Federation should be fixed now (things posted when down wont be federated still but new things will. Were setting up a cron job now to get this updated every day so it shouldnt be a problem any more)

After 3 days of no response lemmy considers things dead but the issue is is its not checking for a response

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

Also adding onto this but there was an issue with the pictrs storage getting full that made the instance offline for a couple days while it affected it and so the instance could be moved to object storage. (communicated about over on the mastodon account since the site was down https://mastodon.social/@programming_dev/111237442491837823). Thats a separate issue from this one (and prevented this from getting tested properly for a bit)

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

Lemmy doesnt have shadow banning

Weve been struggling here with getting outbound federation working after the update to 0.18.5. Have an open issue on the lemmy repository about it. But basically currently any posts or comments made from programming.dev wont federate to other instances (but we still get all content)

Been running through some solutions today trying to get it up and probably going to pin a post about it

The grayed out button is new, normally it still lets you post but just wont show it in other instances.

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

Eh sure, its sort of on the border but if it survives the request zone it can be added. We just require all community ideas get a score of at least 7 from !community_request@programming.dev in order to get added to show theres enough interest in the idea

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

the difference with instances and communities is theres 1k instances and 30k communities. Communities are also created and removed as a much faster pace than instances and there would be different lists per instance (or the same, idk. Just thinking people might get auto subscribed to a bunch of different communities on the same topic, or instead an instance would get ignored)

Going to be making community flairs anyways in pangora so can just add it on

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

Bot guidelines for some of the major instances dont allow bot posting unless its been approved by a mod. Also makes more sense for mods to choose what bots to allow in their community rather than response bots being fully allowed everywhere since that can easily get out of hand if a bunch get made

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

Note the remindme bot uses an allowlist and this community isnt in it, youd have to get your community mods to request it gets added in the repository if you want to use it here

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

Your site activity here is fine, would be happy to have you. Already went through and dmed a couple people that that priority for the role before making a post here so going mostly off of fcfs for people that are at least decently active around various parts of the instance

If you pass me your discord account I can add you to the admin chats

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

Maybe around 5 hours a week. Definitely depends on what tasks youre doing though and for some things its mostly spread out in small intervals. No specific day that its concentrated on currently. tends to depend more on events in the space

Will send you a dm

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

Seems like thats more oriented towards development as opposed to fediverse admins but if theyre fine with admins coming in I can try talking to them. Do you know how I would contact the people running that

view more: ‹ prev next ›

Ategon

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