541
\$\begingroup\$

This "sandbox" is a place where Code Golf users can get feedback on prospective challenges they wish to post to main. This is useful because writing a clear and fully specified challenge on your first try can be difficult, and there is a much better chance of your challenge being well received if you post it in the sandbox first.

Sandbox FAQ

Posting

To post to the sandbox, scroll to the bottom of this page and click "Answer This Question". Click "OK" when it asks if you really want to add another answer.

Write your challenge just as you would when actually posting it, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

When you think your challenge is ready for the public, go ahead and post it, and replace the post here with a link to the challenge and delete the sandbox post.

Discussion

The purpose of the sandbox is to give and receive feedback on posts. If you want to, feel free to give feedback to any posts you see here. Important things to comment about can include:

  • Parts of the challenge you found unclear
  • Comments addressing specific points mentioned in the proposal
  • Problems that could make the challenge uninteresting or unfit for the site

You don't need any qualifications to review sandbox posts. The target audience of most of these challenges is code golfers like you, so anything you find unclear will probably be unclear to others.

If you think one of your posts needs more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended!

It is recommended to leave your posts in the sandbox for at least several days, and until it receives upvotes and any feedback has been addressed.

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]. To search for posts with a certain tag, include the name in quotes: "king-of-the-hill".

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

3657 Answers 3657

1
16 17
18
19 20
122
3
\$\begingroup\$

Volume of a 3d model

In this challenge, you'll take a shape as input, consisting of a number of triangles forming an outer shell. Your task will be to find the volume of the resulting shape.

You can assume the triangles all connect to exactly one other triangle per side, and the surface does not cross over itself. You will not get an input where two separate solids touch only at points or edges.

Test cases and sample implementation coming soon

\$\endgroup\$
7
  • \$\begingroup\$ I like this one. I think that its got some tricky bits to it, like getting the normals for the triangles and ensuring that they are facing the right way. As far as input format goes, an Ascii stl file may be a good option, as it breaks down the meshes into faces and provides the normals as well. \$\endgroup\$
    – JPeroutek
    Oct 15 '21 at 19:36
  • \$\begingroup\$ is the winding of the input going to be consistent or could it be random? also what is the error bound for the output? \$\endgroup\$
    – don bright
    Oct 18 '21 at 3:15
  • \$\begingroup\$ @donbright Random, I'm thinking. For the output, floating point errors are fine, as long as the calculations would theoretically return the correct result. \$\endgroup\$ Oct 18 '21 at 13:27
  • \$\begingroup\$ sounds like a good bit of fun but i kind of predict people will ask for some kind of precise bounding on the error like +/- 1 percent or something. \$\endgroup\$
    – don bright
    Oct 19 '21 at 2:07
  • \$\begingroup\$ @donbright The answer could be off by a thousand percent, if I reimplemented the language with arbitrary precision floats and it worked, I'm fine with it. That's way easier for everyone. Answerers don't need to worry about weird floating point tricks, and I don't need to tell them their answer's invalid :) \$\endgroup\$ Oct 19 '21 at 4:15
  • \$\begingroup\$ i mean the question is how do you know the algorithm works without running it and comparing the result to the known correct value? \$\endgroup\$
    – don bright
    Oct 20 '21 at 2:31
  • \$\begingroup\$ @donbright Probably a mix of trust, and it most likely being close enough to the correct answer that anything other than floating point errors is unlikely \$\endgroup\$ Oct 20 '21 at 2:34
3
\$\begingroup\$

Converting Pinyin to Zhuyin or vice versa

Challenge

Pinyin and Zhuyin are systems that are used to help people pronounce characters in Mandarin Chinese. Write a function/program that converts Pinyin to Zhuyin or vice versa (clarify which one you are doing) according to the tables below. You are not required to deal with tones or incorrect inputs (including edge cases such as ḿ(呣), ǹg(嗯), and ê̄(诶/誒)).

Pinyin to Zhuyin

Pinyin Zhuyin
b
p
m
f
d
t
n (at the beginning)
l
g (at the beginning)
k
h (at the beginning)
j
q
x
zh (except in zhi)
zhi
ch (except in chi)
chi
sh (except in shi)
shi
r (at the beginning)
ri
z (except in zh, zi)
zi
c (except in ch, ci)
ci
s (except in sh, si)
si
a (at the end)
o (except in ao, ou, ong)
e (except in ei, en, eng, er, ie, ue, üe, ye)
e (only in ie, ue, üe, ye)
i (except in ai, ei, ui, iu, iong, yi, zhi, chi, shi, ri, zi, ci, si)
y (except in yong, yi)
yi
u (except in ou, iu, wu, ue and except after j, q, x, y)
w (except in wu)
wu
o (only in ong except in iong, yong)
u (right after j, q, x)
ü
yu
io
yo (only in yong)
ai
ei
i (only in ui)
ao
ou
u (only in iu)
an (except in ang)
ang
en (except in eng)
n (only in in, un except in ing)
eng
ng (only in ing, ong)
er

Zhuyin to Pinyin

Zhuyin Pinyin
b
p
m
f
d
t
n
l
g
k
h
j
q
x
ㄓ (by itself) zhi
ㄓ (not by itself) zh
ㄔ (by itself) chi
ㄔ (not by itself) ch
ㄕ (by itself) shi
ㄕ (not by itself) sh
ㄖ (by itself) ri
ㄖ (not by itself) r
ㄗ (by itself) zi
ㄗ (not by itself) z
ㄘ (by itself) ci
ㄘ (not by itself) c
ㄙ (by itself) si
ㄙ (not by itself) s
a
o
e
e
ㄧ (at the beginning, not by itself, and not before ㄣ, ㄥ) y
ㄧ (after ㄐ, ㄑ, ㄒ) i
ㄧ (by itself or before ㄣ, ㄥ and at the beginning) yi
ㄨ (not at the beginning) u
ㄨ (at the beginning except by itself) w
ㄨ (by itself) wu
ㄨ (before ㄥ and not at the beginning) o
ㄩ (after ㄐ, ㄑ, ㄒ) u
ㄩ (after ㄋ, ㄌ) ü
ㄩ (by itself or before ㄝ, ㄢ, ㄣ and at the beginning) yu
ㄩ (not at the beginning and before ㄥ) io
ㄩ (at the beginning and before ㄥ) yo
ai
ㄟ (not after ㄨ unless ㄨ is at the beginning) ei
ㄟ (after ㄨ unless ㄨ is at the beginning) i
ao
ㄡ (not after ㄧ unless ㄧ is at the beginning) ou
ㄡ (after ㄧ unless ㄧ is at the beginning) u
an
ang
ㄣ (not after ㄧ, ㄨ, ㄩ unless ㄨ is at the beginning) en
ㄣ (after ㄧ, ㄨ, ㄩ unless ㄨ is at the beginning) n
ㄥ (not after ㄧ, ㄨ, ㄩ unless ㄨ is at the beginning) eng
ㄥ (after ㄧ, ㄨ, ㄩ unless ㄨ is at the beginning) ng
er

