Ategon

joined 1 year ago
MODERATOR OF
[โ€“] [email protected] 2 points 10 months ago* (last edited 10 months 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 10 months ago* (last edited 10 months 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 10 months ago* (last edited 10 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

[โ€“] [email protected] 15 points 10 months 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 10 months 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 10 months ago* (last edited 10 months 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 10 months ago* (last edited 10 months 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 10 months ago* (last edited 10 months 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 10 months ago* (last edited 10 months 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 10 months ago* (last edited 10 months 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 10 months ago* (last edited 10 months 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
[โ€“] [email protected] 1 points 10 months ago* (last edited 10 months ago) (1 children)

[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

1
Using Aseprite with Godot (gamefromscratch.com)
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/[email protected]
6
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/[email protected]
 

The jam is going to last for nine days and theme voting is currently open at https://strawpoll.com/polls/eNg69eDbWnA

If youre looking for a team you can use the #FediverseJam hashtag on mastodon or use the INAT community here on lemmy

You can find the jam here https://itch.io/jam/summer-fediverse-jam

 

Welcome to Feedback Friday! This is a day all about getting feedback on your projects.

Have a scene in your game that you want to know if it looks good? Have a mechanic prototype that you want tested? Want to know if your steam page is good? Or do you want feedback on some other part of your game? Feel free to post them below for others to give feedback!

 

Official mod support for dome keeper is out that will let you mod the game using gdscript

Theres a couple mods already out including a mod that adds a new keeper that I made

 

This is currently the largest online game jam. Definitely recommend participating if youre interested.

If anyones making a game for it make sure to show off your progress and finished game in the community!

 

Credit to one of the devs (Ste) for the description here

It's a generalized mod loader for GDScript-based Godot games.

The mod loader provides a convenient solution for users to create and distribute mods for your games in the form of zipped files/resource packs. The key feature is the ability to modify existing scripts without altering and redistributing the original game files.

Yes, we will port to Godot 4 soon. There hasn't been any demand for it yet, since the main games using it are on 3.5

Feel free to join our discord for questions, ideas, and support. https://discord.gg/J5AvdFK4mw

Two larger godot games that are using it currently are Brotato and Dome Keeper

view more: โ€น prev next โ€บ