#AoC 2022 | Day 22 | Solutions & Spoilers

601 messages · Page 1 of 1 (latest)

glass dune
#

🎄 ▶️ #️⃣ 🧊 ⭐

iron sparrow
#

piss.

dull willow
#

upside down c for me

dull idol
#

my actual input looks like

 ##
 # 
## 
#  
kindred finch
#

oh

#

same

dull idol
#

so, uhh, great waste of 15+ minutes I guess

dull willow
#

we all have same?

#

shape i mean

kindred finch
#

damn

#

golfing actually seems possible now

dull idol
#

if everyone has the same shape and it's not the one in the test, then that actively disincentivizes checking on the test

#

because if I'd done all the work I'd done for the actual input, rather than the test, I'd be done right now

dull willow
iron sparrow
magic ridge
kindred finch
dull willow
#

i see

iron sparrow
#

ok but

#

why didn't eric

#

give the same layout

#

for the sample test

#

as he did

dull willow
#

same for robot day

iron sparrow
#

the actual tc

dull willow
#

that threw me

magic ridge
#

are answers in the hundred thousands

iron sparrow
#

yeah

magic ridge
#

my answer is still too high

#

it produces 185100

#

somehow works for test input

dull willow
#

my visualiser for folding

brittle wing
#

Wait did everyone get the same shape LOL

#

I'm ngl I just hardcoded the connections

#

Did anyone actually implement an algorithm to fold the net?

limber torrent
#

!code

flat fjordBOT
#

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

limber torrent
#

!paste

flat fjordBOT
#

Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

limber torrent
#

hey if anyone wants to help me debug

#

:>>

brittle wing
#

That is the worst code I have ever seen

limber torrent
#

thank you

brittle wing
#

Please tell me you didn't write that by hand

limber torrent
#

i did

#

💀

#

🧌

#

there's probably some fancy math shit

#

but i really don't want to figure it out rn

magic ridge
#

help

limber torrent
#

what did your cube look like

brittle wing
#
 01
 2
34
5
limber torrent
#

huh

#

me with my pro logic

#

i give up for now

#

i'll figure it out later

sullen creek
#

i tried using multiplication to figure things out

#

because i had complex numbers

limber torrent
#

pt 2?

#

isn't it 3d

sullen creek
#

yeah

#

but i had a table for connections and transformations

limber torrent
#

damn

sullen creek
#

which for some reason didn't work 😭

magic ridge
#

how do you fold this

limber torrent
#

just draw it out

#

and literally fold it

magic ridge
#

i skipped part 1 and i'm currently in the process of trying to skip part 2

limber torrent
#

if you want to look at my shitty arrows

#

it probably works

magic ridge
#

barely visible outline of the input

limber torrent
#

i think everyone had that

magic ridge
#

how the hell do you fold that

limber torrent
#

with all my arrows

#

🧌

#

im gonna go to sleep

magic ridge
#

i'm making a gif

limber torrent
#

i don't want to do another impl

#

of cube

#

gngn

flat fjordBOT
#

day_22.py lines 113 to 120

face_connections=[
    [(1, (1, 0)), (2, (0, 1)), (3, (1, 0)), (4, (1, 0))],
    [(4, (-1, 0)), (2, (-1, 0)), (0, (-1, 0)), (5, (0, -1))],
    [(1, (0, -1)), (4, (0, 1)), (3, (0, 1)), (0, (0, -1))],
    [(4, (1, 0)), (5, (0, 1)), (0, (1, 0)), (2, (1, 0))],
    [(1, (-1, 0)), (5, (-1, 0)), (3, (-1, 0)), (2, (0, -1))],
    [(4, (0, -1)), (1, (0, 1)), (0, (0, 1)), (3, (0, -1))],
],```
brittle wing
#

Apparently I can't get it to spoiler that lol

sullen creek
#

finally got my soln working

#

that took way too long

kindred finch
#

same

#

I'm just surprised I did the face connections correct first try

sullen creek
#

it was not fun that the cube faces had an even number of characters

#

which screwed up some of my transformations

broken dome
#

Is this normal? A part of the input is split with double lines and a part is not

sullen creek
#

wtf

brittle wing
#

It's not double lines, it's being wrapped

sullen creek
#

weird wrapping then

#

considering the other lines weren't wrapped

#

but have the same number of chars

brittle wing
#

The input doesn't contain trailing whitespace

#

It's very annoying

sullen creek
#

didn't annoy me much ngl

flat fjordBOT
#

day_22.py line 28

"\n".join(f"{row:{max_len}}" for row in map.splitlines()),```
brittle wing
#

😒

sullen creek
#