This is code-golf, so the answer with the least bytes wins.

Test Cases

Pinyin Zhuyin
chuang ㄔㄨㄤ
xue ㄒㄩㄝ
diu ㄉㄧㄡ
juan ㄐㄩㄢ
ri
song ㄙㄨㄥ
ㄌㄩ
qiong ㄑㄩㄥ
zhen ㄓㄣ
huo ㄏㄨㄛ
ying ㄧㄥ

Additional test cases and information

\$\endgroup\$
6
  • \$\begingroup\$ Am I required to support single characters or a word / sentence? Also, there are some edge cases as I know, for example, ḿ(呣), ǹg(嗯), ê̄(诶/誒). Would these be excluded from testcases? May I assume no erhua (儿化/兒化) would be applied? \$\endgroup\$
    – tsh
    Oct 12 '21 at 6:44
  • \$\begingroup\$ There are far more rules than testcases. I would suggest to add more testcases as many rules are not ever touched by any testcases here. \$\endgroup\$
    – tsh
    Oct 12 '21 at 6:54
  • \$\begingroup\$ @tsh Single characters. The edge cases would not be required to check for as inputs. No erhua. I will try to add some more testcases to cover the other rules. \$\endgroup\$
    – Yousername
    Oct 12 '21 at 11:19
  • \$\begingroup\$ Suggest a whole list, it's likely just 300+ possible inputs \$\endgroup\$
    – l4m2
    Oct 12 '21 at 18:13
  • 1
    \$\begingroup\$ The number of rules makes this an intimidating task to write and golf. Consider limited to a simpler subset of rules or situations. \$\endgroup\$
    – xnor
    Oct 13 '21 at 7:12
  • \$\begingroup\$ @xnor It's not actually as many rules as it looks like. A simple regex can be used for most of them. \$\endgroup\$
    – Yousername
    Oct 13 '21 at 21:41
3
\$\begingroup\$

Pythagorean triples given the hypotenuse.

\$\endgroup\$
3
\$\begingroup\$

Is This Scrabble Board Valid?

\$\endgroup\$
3
\$\begingroup\$

Leave ABACABA on the tape

Note that will be removed post sandboxing: This challenge is Brainfuck-specific, but I hope that its contents make the reason why sufficiently clear.

Write a brainfuck program which leaves the following sequence on the tape:

0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 4 0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 ...

This sequence may be familiar to some as ABACABADABACABA... or A007814.

Assume an implementation of BF with an endless tape and arbitrarily large (but not arbitrarily small) integers.

You should link to a visualizer to prove that your program works as you say it does, but if this isn't fast enough to witness the first few (say 4) numbers in ABACABA you'll have to explain it yourself.

This is code-golf, so the shortest program operating within these rules wins. Have fun!

\$\endgroup\$
1
  • \$\begingroup\$ Because a BF program would likely do destructive edits to the previous terms or add scratch data to the end while advancing the sequence, I'd propose a more rigorous definition: "Write a BF program where, given any prefix of the ABACABA sequence, running the program for some finite number of steps will give the pattern at the start of the tape." \$\endgroup\$
    – Bubbler
    Nov 18 '21 at 1:32
3
\$\begingroup\$

Light-Cycle KotH

