kota [he/him]

  • 7 Posts
  • 41 Comments
Joined 5 years ago
cake
Cake day: July 26th, 2020

help-circle










  • 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]@hexbear.nettolibre@hexbear.netLinux laptop suggestions?
    link
    fedilink
    English
    arrow-up
    4
    ·
    edit-2
    5 months 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.



  • 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).