reboot6675

joined 1 year ago
[–] reboot6675@sopuli.xyz 2 points 1 day ago

Agree with Zero Mission. Second would be Dread and then Super. Haven't played Fusion tho, long overdue...

[–] reboot6675@sopuli.xyz 9 points 3 days ago

Usually artists go on tour after releasing a new album, to promote said album. So of course they're going to play new stuff.

The ideal for me is a good balance. Some new songs mixed with the classics.

[–] reboot6675@sopuli.xyz 1 points 2 months ago (1 children)

Go

Using a map to store u|v relations. Part 2 sorting with a custom compare function worked very nicely

spoiler

func main() {
	file, _ := os.Open("input.txt")
	defer file.Close()
	scanner := bufio.NewScanner(file)

	mapPages := make(map[string][]string)
	rulesSection := true
	middleSumOk := 0
	middleSumNotOk := 0

	for scanner.Scan() {
		line := scanner.Text()
		if line == "" {
			rulesSection = false
			continue
		}

		if rulesSection {
			parts := strings.Split(line, "|")
			u, v := parts[0], parts[1]
			mapPages[u] = append(mapPages[u], v)
		} else {
			update := strings.Split(line, ",")
			isOk := true

			for i := 1; i < len(update); i++ {
				u, v := update[i-1], update[i]
				if !slices.Contains(mapPages[u], v) {
					isOk = false
					break
				}
			}

			middlePos := len(update) / 2
			if isOk {
				middlePage, _ := strconv.Atoi(update[middlePos])
				middleSumOk += middlePage
			} else {
				slices.SortFunc(update, func(u, v string) int {
					if slices.Contains(mapPages[u], v) {
						return -1
					} else if slices.Contains(mapPages[v], u) {
						return 1
					}
					return 0
				})
				middlePage, _ := strconv.Atoi(update[middlePos])
				middleSumNotOk += middlePage
			}
		}
	}

	fmt.Println("Part 1:", middleSumOk)
	fmt.Println("Part 2:", middleSumNotOk)
}

[–] reboot6675@sopuli.xyz 1 points 2 months ago

Same, I initially also thought a|b and a|c implies a|c. However when I drew the graph of the example on paper, I suspected that all relations will be given, and coded it with that assumption, that turned out to be correct

[–] reboot6675@sopuli.xyz 2 points 2 months ago

I thought of Ernest & Celestine

[–] reboot6675@sopuli.xyz 2 points 2 months ago

Agree, I filled like half notebook with this game

[–] reboot6675@sopuli.xyz 1 points 2 months ago

Go

Just a bunch of ifs and bounds checking. Part 2 was actually simpler.

Code

func part1(W [][]rune) {
	m := len(W)
	n := len(W[0])
	xmasCount := 0

	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			if W[i][j] != 'X' {
				continue
			}
			if j < n-3 && W[i][j+1] == 'M' && W[i][j+2] == 'A' && W[i][j+3] == 'S' {
				// Horizontal left to right
				xmasCount++
			}
			if j >= 3 && W[i][j-1] == 'M' && W[i][j-2] == 'A' && W[i][j-3] == 'S' {
				// Horizontal right to left
				xmasCount++
			}
			if i < m-3 && W[i+1][j] == 'M' && W[i+2][j] == 'A' && W[i+3][j] == 'S' {
				// Vertical up to down
				xmasCount++
			}
			if i >= 3 && W[i-1][j] == 'M' && W[i-2][j] == 'A' && W[i-3][j] == 'S' {
				// Vertical down to up
				xmasCount++
			}
			if j < n-3 && i < m-3 && W[i+1][j+1] == 'M' && W[i+2][j+2] == 'A' && W[i+3][j+3] == 'S' {
				// Diagonal left to right and up to down
				xmasCount++
			}
			if j >= 3 && i < m-3 && W[i+1][j-1] == 'M' && W[i+2][j-2] == 'A' && W[i+3][j-3] == 'S' {
				// Diagonal right to left and up to down
				xmasCount++
			}
			if j < n-3 && i >= 3 && W[i-1][j+1] == 'M' && W[i-2][j+2] == 'A' && W[i-3][j+3] == 'S' {
				// Diagonal left to right and down to up
				xmasCount++
			}
			if j >= 3 && i >= 3 && W[i-1][j-1] == 'M' && W[i-2][j-2] == 'A' && W[i-3][j-3] == 'S' {
				// Diagonal right to left and down to up
				xmasCount++
			}
		}
	}

	fmt.Println(xmasCount)
}