\$\endgroup\$
9
  • \$\begingroup\$ I'd recommend removing all bots that crash in the same turn. Basing it off of external factors like submission dates is a bit unfair. \$\endgroup\$ Sep 13 '21 at 17:04
  • \$\begingroup\$ My justification for removing only 1 per turn is that it simplifies the logic of generating a leaderboard and removes some edge cases, otherwise things like 3-way ties for first place might be possible if all the bots crash at the same time. \$\endgroup\$
    – thesilican
    Sep 13 '21 at 20:51
  • \$\begingroup\$ I feel like biasing the rules against newer submissions is fair. After all, new submissions inherently have the advantage that they're able to see the older submissions and can strategize around these existing submissions. \$\endgroup\$
    – thesilican
    Sep 13 '21 at 20:55
  • \$\begingroup\$ The issue is that the oldest submissions functionally move first, meaning that being the first bot posted is a significant advantage. What about edits? If a bot is changed, does it drop to the bottom? I agree that removing all bots which crash is the right call. \$\endgroup\$ Sep 14 '21 at 18:36
  • \$\begingroup\$ Hmm... I was going to disallow edits, so that anyone who wanted to update their bot must instead post it as a new bot. @Spitemaster Are edits typically allowed for KotH submission? \$\endgroup\$
    – thesilican
    Sep 14 '21 at 20:27
  • \$\begingroup\$ Frequently; not always. But you've still got the problem of earlier entries effectively moving first. If you really want to do it this way, it doesn't make sense to have simultaneous movement (because it's not really simultaneous). \$\endgroup\$ Sep 14 '21 at 20:34
  • \$\begingroup\$ Ok, that seems fair, I will update post to allow for simultaneous movement \$\endgroup\$
    – thesilican
    Sep 14 '21 at 20:49
  • \$\begingroup\$ If I were you, I'd consider sizing the arena based on number of bots. \$\endgroup\$
    – emanresu A
    Sep 14 '21 at 20:56
  • \$\begingroup\$ That seems like a reasonable suggestion, what kind of scaling do you think would be good? I'm thinking maybe something like a square with side-length 2n+6, for n players. \$\endgroup\$
    – thesilican
    Sep 14 '21 at 21:02
3
\$\begingroup\$

Randomly capitalize half of a string

\$\endgroup\$
3
  • \$\begingroup\$ Will a string of length 0 ever be an input? \$\endgroup\$
    – dzaima
    Jun 15 '17 at 12:26
  • \$\begingroup\$ @dzaima no, clarified by saying length will always be positive \$\endgroup\$
    – Mayube
    Jun 15 '17 at 13:57
  • 2
    \$\begingroup\$ Change "positive" to "non-zero"? You can't have a negative-length string, last time I checked... \$\endgroup\$
    – pxeger
    Dec 1 '21 at 18:15
3
\$\begingroup\$

Write a number in overflowed binary

\$\endgroup\$
1
  • \$\begingroup\$ Maybe define a overflowed binary number a binary number where one or more of it's digits goes over 1? \$\endgroup\$
    – Bgil Midol
    Dec 3 '21 at 17:21
3
\$\begingroup\$

Solve an Inglenook Sidings Puzzle

Tags:

Posted! After about 2 weeks in Sandbox

\$\endgroup\$
3
  • \$\begingroup\$ "Model railroading", not "railroad modeling?" \$\endgroup\$
    – Bubbler
    Nov 25 '21 at 2:17
  • \$\begingroup\$ @Bubbler specifically model railroading. The puzzle was made to create operational interest on small layouts, since it only needs 2 switches and 4 pieces of relatively short track \$\endgroup\$
    – bigyihsuan
    Nov 25 '21 at 4:05
  • \$\begingroup\$ So this challenge proposal has been in here for just about a week now; are there any flaws in this? I don't want to post this to the main site and get feedback that should've been caught in meta \$\endgroup\$
    – bigyihsuan
    Dec 1 '21 at 16:11
3
\$\begingroup\$

Simulate weathering

\$\endgroup\$
3
  • \$\begingroup\$ I like this idea. I'd suggest extending the example for another iteration or two, and it wouldn't hurt to add other test cases. Just a thought (no strong opinion either way): you could remove the second input (\$n\$) and have the simulation run until the rock disappears, with the shape being printed at each iteration. \$\endgroup\$
    – Dingus
    Nov 4 '21 at 22:57
  • \$\begingroup\$ @Dingus edited. removed the second input since outputing until the rock disappears makes more sense. \$\endgroup\$
    – PyGamer0
    Nov 5 '21 at 4:54
  • 1
    \$\begingroup\$ First, I'd be more fluid with the I/O format - allow a bit matrix, char matrix, list of strings, etc. Also, a different idea that might warrant its own challenge: What if you just removed one rock at a time? \$\endgroup\$
    – emanresu A
    Nov 5 '21 at 7:18
3
\$\begingroup\$

Worst time complexity in under 100 bytes

Time complexity, typically represented in Big O notation, represents how long a program will typically take to run given some input(s), ignoring constants.

Your task is to do one of the following things, with the worst time complexity possible:

  • Sort an array of integers
  • Find duplicates in an array
  • Find longest strictly increasing slice of an array of integers

Tasks:

All of the tasks involve taking one input, an array of items, in any reasonable format, and returning an array. If your language supports mutable array data types, this is an allowed output format. Assume all items in the arrays will be (not necessarily positive) integers.

If you choose sorting: You may choose to sort the array by minimum or maximum.

If you choose listing duplicates: You may include a duplicate item any number of times in the output; [1, 2, 2, 3, 4] could result in [2, 4], [2, 2, 4], or even [2, 4, 4, 4].

If you choose longest strictly increasing slice: Duplicate items do not count as increasing, so [1, 2, 2, 4] is not strictly increasing. The items do not have to increase by a steady amount; [-1, 4, 14, 16, 17] is strictly increasing.

Rules:

Your program must be 100 bytes or less. Your program should terminate in a finite amount of time. You can assume your program will never run out of memory, and it does not have to terminate before the heat death of the universe.

This is a . The winner will be based on the average time complexity, with slower being better, followed by the best case and then worst case for ties.

\$\endgroup\$
5
  • \$\begingroup\$ Unfortunately, this answer broke all "irreducible" challenges. You can execute (almost) arbitrary code unrelated to the task without breaking the "irreducible" requirement. \$\endgroup\$
    – Bubbler
    Apr 22 '21 at 0:16
  • \$\begingroup\$ @Bubbler Hmm, and I don't think irreducible is a sensible requirement for this either. It definitely makes more sense with bytes than time, along with pristine. I'll have to think about some creative limitations. Maybe unique bytes only? \$\endgroup\$ Apr 22 '21 at 0:22
  • \$\begingroup\$ Now this is somewhat too close to bignum computation challenge, since all the biggest numbers are actually a fast-growing function applied to some number. They can be trivially converted to take the length of the input, and then used in the algorithm in some way (or just discarded). \$\endgroup\$
    – Bubbler
    Dec 16 '21 at 8:32
  • \$\begingroup\$ How about this: Choose a decision problem, and write code that solves it, within 100 bytes (or use a partially ordered score instead of a byte limit). Answers are compared based on the minimal time complexity of the problem, not the implementation. So if someone solves an EXPTIME-hard problem, they beat whoever solves a problem in P. This solves the problem of people doing useless calculations, since it doesn't help them. Writing a sorting function that takes exponential time is not in any way better than just doing a sort in O(nlogn) time. \$\endgroup\$
    – AnttiP
    Dec 16 '21 at 11:25
  • \$\begingroup\$ @AnttiP That could be cool, but it sort of goes against what I was going for (ridiculously slow sorting algorithms). Maybe a separate challenge idea? \$\endgroup\$ Dec 16 '21 at 14:27
3
\$\begingroup\$

Stich a hitomezashi pattern

\$\endgroup\$
2
3
\$\begingroup\$

Nth FizzBuzz Number

\$\endgroup\$
1
  • \$\begingroup\$ Maybe allow any different 4 distinct inputs for Fizz, Buzz, FizzBuzz and Number? \$\endgroup\$
    – pajonk
    Dec 16 '21 at 11:48
3
\$\begingroup\$

Light it up

\$\endgroup\$
4
  • \$\begingroup\$ Maybe you can fill empty cells by some characters like . in your examples and testcases. Or it could be confusing: L.#. is falsy but L.# is truthy, but it is hard to see the difference. \$\endgroup\$
    – tsh
    Nov 2 '21 at 1:53
  • \$\begingroup\$ @tsh Ok, thanks! \$\endgroup\$
    – emanresu A
    Nov 2 '21 at 2:02
  • \$\begingroup\$ "some squares are walls, some are empty, and some are lights". Since there are testcases where only empty cell is there, will there be any testcases like ####? \$\endgroup\$
    – tsh
    Nov 2 '21 at 5:23
  • \$\begingroup\$ @tsh Yes, see the fourth truthy one. I'll be more explicit that some may not occur at all. \$\endgroup\$
    – emanresu A
    Nov 2 '21 at 6:13
3
\$\begingroup\$

Print □□Square□□ Numbers

Your task is to write a program or function that accepts an integer as input/argument and prints/returns all square numbers from 0 up to but not including n².

But the numbers should not just be perfect squares in the mathematical sense. They should be square in every sense. That is, the digits should

  • • occupy a square space, 5 lines by 5 columns (including separating space)
  • • form right angles at their joints
  • • be formed entirely from □ and space characters

Actually, the digits must be shaped exactly like these:

   □ □□□□ □□□□ □  □ □□□□ □□□□ □□□□ □□□□ □□□□ □□□□ 
   □    □    □ □  □ □    □       □ □  □ □  □ □  □ 
   □ □□□□ □□□□ □□□□ □□□□ □□□□    □ □□□□ □□□□ □  □ 
   □ □       □    □    □ □  □    □ □  □    □ □  □ 
   □ □□□□ □□□□    □ □□□□ □□□□    □ □□□□ □□□□ □□□□ 

Note the single column of space between each digit. Spaces at the end of each line are optional. (The three empty columns of spaces on the left side of the digit 1 are not optional.)

Each square number shall be printed on exactly 5 lines using these digits, and between each of these numbers shall be a single line containing no non-whitespace characters. You may optionally include extra blank lines at the beginning or end of the output.

Standard loopholes etc. Shortest solution in bytes is the coolest of beans.

Example Output (given the input 5):

□□□□
□  □
□  □
□  □
□□□□

   □
   □
   □
   □
   □

□  □
□  □
□□□□
   □
   □

□□□□
□  □
□□□□
   □
□□□□

   □ □□□□
   □ □
   □ □□□□
   □ □  □
   □ □□□□

(Note for sandbox: I know this is a good challenge because I had fun solving it myself. But I am worried there is another challenge I haven't seen that is too similar. Please let me know. I'll abandon it if so.)

\$\endgroup\$
3
  • \$\begingroup\$ Can't find any dupes on this search so it is probably clear. \$\endgroup\$
    – Razetime
    Jan 7 at 4:45
  • 1
    \$\begingroup\$ Closely related \$\endgroup\$
    – pxeger
    Jan 7 at 7:58
  • \$\begingroup\$ @pxeger yeah that's probably similar enough not to post this \$\endgroup\$
    – quintopia
    Jan 7 at 17:37
3
\$\begingroup\$

Remove consistently dependent smaller integers

\$\endgroup\$
2
  • \$\begingroup\$ If lists can be empty I would add an example where one is empty, if they cannot I would make that explicit in the text. Otherwise this seems fine +1. \$\endgroup\$
    – Wheat Wizard Mod
    Jan 6 at 14:20
  • \$\begingroup\$ @WheatWizard i will explicitly specify. Thank you:) \$\endgroup\$ Jan 6 at 14:23