i just stored it in a dict

#

just seems like the easier solution ngl

magic ridge
kindred finch
#

you don't

#

you calculate it once and assume it works after that

sullen creek
#

now we wait for someone to golf

kindred finch
#

I can't golf mine bc it uses numpy

brittle wing
#

It tells you your new face and direction

sullen creek
#

mine is full vanilla but i need to add logic for generating the transformation and adjacency tables

brittle wing
#

Same here

kindred finch
sullen creek
#

no

kindred finch
#

oh no

sullen creek
#
 XX
 X
XX
X```
#

wait

#

nvm

kindred finch
#

yeah I thought so

sullen creek
#

on mobile the spaces on the first line don't show

#

looked like this

kindred finch
#

ah

sullen creek
#

my alt had the same shape input

#

so maybe everyone does get the same shape

kindred finch
#

everyone else here seems to have the same shape as well

#
  • reddit too
sullen creek
#

pretty much confirmed then

kindred finch
#

yeah

sullen creek
#

golf will be a bit easier

kindred finch
#

a lot easier imo, I don't even know where to get started on algorithmically folding a cube and linking its edges

timid escarp
#

I did a for num, dir in re.findall(r"(\d+)(R|L)", path): on the first problem and I took a second to think "is this going to bite me? Na..." and then it bit me because it ended with a number. If not for that mistake, I would've made the global leaderboard for part 1

timid escarp
broken dome
brittle wing
#

Zoom out

#

(the lines are 150c long)

magic ridge
brittle wing
#

It's looking like it, yeah

solar tree
#

the ascii art of someone slowly going insane

kindred finch
#

at least it wasn't an isocahedron or something

olive falcon
#

someone else strip'd the input? 👀

solar tree
#

rust macros are fun, you can turn your structured notes into code 😄

brittle wing
#

Yeah macros are great for that

drowsy lichen
#

this one is hard

solar tree
brittle wing
#

That reminds me, I need to fix aoc_helper's example fetching stripping the front lol

solar tree
#

I feel this one is hard implementation-wise, rather than being conceptually hard

#

i.e. it's obvious conceptually what to do, actually executing it and writing semi-sane code for it is the hard part 😛

brittle wing
#

I totally agree with that

olive falcon
#

i've spent quite a long time hard-coding and bug fixing the edges.

#

but it was almost impossible to debug.

solar tree
#

I did get the edges correct, I'm so happy I did the macros to keep the cases readable

#

having mostly the same code duplicated 14 times would have been painful

solar tree
#

think hard once to create the diagram, refer to the diagram N times later on

dull idol
# kindred finch ~~at least it wasn't an isocahedron or something~~

aoc 2023 day22 part 2 is gonna be like

You approach the strange input device, but it isn't quite what the monkeys drew in their notes. Instead, you are met with a strange-looking shape; each of its twenty-four faces is a square of 50x50 tiles.
To be fair, the monkeys' map does have 24 50x50 regions on it. If you were to carefully fold the map in four dimensions, you should be able to shape it into a hypercube!

iron sparrow
#

someone please tell me

#

how to implement a cube

timid escarp
# iron sparrow how to implement a cube

I and sounds like a lot of other people did it pretty manually. I made a paper cube and number the sides like the numbers I assigned to the unfolded one. Then I carefully noted which other sides were on the top/bottom/left/right of each face. As long as you know which face to go to next when you leave off a certain side AND which incoming side of that face you'll be on, you can write a very complex and error prone translation formula. I had to do that twice, once for the input and once for the example because the input failed... turns out I had a dozen or so errors in my formulas that I had to overcome one at a time as I checked the example input one step at a time.

proven drift
#

when in numpy you do np.where(arr == '.') is there a way to do np.where(col in my_list_of_things_to_search_for)

cursive elbow
#

Please kill me.

#

Ugly solution is ugly.

proven drift
# cursive elbow

Im still on pt 1 and I keep seeign these cubes... im not sure this is good

proven drift
#

Ill just keep doing pt1 blissfully unaware that pt2 looks like hell.

#

ok im on pt 2 - I did think that the map looked a bit like a slice of a map that could be folded up.

#

github copilot ai suggestion for pt2:

def pt_2(space, directions):
    pass
timid escarp
tough thunder
proven drift
tough thunder
#

with portals

#

the positions are converted from the flat coordinates, to face specific coordinates

proven drift
#

Are you splitting the thing up into faces?

tough thunder
#

yeah

proven drift
#

Ah right! I cant decide an approach, I did consider doing a 3D numpy array at one point but I think that is a bad idea 😂

tough thunder
#

a (6, L, L) array would be better than a (L, L, L) array where most of it isn't used

#

though you could use numpy rotations with the (L, L, L) array

proven drift
#

And just fill it with None if you ever hit a None you know youre in the wrong place I guess

#

seems excessive though

#

I think keeping it 2D and using portals is probably easier

timid escarp
# tough thunder i still want to clean up this solution: https://github.com/salt-die/Advent-of-Co...

When I initially started manually creating my object very similar to portals, I had a very similar amount of fields, but, being worried about making a typo somewhere in all that data, I realized that I could get away with just knowing the new face number. From there I figure out the entry side by iterating through the new side's entries in the same object to see where which side the old face comes from.

open sierra
#

just started part2

proven drift
open sierra
#

just entered hell

tough thunder
#

i could just store a connection and a rotation though

sullen creek
iron sparrow
#

yeah

#

this is fine

solar tree
#

if moving from one face into some invalid "face", then teleport to the correct cell and apply the relevant rotation

open sierra
#

@solar tree this is what I'm working on too but I'm shit at math

#

I'm trying to figure out the transformation matrix for each faces to each faces

proven drift
#

Agh

#

I made a mistake somewhere

#

somewhere in my 24 hard coded portals between faces

iron sparrow
#

24??

proven drift
open sierra
#

isn't that 12 ?

iron sparrow
proven drift
#

6 * 4 = 24

proven drift
iron sparrow
#

ffff

proven drift
#

it does make it easier to work out which edge you have come off though

#

Im nearly 80% sure that my code works, its just my portals are wrong

open sierra
#

shit I need help with translation matrices

#

from what I've remember it should be
[1, 0, x]
[0, 1, y]
[0, 0, 1]

#

but I don't remember how to apply that to a 2D point

iron sparrow
#

WHAT THE PISS

#

SOMEHOW

#

I ACCIDENTALLY STARTED AT THE RIGHT TOP CORNER INSTEAD OF THE LEFT TOP CORNER

#

AND IT WORKED FOR MY P1 TEST CASE

#

BUT NOT P2

#

WHA

brittle wing
#

LOOOL

iron sparrow
#

oh i get it

brittle wing
#

Probably means you wrapped around and hit the wall you would have hit anyway

iron sparrow
#

it's because you ram into a wall asap

#

yeah

#

but still

#

what the piss

#
p2_wrap = {}
for i in range(DIM):
    p2_wrap[(1 + 2 * DIM, 1 + i, Dir.UP)] = (1 + DIM + i, 1 + DIM, Dir.RIGHT)
    p2_wrap[(1 + 2 * DIM + i, 1, Dir.LEFT)] = (DIM - i, 1 + DIM, Dir.RIGHT)
    p2_wrap[(1 + 3 * DIM + i, 1, Dir.LEFT)] = (1, 1 + DIM + i, Dir.DOWN)
    p2_wrap[(4 * DIM, 1 + i, Dir.DOWN)] = (1, 1 + 2 * DIM + i, Dir.DOWN)
    p2_wrap[(3 * DIM, 1 + DIM + i, Dir.DOWN)] = (1 + 3 * DIM + i, DIM, Dir.LEFT)
    p2_wrap[(1 + 2 * DIM + i, 2 * DIM, Dir.RIGHT)] = (DIM - i, 3 * DIM, Dir.LEFT)
    p2_wrap[(1 + DIM + i, 2 * DIM, Dir.RIGHT)] = (DIM, 1 + 2 * DIM + i, Dir.UP)
#

cleaner than i thought it would be

solar tree
#

though why bother with matrices here?

open sierra
#

idk I have rotations and translation, so I figured why not

#

what would you recommand

solar tree
#

just do the translations and 90 degree rotations pithink

open sierra
#

Im done for today thi, I'll finish some other day

#

I feel dumb to ask but... how do you apply 90° rotations without matrix ?

#

*sight* I should have worked more in school

brittle wing
#

Are you trying to rotate a [[]] structure, or a (x, y) facing pair?

solar tree
#

all rotations of a point:
(x, y), (y, -x), (-x, -y), (-y, x)

brittle wing
#

(that's for anti-clockwise, assuming +x is right and +y is down)

open sierra
#

u.u I'm not bad at my job I swear, please don't judge me

solar tree
#

right, what direction is left/right depends on your coordinate system

brittle wing
#

If you wanted to know for a structure, there's [*zip(*[iter(grid)]*len(grid))][::-1] and [*zip(*[iter(grid[::-1])]*len(grid))]

open sierra
#

rn I have all my points in a "global" coordinate system, and I was about to have one coordinate system per face with its own transformation

brittle wing
#

(anti-clockwise and clockwise, respectively, assuming +x being right and +y being down, in a [y][x] 2d list)

solar tree
#

I have a global one and apply transformations when the you exit the "valid" space

open sierra
#

that's my idea too

tough thunder
#

i only use the global coordinates at the end to get the score

brittle wing
#

I only use the global coordinates

tough thunder
#

i'm on the fence about putting these faces in a raycaster

brittle wing
#

do it

#

Bonus points if you do part 1, then show the net being folded for part 2

tough thunder
#

my 3d rendering is limited mostly to cubes

brittle wing
#

Dang

tough thunder
#

for now

solar tree
#

no planes?

#

wouldn't planes be the most basic thing?

#

other than maybe spheres

tough thunder
#

planes aren't exactly 3d

solar tree
#

err

#

I guess more true than möbius bands not being 2d, but...

tough thunder
#

i can render the polygons for the faces of the cube though -- but i don't have methods to interpolate textures to the deformed polygons -- and doing it in python will be too slow

brittle wing
#

Render more cubes where there would be stuff on the cubes

#

Raised walls 👀

tough thunder
#

the low res of a terminal limits how much stuff you want to draw though

brittle wing
#

Fair

tough thunder
#

i did do 3d for lava drops

brittle wing
#

render with braille characters, 2x4 per character

tough thunder
brittle wing
#

Yeah I saw that one on the SR, it's neat

#

I wonder if someone has made a text art font that replaces the dots in the braille characters with flush rectangles lol

#

Probably, right?

#

(btw if you want to render a braille character, it's super easy)

tough thunder
#

dunno, i was looking for unicode hexagons the other day, that would tile

brittle wing
#

U+2800 + (value)
where value is a byte

03
14
25
67
tough thunder
#

i have a braille video player and braille image widget already

plush fern
#

"You begin the path in the leftmost open tile of the top row of tiles."
Alright, so shouldnt it be here?

#

im confused

plush fern
#

oh

#

i thought it was the left most col, first row

#

got it

open sierra
#

the most left point of the most up points

plush fern
#

sorry ^^

#

thanks

tough thunder
#

the uppitest most leftest

plush fern
#

yup yup

#

thx ^^

brittle wing
#

(that would be the one that they chose)

tough thunder
#

you have to uppitest first

brittle wing
#

Yes, which means that that is the thing being modified, so it comes after the modifier

#

The left-most of the top

plush fern
#

thats even easier lol

brittle wing
#

Not the top-most of the left

plush fern
#

right

tough thunder
#

no it means the uppitest most leftest

#

it comes in the order i say it

brittle wing
#

'the uppitest-most leftest' means the most uppity of the leftest points

tough thunder
#

there are special rules to using uppitest

#

you obviously aren't familiar with them

#

i have the 10 volume text on using uppitest here at my desk

brittle wing
#

It works if you use RPN I guess

#

Wait do I mean RPN or standard polish

tough thunder
#

dunno i don't speak polish

brittle wing
#

Yeah I mean RPN

#

tiles topmost leftmost is the correct operation

tough thunder
#

but it depends on the face you're on, maybe it's the bottomest rightest

ember jetty
#

wow

#

today was weird

#

I ended up hardcoding the folding of the cube but not the edge links

#

there's a lot I could fix up on I think

#

like not having a 16 case match statement

hushed comet
#

because u showed me lazy thing

#
(\d+)(R|L)?
#

so this would have included the last number then

ember jetty
#

did anyone else do it with complex numbers?

#

I found them to be quite elegant in representing rotations as well as coordinates

magic ridge
#

failed on actual input in p1

ember jetty
#

mine worked fine

#

i had this for pt1

#

lots of symmetry in this one

#

should make the golf interesting

kindred finch
ember jetty
#

i did r'\d+|[LR]'

kindred finch
#

L|R is shorter

ember jetty
#

[LR] conveys that L and R are both turns

timid escarp
hushed comet
timid escarp
hushed comet
#

i expected them to output the same tbh

timid escarp
# hushed comet i expected them to output the same tbh

It would be, they're largely the same, but yours was conceptually cleaner, because it wasn't really R, L, or nothing, it was R or L which wasn't there. Also, I'm more comfortable with the greedy nature of ? knowing it'll grab as much as it can when it can. With R|L|, it'd still be the same, but its grabbing the R or L because its earlier in the list.

hushed comet
timid escarp
hushed comet
#

oh i see

hushed comet
#

i dont really plan on doing it rn

#

but if i would i would have written conditionals so that my "cursor" moves through portals at the edges

#

whats the smarter way to do p2?

timid escarp
ember jetty
#

i hardcoded the foldings of the cube in a dict that would give the new face and the new facing for each direction

hushed comet
#

but different

ember jetty
#

kinda

trim needle
#

literally called my dictionaries portals for p1 and cube_portals for p2

cunning linden
#

finally fully automated today

#

something of a "if it doesn't work, shove another minus sign somewhere" approach

#

but it works!

#

and nothing is hardcoded except the size of each face (which is given in the problem)

timid escarp
cunning linden
#

the Map protocol is implemented by BasicMap, for part 1, and CubeMap, for part 2

ember jetty
#

nice

worthy venture
#

for p2, my original input was like

 S#
 #
##
#

I re-shape it into

#S#
 #
 #
 #

every time when I move to the side, I rotate the cube to ensure the current side is at the top center position

iron sparrow
#

god that sounds convoluted

iron sparrow
ember jetty
#

I keep a separate dict for every face and sort them by their row and then their column

#

along with the top left element of each face

#

and then when I need to switch faces I take the complex vector of the original position from the original face and modify it to a new vector for the new face

junior zephyr
#

Has anyone tried splitting the input into 6 lists and manipulating the lists instead of turning? These are small, it should take much time.

#

I hate 3d problems. They break my brain. This is hurts me as much as day 18 did.

ember jetty
#

wdym lists

#

like a numpy array?

junior zephyr
#

just a multi dimensional list like map[y][x], and have one for reach side. Then rotate the maps when needed.

ember jetty
#

so like instead of rotating the person you rotate the entire face?

junior zephyr
#

yes, and switch maps out when you hit the end of a list.

ember jetty
#

seems like it'd be the same complexity

junior zephyr
#

and slower

ember jetty
#

and harder to think about

#

I liked my complex number method for rotations because it was easy to visualize

#

since I had to imagine the cube in my head

junior zephyr
#

it is easier for me to think of it the way described it.

ember jetty
#

fair

junior zephyr
#

i don't know complex numbers.

#

I have no experience with 3d anything.

ember jetty
#

I don't have much experience with 3d stuff either

#

which is why I stuck to 2d

#

the alternative would've been having a 3d numpy array and that felt really annoying

#

considering we aren't even using the entire inner cube

junior zephyr
#

true

near field
#

At the seam, convert the coordinate & direction to 3D, do the move, and then project back to 2D and continue there.

near field
junior zephyr
#

I should really start using classes. I don't know what I have against them, but when ever I try to use one, I end up getting rid of it.

ember jetty
#

i used to use classes a lot

#

but now i prefer just passing around lists and stuff

#

more of a functional person now ig

junior zephyr
#

That's how I feel. It seems like so much extra typing.

ember jetty
#

i use the occasional attrs class for some stuff

fervent sail
#

I'm pleased with myself that I finally managed to solve part 2 without looking at spoilers... after lots of head scratching and drawing cubes on a whiteboard 😅

#

(Whiteboard needs a clean, I know...)

ember jetty
#

these past few days haven't been that bad tbh

#

day 22 was easier than day 16

fervent sail
# ember jetty i use the occasional attrs class for some stuff

Yeah, I've settled into doing something similar. I have a few method-less dataclasses, and functions that operate on them. Sometimes I will make a function a method of a class if it feels natural, but often I can't decide which class the method should belong to, if you get what I mean pithink

fervent sail
# ember jetty day 22 was easier than day 16

I found figuring out how to represent the orientation of the cube tricky because it's not something I've done before. But I'm pretty satisfied with the representation I settled on (just a permutation of the corner numbers, essentially).

#

'Folding' the net was alright once I found this representation. I essentially rolled the cube over the net, if that makes sense lemon_sweat (to figure out how the corners of each square of the net correspond to the eight corners of the cube (you can see an example of this in the picture I posted)).

#

On to day 23...

ember jetty
#

I just kept a "canonical representative" of each face of the cube (top left corner) and then used the vector from the representative to the current point to determine the vector of the representative on the new face to the new point

brittle wing
#

I asked GPT to implement a net folding function for me and I don't think this works but I can't reason about it right now and I'm in bed
https://paste.pythondiscord.com/mocujapuga edit: replaced topaz paste with pydis paste
Can anyone with more brain power and/or a computer to hand confirm my suspicion lol

#

Wtf why is it so long

gaunt scarab
#

Finally finished part 2 of day 22 without any hardcoding!

#

Wrote the net folding algorithm all by myself

#

well chuffed

cunning linden
#

congrats

#

what was your approach? mine felt quite overcomplicated

#

but idk a better way

gaunt scarab
#

Oh mine was definitely complex as well

#

I represent the initial net as a list of Nones and number ids, like so

#
[None, None, 1   , None]
[2   , 3   , 4   , None]
[None, None, 5   , 6   ]
#

taking a leaf out of the AOC example

#

then I write an algorithm to match up all the edges of the different ids together

brittle wing
#

'first I make a list of faces and then I do the hard bit'

#

kekw

gaunt scarab
#

LOL XD

#

The algorithm to match up the edges of each face is pretty complex for me

brittle wing
#

It's a hard problem

gaunt scarab
#

brb reading up what I did again

#

right - ok

brittle wing
#

Which is why almost everyone gave up and just hardcoded it

gaunt scarab
#

Yeah I was close to that as well

#

but my self-imposed restriction is that I am not allowed to hardcode anything that could be derived from the input

#

anything in the description is fair game to be hardcoded but not from the input

#

that and my solution must work for both example and real input

cunning linden
#

yeah i stuck to it but it was definitely the hardest to code of all the days

gaunt scarab
#

that it was - this has been the biggest gulf between "I know what I need to do conceptually" and "I know what code I need to type in"

#

conceptually I knew exactly what I needed to do

#

but representing it in code, oh man...

brittle wing
#

This is a classic example of 'computers have no understanding of the axioms of the physical world (so you need to write them yourself)'

gaunt scarab
#

pretty much

brittle wing
#
#

This also

cunning linden
#

My impl was something like:

  • make a list of the coordinates of each face
  • for each face, determine which face they are joined to (in the net) in each of the four positions
  • take one face and put it on the surface of a cube
  • put the other faces it joins to in the relevant positions around it
  • repeat for each of those faces until the cube is full
  • then, use the faces each face is now adjacent to on the cube to make a mapping of which faces join to which others, in the original four positions
    plus a bit more complicated stuff to work out your coordinates and direction when you walk on to a face
brittle wing
#

I figured out that that was the algorithm to use I just couldn't figure out how to implement it at 5AM

#

And didn't bother after the fact

gaunt scarab
#

my algorithm is as follows:

  • make a list of the faces as described above
  • join up the face edges of the faces already joined together in the net
  • work out the "corners" of the edges - this is where one face in the net is joined to two others around a corner
  • join up the edges that jut out straight from both directions of the corner
    once I've done the above, I'm left with either one or two pairs of edges unpaired
  • if one pair of edges is unpaired, then just pair them (easy)
  • if two pairs of edges is unpaired, work out their neighbours so that you can form two pairs, then pair them like the point above
#

not sure if that makes sense but that's how I did that

brittle wing
#

I don't think that's reliable

#

Think about a T-shaped net

#
123
 4
 5
 6
#

After connecting the corners you'll be left with 5 and 6 sticking out, you need a loop

gaunt scarab
#

actually it's fine for that case

#

perhaps I need to explain my corner thing more

#

take the first corner, which is

1 2 
  4
#

so, I work out that 2 is a corner around 1 and 4

#

from there, I work out how far in each direction I can go along 1 and 4

#

I can go one along 1, and three along 4, (going through 4, 5, and 6)

#

then I pair the left edges of 4 5 6 with the edges around 1

brittle wing
#

Ahh I see

gaunt scarab
#

this is actually one of the easier to do

#

because you are only left with one unpaired at the end

#

top edge of 2 and bottom edge of 6

brittle wing
#

What happens with

12
 34
  56

?

#

That seems like the hardest case to parse with your algo

gaunt scarab
#

let me figure out, one sec

#

gotta have to draw it out each time you ask lol

brittle wing
#

LOL sorry

#

figured you were just throwing the Python code at it lol

gaunt scarab
#

nope lol

#

I do have the Py code if you are interested

brittle wing
#

I am, yeah

gaunt scarab
#

not sure anyone can read it but me though

#

!paste

flat fjordBOT
#

Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

gaunt scarab
#

please do not comment on the style of the code itself, it's quite horrid

#

but I assure you it works :)

brittle wing
#

Lmao

gaunt scarab
#

462 lines

brittle wing
#

I mean you use Black it can't be that bad

gaunt scarab
#

note that some of that allows for unittesting though

#

haha yes I do :)

brittle wing
#

Smh you hardcoded the number 50

#

:P

cunning linden
#

tbf it gives that in the problem

#

but it is nice to work for the example too

gaunt scarab
#

yup - I allow myself that because of it :)

brittle wing
#

You can totally work that out as int((len([c for c in input if c not in '\n ']) / 6) ** 0.5)

cunning linden
gaunt scarab
#

my unit tests pass in a different param

cunning linden
#

unit tests for aoc

#

fancy

gaunt scarab
#
def test_monkey_map_simulation_2():
    notes = """\
        ...#
        .#..
        #...
        ....
...#.......#
........#...
..#....#....
..........#.
        ...#....
        .....#..
        .#......
        ......#.

10R5L5R10L4R5L5
"""
    mm = process_2.MonkeyMap(notes, face_size=4)

    mm_it = iter(mm)

    for _ in mm_it:
        pass

    assert str(mm) == """\
        >>v#    
        .#v.    
        #.v.    
        ..v.    
...#..^...v#    
.>>>>>^.#.>>    
.^#....#....    
.^........#.    
        ...#..v.
        .....#v.
        .#v<<<<.
        ..v...#."""

    assert mm.curr_pos == process_2.Coords(7, 5)
    assert mm.curr_dir == process_2.Direction.UP

    assert mm.password == 5031
#

that's an example of one of them

brittle wing
#

zip(itertools.count(1), map_str.splitlines())
Any reason you didn't just enumerate here?

gaunt scarab
#

because I'm taking chunks of 4

#

or of 50

brittle wing
#

(ok? enumerate can handle that fine?)

gaunt scarab
#

I guess I could have used enumerate with step

brittle wing
#

AFAIK enumerate(x, n) is exactly equivalent to zip(count(n), x)

gaunt scarab
#

didn't think about it at the time

cunning linden
gaunt scarab
brittle wing
#

That feels like that shouldn't work

gaunt scarab
#

I'm left with three unpaired pairs of edges

#

at the moment my algo wouldn't work for that, but it could be easily modified to

cunning linden
gaunt scarab
#

I would just pair as many as I could in a loop, going round and round til they were all parired

cunning linden
#

oh right fair

#

yeah

brittle wing
#

Tbf I had to google cube nets in order to find that lol

#

That's actually the only one that doesn't fit

cunning linden
#

soooo we could probably special case it

#

is that the only one where one dimension is more than twice the other

brittle wing
#

What if you get this cube net 🙃

cunning linden
#

lmao

brittle wing
cunning linden
#
width, height = max(map(len, lines)), len(lines)
short, long = (width, height) if width < height else (height, width)
if long > short * 2:
    size = short // 2
else:
    size = long // 4
```longer code than yours but more efficient
gaunt scarab
#