func part2(W [][]rune) {
	m := len(W)
	n := len(W[0])
	xmasCount := 0

	for i := 0; i <= m-3; i++ {
		for j := 0; j <= n-3; j++ {
			if W[i+1][j+1] != 'A' {
				continue
			}
			if W[i][j] == 'M' && W[i][j+2] == 'M' && W[i+2][j] == 'S' && W[i+2][j+2] == 'S' {
				xmasCount++
			} else if W[i][j] == 'M' && W[i][j+2] == 'S' && W[i+2][j] == 'M' && W[i+2][j+2] == 'S' {
				xmasCount++
			} else if W[i][j] == 'S' && W[i][j+2] == 'S' && W[i+2][j] == 'M' && W[i+2][j+2] == 'M' {
				xmasCount++
			} else if W[i][j] == 'S' && W[i][j+2] == 'M' && W[i+2][j] == 'S' && W[i+2][j+2] == 'M' {
				xmasCount++
			}
		}
	}

	fmt.Println(xmasCount)
}

func main() {
	file, _ := os.Open("input.txt")
	defer file.Close()
	scanner := bufio.NewScanner(file)

	var W [][]rune
	for scanner.Scan() {
		line := scanner.Text()
		W = append(W, []rune(line))
	}

	part1(W)
	part2(W)
}

[–] reboot6675@sopuli.xyz 1 points 2 months ago

Honestly this is soo much better, I'm not proud of my code at all haha. Thanks for sharing, definitely adding that | to my bag of tricks

[–] reboot6675@sopuli.xyz 3 points 2 months ago (2 children)

Go

Part 1, just find the regex groups, parse to int, and done.

Part 1

func part1() {
	file, _ := os.Open("input.txt")
	defer file.Close()
	scanner := bufio.NewScanner(file)

	re := regexp.MustCompile(`mul\(([0-9]{1,3}),([0-9]{1,3})\)`)
	product := 0

	for scanner.Scan() {
		line := scanner.Text()
		submatches := re.FindAllStringSubmatch(line, -1)

		for _, s := range submatches {
			a, _ := strconv.Atoi(s[1])
			b, _ := strconv.Atoi(s[2])
			product += (a * b)
		}
	}

	fmt.Println(product)
}

Part 2, not so simple. Ended up doing some weird hack with a map to check if the multiplication was enabled or not. Also instead of finding regex groups I had to find the indices, and then interpret what those mean... Not very readable code I'm afraid

Part2

func part2() {
	file, _ := os.Open("input.txt")
	defer file.Close()
	scanner := bufio.NewScanner(file)

	mulRE := regexp.MustCompile(`mul\(([0-9]{1,3}),([0-9]{1,3})\)`)
	doRE := regexp.MustCompile(`do\(\)`)
	dontRE := regexp.MustCompile(`don't\(\)`)
	product := 0
	enabled := true

	for scanner.Scan() {
		line := scanner.Text()
		doIndices := doRE.FindAllStringIndex(line, -1)
		dontIndices := dontRE.FindAllStringIndex(line, -1)
		mulSubIndices := mulRE.FindAllStringSubmatchIndex(line, -1)

		mapIndices := make(map[int]string)
		for _, do := range doIndices {
			mapIndices[do[0]] = "do"
		}
		for _, dont := range dontIndices {
			mapIndices[dont[0]] = "dont"
		}
		for _, mul := range mulSubIndices {
			mapIndices[mul[0]] = "mul"
		}

		nextMatch := 0

		for i := 0; i < len(line); i++ {
			val, ok := mapIndices[i]
			if ok && val == "do" {
				enabled = true
			} else if ok && val == "dont" {
				enabled = false
			} else if ok && val == "mul" {
				if enabled {
					match := mulSubIndices[nextMatch]
					a, _ := strconv.Atoi(string(line[match[2]:match[3]]))
					b, _ := strconv.Atoi(string(line[match[4]:match[5]]))
					product += (a * b)
				}
				nextMatch++
			}
		}
	}

	fmt.Println(product)
}

[–] reboot6675@sopuli.xyz 2 points 2 months ago

Really cool trick. I did a bunch of regex matching that I'm sure I won't remember how it works few weeks from now, this is so much readable

[–] reboot6675@sopuli.xyz 4 points 2 months ago

Go. I actually I haven't written a single line of Go since last year's AoC so it's a good excuse to go again (pun intended).

[–] reboot6675@sopuli.xyz 3 points 2 months ago

I liked Digital Minimalism by Cal Newport. I found myself reaching for my phone more often than I would few years back, and doomscrolling at nights, and I got some good tips from this book.

I wouldn't say it solved all of my issues and I will be taking a look at the other books recommended here. But it did help me reduce screen time and focus more on tasks without feeling that I have to look at my phone every 5 minutes.

 
 

GOAT

579
Smile! (sopuli.xyz)
 

We're all gonna end up in one of those aren't we...

 

They turned around a 3-0, and won in penalties (6-5, went to sudden death)

I think more leagues should have relegation playoffs. One last chance of salvation for the upper team, one last chance of promotion for the lower team, and a thrilling game for the neutral fans.

 

So I joined a new gym last year and was pleasantly surprised. They gave me a smart card to get in and out, that's it, no app, no accounts, no nothing. Well, today I got to the gym and saw the announcement that they are phasing out the access with the smart card and starting to use, you guessed it, an app.

Now, I know this is not such a big deal in the grand scheme of things. But I'm just tired of this trend of replacing perfectly functioning systems with apps (public transport tickets come to mind). Just more ways to harvest people's data, I guess...

Ah and by the way, in my previous gym they not only required an app for accessing the place, they also incentivized people to track their workouts, meals and bodyweight using the gym's app (of course I never used any of these features).

 
 

Context: the creator of Linux is from Finland

 

They keep this 20+ year old laptop around because it has a serial port and every now and then that comes in handy.

You can't really see it in the picture but the laptop is pretty thick and heavy.

 

The news was already posted here last week, but I found this great technical explanation of the flaw. Long story short: Apple is using bad cryptography. They got alerted by researchers back in 2019 but didn't fix it.

 

Recently stumbled upon the PhD thesis of a researcher at the Eindhoven University of Technology from ~2 years ago. I haven't read the whole thing, but I thought it might be of interest for someone here. It's freely available for download on the link.

Excerpts from the preface:

The sheer number of the surveillance systems that we document in subsequent chapters reflects the industrial scale of data collection in the twenty-first century. We hope that future researchers will take up the challenge of addressing each covert program as a research subject to fully and completely explore, and to freely share their findings with the wider world in the spirit of open academic discussion. This kind of basic research is crucial to anti-surveillance software and hardware development.

The machinery of mass surveillance is simply too dangerous to be allowed to exist. We must work to ensure that no one will be able to say that they did not know, or that they were not warned. We must use all of the tools in our toolbox – economic, social, cultural, political, and of course, cryptographic – to blind targeted and mass surveillance adversaries.

 

So recently I was thinking how games with pixel art graphics are popular nowadays, and I was wondering if there are new games being made with other kinds of "retro" graphics, for example, games that look like the PS1 or PS2 eras.

Any recommendations?

 

I no longer build software; I now make furniture out of wood.

Source

view more: next β€Ί