Ategon

joined 2 years ago
MODERATOR OF
[โ€“] [email protected] 2 points 1 year ago

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

[โ€“] [email protected] 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)

[โ€“] [email protected] 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

[โ€“] [email protected] 4 points 1 year ago* (last edited 1 year 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

[โ€“] [email protected] 14 points 1 year ago (4 children)

Starting off banner submissions with a quick banner generated from midjourney

Example view of it in lemmy explorer

[โ€“] [email protected] 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

[โ€“] [email protected] 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;
      }
    }
  }
}

[โ€“] [email protected] 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)

[โ€“] [email protected] 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

[โ€“] [email protected] 2 points 1 year ago* (last edited 1 year ago) (5 children)

the keep aspect covered is similar but one side will clip out while the other is the right size, and keep aspect with no modifier (and centered) will fit but not take the full button (it will take as much as it can without destroying the texture)

if theres issues with it appearing and you have scale set it might be something to do with the border being too small or sizes being a bit wonky so that it tries to take up the full space but it goes out of the bounds of the parent

I would try it with just a texturebutton like I did there with nothing else as the parent (or a basic control) and just set stretch mode and normal texture and see what happens

[โ€“] [email protected] 1 points 1 year ago* (last edited 1 year ago) (6 children)

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

[โ€“] [email protected] 1 points 1 year ago* (last edited 1 year 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
 

Bot I made for the [email protected] community to notify me when a post got a large amount of upvotes so I can make the requested community. Can be adapted for different cases if you want to ping someone, give a congratulations message, etc.

If you have any feature requests feel free to throw them into the issues tab in the repo

4
submitted 2 years ago* (last edited 2 years ago) by [email protected] to c/[email protected]
 

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.


  • ๐Ÿ”— 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 @[email protected] 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 [email protected] [email protected] and [email protected] 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

view more: โ€น prev next โ€บ