3
\$\begingroup\$

Expand a Rubik's Cube Commutator

Tags:

Posted: Expand a Rubik's Cube Commutator

\$\endgroup\$
5
  • \$\begingroup\$ What do you mean by "expand" the commutator? Also, 3x3x3*, a 3x3 would be a rubik's square :) \$\endgroup\$ Jan 11 at 15:12
  • \$\begingroup\$ @thejonymyster The common names for Rubik's cubes are by the size of a face since they're usually cubes, so we just call them "3x3" for a 3x3x3 cube, etc. Only in cuboids like the 3x3x4 cuboid actually have the 3rd dimension "Expanding" the commutator == Listing out all the moves performed in the commutator \$\endgroup\$
    – bigyihsuan
    Jan 11 at 19:59
  • \$\begingroup\$ ahh, that makes sense, for both parts. +1 \$\endgroup\$ Jan 11 at 20:03
  • 1
    \$\begingroup\$ "Each part of the commutator can be a separate value" - I see this is to make IO more flexible than flat string to flat string, which is good, but I would go further and allow the moves themselves be separate values in each part, and allow a list of moves as the output in order to focus on the challenge itself. This would allow, for example, [["F'", "U2", "R"], ["D", "B2"]] -> ["F'", "U2", "R", "D", "B2", "R'", "U2", "F", "B2", "D'"]. \$\endgroup\$ Jan 11 at 23:07
  • \$\begingroup\$ I couldn't resist and just gave it a go in Jelly and got a 15 byte solution (assuming IO is further relaxed as I suggested, which I believe you will do given your current relaxation). This is a good challenge IMO. \$\endgroup\$ Jan 11 at 23:20
3
\$\begingroup\$

Reversed Multiple Pair

Intro

A reversed multiple pair with number \$a\$ and number \$b\$ that satisfy the following property:

\$ a\times b = reversed( (a-1)\times b ) \$

Example

\$a=6, b=9\$

$$6\times9=54,5\times9=45$$

As you can see, \$45\$ is the reversed version of \$54\$.

Task

Given two integers, \$a\$ and \$b\$, output if these two numbers is a reversed multiple pair.

Test Cases

6 9 => True
4 5 => False
3 2178 => True
34 2079 => True
7 8 => False
600 100 => False
46 1089 => True
817 503 => False
6 9009 => True

