kota [he/him]

  • 21 Posts
  • 224 Comments
Joined 4 years ago
cake
Cake day: July 26th, 2020

help-circle


  • kota [he/him]toprogrammingAdvent of Code 2024 Day 1
    ·
    23 days ago

    Guess I'm a bit late on day one. Wound up doing mine in go, but maybe if I'm motivated I'll use something cooler later. Those elixir solutions are rad!

    part 1
    func main() {
    	b, err := os.ReadFile("input.txt")
    	if err != nil {
    		log.Fatalln(err)
    	}
    
    	d, err := distance(string(b))
    	if err != nil {
    		log.Fatalln(err)
    	}
    	fmt.Println(d)
    }
    
    func distance(input string) (int, error) {
    	var left []int
    	var right []int
    	for _, line := range strings.Split(input, "\n") {
    		fields := strings.Fields(line)
    		if len(fields) != 2 {
    			continue
    		}
    
    		l, err := strconv.Atoi(fields[0])
    		if err != nil {
    			return 0, err
    		}
    		left = append(left, l)
    
    		r, err := strconv.Atoi(fields[1])
    		if err != nil {
    			return 0, err
    		}
    		right = append(right, r)
    	}
    
    	slices.Sort(left)
    	slices.Sort(right)
    
    	var total int
    	for i := 0; i < len(left); i++ {
    		total += int(math.Abs(float64(left[i] - right[i])))
    	}
    
    	return total, nil
    }
    
    part 2
    func main() {
    	b, err := os.ReadFile("input.txt")
    	if err != nil {
    		log.Fatalln(err)
    	}
    
    	s, err := similarity(string(b))
    	if err != nil {
    		log.Fatalln(err)
    	}
    	fmt.Println(s)
    }
    
    func similarity(input string) (int, error) {
    	collisions := make(map[int]int)
    	var left []int
    	var right []int
    	for _, line := range strings.Split(input, "\n") {
    		fields := strings.Fields(line)
    		if len(fields) != 2 {
    			continue
    		}
    
    		l, err := strconv.Atoi(fields[0])
    		if err != nil {
    			return 0, err
    		}
    		left = append(left, l)
    		collisions[l] = 0
    
    		r, err := strconv.Atoi(fields[1])
    		if err != nil {
    			return 0, err
    		}
    		right = append(right, r)
    	}
    
    	for _, r := range right {
    		c := collisions[r]
    		collisions[r] = c + 1
    	}
    
    	var total int
    	for _, l := range left {
    		v := collisions[l]
    		total += l * v
    	}
    
    	return total, nil
    }
    



  • kota [he/him]tolibreLinux laptop suggestions?
    ·
    edit-2
    29 days ago

    Reasonably okay (but maybe don't get the absolute newest model), but not as good as the others which are all excellent. I mostly put them in the list because they've got excellent build quality, good keyboard, trackpad, etc, and a very nice screen. Basically if you want a macbook with linux (for cheaper than a macbook with linux https://asahilinux.org/) they're pretty reasonable. They also support openbsd which is neat https://jcs.org/2021/08/20/matebook

    The laptops I listed are in order of preference imo. Framework is definitely in a class of itself, but if they don't ship to your country or something then getting an xps with linux pre-installed is great and then finally as a backup either a thinkpad or matebook.



  • kota [he/him]tolibreLinux laptop suggestions?
    ·
    29 days ago

    Framework for sure, specifically the 13 with the new higher res screen. It’s a perfect 2x scale which is really nice.

    The older screen is fine, but some older x11 programs will be scaled wrong.

    There are other nice laptops of course: dell xps, thinkpad x1c, huawei matebooks, but imo the framework laptops are better in most regards and as a bonus you can upgrade the ram, cpu, and motherboard without needing to buy a new computer. You also can buy them without a windows license which usually makes them cheaper than the others for similar specs (unless you’re going for used of course).










  • If I had to take a wild shot in the dark my best guess is that your router's upstream connection settings are a bit messed up and whenever your ISP gives you a new ip dhcp is taking a long time for whatever reason. You could try to pay attention to if your outgoing ip changes whenever this happens https://www.showmyip.com/

    I guess also I'm assuming you're using a router with a built-in either cable or fiber modem? If you have a separate modem you might want to see about resetting it as well.


  • Wow that is fucking bizarre.. this isn't using powerline networking (ethernet over your power system via little wall sockets) or anything like that is it?

    I'd definitely start with a factory reset of your router. Some routers have a little pin you need to hold down with a paper clip. With others you'll have to do it from their web interface...

    You can usually get to the web interface by entering your default gateway in a browser. Something like http://192.168.0.1 or http://10.0.0.1 are common. It might be written on the back of your router. You can also usually find your default gateway in your connected network settings pretty easily: on my android phone it's just called "Gateway".

    Once you're in the web interface you'll probably need to put in login info which is almost always written on your router. Then navigate that hellscape until you can do a factory reset.

    Also if you're in the US and have a router provided by one of the big ISPs like Comcast, Verizon, Frontier, etc you're almost certainly renting your router for like $10 a month from those bastards. So call them up and make them fix it or get you a new router if they can't figure it out. You might as well try this before spending money buying a router. I saw your other comment that you've actually bought this router yourself. Resetting it might be slightly more tricky since you might need to configure the modem settings a bit, but it's usually pretty easy. Probably worth looking up and downloading a pdf of the manual for your router before you reset it though in case you need to read it without internet.