looking at the subreddit I feel super accomplished I did this algorithmically now

brittle wing
#

You should, it's tricky

gaunt scarab
#

three more days left for me to do

#

I've been doing these in strict order

brittle wing
#

Fair enough

#

Have fun with the rest!

formal crater
#

i just can't even

#

my mind just can't comprehend how to rotate the faces of the cube for this to make sense

solar tree
formal crater
#

no i'm trying to do a cube with faces

#

but somehow an x rota for example isn't just the left and right face that get rotated + switching the active face

#

instead my current observation is that whatever face was on top now gets to the back rotated 2 times (or maybe 1 time because instead every face gets rotated idk)

#

weird

gaunt scarab
fervent sail
gaunt scarab
#

I think I only stared at the screen in horror for at least 10 minutes lol

#

part of me wishes there had been multiple cubes to resolve such that hardcoding would have been infeasible :3

fervent sail
#

Ah yeah. Although weirdly I don’t think I’d have the patience to hard code it.

gaunt scarab
#

I'd be worried that I did it wrong

#

and if you do it wrong, trying to debug and find out where you screwed up would become pretty difficult indeed

ember jetty
#

tbf hardcoding it wrong is a pain to debug as well

#

that's what I did

#

couldn't figure it out for like 2 hours

#

oh wait you guys are talking about hardcoding it not writing code for the net folding