Shortest code wins!

Meta

  • Is this clear and fun?
  • Is there special mathjax for reversing a number?
  • Are there any more pairs of numbers that satisfy this property?
\$\endgroup\$
5
  • \$\begingroup\$ maybe give an example and a step by step of evaluating if it is reversed multiple? \$\endgroup\$ Jan 13 at 20:19
  • \$\begingroup\$ @thejonymyster Done \$\endgroup\$
    – Bgil Midol
    Jan 13 at 20:29
  • 2
    \$\begingroup\$ really simple, but it is clearly specified. seems like a decent easy challenge. To make it slightly more difficult you can make this a challenge of finding all reversed multiple pairs under a given limit. \$\endgroup\$
    – Razetime
    Jan 14 at 3:35
  • \$\begingroup\$ @Razetime codegolf.meta.stackexchange.com/a/9384/105116? \$\endgroup\$
    – Bgil Midol
    Jan 14 at 15:31
  • \$\begingroup\$ it's your choice whether that change makes it more interesting or whether it is an unnecessary burden. \$\endgroup\$
    – Razetime
    Jan 14 at 15:55
3
\$\begingroup\$

Will the tower balance?

You are given as input a tower made of bars of unit height, and your task is to decide if the tower is stable. Here is an ascii art drawing of a tower:

 #
####
# ####
#####

For extra clarity here is the same tower but with the different bars in different characters:

 A
BBBB
C DDDD
EEEEE

The bars are rigid, but they are not connected to each other. Even though the bars are not connected, they stay still under the influence of gravity. Here however is a tower that is not stable:

      B
CCCCCCCC
   D
  EEE
FFFFFFFF

In this tower, under the influence of gravity, the top bar will fall to the right.

The following tower is metastable:

AA
B

The center of mass of the A-bar lies on top of the edge of the B-bar. In this kind of situation the tower is considered unstable, since even a small perturbation will cause it to fall eventually.

Input/output format

The input format is an ascii drawing of the tower like so:

 ###
  #
### #

In this picture there are 4 bars. It is guranteed that all bars are on top of another bar or on top of the ground and that every row has at least one bar. You can use a different printable ascii character instead of #. You can also take a 2d array instead of a string and use two distinct values for # and . In that case please use simple values, that don't encode extra information (standard loopholes prohibited).

Output two distinct values for STABLE and UNSTABLE.

Test cases

#

STABLE

###
 #
 ##
  #

UNSTABLE

  ###
 ###
###

UNSTABLE (metastable)

#
#     ######
####    ##
 #      ##

STABLE

###
 #
#####
 #

STABLE

 #
#####
 #

UNSTABLE

######  #
 #  #   #
### #####
 #   #
 #####
   #

STABLE

\$\endgroup\$
2
  • 1
    \$\begingroup\$ The rules do not actually specify what makes a tower stable. The stable test cases use balancing methods not stated anywhere, and the rules themselves just seem to be more examples. As a non physicist, "use gravity" isn't enough information IMO. This is a cool idea though and +1 once that's fixed \$\endgroup\$ Jan 17 at 13:49
  • \$\begingroup\$ Just highlighting the bars on their own would be interesting IMO \$\endgroup\$
    – emanresu A
    Jan 17 at 18:36
3
\$\begingroup\$

Recursive palindromes

\$\endgroup\$
3
\$\begingroup\$

Shrink ASCII art

\$\endgroup\$
1
  • \$\begingroup\$ convert like ---, 3 to [---, 3]? \$\endgroup\$
    – Fmbalbuena
    Dec 26 '21 at 0:48
3
\$\begingroup\$

Is this continuous terrain? Part II

\$\endgroup\$
1
  • 1
    \$\begingroup\$ i like it emanresu A! \$\endgroup\$
    – DialFrost
    Jan 19 at 8:50
3
\$\begingroup\$

Only one from each set

\$\endgroup\$
3
  • \$\begingroup\$ "There are no gaps in the numbers " does it means that the input flattened must contain all the numbers [1..n] where n is the maximum number in it? \$\endgroup\$
    – AZTECCO
    Jan 23 at 10:31
  • \$\begingroup\$ @AZTECCO Yes, exactly \$\endgroup\$
    – AnttiP
    Jan 23 at 10:32
  • \$\begingroup\$ Ok, i think you should explain it, careful.. there are some test cases non valid. I think you may also specify that inner lists are sorted (if it's so I guess) \$\endgroup\$
    – AZTECCO
    Jan 23 at 10:40
3
\$\begingroup\$

Shanghai ascii game sticks

Posted

\$\endgroup\$
4
  • \$\begingroup\$ Looks great, ready to post \$\endgroup\$ Jan 21 at 10:38
  • \$\begingroup\$ @ThisFieldIsRequired thanks, I still got something to tweak.. I'm gonna take some time \$\endgroup\$
    – AZTECCO
    Jan 21 at 12:32
  • \$\begingroup\$ How are the last two testcases possible? \$\endgroup\$
    – emanresu A
    Jan 22 at 19:29
  • 2
    \$\begingroup\$ @emanresu A the last test case is an edge case were 4 sticks are all bounded and one sits by itself and satisfy the one and only one stick removable condition, you are not required to remove all sticks but just the first \$\endgroup\$
    – AZTECCO
    Jan 22 at 20:11
3
\$\begingroup\$

Highlight a Wordle guess

\$\endgroup\$
7
  • \$\begingroup\$ confused to be honest . maybeeee abit too hard? \$\endgroup\$
    – DialFrost
    Jan 17 at 9:57
  • \$\begingroup\$ @DialFrost Can you be more specific? What part are you confused about? \$\endgroup\$
    – pxeger
    Jan 17 at 9:58
  • \$\begingroup\$ er mostly about the highlighting value \$\endgroup\$
    – DialFrost
    Jan 17 at 10:00
  • \$\begingroup\$ @DialFrost do you mean: 1) you don't understand when to highlight the letters in which colour; or 2) you don't understand how the output values used for highlighting can be chosen? Or something else? \$\endgroup\$
    – pxeger
    Jan 17 at 10:01
  • \$\begingroup\$ both i dont understand \$\endgroup\$
    – DialFrost
    Jan 17 at 10:01
  • \$\begingroup\$ @DialFrost without some more details on what you're missing, I can't help you to understand or clarify the description. What bits you do you understand? \$\endgroup\$
    – pxeger
    Jan 17 at 10:05
  • \$\begingroup\$ pretty much none i just meant i dont understand the hilighting value and how it works the most \$\endgroup\$
    – DialFrost
    Jan 17 at 10:06
