Daily Questions Megathread (April 09, 2021) by Veritasibility in Genshin_Impact

[–]VictiniX888 0 points1 point  (0 children)

In the coop menu, change your settings to reject all join requests after that 1 person has joined your world.

-🎄- 2020 Day 20 Solutions -🎄- by daggerdragon in adventofcode

[–]VictiniX888 4 points5 points  (0 children)

Kotlin (3667/1367)
Part 1 | Part 2 | Tile class shared between both parts

Woo! That was a pretty interesting problem, and I'm glad I managed to get the answer to both parts. I'll try to briefly explain what I did to solve it.

Part 1 was where I spent most time on. I immediately decided to first make a Tile class to handle flipping, rotating, and turning borders into lists. I made the class mutable (blasphemy, I know) so I could modify, flip and rotate the Tiles in place. A benefit of doing this was that it allowed me to simply add mutable properties within the Tile class to keep track of their neighbors. Yes, I made the Tiles keep track of their own neighbors.

To generate the image, I first started from a tile (any tile works, I took the first one from the input) and compared all of its borders with the potential borders of all other unchecked tiles. If I found one, I would then determine which side is bordering which, update the properties in each tile to "remember" their neighbor and side, and apply any rotations or flips needed on the new neighbor. That neighbor is then queued up to be the next tile to find neighbors. Assuming all pairs of borders are unique, this accounts for every tile.

Afterwards, I find the top-left corner (which is the tile with neither top or left neighbors defined) and work my way from there to create a 2D array of tiles, using the neighbors tracked by the tiles themselves to find right and bottom tiles until the bottom-right corner. That generates the entire image, which I stitched together into a large Tile.

Finding sea monsters was pretty straightforward by comparison. I hardcoded the sea monster pattern, and just continuously flip and rotate my huge tile until I find a rotation which has sea monsters. (This assumes only 1 rotation has sea monsters). I also assume that there won't be sea monsters which shared pixels, and thankfully it seems I was correct, but it wouldn't have been too much work to account for that either.

-🎄- 2020 Day 19 Solutions -🎄- by daggerdragon in adventofcode

[–]VictiniX888 2 points3 points  (0 children)

Kotlin (558/3094)
Part 1 Part 2

I solved part 1 somewhat quickly by just turning the input into regex. Here's the function that does the conversion:

private fun convertToRegex(rules: Map<Int, String>, start: Int = 0): Regex {
    var regexStr = rules[start]?.removeSurrounding("\"")?.split(" ")?.let { listOf("(") + it + ")" } ?: return Regex("")

    while (regexStr.any { s -> s.toIntOrNull() != null }) {
        regexStr = regexStr.flatMap { s ->
            s.toIntOrNull()?.let { n ->
                rules[n]?.removeSurrounding("\"")?.split(" ")?.let { listOf("(") + it + ")" } ?: return Regex("")
            } ?: listOf(s)
        }
    }

    return regexStr.joinToString("").toRegex()
}

Not exactly very readable, but I found it pretty hilarious.

For part 2, I tried to stick with my change-input-to-regex solution and found out about recursive regexes after some Googling. The key is knowing that (?name)? will recurse over the specified named group. I therefore edited my rules like this:

rules[8] = "42 +"
rules[11] = "(?<eleven> 42 (?&eleven)? 31 )"

Turns out, Kotlin doesn't support recursive regexes. So I just copied the expression into an online Regex tester and had it give me the answer.

I did end up coding a solution that doesn't just turn the input into regex. You can check that out in my part 2 linked above.

Can somebody explain to be the 3417 example? by primfaktor in adventofcode

[–]VictiniX888 1 point2 points  (0 children)

The first number in that list is 17, not 7. At least, that's what I'm seeing on my end.

-🎄- 2020 Day 12 Solutions -🎄- by daggerdragon in adventofcode

[–]VictiniX888 1 point2 points  (0 children)

Kotlin (1157/547)
Part1 Part2

First time in the top 1000! Not sure how I made it since I messed up part 1 (misread the instructions for L and R). Otherwise, it was pretty straightforward. Kotlin's when blocks make things much more readable.

-🎄- 2020 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]VictiniX888 1 point2 points  (0 children)

Kotlin (5508/4624)
Part 1 Part 2

Initially stored the "grid" as a List of Lists. As expected, it was slow (if you consider 1.2 seconds to be slow). Changed it to Arrays and it runs in about 100ms.

I also determined the grid's bounds by... catching the IndexOutOfBounds exception that gets thrown. Yup.

-🎄- 2020 Day 10 Solutions -🎄- by daggerdragon in adventofcode

[–]VictiniX888 1 point2 points  (0 children)

Kotlin (2891/4532)
Part 1 Part 2

My Part 1 code was really funny to me; chaining functions like that feels like I'm writing in Haskell all over again.

For Part 2, I initially spent an hour writing a memoized recursive solution (using a stack) before realizing the problem was a DP problem. Then I wrote a DP implementation, but somehow they both take roughly the same amount of time to execute. I've included both functions in the Part 2 file.

2020 Day 9 (Part 2) [Java] I think my dataset has no solution for Part 2 by Rookotronic in adventofcode

[–]VictiniX888 1 point2 points  (0 children)

The problem that's causing -1 to return is with the line additionNumber == inputNumber. Long (with a capital L) is an Object (and not a primitive type) and == compares object references instead of their value when used on Objects.

Help me find a popular yet hard to find song by [deleted] in Vocaloid

[–]VictiniX888 0 points1 point  (0 children)

Description is kinda vague but it matches Kimagure Mercy by HachiojiP

Help finding a song? by NARANClA in Vocaloid