formal crater
#

I wish I were talking about folding I'm just trying to keep track of orientation

fervent sail
# formal crater I wish I were talking about folding I'm just trying to keep track of orientation

The way I did it is to label the corners of the cube 0 to 7, then rotating the cube is just a matter of permuting those numbers in some way. For example, you could start with the corners labelled like this: 0-----------1 |\ /| | 4-------5 | | | | | | 6-------7 | |/ \| 2-----------3 If you rotate it left, to view the face on the right, this is where all the corners would end up: 1-----------5 |\ /| | 0-------4 | | | | | | 2-------6 | |/ \| 3-----------7 If you rotate the original cube up, to view the bottom face, it would end up like this: ```
2-----------3
|\ /|
| 0-------1 |
| | | |
| 4-------5 |
|/ |
6-----------7

#

!eval Rotating the cube to the right is just the same as rotating it to the left three times. And rotating it down is the same as rotating it up three times: ```py
import numpy as np
CUBE = np.array([0, 1, 2, 3, 4, 5, 6, 7])
L = CUBE[[1, 5, 3, 7, 0, 4, 2, 6]]
R = CUBE[L][L][L]
U = CUBE[[2, 3, 6, 7, 0, 1, 4, 5]]
D = CUBE[U][U][U]
print(L)
print(R)
print(U)
print(D)