2
\$\begingroup\$

Metagolf: Catlike Piet

The goal of this is to write a catlike program, which would be executed (in a Unix environment, though you needn't stick to that) by the following:

yourprogram < file > output
piet output

where piet output writes the contents of file to stdout. That is, you're to generate a Piet program which prints the input to yourprogram.

One-liners

Straight line programs can be written in Piet... in straight lines. If you're willing to take a hit to your score, your output can take the form of a string of commands:

=  none (continue color block)
|  push
^  pop
+  add
-  subtract
*  multiply
/  divide
%  mod
~  not
>  greater
.  pointer
\  switch
:  duplicate
@  roll
$  input number
?  input character
#  output number
!  output character

which is trivial to convert to a Piet program with the following (partially golfed) Python code:

def P(s):
 h=v=0;l=len(s)+1;R="P3 %i 2 255 192 0 0 "%(l+2)
 C=[1,3,2,6,4,5];V=[0,192,192,255,0,255]
 for x in map("=|^+-*/%~>.,:@$?#!".find,s):
  C=C[x//3:]+C[:x//3];V=V[x%3*2:]+V[:x%3*2]
  for i in [1,2,4]:R+="%i "%V[(C[0]//i)%2]
 return R+"255 "*4+"0 0 "+"255 "*l*3+"255 0 0 "*2

The dimension of said program is (n+3) x 2 if there are n characters in the string.

Scoring

Your code will be judged on the maximum dimension of the images that it outputs.

  • Part 1: Take the maximum score taken over all ascii codes (that is, single-character inputs), discounting EOF.

  • Part 2: Take the score for the input "Hello. My name is Inigo Montoya. You killed my father. Prepare to die."

Your score is the product of the scores in part 1 and part 2.

Punishment: Double your score if you write one-liners as above (that is, if you don't output an image).

Bonus: If your program is written in Piet, take the square root of your score above.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ It took me a while to understand the task as "Write a program taking INPUT which produces as output a piet program that takes no input but produces INPUT." I think it is a interesting and challenging, but it's reception will depend entirely on how many people are willing to learn/futz-around-in/deal-with piet. And I have no feel for how many that is. \$\endgroup\$ Jul 7 '11 at 3:12
  • \$\begingroup\$ @dmckee; would it be better if I just used a reduced instruction set, and only ask for the instruction stream? I think this is still challenging with {push 1,duplicate,add,subtract,multiply,output}. Come to think of it, if I restrict to {push 1,duplicate,add,output}, there's a reduction to some awesome algorithms. \$\endgroup\$
    – boothby
    Jul 7 '11 at 4:48
  • \$\begingroup\$ I did this in piet some time ago: craigoclock.blogspot.com/2011/05/metaprogramming-in-piet.html \$\endgroup\$
    – captncraig
    May 21 '12 at 18:31
  • \$\begingroup\$ Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) \$\endgroup\$
    – user58826
    Jun 9 '17 at 15:22
2
\$\begingroup\$

Play Simple 2-Dimensional Minecraft

Recently I found this video of "HansLemurson" showing a computer that was built in minecraft, which runs minecraft. He is playing minecraft on a computer that was built in minecraft that is running on his computer. To be specific, it is a two dimensional version with an 8x8 grid of cells. There is gravity, block placement, and even jumping. It is worth noting that the computer is single purpose. The same person has built programmable computers, but making them single purpose allows the computer to be much smaller.

Details

The minecraft world is an 8x8 grid (one horizontal and one vertical dimension). The grid is comprised of either Xs (representing blocks) or empty spaces. The player is an X that is blinking on and off about once every second.

There are two modes in the game, controlled by a toggle switch. The first mode is movement. This is controlled by a WASD-like button arrangement. If the player chooses to move left/right/down, the computer checks to see if the space immediately in that direction is empty. If so, then the player moves into that space.

If the player chooses to move up, then the computer checks that the block underneath the player is solid. If so, then the player moves upward two units. Notice that this can propel the player into a solid block. If this happens, the player is obscured by the solid block, but can still move to an empty block next to him. When the player is inside on a solid block, the game continues as if the block isn't there, although the block is still there once the player leaves it.

After each move, the player falls down one unit if there is empty space there. This simulates gravity. This is also why moving up moves up two units, so that the gravity makes a net movement of up one unit. Gravity does not cause the player to fall all of the way to the ground, just one unit.

The second mode is block placement. In this mode, the same exact WASD buttons are used. Instead of moving the player, they toggle the state of the block in that direction. If the player presses "left" and there is a block there, then the block is destroyed. If there is not a block there, then a block is placed. Again after this move, the player is again subject to gravity. The blocks are not subject to falling.

Toggling the toggle switch does not count as a move, and does not invoke gravity.

The game board is a torus, so all actions (movement, block creation) can wrap around the board. The board does not scroll with the player. The player moves, and the blocks stay in the same place.

The challenge

You challenge is to write the shortest program that simulates this game. Your program should display and update the map correctly (with Xs as blocks, and with the blinking player). It should accept input from a button that toggles the state and four buttons for movement and actions. This is code golf.

There are imaginary bonus points for adding more features (block types, game size, etc) to your game.

Suggestions?

\$\endgroup\$
4
  • 3
    \$\begingroup\$ With more complicated challenges I find that it helps to do a reference implementation so that you have a very concrete idea of how much work is involved. Aside from that, I like it. \$\endgroup\$ Jun 3 '12 at 20:11
  • \$\begingroup\$ Is the blink rate selected to fit with the ANSI escape sequence? Either way I would explicitly allow that, because it's the obvious way to do it on compatible terminals. \$\endgroup\$ Jun 5 '12 at 7:14
  • \$\begingroup\$ The blink rate wasn't selected to be anything specific. I think that I will broaden the restriction. Maybe any blink rate between 3 blinks per second to 1 blink every 2 seconds. \$\endgroup\$
    – PhiNotPi
    Jun 5 '12 at 20:21
  • \$\begingroup\$ @programmer5000 No, for two main reasons: First, challenges can go extended periods of time in the sandbox before they are posted and/or adopted. In the past I've posted challenges after not touching them for 4 years. Second, deleting this answer will not reduce lag, as deleted answers are still present, simply not visible. Users with sufficient rep will see all 4040 answers in the sandbox, and you will too once you earn the "view deleted answers" privilege. \$\endgroup\$
    – PhiNotPi
    Apr 13 '17 at 18:15
2
\$\begingroup\$

Bad Voice Recognition Calculator

Overview:

Let's say you've decided to operate your computer using voice recognition software, but unfortunately you did a horrible job researching the various products out there and chose a package that does not recognize numbers as numerals, only words. (i.e. "one" (spoken) == "one" (typed), not "1".) Rather than spend more money to get another option, you decide to make do. Now you want to use the computer's calculator, but this poses a problem, since your machine doesn't know how to add "one plus one".

Objective:

Implement a basic calculator that will read in a string of the written-out equation, perform the correct calculations, then return the result in its text form. Your code should be as short as possible; this is code golf.

Rules/Constraints:

  • Input/output will be using your preferred method (STDIN, ARGV, etc.).
  • Your calculator must be able to handle input and output within the billions (non-inclusive) -1,000,000,000 < i < 1,000,000,000, but you may expand to more if you wish.
  • Decimal values and/or parts must be accepted (0 < i < 1) up to 3 places/digits.
    • When calculating answers, proper rounding must be used, so "three point one four one five nine two six" must be returned as "three point one four two".
  • Basic calculator functions required:
    • "Add"/"Plus"/"Sum"/"And" (+)
    • "Subtract"/"Minus"/"Remove" (-)
    • "Multiply"/"Times" (*)
    • "Divide"/"Divided"/"Divide by"/"Divided by" (/)
    • "Raise"/"Exponent"/"Power"/"To the power of" (^)
    • "<Base>Root"/"<Base>Radical" (√)
    • "Point"/"Decimal" (.)
    • "Pi" (π)
  • All strings in the list above must be accounted for in your code, capitalization does not matter.
  • Numbers may be presented as their full value ("one thousand") or by digit (one zero zero zero).
  • Negative numbers may be assigned using "Minus" or "Negative".
    • The string "Minus" bust be accounted for as an operator and identifier. (see example)
  • "And" is only acceptable as an operator, not as part of a named number.
    • "one hundred and one"
    • "one hundred one"
  • "a" or the absence of a number does not equate to any number; all numbers will be explicitly accounted for in the program input.
    • "a hundred" does not equate to "one hundred" and is not a valid input.
  • No more than 2 terms will be used.
    • "one plus one minus one" will not be implemented.
  • If an invalid input is supplied, your function/program should handle the error and exit gracefully with an error description.

Example I/O:

  • "one add one" --> "two"
  • "five thousand thirty four subtract ten thousand six hundred" --> "negative five thousand five hundred sixty six"
    • Alternatively: "five zero three four subtract one zero six zero zero"
  • "three root twenty seven" --> "three"
  • "ten minus minus ten" --> "twenty"
    • Alternatively: "ten subtract negative ten"

Sandbox Questions:

  1. Is this too basic/complicated? (I'm assuming some languages will handle this much more simply than the method I have in my head...)
  2. Does the title fit?
  3. Are there any constraints that should be added/lifted?
  4. Are any more examples needed for clarification?

Thanks for your input, guys!

\$\endgroup\$
6
  • \$\begingroup\$ Not everyone says numbers the same way. Does the parser have to treat the following as equivalent? "negative one hundred five", "minus one hundred five", "negative one hundred and five", "minus one hundred and five", "negative a hundred five", "negative a hundred and five", ...? \$\endgroup\$ Jun 15 '12 at 15:12
  • \$\begingroup\$ @PeterTaylor I had had a similar thought re: operators. ("plus" versus "add", etc.) I think it would be more interesting to account for all, but given the wide variety of possible inputs, it may generally be better to limit the options to a specifically defined set (which I have yet to define). \$\endgroup\$
    – Gaffi
    Jun 15 '12 at 15:18
  • \$\begingroup\$ @PeterTaylor I've added some of these details. Please let me know if there's anything unclear about them. \$\endgroup\$
    – Gaffi
    Jun 15 '12 at 16:10
  • \$\begingroup\$ I don't spot any ambiguities in the parser. There is still an ambiguity relating to decimals, though. What precision should be used? Also, I notice now that there's no winning condition. Is this intended to be code-golf? (Ugh - tons of strings which will have to be hard-coded in most languages. I expect Perl has a suitable parser already in CPAN, though...) \$\endgroup\$ Jun 19 '12 at 9:03
  • \$\begingroup\$ @PeterTaylor I don't know where I went... I've updated the spec. re: decimal places and objective. \$\endgroup\$
    – Gaffi
    Jun 29 '12 at 13:24
  • 1
    \$\begingroup\$ @PeterTaylor metacpan.org/pod/Lingua::EN::Words2Nums \$\endgroup\$
    – msh210
    Apr 27 '16 at 20:37
2
\$\begingroup\$

Huffman Decoding

Write a programm which takes two strings as input and prints a text.


The first argument is a Huffman Tree, serialized in the following format:

  • every ascii character except ~ is always a leaf, if ~ is the first characater it is also a leaf.
  • <tree0><tree1>~ is a tree where <tree0> is the left subtree and <tree1> is the right subtree.

Example: ab~cde~~~ generates this tree:

 ┌─┴─┐
┌┴┐ ┌┴─┐
a b c ┌┴┐
      d e

where a would have the key 00, b 01, c 10, d 110 and e the key 111.


The second argument is a text that has been compressed with with the Huffman code that is defined by the first parameter. This bit-string can contain any bit sequence (also null-bytes and non-printable characters) and is not byte aligned, therefore it has been encoded with a variation of the standard Base64 encoding:

  • the characters used for the encoding are the standard base64 characters: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
  • the bitstring is broken up into 6-bit chunks and mapped to this characters
  • if the last chunk is smaller than 6 bits, a character with this prefix is used, and padding characters are added to the string:
  • - : the last chunk was five bits long
  • = : the last chunk was four bits long
  • =- : the last chunk was three bits long
  • == : the last chunk was two bits long
  • ==- : the last chunk was one bit long

Example:

bits:       1 1 1 1 0 1 1 0 1 0 0 1 1 1 0 1 0 1 0 0 0 1 1 0 1
chunks:    |1 1 1 1 0 1|1 0 1 0 0 1|1 1 0 1 0 1|0 0 0 1 1 0|1[0 0 0 0 0]|
characters:       9           p           1           G           g
base64:     9p1Gg==-

Your programm has to decode the text encoded in the second parameter and print it to stdout.

You have to provide your source code encoded in the way described above. The length of your encoded source code + the length of your serialized huffman tree will be the winning criterion.

TODO: example input

\$\endgroup\$
2
  • \$\begingroup\$ It would be helpful to explicitly state the 64 characters used in the encoding. I presume they're A-Za-z0-9+/ but (especially if you're expecting people to implement that part explicitly) it's best to make the problem self-contained. \$\endgroup\$ Oct 8 '12 at 16:23
  • \$\begingroup\$ Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) \$\endgroup\$
    – user58826
    Jun 9 '17 at 15:30
2
\$\begingroup\$

Code golfing problem: Surface classification

The task: Given a surface-word reply with the classification of what surface it is.

Example 1: Input: aba'b' ----> Output: 1T

Example 2: Input: aabcb'c' ----> Output: 3P

Bounds on the problem: Since there are only 26 letters, there will never be more than that many labels. Additionally output should be in the form S,nT,mP for n,m positive integers.

Background: In the study of algebraic topology students are often presented with diagrams such as the one below. The represent instructions for how to assemble a surface. The assembly is prescribed as: if there are two edges labeled with the letter x then glue them together so that the arrows point the same direction. To make our job easy, topologists have discovered an algorithmic way to classify surfaces using 'words' assembled from these 'plane gluing-diagrams'.

enter image description here Choosing a corner arbitrarily (top right) and orientation (ccw) we read off the labels on the edges where an inverse appears wherever the arrow points against the orientation. In this case the 'word' that represents this plane model is given as abab.

A surface word is a string that contains the letters a,b,...,@ up to some letter @ and each letter is contained in it exactly twice. In the two occurrences of each letter: 0, 1, or 2 of them may be postfixed by a ' which I am considering using to represent 'inverse' (opposite orientation).

If in a surface word all letters appear twice: once without the ' and once with it (f.ex. ba'b'a) then we say that the surface the word represents is orientable. If a surface is orientable then it is necessarily the direct sum of n Tori for some non-negative integer n. If this condition doesn't hold (like in aab'b) then the surface represented is non-orientable: in this case it is the direct sum of m Projective Planes for some positive integer m.

Once you have found out if the reduced word is orientable or not, the final answer is given as follows. If orientable and number of unique letters in the reduced word is 1 then output should be S. Otherwise if the number of unique letters in an orientable word is n (it will be even) then the output should be sT where s = n/2. If the word is non-orientable then the output should be mP where m is the number of distinct letters in the reduced word.

The goal is to take as input some surface word, reduce it via reduction rules 1-6 and then classify it as a sphere, some number of connected tori, or some number of connected projective planes. Here are the 6 reduction rules where ~ represents 'reduces to':

Let M,A,B,C,D be surface words, x be a single letter, and juxtaposition represents concatenation:

  1. Cycle Rule: If M = AB then M ~ BA
  2. Flip Rule: M ~ M'
  3. Sphere Rule: Axx'B ~ AB
  4. Block Rule: ABC ~ ADC if B is a surface word and B ~ D by 1 or 2
  5. Cylinder Rule: If M = AxBCx'D, then M ~ AxCBx'D
  6. Möbius Rule: If M = AxBxC then M ~ AxxB'C ~ AB'xxC

I am looking for input on:

  • should this be code-golf or programming-challenge?
  • how would scoring work?
  • ???

If I feel satisfied with the question in a few days I'll post it to the site.

\$\endgroup\$
5
  • \$\begingroup\$ If, for each input, there is only one correct output, then it should probably be code-golf. The scoring criteria would then be source code length. \$\endgroup\$
    – PhiNotPi
    Jun 8 '13 at 14:33
  • \$\begingroup\$ Yes, this is the case. In general however there is not a unique series of applications of the reduction rules for any given instance. \$\endgroup\$
    – Kaya
    Jun 8 '13 at 16:21
  • \$\begingroup\$ I don't think the order of explanation is correct. You should explain reduction before talking about "the reduced word". And "reduce it via reduction rules" doesn't entirely make sense, because the rules are presented as equivalences rather than reductions, and most of them don't have a "natural" direction. \$\endgroup\$ Jun 10 '13 at 8:49
  • \$\begingroup\$ It's also occurred to me that you haven't defined the notation M'. Does it just consist of toggling the orientation of each token, or does it also reverse the entire string? And do you have test cases which between them force implementation of all of the reduction rules? \$\endgroup\$ Jun 11 '13 at 8:32
  • \$\begingroup\$ Good call on the string inverse, yes you have the right idea and I will make it clear. I have a lot of test cases from when I did a number of these computations by hand in a university course and (anecdotal experience) I am pretty sure that it is possible to force the use of all the reduction rules (except maybe 4 which is really just a meta-rule for convenience when doing proofs). Additionally you have alerted me to some concerns regarding the form of the proper output: it's definitely underspecified. I'll put some work into this today. \$\endgroup\$
    – Kaya
    Jun 11 '13 at 14:04
1
16 17
18
19 20
122

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .