Skip Navigation

Posts
421
Comments
587
Joined
3 yr. ago

Indie game developer 🇨🇦

Working on some games for game jams in my free time

Admin of programming.dev and frontend developer for sublinks

Account has automation for some scheduled posts

Site: https://ategon.dev/ Socials: https://ategon.carrd.co/

  • [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
    // ======
    
    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
    // ======
    
    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;
          }
        }
      }
    }
    
      
  • 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)

  • To make it go smaller tick the ignore texture size box

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

  • 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

  • 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

  • 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
  • [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
    // ======
    
    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
    // ======
    
    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

  • yeah that was updated a bit ago to let first requests be free. Looks like for some reason this post didnt federate to p.d until recently though

    Ill check out the code later in the week Edit: exams are taking too much of my time, maybe after exams

  • had some trolls who made an account there and started spamming nsfl content in a bunch of comment sections

  • Update: Ada is back and banned them, im refederating

  • Im going to temporarily defederate for now until they get the spam bot problem under control but once the admin comes online and gets everything sorted im refererating

  • Lemmy doesn't handle certain characters well currently such as left angle brackets and ampersands due to some sanitization in the back end to stop scripting attacks

  • [Rust] Harder one today, for part 1 I ended up getting stuck for a bit since I wasnt taking numbers at the end of lines into account and in part 2 I defined my gears vector in the wrong spot and spent a bit debugging that

    (lemmy removes some chars, all chars are in code link)

     
        
    use std::fs;
    
    fn part1(input: String) -> u32 {
        let lines = input.lines().collect::>();
        let mut sum = 0;
    
        for i in 0..lines.len() {
            let mut num = 0;
            let mut valid = false;
            let chars = lines[i].chars().collect::>();
    
            for j in 0..chars.len() {
                let character = chars[j];
                let parts = ['*', '#', '+', '$', '/', '%', '=', '-', '&', '@'];
    
                if character.is_digit(10) {
                    num = num * 10 + character.to_digit(10).unwrap();
    
                    if i > 0 {
                        if parts.contains(&lines[i - 1].chars().collect::>()[j]) {
                            valid = true;
                        }
    
                        if j > 0 {
                            if parts.contains(&lines[i - 1].chars().collect::>()[j - 1]) {
                                valid = true;
                            }
                        }
    
                        if j < chars.len() - 1 {
                            if parts.contains(&lines[i - 1].chars().collect::>()[j + 1]) {
                                valid = true;
                            }
                        }
                    }
    
                    if i < lines.len() - 1 {
                        if parts.contains(&lines[i + 1].chars().collect::>()[j]) {
                            valid = true;
                        }
    
                        if j > 0 {
                            if parts.contains(&lines[i + 1].chars().collect::>()[j - 1]) {
                                valid = true;
                            }
                        }
    
                        if j < chars.len() - 1 {
                            if parts.contains(&lines[i + 1].chars().collect::>()[j + 1]) {
                                valid = true;
                            }
                        }
                    }
    
                    if j > 0 {
                        if parts.contains(&lines[i].chars().collect::>()[j - 1]) {
                            valid = true;
                        }
                    }
    
                    if j < chars.len() - 1 {
                        if parts.contains(&lines[i].chars().collect::>()[j + 1]) {
                            valid = true;
                        }
                    }
                }
                else {
                    if valid == true {
                        sum += num;
                    }
    
                    num = 0;
                    valid = false;
                }
    
                if j == chars.len() - 1 {
                    if valid == true {
                        sum += num;
                    }
    
                    num = 0;
                    valid = false;
                }
            }
        }
    
        return sum;
    }
    
    fn part2(input: String) -> u32 {
        let lines = input.lines().collect::>();
        let mut gears: Vec<(usize, usize, u32)> = Vec::new();
        let mut sum = 0;
    
        for i in 0..lines.len() {
            let mut num = 0;
            let chars = lines[i].chars().collect::>();
            let mut pos: (usize, usize) = (0, 0);
            let mut valid = false;
    
            for j in 0..chars.len() {
                let character = chars[j];
                let parts = ['*'];
    
                if character.is_digit(10) {
                    num = num * 10 + character.to_digit(10).unwrap();
    
                    if i > 0 {
                        if parts.contains(&lines[i - 1].chars().collect::>()[j]) {
                            valid = true;
                            pos = (i - 1, j);
                        }
    
                        if j > 0 {
                            if parts.contains(&lines[i - 1].chars().collect::>()[j - 1]) {
                                valid = true;
                                pos = (i - 1, j - 1);
                            }
                        }
    
                        if j < chars.len() - 1 {
                            if parts.contains(&lines[i - 1].chars().collect::>()[j + 1]) {
                                valid = true;
                                pos = (i - 1, j + 1);
                            }
                        }
                    }
    
                    if i < lines.len() - 1 {
                        if parts.contains(&lines[i + 1].chars().collect::>()[j]) {
                            valid = true;
                            pos = (i + 1, j);
                        }
    
                        if j > 0 {
                            if parts.contains(&lines[i + 1].chars().collect::>()[j - 1]) {
                                valid = true;
                                pos = (i + 1, j - 1);
                            }
                        }
    
                        if j < chars.len() - 1 {
                            if parts.contains(&lines[i + 1].chars().collect::>()[j + 1]) {
                                valid = true;
                                pos = (i + 1, j + 1);
                            }
                        }
                    }
    
                    if j > 0 {
                        if parts.contains(&lines[i].chars().collect::>()[j - 1]) {
                            valid = true;
                            pos = (i, j - 1);
                        }
                    }
    
                    if j < chars.len() - 1 {
                        if parts.contains(&lines[i].chars().collect::>()[j + 1]) {
                            valid = true;
                            pos = (i, j + 1);
                        }
                    }
                }
                else {
                    if valid == true {
                        let mut current_gear = false;
                        
                        for gear in &gears {
                            if gear.0 == pos.0 && gear.1 == pos.1 {
                                sum += num * gear.2;
                                current_gear = true;
                                break;
                            }
                        }
                        
                        if !current_gear {
                            let tuple_to_push = (pos.0.clone(), pos.1.clone(), num.clone());
                            gears.push((pos.0.clone(), pos.1.clone(), num.clone()));
                        }
                    }
    
                    num = 0;
                    valid = false;
                }
    
                if j == chars.len() - 1 {
                    if valid == true {
                        let mut current_gear = false;
                        
                        for gear in &gears {
                            if gear.0 == pos.0 && gear.1 == pos.1 {
                                sum += num * gear.2;
                                current_gear = true;
                                break;
                            }
                        }
                        
                        if !current_gear {
                            let tuple_to_push = (pos.0.clone(), pos.1.clone(), num.clone());
                            gears.push((pos.0.clone(), pos.1.clone(), num.clone()));
                        }
                    }
    
                    num = 0;
                    valid = false;
                }
            }
        }
    
        return sum;
    }
    
    fn main() {
        let input = fs::read_to_string("data/input.txt").unwrap();
    
        println!("{}", part1(input.clone()));
        println!("{}", part2(input.clone()));
    }
    
      

    Code Link

  • Zoomed out graph including some months before the join wave

    Users/month are relatively stable now at 33x users/month compared to pre join wave (users/month is people who have posted or commented)

  • Rust (Rank 7421/6311) (Time after start 00:32:27/00:35:35)

    Extremely easy part 2 today, I would say easier than part 1 but they share the same sort of framework

    (Note lemmy removed some characters, code link shows them all)

     
        
    use std::fs;
    
    fn part1(input: String) -> i32 {
        const RED: i32 = 12;
        const GREEN: i32 = 13;
        const BLUE: i32 = 14;
    
        let mut sum = 0;
    
        for line in input.lines() {
            let [id, content] = line.split(": ").collect::>()[0..2] else { continue };
            let id = id.split(" ").collect::>()[1].parse::().unwrap();
    
            let marbles = content.split("; ").map(|x| { x.split(", ").collect::>() }).collect::>>();
            let mut valid = true;
    
            for selection in marbles {
                for marble in selection {
                    let marble_split = marble.split(" ").collect::>();
                    let marble_amount = marble_split[0].parse::().unwrap();
                    let marble_color = marble_split[1];
    
                    if marble_color == "red" && marble_amount > RED {
                        valid = false;
                        break;
                    }
    
                    if marble_color == "green" && marble_amount > GREEN {
                        valid = false;
                        break;
                    }
    
                    if marble_color == "blue" && marble_amount > BLUE {
                        valid = false;
                        break;
                    }
                }
            }
    
            if !valid {
                continue;
            }
    
            sum += id;
        }
    
        return sum;
    }
    
    fn part2(input: String) -> i32 {
        let mut sum = 0;
    
        for line in input.lines() {
            let [id, content] = line.split(": ").collect::>()[0..2] else { continue };
            let id = id.split(" ").collect::>()[1].parse::().unwrap();
    
            let marbles = content.split("; ").map(|x| { x.split(", ").collect::>() }).collect::>>();
            
            let mut red = 0;
            let mut green = 0;
            let mut blue = 0;
    
            for selection in marbles {
                for marble in selection {
                    let marble_split = marble.split(" ").collect::>();
                    let marble_amount = marble_split[0].parse::().unwrap();
                    let marble_color = marble_split[1];
    
                    if marble_color == "red" && marble_amount > red {
                        red = marble_amount;
                    }
    
                    if marble_color == "green" && marble_amount > green {
                        green = marble_amount;
                    }
    
                    if marble_color == "blue" && marble_amount > blue {
                        blue = marble_amount;
                    }
                }
            }
    
            sum += red * green * blue;
        }
    
        return sum;
    }
    
    fn main() {
        let input = fs::read_to_string("data/input.txt").unwrap();
    
        println!("{}", part1(input.clone()));
        println!("{}", part2(input.clone()));
    }
    
      

    Code Link

  • Im not sure how lemm.ee handles it but a lot of instances that aren't lemm.ee dont have uploads disabled

    For example this post has an image uploaded to .world

  • I dug through the code and turns out the post read table does store when its read (with number of comments when it was read stored in a person post aggregates table), it just only stores it for people from your instance so I cant get accurate numbers from all of lemmy (and why it seemed like there was a low amount)

  • The 118k is half year aka 6 months

    The one around 35k is month

  • Dont have access to those stats in the database so adding on voting is the best I can do

    Theres a post read table but its only people who have explicitly marked something as read and is way less than the post likes

  • Godot @programming.dev

    10 fresh Indie Games Made in the Godot Engine

  • Programming @programming.dev

    Community content vote results

  • Godot @programming.dev

    Weekly Discussion - July week 1

  • IAmA @programming.dev

    I'm Ategon, one of the admins on programming.dev, AMA!

  • Programming @programming.dev

    Community Content Vote

  • Lemmy Bots and Tools @programming.dev

    Awesome GitHub list of useful apps, tools and websites for Lemmy: dbeley/awesome-lemmy

    github.com /dbeley/awesome-lemmy
  • Godot @programming.dev

    Background Loading in Godot 4!

  • Godot @programming.dev

    Showcase Sunday

  • Godot @programming.dev

    Using Aseprite with Godot

    gamefromscratch.com /using-aseprite-with-godot/
  • Unity @programming.dev

    12 recipes for popular visual effects using the Universal Render Pipeline | Unity Blog

    blog.unity.com /engine-platform/12-recipes-for-popular-visual-effects-using-universal-render-pipeline
  • Unity @programming.dev

    The new Water System in Unity 2022 LTS and 2023.1 | Unity Blog

    blog.unity.com /engine-platform/new-hdrp-water-system-in-2022-lts-and-2023-1
  • Godot @programming.dev

    Dome Keeper - V 2.6 Mod Support Update is out now!

    store.steampowered.com /news/app/1637320/view/3649653272173229010
  • Cool GitHub Projects @programming.dev

    GitHub - jszczerbinsky/lwp: Multi-platform parallax wallpaper engine

    github.com /jszczerbinsky/lwp
  • Godot @programming.dev

    Godot Mod Loader V6.0 has been released

    github.com /GodotModding/godot-mod-loader/
  • Godot @programming.dev

    Sci Fi in Godot 4 ( Free Asset Download )

  • I Need a Team @programming.dev

    Welcome to INAT!

  • Haskell @programming.dev

    Welcome to the Programming.Dev haskell community!

  • Godot @programming.dev

    Showcase Sunday

  • Programming.dev Meta @programming.dev

    New community request community

    programming.dev /c/community_request
  • Unreal Engine @programming.dev

    Game Development Communities