flat fjordBOT
#

@fervent sail :white_check_mark: Your 3.11 eval job has completed with return code 0.

001 | [1 5 3 7 0 4 2 6]
002 | [4 0 6 2 5 1 7 3]
003 | [2 3 6 7 0 1 4 5]
004 | [4 5 0 1 6 7 2 3]
fervent sail
#

Say you have a net that looks like this: ```
+---+
| |
+---+---+---+
| | | |
+---+---+---+---+
| | |
+---+---+

#

First of all, pick a face to represent the original 'front' of the cube and label its corners: ```
0---1 0-----------1
| X | |\ /|
+---+---2---3 | 4-------5 |
| | | | | | | |
+---+---+---+---+ | 6-------7 |
| | | |/ |
+---+---+ 2-----------3

#

Then you can figure out what all the other corner numbers should be by walking around the net, and rotating the cube accordingly as you go. For example, to go down you rotate the cube up: 0---1 2-----------3 | | |\ /| +---+---2---3 | 0-------1 | | | | X | | | | | +---+---6---7---+ | 4-------5 | | | | |/ \| +---+---+ 6-----------7 To go left, you rotate the cube right: ```
0---1 0-----------2
| | |\ /|
+---0---2---3 | 1-------3 |
| | X | | | | | |
+---4---6---7---+ | 5-------7 |
| | | |/ |
+---+---+ 4-----------6

#

Then you just visit all the other faces using some kind of search: ```
0---1
| |
1---0---2---3
| | | |
5---4---6---7---3
| | |
4---5---1

