Ategon

joined 2 years ago
MODERATOR OF
[โ€“] Ategon@programming.dev 2 points 11 months ago* (last edited 11 months ago) (1 children)

This is more a community for the development side being activitypub instead of fediverse

Theres communities like !fediverse@lemmy.world though

I haven't touched friendica much so dont know the answer to that

[โ€“] Ategon@programming.dev 1 points 11 months ago* (last edited 11 months 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 2 points 11 months ago* (last edited 11 months ago)

top left of the site in the navbar, and for sites who collect all of the different instances such as join-lemmy and lemmyverse. Also shows up in things like error pages in the new frontend

Smaller in the navbar but in the cases of join-lemmy and the things like error pages its larger (you can see the size by going to https://join-lemmy.org/instances?topic=all_topics&language=all&scroll=true)

[โ€“] Ategon@programming.dev 2 points 11 months ago

Uses typescript but can be used for both js and ts, I make bots in Javascript using it

[โ€“] Ategon@programming.dev 2 points 1 year ago* (last edited 1 year ago)

[JavaScript] Relatively easy one today

Paste

Part 1

function part1(input) {
  const split = input.split("\n");
  const times = split[0].match(/\d+/g).map((x) => parseInt(x));
  const distances = split[1].match(/\d+/g).map((x) => parseInt(x));

  let sum = 0;

  for (let i = 0; i < times.length; i++) {
    const time = times[i];
    const recordDistance = distances[i];

    let count = 0;

    for (let j = 0; j < time; j++) {
      const timePressed = j;
      const remainingTime = time - j;

      const travelledDistance = timePressed * remainingTime;

      if (travelledDistance > recordDistance) {
        count++;
      }
    }

    if (sum == 0) {
      sum = count;
    } else {
      sum = sum * count;
    }
  }

  return sum;
}

Part 2

function part2(input) {
  const split = input.split("\n");
  const time = parseInt(split[0].split(":")[1].replace(/\s/g, ""));
  const recordDistance = parseInt(split[1].split(":")[1].replace(/\s/g, ""));

  let count = 0;

  for (let j = 0; j < time; j++) {
    const timePressed = j;
    const remainingTime = time - j;

    const travelledDistance = timePressed * remainingTime;

    if (travelledDistance > recordDistance) {
      count++;
    }
  }

  return count;
}

Was a bit late with posting the solution thread and solving this since I ended up napping until 2am, if anyone notices theres no solution thread and its after the leaderboard has been filled (can check from the stats page if 100 people are done) feel free to start one up (I just copy paste the text in each of them)

[โ€“] Ategon@programming.dev 5 points 1 year ago* (last edited 1 year ago) (2 children)

Theres a lot of different frameworks to use for creating them

The most popular one is lemmy-bot which uses js (and has descriptions for how to use it on the page)

Theres also one in python though here with a couple examples in its repo

[โ€“] Ategon@programming.dev 4 points 1 year ago* (last edited 11 months ago) (2 children)

Ill be submitting some logos and another banner that im making in gimp later in the week

Edit: exams are pain, will do that before the end of the month

[โ€“] Ategon@programming.dev 15 points 1 year ago (4 children)

Starting off banner submissions with a quick banner generated from midjourney

Example view of it in lemmy explorer

[โ€“] Ategon@programming.dev 1 points 1 year 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 5 points 1 year ago* (last edited 1 year ago) (3 children)

[JavaScript] Well that was by far the hardest out of all of the days, part 1 was relatively fine but part 2 took me awhile of trying different things

Ended up solving it by working backwards by trying different location values and seeing if that can become a valid seed. Takes around 3 secs to compute the answer.

Link to code

Part 1 Code Block

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

function part1(input) {
  const split = input.split("\r\n\r\n");

  let pastValues = split[0].match(/\d+/g).map((x) => parseInt(x));
  let currentValues = [];

  for (const section of split.slice(1)) {
    for (const line of section.split("\r\n")) {
      const values = line.match(/\d+/g)?.map((x) => parseInt(x));

      if (!values) {
        continue;
      }

      const sourceStart = values[1];
      const destinationStart = values[0];
      const length = values[2];

      for (let i = 0; i < pastValues.length; i++) {
        if (
          pastValues[i] >= sourceStart &&
          pastValues[i] < sourceStart + length
        ) {
          currentValues.push(destinationStart + pastValues[i] - sourceStart);
          pastValues.splice(i, 1);
          i--;
        }
      }
    }

    for (let i = 0; i < pastValues.length; i++) {
      currentValues.push(pastValues[i]);
    }

    pastValues = [...currentValues];
    currentValues = [];
  }

  return Math.min(...pastValues);
}

Part 2 Code Block

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

function part2(input) {
  const split = input.split("\r\n\r\n");

  let seeds = split[0].match(/\d+/g).map((x) => parseInt(x));
  seeds = seeds
    .filter((x, i) => i % 2 == 0)
    .map((x, i) => [x, seeds[i * 2 + 1]]);

  const maps = split
    .slice(1)
    .map((x) => {
      const lines = x.split("\r\n");
      return lines
        .map((x) => x.match(/\d+/g)?.map((x) => parseInt(x)))
        .filter((x) => x);
    })
    .reverse();

  for (let i = 0; true; i++) {
    let curValue = i;

    for (const map of maps) {
      for (const line of map) {
        const sourceStart = line[1];
        const destinationStart = line[0];
        const length = line[2];

        if (
          curValue >= destinationStart &&
          curValue < destinationStart + length
        ) {
          curValue = sourceStart + curValue - destinationStart;
          break;
        }
      }
    }

    for (const [seedRangeStart, seedRangeLength] of seeds) {
      if (
        curValue >= seedRangeStart &&
        curValue < seedRangeStart + seedRangeLength
      ) {
        return i;
      }
    }
  }
}

[โ€“] Ategon@programming.dev 3 points 1 year ago* (last edited 1 year ago) (1 children)

Yeah, if that's causing the issue you might be running into a case where when trying to make the image smaller it ends up not having enough pixels to show the border properly. Typically people make textures the size of what they want the final texture size to be rather than messing with proportions afterwards due to things like that (and so you don't have to store larger images than required)

[โ€“] Ategon@programming.dev 2 points 1 year ago* (last edited 1 year ago) (3 children)

To make it go smaller tick the ignore texture size box

That will make it so you can force it past the texture size

17
submitted 1 year ago* (last edited 1 year ago) by Ategon@programming.dev to c/lemmy_dev@programming.dev
 

Heres a list of lemmy bots that you can find! If you have any to add feel free to add a reply and mention them


Global Bots (active in most instances)


  • โŒ› RemindMe (programming.dev) - A reminder bot that triggers off of both mentions and keywords to catch people trying to use the reddit bot syntax.

  • โŒ› remindme (lemmy.icyserver.eu) - A reminder bot that triggers off of mentions.

  • ๐Ÿ”— CommunityLinkFixerBot (lemmings.world) - A bot that responds with fixed links to communities when a regular community link is posted so people dont have to leave their instance


Programming.Dev Bots (active in certain communities in programming.dev)





  • ๐Ÿค– AutoTLDR - A bot that creates a summary of a post, comment, or link when mentioned


feddit.nl Bots (active in certain communities in feddit.nl)


  • ๐Ÿ“ˆ tcbot - A bot that shows currently trending communities

 

Im currently hosting this bot here on programming.dev and have it set to federate with everything programming.dev does so you dont need to self host

To trigger the bot just tag @RemindMe@programming.dev at the start of your comment and then put the amount of time you want to be reminded in

  • Supports everything from seconds to years up to a maximum of 10 years
  • Supports other activitypub platforms as long as they can make a message in lemmy (ex. mastodon)

If you have any improvements or suggestions feel free to make an issue/pull request in the repo

~~Edit: Now works based on keywords so you can summon it with !remindme instead of a full ping~~ See edit 4

~~Edit 2: Kbin seems to break it if your comment doesnt have language set to english. Not something I can fix, kbin is going to have to~~ See edit 3

Edit 3: Ive fixed the kbin bug for all communities in the instance. No promises if it doesnt respond in a non programming.dev instance though as their language settings may be different and block replies to your comments

Edit 4: The bot is temporarily offline so I can make it follow the lemmy.world bot guidelines

 

This is a bot I made for the programming books community here on programming.dev to prevent pirating but can be adapted to any community.

It has functionality for both a whitelist and a blacklist and has templates so you can share ban lists between communities. It also detects in both posts and comments

Since it deals with deleting messages it needs mod permissions in communities you want to use it for

Feel free to dm me if you need some help with getting it set up

 

This is a place where you can share and discuss books relating to the instance

Links are currently disabled in the community. If you have a domain that you feel should be whitelisted feel free to let me know and ill add it. (This rule is just in place to prevent pirating books)

And if you want to be a mod for the community let me know

 

The bot api got updated so updated my rss feed bot to V0.18 as well

It auto posts new things from rss feeds into communities. I currently have it set up in !godot@programming.dev !unity@programming.dev and !unreal_engine@programming.dev posting official news from the engines and some other people are using it as well (one having adapted it to post news from their city)

If you want to set it up and are having issues feel free to ask me about it.

In this update theres also some other things about the bot that have changed

  • Data is now pulled from a yaml file so its easier to deal with as opposed to digging through the javascript code in order to change stuff
  • Important values such as how long the bot will wait before checking for new posts have been parameterized
  • You can now post things that are in two rss feeds or in one rss feed but not another if you want to filter posts down a bit more
  • You can set a date cutoff for how long ago you want to backpost posts from
 
 

Prop Game, Chelesste, 3D Adventure Minigolf, Astrobrawl, Aether, AXIAL: Prototype, Barkelona, Knights of the Road, Bunker 21 Extended Edition

 

cross-posted from: https://programming.dev/post/653659

The theme of the game jam voted on by participants is Parallel Worlds

Feel free to share progress of games you're working for it around the fediverse. We have a hashtag on the microblogging platforms #FediverseJam and there are engine specific communities like godot, unity, unreal, etc. that you can find on programming.dev

The jam will last for nine days before submissions to the itch.io page close https://itch.io/jam/summer-fediverse-jam

Ill be streaming games submitted to the jam and will do a video showcasing the entries once results are out

Hope you enjoy! Ill be aiming to run these twice a year as a way to encourage some more game dev activity around the fediverse

view more: โ€น prev next โ€บ