Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges Net​​ or​​ not?

Python 3, 189 173 bytes lambda s:(f:=lambda i,a,b,c,d:l[i]&1 and(exec('l[i]=0')or a/b+b/c+c/d+d/a+f(i-7,c,a,d,b)+f(i-1,d,c,a,b)+f(i+1,c,d,b,a)+f(i+7,b,d,a,c)))((l:=3*s).index(35,41),4,8,63,7...

posted 7d ago by wizzwizz4‭  ·  edited 7d ago by wizzwizz4‭

Answer
#3: Post edited by user avatar wizzwizz4‭ · 2026-09-10T11:23:56Z (7 days ago)
Restored attribution, elaborated slightly.
  • # [Python 3], <del>189</del> <ins>173</ins> bytes
  • <!-- language-all: lang-python -->
  • lambda s:(f:=lambda i,a,b,c,d:l[i]&1 and(exec('l[i]=0')or a/b+b/c+c/d+d/a+f(i-7,c,a,d,b)+f(i-1,d,c,a,b)+f(i+1,c,d,b,a)+f(i+7,b,d,a,c)))((l:=3*s).index(35,41),4,8,63,72)==111
  • [Try it online!][TIO-mtvea3d6]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-mtvea3d6]: https://tio.run/##pVlNj9NIEL3nV1h@EtjE9Gx2gEGRcmHFFQ4Lpw0a2XFGRARnlASJ0YrfPjjf7nZ31eshF4897epyfb1X1fcP26@r5vrt/fqxm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2@sQuQCAObeT5i6MBU5b0kVTom29pXwjbXiEMYbXle@5CQvYeEEiDGLHHvTpisKK1WoZPGNU6eOli6P5qzgD92FsCLe6aMiN9olO3j/zgkT2dTC6MJHYzggMcjMz8O4xLxcD9FGUNCDsLAWdBSfHEsaiQ9s/qIRcMiK99ZTDjdBUN7Zqqz1qd4aAP5gVuwhzFvfEpt8LnCepxEANJqLpV3G435ziaXwA/JnN3WqdzH5U89tmvk0WTXI@vxkPkvZXbjbz9TZpsuphOy/X6/IhO63O8yK5S7P/T/e/8mTzdfVjWSfVPCn3QpP2cbrfolltb7vbWEdF9lYre7vum6ctu88u2@7edLa@Xy@abZZ@/Jbmj78B "Python 3 – Try It Online"
  • Input is given as an ASCII-encoded `bytearray`.
  • ## Explanation
  • We're solving this one _properly_. A cube has 6 faces, each of which can have 4 orientations, for a total of 24 rotational states, each corresponding to a permutation of the cube's diagonals. Labelling these diagonals:
  • | | |
  • | - | - |
  • | 3 | 2 |
  • | 4 | 1 |
  • where they touch the front face, a north rotation is $(a,b,c,d)\mapsto(c,a,d,b)$, and an east rotation is $(a,b,c,d)\mapsto(c,d,b,a)$. The rotation $(a,b,c,d)\mapsto(b,c,d,a)$ does not change which face is shown, so is useful for determining which face that is. If we represent the diagonals by $4$, $8$, $63$ and $72$, the hash function $(a,b,c,d)\mapsto\frac ab+\frac bc+\frac cd+\frac da$ assigns a unique double to each face, with sum $111$ iff a 6-face net is a valid cube.
  • Now we just need a flood fill algorithm. First, we need to ensure that it won't go out of bounds. The input is "represented as 6 newline _separated_ strings of 6 characters", therefore tripling the string will cause the columns to be slightly offset, meaning that the vertical line input won't take the flood out of bounds. To find our starting `#`, we'll start our search at the beginning of the second copy, at index $36+5=41$. East-west are offset by 1, and north-south are offset by 7. From here, we can simply recurse.
  • Since `.` and `\n` are both even characters, while `#` is odd, we can take input as a bytestring, and then the test is simply `&1`. To make sure we don't double-count a square, we zero it out once we've visited it. The walrus operator `:=` doesn't work for item assignment, so we use `exec` to turn it into an expression: expensive, but still shorter than `__setitem__`. This returns a falsy value, which requires an extra pair of brackets in the short-circuiting `and` / `or` expression.
  • # [Python 3], <del>189</del> <ins>173</ins> bytes
  • <!-- language-all: lang-python -->
  • lambda s:(f:=lambda i,a,b,c,d:l[i]&1 and(exec('l[i]=0')or a/b+b/c+c/d+d/a+f(i-7,c,a,d,b)+f(i-1,d,c,a,b)+f(i+1,c,d,b,a)+f(i+7,b,d,a,c)))((l:=3*s).index(35,41),4,8,63,72)==111
  • [Try it online!][TIO-mtvea3d6] (test harness adapted from [this answer](https://codegolf.codidact.com/posts/292173/294030#answer-294030))
  • [Python 3]: https://docs.python.org/3/
  • [TIO-mtvea3d6]: https://tio.run/##pVlNj9NIEL3nV1h@EtjE9Gx2gEGRcmHFFQ4Lpw0a2XFGRARnlASJ0YrfPjjf7nZ31eshF4897epyfb1X1fcP26@r5vrt/fqxmUwfl@X3qi6TzTi7G0@ON4uiLKpiVtTj5X@LL89GSdnU2fznfJY93z2Y/PU8X62T8qoaVlez4eyqHtZX5fAuW7y8ad8qi7qo8v3tqP1z9@BwOxztZLaSy8PtTftn3f53lud5li3Hk@sXm9wsmnr@M7t@Xbwa5cWr4m3x5rq4@TufTEaj0eM/n9@9v/3w/tO/ySSp0jSdDmB2vwHa3@5yuDO@y8DgcGtd9u/1lxqDi9TjnV/qSYBPeE8B@BQwqgLiZ8G7s/ezbGMpn3WSg9D39KXqFtg/5pZaCgC0Y4/CYQIKoOt1REr1vuF@lgFjV32psQJEUQCXNbKxjgKspRBDe@8Dv7iuAghkU@CznK/zhII/U@z3naVRkeV7I@RYkOECImF6IYU4b/l1dTKWCm0iBrxBCCK3uCBkk5vJgkBIQdU1qr5KaWh9upJbtrcM2PrKhwuDMJQLHDQUIwtaVgcqIZGxFBqa2DQMBJhIHSDZFSzG@sURFpBdYCsQn1vQdZUjC3waesWBT0MQMcAbS6aPdhZwBV6JgemgJbFmc79cbLMqnTbTJs0H7e/Dx0@3fa7bUVbD4/MaHY8DaeDDYy90h/AYhgQD6EDsR05EgKxATLq1mLHr0aUgeY6fnvdCC914iW5ifC5wvGXCOSYyrL5jD7oaNrIgdFp@jIMcLmq59EeWgvLQ6kogtLnyogahCwbQdTU8IbD0AKGr1/lBRiJSIiiAEaouRL9jGGM5uAEtuSNC241wmRbjSa0RIIY2TbQoBfROq1cJGakWZDKNgUui2NCWGwOjDwi8azQLxM8SwJYMKbfOrAWRpVikb9Bt74c4B2GkNNS4Lp0w58iiQ9vovdmFsGl69CkeG69S6Qo5X1gqQbbCB6iE0YumsHOoORT5QCx9NNGcUMqbXn2luYsM8jbG8iwjwq7gjcWwYm5UCtYFLrbpxophRISu0IdeVhMFsazIueW7uBOXmHiVahZ4SuatQFAmwPT8U@dZNnGl@gKjz2ph6ISBoRm8ywdopomIOmCY0DZsyWAUcOfkTMIQo32dDvcGFDtTaGcL@zURYw8wGQs1VcWe2@sQuQCAObeT5i6MBU5b0kVTom29pXwjbXiEMYbXle@5CQvYeEEiDGLHHvTpisKK1WoZPGNU6eOli6P5qzgD92FsCLe6aMiN9olO3j/zgkT2dTC6MJHYzggMcjMz8O4xLxcD9FGUNCDsLAWdBSfHEsaiQ9s/qIRcMiK99ZTDjdBUN7Zqqz1qd4aAP5gVuwhzFvfEpt8LnCepxEANJqLpV3G435ziaXwA/JnN3WqdzH5U89tmvk0WTXI@vxkPkvZXbjbz9TZpsuphOy/X6/IhO63O8yK5S7P/T/e/8mTzdfVjWSfVPCn3QpP2cbrfolltb7vbWEdF9lYre7vum6ctu88u2@7edLa@Xy@abZZ@/Jbmj78B "Python 3 – Try It Online"
  • Input is given as an ASCII-encoded `bytearray`.
  • ## Explanation
  • We're solving this one _properly_. A cube has 6 faces, each of which can have 4 orientations, for a total of 24 rotational states, each corresponding to a permutation of the cube's diagonals. Labelling these diagonals:
  • | | |
  • | - | - |
  • | 3 | 2 |
  • | 4 | 1 |
  • where they touch the front face, a north rotation is $(a,b,c,d)\mapsto(c,a,d,b)$, and an east rotation is $(a,b,c,d)\mapsto(c,d,b,a)$. The rotation $(a,b,c,d)\mapsto(b,c,d,a)$ does not change which face is shown, so is useful for determining which face that is. If we represent the diagonals by $4$, $8$, $63$ and $72$, the hash function $(a,b,c,d)\mapsto\frac ab+\frac bc+\frac cd+\frac da$ assigns a unique double to each face, with sum $111$ iff a 6-face net is a valid cube.
  • Now we just need a flood fill algorithm. First, we need to ensure that it won't go out of bounds. The input is "represented as 6 newline _separated_ strings of 6 characters", therefore tripling the string will cause the columns to be slightly offset, meaning that the vertical line input won't take the flood out of bounds. To find our starting `#`, we'll start our search at the beginning of the second copy, at index $36+5=41$. East-west are offset by 1, and north-south are offset by 7. From here, we can simply recurse.
  • Since `.` and `\n` are both even characters, while `#` is odd, we can take input as a bytestring, and then the test is simply `&1`. To make sure we don't double-count a square, we zero it out once we've visited it. The walrus operator `:=` doesn't work for item assignment, so we use `exec` to turn it into an expression: expensive, but still shorter than `__setitem__`. This returns a falsy value, which requires an extra pair of brackets in the short-circuiting `and` / `or` expression.
  • This solution does not require that nets are aligned to the top-left, and it also works for several nets that are not hexominoes (though there is a septomino that crashes it, so be warned).
#2: Post edited by user avatar wizzwizz4‭ · 2026-09-10T10:47:28Z (7 days ago)
Saved 16 bytes by changing the hash function and rewriting to a lambda expression.
  • # [Python 3], 189 bytes
  • <!-- language-all: lang-python -->
  • def n(s):
  • def f(i,a,b,c,d):
  • if l[i]&1:l[i]=0;l[0]+=10*(a/b+b/c+c/d+d/a);f(i-7,c,a,d,b);f(i-1,d,c,a,b);f(i+1,c,d,b,a);f(i+7,b,d,a,c)
  • l=[0,*3*s];f(l.index(35,42),1,4,5,8);return l[0]==487
  • [Try it online!][TIO-mtujoxev] (test harness adapted from [this answer](https://codegolf.codidact.com/posts/292173/294030#answer-294030))
  • [Python 3]: https://docs.python.org/3/
  • [TIO-mtujoxev]: https://tio.run/##pVpNb9NAEL3nV6z8JBQ3ZtvQoiKqXEBc4QCc2qrKp4iInCpJJRDitxc7n9717szbkotjZz0ez9d7M5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h1sDitoU2t7Cdk3C2ANMxkJNVbHnDjpELgBg9u2kuQtjgcMj6aIp0bbWUr6RtjzCWMvryvfchAVcvCARBqljD3p3RWHFarWM7jGq9PHUxdH8VZyBhzA2hltNNORG@0QnH555QSL7OhidmEhqZwQGuZkZeHObl4sBeitKGhA2loLOgoNjCWPRoR0eVEIuGYneesnmRmyqm1q11R61OUPAf8yKfYQ5inth0x8EzoNUYqAGm9D0qzjcbk7xMj4Afs9mtlyZ8dNo@lBON2ZemuP@Tf2/KmOG6/V0tTFl97AmL8ws6/45nP7NzfrH8mkxMaOpGW4lmepytpVbLjcPTdnO/pArf1k/o7l@/5zmpdOz6uXe8x5X83LTzb78zPLnfw "Python 3 – Try It Online"
  • We're solving this one _properly_. A cube has 6 faces, each of which can have 4 orientations, for a total of 24 rotational states, each corresponding to a permutation of the cube's diagonals. Labelling these diagonals:
  • | | |
  • | - | - |
  • | 3 | 2 |
  • | 4 | 1 |
  • where they touch the front face, a north rotation is $(a,b,c,d)\mapsto(c,a,d,b)$, and an east rotation is $(a,b,c,d)\mapsto(c,d,b,a)$. The rotation $(a,b,c,d)\mapsto(b,c,d,a)$ does not change which face is shown, so is useful for determining which face that is. If we represent the diagonals by $1$, $4$, $5$ and $8$, the hash function $(a,b,c,d)\mapsto5(\frac ab+\frac bc+\frac cd+\frac da)$ assigns a unique double to each face, with sum $243.5$ iff a 6-face net is a valid cube.
  • Now we just need a flood fill algorithm. First, we need to ensure that it won't go out of bounds. The input is "represented as 6 newline _separated_ strings of 6 characters", therefore tripling the string will cause the columns to be slightly offset, meaning that the vertical line input won't take the flood out of bounds. To find our starting `#`, we'll start our search at the beginning of the second copy, at index $36+5=41$. East-west are offset by 1, and north-south are offset by 7. From here, we can simply recurse.
  • Since `.` and `\n` are both even characters, while `#` is odd, we can take input as a bytestring, and then the test is simply `&1`. Of course, we also need a place to store the running total: the `nonlocal` keyword costs a few bytes, so we'll stuff it at the beginning of the list, and add 1 to the indexes.
  • # [Python 3], <del>189</del> <ins>173</ins> bytes
  • <!-- language-all: lang-python -->
  • lambda s:(f:=lambda i,a,b,c,d:l[i]&1 and(exec('l[i]=0')or a/b+b/c+c/d+d/a+f(i-7,c,a,d,b)+f(i-1,d,c,a,b)+f(i+1,c,d,b,a)+f(i+7,b,d,a,c)))((l:=3*s).index(35,41),4,8,63,72)==111
  • [Try it online!][TIO-mtvea3d6]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-mtvea3d6]: https://tio.run/##pVlNj9NIEL3nV1h@EtjE9Gx2gEGRcmHFFQ4Lpw0a2XFGRARnlASJ0YrfPjjf7nZ31eshF4897epyfb1X1fcP26@r5vrt/fqxmUwfl@X3qi6TzTi7G0@ON4uiLKpiVtTj5X@LL89GSdnU2fznfJY93z2Y/PU8X62T8qoaVlez4eyqHtZX5fAuW7y8ad8qi7qo8v3tqP1z9@BwOxztZLaSy8PtTftn3f53lud5li3Hk@sXm9wsmnr@M7t@Xbwa5cWr4m3x5rq4@TufTEaj0eM/n9@9v/3w/tO/ySSp0jSdDmB2vwHa3@5yuDO@y8DgcGtd9u/1lxqDi9TjnV/qSYBPeE8B@BQwqgLiZ8G7s/ezbGMpn3WSg9D39KXqFtg/5pZaCgC0Y4/CYQIKoOt1REr1vuF@lgFjV32psQJEUQCXNbKxjgKspRBDe@8Dv7iuAghkU@CznK/zhII/U@z3naVRkeV7I@RYkOECImF6IYU4b/l1dTKWCm0iBrxBCCK3uCBkk5vJgkBIQdU1qr5KaWh9upJbtrcM2PrKhwuDMJQLHDQUIwtaVgcqIZGxFBqa2DQMBJhIHSDZFSzG@sURFpBdYCsQn1vQdZUjC3waesWBT0MQMcAbS6aPdhZwBV6JgemgJbFmc79cbLMqnTbTJs0H7e/Dx0@3fa7bUVbD4/MaHY8DaeDDYy90h/AYhgQD6EDsR05EgKxATLq1mLHr0aUgeY6fnvdCC914iW5ifC5wvGXCOSYyrL5jD7oaNrIgdFp@jIMcLmq59EeWgvLQ6kogtLnyogahCwbQdTU8IbD0AKGr1/lBRiJSIiiAEaouRL9jGGM5uAEtuSNC241wmRbjSa0RIIY2TbQoBfROq1cJGakWZDKNgUui2NCWGwOjDwi8azQLxM8SwJYMKbfOrAWRpVikb9Bt74c4B2GkNNS4Lp0w58iiQ9vovdmFsGl69CkeG69S6Qo5X1gqQbbCB6iE0YumsHOoORT5QCx9NNGcUMqbXn2luYsM8jbG8iwjwq7gjcWwYm5UCtYFLrbpxophRISu0IdeVhMFsazIueW7uBOXmHiVahZ4SuatQFAmwPT8U@dZNnGl@gKjz2ph6ISBoRm8ywdopomIOmCY0DZsyWAUcOfkTMIQo32dDvcGFDtTaGcL@zURYw8wGQs1VcWe2@sQuQCAObeT5i6MBU5b0kVTom29pXwjbXiEMYbXle@5CQvYeEEiDGLHHvTpisKK1WoZPGNU6eOli6P5qzgD92FsCLe6aMiN9olO3j/zgkT2dTC6MJHYzggMcjMz8O4xLxcD9FGUNCDsLAWdBSfHEsaiQ9s/qIRcMiK99ZTDjdBUN7Zqqz1qd4aAP5gVuwhzFvfEpt8LnCepxEANJqLpV3G435ziaXwA/JnN3WqdzH5U89tmvk0WTXI@vxkPkvZXbjbz9TZpsuphOy/X6/IhO63O8yK5S7P/T/e/8mTzdfVjWSfVPCn3QpP2cbrfolltb7vbWEdF9lYre7vum6ctu88u2@7edLa@Xy@abZZ@/Jbmj78B "Python 3 – Try It Online"
  • Input is given as an ASCII-encoded `bytearray`.
  • ## Explanation
  • We're solving this one _properly_. A cube has 6 faces, each of which can have 4 orientations, for a total of 24 rotational states, each corresponding to a permutation of the cube's diagonals. Labelling these diagonals:
  • | | |
  • | - | - |
  • | 3 | 2 |
  • | 4 | 1 |
  • where they touch the front face, a north rotation is $(a,b,c,d)\mapsto(c,a,d,b)$, and an east rotation is $(a,b,c,d)\mapsto(c,d,b,a)$. The rotation $(a,b,c,d)\mapsto(b,c,d,a)$ does not change which face is shown, so is useful for determining which face that is. If we represent the diagonals by $4$, $8$, $63$ and $72$, the hash function $(a,b,c,d)\mapsto\frac ab+\frac bc+\frac cd+\frac da$ assigns a unique double to each face, with sum $111$ iff a 6-face net is a valid cube.
  • Now we just need a flood fill algorithm. First, we need to ensure that it won't go out of bounds. The input is "represented as 6 newline _separated_ strings of 6 characters", therefore tripling the string will cause the columns to be slightly offset, meaning that the vertical line input won't take the flood out of bounds. To find our starting `#`, we'll start our search at the beginning of the second copy, at index $36+5=41$. East-west are offset by 1, and north-south are offset by 7. From here, we can simply recurse.
  • Since `.` and `\n` are both even characters, while `#` is odd, we can take input as a bytestring, and then the test is simply `&1`. To make sure we don't double-count a square, we zero it out once we've visited it. The walrus operator `:=` doesn't work for item assignment, so we use `exec` to turn it into an expression: expensive, but still shorter than `__setitem__`. This returns a falsy value, which requires an extra pair of brackets in the short-circuiting `and` / `or` expression.
#1: Initial revision by user avatar wizzwizz4‭ · 2026-09-10T08:36:18Z (7 days ago)
# [Python 3], 189 bytes

<!-- language-all: lang-python -->

    def n(s):
     def f(i,a,b,c,d):
      if l[i]&1:l[i]=0;l[0]+=10*(a/b+b/c+c/d+d/a);f(i-7,c,a,d,b);f(i-1,d,c,a,b);f(i+1,c,d,b,a);f(i+7,b,d,a,c)
     l=[0,*3*s];f(l.index(35,42),1,4,5,8);return l[0]==487

[Try it online!][TIO-mtujoxev] (test harness adapted from [this answer](https://codegolf.codidact.com/posts/292173/294030#answer-294030))

[Python 3]: https://docs.python.org/3/
[TIO-mtujoxev]: https://tio.run/##pVpNb9NAEL3nV6z8JBQ3ZtvQoiKqXEBc4QCc2qrKp4iInCpJJRDitxc7n9717szbkotjZz0ez9d7M5vH35sfy/Ly@XkynZmyu87fd0z9ddadF8NiVIyLSX3JzGdmcTu/f9V/Xx8GFzeL24v73qB/cdYdno96o/Nxb3w@6U3Oh/lNde/r6@rOYTEpRrvTfvW1vrA77fVruZX03eLedfV1Uv06zjtmMbi9KM4uz9b31U8LOy8n01/dy7fF1Zu86BdXxdviXX6zmm6eVqWpdRgMrt5dP3/8/uHTw@dP376agRllWXbXga0/HVSf@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9D0qzjcbk7xMj4Afs9mtlyZ8dNo@lBON2ZemuP@Tf2/KmOG6/V0tTFl97AmL8ws6/45nP7NzfrH8mkxMaOpGW4lmepytpVbLjcPTdnO/pArf1k/o7l@/5zmpdOz6uXe8x5X83LTzb78zPLnfw "Python 3 – Try It Online"


We're solving this one _properly_. A cube has 6 faces, each of which can have 4 orientations, for a total of 24 rotational states, each corresponding to a permutation of the cube's diagonals. Labelling these diagonals:

|   |   |
| - | - |
| 3 | 2 |
| 4 | 1 |

where they touch the front face, a north rotation is $(a,b,c,d)\mapsto(c,a,d,b)$, and an east rotation is $(a,b,c,d)\mapsto(c,d,b,a)$. The rotation $(a,b,c,d)\mapsto(b,c,d,a)$ does not change which face is shown, so is useful for determining which face that is. If we represent the diagonals by $1$, $4$, $5$ and $8$, the hash function $(a,b,c,d)\mapsto5(\frac ab+\frac bc+\frac cd+\frac da)$ assigns a unique double to each face, with sum $243.5$ iff a 6-face net is a valid cube.

Now we just need a flood fill algorithm. First, we need to ensure that it won't go out of bounds. The input is "represented as 6 newline _separated_ strings of 6 characters", therefore tripling the string will cause the columns to be slightly offset, meaning that the vertical line input won't take the flood out of bounds. To find our starting `#`, we'll start our search at the beginning of the second copy, at index $36+5=41$. East-west are offset by 1, and north-south are offset by 7. From here, we can simply recurse.

Since `.` and `\n` are both even characters, while `#` is odd, we can take input as a bytestring, and then the test is simply `&1`. Of course, we also need a place to store the running total: the `nonlocal` keyword costs a few bytes, so we'll stuff it at the beginning of the list, and add 1 to the indexes.