gaunt scarab
#

Seems like a nice approach

#

Avoids the problem of “loose edges” like there was with my algo

fervent sail
#

Thanks!

formal crater
#

thank you!

gaunt scarab
formal crater
#

i was thinking of only moving right, and instead of changing the direction i rotate the face, since i'm only moving right i'll always know that the shared edge will be from right to left so i can rotate the next face until the edge i'm entering from is on the left

#

that might just shift the problem to input parsing, i don't know about that since i haven't had the time to work on it today

#

more basic is probably a better description than easier

formal crater
gaunt scarab
#

bad = [[1,2,3,5], [4,2,0,5], [1,4,3,0], [4,5,0,2], [1,5,3,2], [4,1,0,3]]
:|

formal crater
#

its called bad for a reason 😛

gaunt scarab
#

presumably it only works for the real input?

formal crater
#

i'll figure mapping out once the rotation works

gaunt scarab
#

not the example one?

formal crater
#

i really just want to know if x and y are correct and i'm just messing up rotation

gaunt scarab
#

kk. Will get to this in a little bit :)

#

FYI, sharing inputs in general is not recommended, and not necessary for this days' problem anyway since everyone's real input is the same net

formal crater
#

as far as i read up on the topic individual inputs are fine and just the collection of inputs isn't really whats desired

#

but i guess it's not required to check what i was asking so I'll delete it

#

@gaunt scarab i've updated my code to be a little more readable in case you're looking at it

gaunt scarab
#

ah cool - is it on the same hastebin?

formal crater
#

i edited the link

gaunt scarab
#

I was going to try and print the password at each step to compare with mine at each step

#

but I don't think I can even try that option with your program, can I?

#

you have some code after you iterate over all the instructions that occurs before you generate the password

formal crater
#

yeah hmm

#

i'll try to rewrite it to do that every step

#

define step actually, between instruction types or litreally every move

gaunt scarab
#

either works for me

#

for me I can literally print out the password after every move

#

actually

formal crater
#

ahhh i might already see the problem

gaunt scarab
#

hah

formal crater
#

why am i rotating the face

#

still wrong hmm

gaunt scarab
#

if your code can print out the x, y and direction after each instruction

#

then I can go and compare with my solution to see at which place your code would deviate from mine

formal crater
#

alright this prints after every instruction i hope

#

and does weird stuff immediately

#

ok thats whack, i'll go back to figuring it out myself first

gaunt scarab
formal crater
#

yea i hope converting back is just the problem we'll see

formal crater
#

alright, i still had a million bugs and in the end the best thing to do was map out the example real quick, but i finally finished d22

ember jetty
#

dw most people here hardcoded the map as well