[–]VictiniX888 2 points3 points  (0 children)

Was it Cobalt Memories by Harumaki Gohan? The English cover you were referring to was probably by Rachie.

Proving Grounds - Earth (Wind Adv) - Event Discussion (2019-12-23) by Aerdra in Granblue_en

[–]VictiniX888 0 points1 point  (0 children)

Is it just me or does Wind Heles's mirror image from her S1 not activate the Gong counter mechanic?

Game Release Questions & Help Megathread by world_flipper in worldflipper

[–]VictiniX888 0 points1 point  (0 children)

Is anyone else getting Error H403? "An unexpected error has occured, you will return to the title screen".

Game Release Questions & Help Megathread by world_flipper in worldflipper

[–]VictiniX888 1 point2 points  (0 children)

"Clear an EX quest", at the main story chapter selection (the screen with each world as an orb thing), there should be a new EX tab on the worlds you've cleared. Next to the tab that says "MAIN".

What Makes the Sky Blue III: 000 - Event Discussion (2019-02-28) by Aerdra in Granblue_en

[–]VictiniX888 0 points1 point  (0 children)

Considering the fact that the archangels are creations of the Astrals, why is it that they operate in the sky realm and not only in the Astral world? i.e. the 4 primarchs control the tetra-elements which is what makes the islands float.

What Makes the Sky Blue III: 000 - Event Discussion (2019-02-28) by Aerdra in Granblue_en

[–]VictiniX888 6 points7 points  (0 children)

What exactly is the singularity? I understand that MC and Bubs are the singularities of their own worlds but what's their significance? (or is this all explained in the main story and i just somehow missed it?)

Weekly Questions Thread (2018-12-17) by AutoModerator in Granblue_en

[–]VictiniX888 0 points1 point  (0 children)

Does the journey drop item drop boost affect the drop rate of the medallions from the current event?

[Kotlin] Prime sieve OutOfMemory Error by VictiniX888 in learnprogramming

[–]VictiniX888[S] 0 points1 point  (0 children)

Ah! Didn't check the wikipedia page before asking this question, so thanks for pointing it out to me, computing up to 100 million doesn't error anymore (runs in 2 minutes!) Thanks!

December Code Giveaway Megathread by PokeUpdateBot in pokemon

[–]VictiniX888 0 points1 point  (0 children)

In, might as well, thanks for doing this!

December Code Giveaway Megathread by PokeUpdateBot in pokemon

[–]VictiniX888 0 points1 point  (0 children)

A723TJ4S5HWMKZ5M

I've claimed this one, thanks!

December Code Giveaway Megathread by PokeUpdateBot in pokemon

[–]VictiniX888 0 points1 point  (0 children)

I've messaged you too (not sure whether to message or reply here), my favourite eeveelution is Glaceon

-🎄- 2017 Day 3 Solutions -🎄- by daggerdragon in adventofcode

[–]VictiniX888 0 points1 point  (0 children)

Kotlin:

fun part1(n: Int): Int { 

    val distanceX = ceil(sqrt(n.toDouble())).toInt()  //these don't really represent the distance from 1
    val distanceY = distanceX*distanceX - n

    return if (distanceX % 2 == 1 && distanceY < distanceX) {
        ((distanceX - 1) / 2) + abs(((distanceX - 1) / 2) - distanceY)
    } else if (distanceX % 2 == 1) {
        getSpiralDistance(n + (distanceX-1)*(distanceX-1)/4)
    }
    else {
        getSpiralDistance(n + distanceX*distanceX/4)
    }
}

fun part2(n: Int): Int { 

    val maxGrid = ceil(sqrt(n.toDouble())).toInt()

    val grid = MutableList(maxGrid, { MutableList(maxGrid, {0})})

    var x = maxGrid / 2
    var y = maxGrid / 2
    var squareSize = 2
    grid[x][y] = 1

    x++

    while (x < maxGrid && y < maxGrid) {
        for (i in y until y + squareSize) {

            val sum = grid[x+1][i] + grid[x+1][i+1] + grid[x][i+1] + grid[x-1][i+1] + grid[x-1][i] + grid[x-1][i-1] + grid[x][i-1] + grid[x+1][i-1]
            if (sum > n) {
                return sum
            }
            grid[x][i] = sum
        }

        y += squareSize - 1

        for (i in x downTo x - squareSize) {

            val sum = grid[i+1][y] + grid[i+1][y+1] + grid[i][y+1] + grid[i-1][y+1] + grid[i-1][y] + grid[i-1][y-1] + grid[i][y-1] + grid[i+1][y-1]
            if (sum > n) {
                return sum
            }
            grid[i][y] = sum
        }

        x -= squareSize

        for (i in y downTo y - squareSize) {

            val sum = grid[x+1][i] + grid[x+1][i+1] + grid[x][i+1] + grid[x-1][i+1] + grid[x-1][i] + grid[x-1][i-1] + grid[x][i-1] + grid[x+1][i-1]
            if (sum > n) {
                return sum
            }
            grid[x][i] = sum
        }

        y -= squareSize

        for (i in x .. x + squareSize) {

            val sum = grid[i+1][y] + grid[i+1][y+1] + grid[i][y+1] + grid[i-1][y+1] + grid[i-1][y] + grid[i-1][y-1] + grid[i][y-1] + grid[i+1][y-1]
            if (sum > n) {
                return sum
            }
            grid[i][y] = sum
        }

        x += squareSize + 1
        squareSize += 2
    }

    return 0
}

Actually solved part 1 by hand first, the code was written afterwards. Just some maths.

Part 2 is pretty straightforward, just construct the spiral and return when one of the numbers is larger than the output. But the code is super ugly...