468
\$\begingroup\$

What is the Sandbox?

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

To post to the Sandbox, scroll to the bottom of this page or click on the "Add Proposal" link below, 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. 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, replace the post here with a link to the challenge and delete it.

See the Sandbox FAQ for more information on how to use the Sandbox.

The Sandbox works best if you sort posts by "active".

Add Proposal

Search the Sandbox

Browse your pending proposals

Get the Sandbox Viewer to view the sandbox more easily

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]

\$\endgroup\$
  • \$\begingroup\$ How are tags added to questions? \$\endgroup\$ – guest271314 Jan 9 '19 at 7:51
  • \$\begingroup\$ @guest271314 You can use this markup to create a tag in a draft: [tag:code-golf] \$\endgroup\$ – James Aug 29 '19 at 15:19
  • \$\begingroup\$ Why no featured anymore? Can't we have it auto-added or something? \$\endgroup\$ – S.S. Anne Sep 26 '19 at 15:57
  • 3
    \$\begingroup\$ @JL2210 We now have a permanent info box that links to the Sandbox, so the featured tag isn't necessary \$\endgroup\$ – caird coinheringaahing Sep 29 '19 at 13:43

2739 Answers 2739

1
43 44
45
46 47
92
1
\$\begingroup\$

Shortest way to get an EOF Error

It's simple, simply write the shortest code to raise an EOF Error. An EOF Error happens when the language expects more code to be entered into the source code; however, the language encounters an EOF character. So here is a sample Python program to throw an EOF error.

id(

Python expects more code to be entered, but EOF is entered instead. Therefore it throws an "EOF Error" (technically a Syntax Error though, but the interpreter says unexpected EOF while parsing).

To simplify that, output text to STDERR containing the string EOF. Normally a language will exit after outputting to STDERR with an error, so if you are hard-coding the value out to STDERR, you should also exit the program with a 1 value.

Input/Output

Your input will be none; however, you should output a message to STDERR that proves that the program generates an EOFError.

Rules

  • Since this is , the shortest answer wins.
  • No standard loopholes please.
  • Any method approved by Standard I/O is allowed.

Feedback

  • Is this clear enough?
  • I don't believe this is a duplicate (I found this, but it's restricted to a single language), but does anyone recognise this?
  • The tags as code-golf, error-message. Anything else?
  • Any further feedback?
  • Is it possible to have trivial answers on most languages for this challenge?
\$\endgroup\$
  • \$\begingroup\$ So just taking empty input would cause an EOF error? That'd lead to a whole bunch of trivial 1 byte answers in golfing languages. \$\endgroup\$ – Lyxal Oct 4 '19 at 0:19
1
\$\begingroup\$

A Musical Tuner

Oh no! My tuner's batteries ran out, I need to play in a concert in a few minutes, and I need to know if my instrument's in tune! I need this tuner quick, so it needs to be short.

Background

In music, all notes are given a letter from A-G/H, an optional sharp/flat ♯/♭, and a number specifying what octave it is in, starting from 0. This is called scientific pitch notation.

In equal temperament, \$\sqrt 2 \approx 1.05946 \$ is an important ratio, as used in the formula $$ P_n = P_a (\sqrt2)^{n-a} $$ where

  • \$ P_n \$ is the desired frequency, in hertz.
  • \$ n \$ is the number of keys from the left on a piano the desired note is.
  • \$ P_a \$ is the reference frequency, in hertz.
  • \$ a \$ is the number of keys from the left on a piano the reference note is.

A piano begins at \$ A_0 \$ as the 1st key, and with reference frequency of \$ A_4 = P_a = 440 \$ Hz, at the 49th key.

The whole step, the tonal distance between two notes separated by one key, is divided into 100 cents. A half step is exactly 50 cents.

The Challenge

Write a full program that, when given a decimal number in hertz, outputs the closest note in scientific pitch notation, and how far it is from that note in cents.

Input

A positive number in hertz. This can be a string, number, list of whole number and decimal, etc. You can always assume this to be positive, and a number with maximum 3 decimal places.

The input is in the range \$ 27.5 \le P_n \le 4186 \$.

Output

A note in scientific pitch notation, and how many cents it is from, in the form

[Note letter][Sharp/Flat][Octave number][+/-][Cents]

  • If a note is determined to be close to a natural note, no sharps or flats should be output.
  • Output either sharps or flats.
  • Sharps can be either ♯/# , and flats either ♭/b.
  • Octave number ranges from 0 to 8.

Other Rules

Test Cases

Input --> Output
440 --> A4
261.626 --> C4
24.995 --> G♯0-8 (OR G#0-8)
1320.068‬ --> E6+1
3674.882‬ --> B♭7-13 (OR Bb7-13 OR A7+13)
\$\endgroup\$
  • \$\begingroup\$ The +/- 1 cent rule seems to be an unnecessary complication, I would suggest removing that. \$\endgroup\$ – flawr Oct 4 '19 at 6:49
  • \$\begingroup\$ The third example seems to be outside of the input range. I might be missing something obvious (I am almost entirely ignorant of music theory) but I don't think you explain how to get the note letter or the sharp/flat from the frequency. I think your question is unclear if you don't specify how that works in your challenge body. I assume what you intend for us to do is use the formula you provide to find \$ n \$ and then look up what key on a piano \$ n \$ refers to? In which case I think you should include the list of keys in order. \$\endgroup\$ – FryAmTheEggman Oct 4 '19 at 18:39
1
\$\begingroup\$

Fewest number of button presses to set the cook time

A GolfCo™ microwave oven has a 12-button keypad like this:

[1]  [2]  [3]
[4]  [5]  [6]
[7]  [8]  [9]
     [0]  [+30]
   [START]

How the microwave operates

The microwave reads and processes button presses as follows:

  1. Buttons [0]-[9] add the corresponding digit to the right end of the cook time, up to 4 digits total. Once started, these buttons do not function.
  2. The [+30] button adds 30 seconds to the cook time, and starts the cooking process (if not already started).
  3. The [START] button starts the cooking process.

The microwave can be programmed with a cooking time ranging from 1 second to 99 minutes and 59 seconds.

Any one or two-digit cook time is interpreted as seconds only, ranging from 1 to 99 seconds.

Any three or four-digit cook time is interpreted as two digits of minutes and two digits of seconds. In this mode, the minutes portion of the cook time can range from 0 to 99 minutes, while the seconds can range from 0 to 59 seconds.

The challenge

Given a time in minutes:seconds (eg. "4:45" for four minutes and 45 seconds), print the button sequence with the least number of button presses required to set the cook time and start the cooking process.

As this is code golf, the smallest program in bytes wins.

Input

Input will be given in the common MM:SS format, where "MM" specifies minutes and "SS" specifies seconds, separated by a colon.

Minutes can be zero padded to 2 digits or the leading zero omitted, at the golfer's discretion. Minutes can range from 00 to 99.

Seconds will always be 2 digits, ranging from 00 to 59.

The cook time will range from 00:01 to 99:59.

Output

The program will output the sequence of button presses needed to program the cook time and start the microwave.

Buttons [0] to [9] will be output as the corresponding digit "0"-"9".

The [+30] button will be output as "+".

The [START] button will be output as "S".

Test cases

Input                  Output
=======================================
04:45 (or 4:45)        4 4 5 S
00:08                  8 S
00:30                  +
00:35                  5 +
00:20 (or 0:20)        2 0 S
01:20 (or 1:20)        8 0 S
01:25 (or 1:25)        8 5 S     ("2 5 + +" and "1 2 5 S" are both too long)
01:30 (or 1:30)        + + +     ("9 0 S" is also correct)
01:35 (or 1:35)        5 + + +   ("1 3 5 S" is also correct)
01:39 (or 1:39)        9 + + +   ("1 3 9 S" is also correct)
01:40 (or 1:40)        1 4 0 S   ("1 0 + + +" is incorrect)
01:50 (or 1:50)        1 5 0 S   
02:00 (or 2:00)        2 0 0 S   ("+ + + +" is also correct)
02:30 (or 2:30)        2 3 0 S   ("+ + + + +" is incorrect)
03:00 (or 3:00)        3 0 0 S   
10:00                  1 0 0 0 S
99:59                  9 9 5 9 S
\$\endgroup\$
  • \$\begingroup\$ Can we wait between pressing buttons? I think I've seen a related challenge. \$\endgroup\$ – my pronoun is monicareinstate Oct 11 '19 at 0:44
  • \$\begingroup\$ @someone, can you please explain how it would help? The only way I can see is if pressing buttons 0-9 is allowed after the oven is started, which I realize now I didn’t not state in the challenge. Is there some other use? \$\endgroup\$ – spuck Oct 11 '19 at 1:13
  • \$\begingroup\$ to wait for 300s, is it allowed to do +0? To wait 291s, can you press +, wait for 1 second and press 0? \$\endgroup\$ – my pronoun is monicareinstate Oct 11 '19 at 1:33
  • \$\begingroup\$ The +30 button starts the oven, and after the oven is started, the 0-9 buttons do not function. \$\endgroup\$ – spuck Oct 11 '19 at 3:07
  • \$\begingroup\$ Some microwaves let you do more than 59 for the seconds. E.g. if I type in 87, it will read it as 1:27. 60 reads as 1:00, 192 reads as 2:32. This can allow you to enter certain times in fewer button presses. Would be an interesting added challenge to support this feature. Basically, if the last 2 digits are more than 59, subtract 60 and add 1 to the minutes. (It would raise the maximum up to 100:39, if you were to type 9999...) Edit: I see you did this in one example - that rule should be explicitly stated if you want to make sure it's enforced. \$\endgroup\$ – Darrel Hoffman Oct 15 '19 at 17:21
  • \$\begingroup\$ @DarrelHoffman, that is part of the challenge. The Input section states that the cook time will always been given as MM:SS and the allowed ranges, and the Operation section states that 1 or 2 digit cook times are interpreted by the microwave as seconds, from 01 to 99 seconds. Please let me know how I could edit to make that more clear. \$\endgroup\$ – spuck Oct 15 '19 at 17:24
  • \$\begingroup\$ I guess just make sure to say that the seconds can be from 0-99, even if there are more than 2 digits, like my 192 example. (Although 192 is the same number of buttons as 232. Better example would be 960 which reads as 10:00 and takes 1 less button than 1000.) \$\endgroup\$ – Darrel Hoffman Oct 15 '19 at 17:26
  • \$\begingroup\$ I think this would be more interesting if the 1-6 buttons were "instant start" number of minutes buttons and the 0 button allowed entering typing mode. \$\endgroup\$ – Beefster Oct 18 '19 at 22:54
1
\$\begingroup\$

Measure the Discrepancy

Given a finite sequence of real numbers \$ s_1, s_2, \ldots, s_n\$ and an interval \$I=[a,b]\$ that contains the whole sequence, find its discrepancy \$D_n\$.

Definition*

Let \$I = [a,b]\$ be an interval that covers the whole sequence \$(s_i)_i\$, that means for all \$i\$ we have \$s_i \in I\$. The discrepancy \$D_n\$ is defined as

$$D_n = \sup_{[u,v] \subseteq I} \left| \frac1n N(u,v) - \frac{v-u}{b-a} \right|$$

Here \$N(u,v) = \#\{i \mid 1 \leqslant i \leqslant n, s_i \in [u,v]\}\$ denotes the number of values of the sequence \$(s_i)_i\$ that are in the interval \$[u,v]\$.

* Technically the discrepancy \$D\$ is defined for infinite sequences as \$D = \lim_{n\to \infty} D_n\$. Intuitively speaking, the *discrepancy measures how uniformly distributed the sequence is in the given interval \$I\$. Sampling an uniform distribution on \$i\$ infinitely many times results in an discrepancy of \$D=0\$.

Examples

to be added...

\$\endgroup\$
  • \$\begingroup\$ I feel like u - v should be v - u? \$\endgroup\$ – Kroppeb Oct 17 '19 at 16:00
  • \$\begingroup\$ @Kroppeb You're right, thanks for pointing it out! \$\endgroup\$ – flawr Oct 17 '19 at 18:22
  • \$\begingroup\$ There is always the issue of taking real numbers as input, since there are more real numbers than binary strings. How should this fact be handled? \$\endgroup\$ – Ad Hoc Garf Hunter Oct 17 '19 at 19:58
  • \$\begingroup\$ @SriotchilismO'Zaic We usually take floats as representations of reals. But I think we could even restrict it to integers and it wouldn't change much. \$\endgroup\$ – flawr Oct 17 '19 at 20:16
  • \$\begingroup\$ I think that this challenge is more interesting if you need answers to be precisely correct. Floating points open this up to brute force approaches which then boil down to just doing the operations. Which I just don't think is as interesting. \$\endgroup\$ – Ad Hoc Garf Hunter Oct 17 '19 at 20:28
  • \$\begingroup\$ Please include a plain English description of the challenge. Surely I can't be the only one here that can't read mathematical notation! \$\endgroup\$ – Shaggy Oct 19 '19 at 23:03
  • \$\begingroup\$ @Shaggy Thanks for the feedback. I don't think I could remove all notation, but at the same time I have difficulties knowing where to start. Can you maybe point some notations out that you do or do not understand or think the average users might have trouble with? \$\endgroup\$ – flawr Oct 20 '19 at 10:16
1
\$\begingroup\$

Subtract two numbers with Rule 110

Background :

It is known that Rule 110 is Turing complete, but in general, I have seen a lack of actual programs that utilize this property of Rule 110, so I propose that we do something about it ;)

Some explanation

Rule 110 is a one dimensional cellular automaton, consisting of cells on/off, and the neighbors of those cells change the cell in the next iteration. Here is a page detailing how rule 110 works, but here is also a basic table that summarizes the rule (the center number is the current cell's state, the two on the outside are its neighbors, the number to the right of the equals is the state for the next generation)

111 = 0
110 = 1
101 = 1
100 = 0
011 = 1
010 = 1
001 = 1
000 = 0

The Challenge

I want you to subtract two numbers, unsigned, eight bits long (No handling of negatives, input one will always be greater than or equal to input two)

Note : Index 0 is where the first 1 starts, which denotes your program, simply because the "tape" is infinite, and leading zeroes cannot be distinguished, so it must start at the first one

Input have to be inputted in unary, and must be inputted at a set interval from a specific point from the beginning of your program, and the inputs must not overlap. That may sound confusing, but here are some examples.

First, clarification on input. Input needs to be 8 bits long, and must be formatted to be so, if you had zero, it would be inputted as follows : 00000000, 2 would be 00000011, 7 would be 01111111 etc..., up to eight.

The first input is at intervals of 2 starting at index 1, the second input has an interval of 3 and starts at 25

1 _ 01 _ 01 _ 10 _ 10 _ 10 _ 10 _ 10 _ 101 = 011 = 111 = 000 = 110 = 110 = 110 = 001 = 1010100101

The "_" is the first input, the "=" is the second input, they cannot overlap, and the interval represents the set distance that they must be seperated by. The bits themselves are inputed as ones, so if my first input was 00000111 and my second input 00111111 then my program would look like this

1 0 01 0 01 0 10 0 10 0 10 1 10 1 10 1 101 0 011 0 111 1 000 1 110 1 110 1 110 1 001 1 1010100101

The output is also defined in a similar fashion, from the start of the program (denoted by a 1) at specific intervals the bits represent the unary output

Example:

input one = 00011111, input two = 00000011

output = 00000111

Score

The number of bytes from the first one to the last one in the initial program. Lowest score wins! Good luck!!!

I thought this was ready for the main, but it wasn't, so if ya'll have any problems, please let me know and I'll address them, as I will for the problems already proposed

\$\endgroup\$
  • 4
    \$\begingroup\$ I think this is missing a lot before it can be a proper challenge, so sorry if this comes off as harsh, and thanks for using the sandbox. Since this is about a CA I don't understand what you mean by "bits" and "bytes" in several places, do you not mean to refer to cells? The difference between unary and binary IO is so significant that you should just pick one, having bonuses is highly discouraged anyway as it leads to unpleasant patterns for answerers. Is the scoring based on the initial width of the region that contains live cells? Or something else? \$\endgroup\$ – FryAmTheEggman Oct 5 '19 at 18:40
  • \$\begingroup\$ If you mean that there are boundary cells (i.e. bits with only 1 neighbour instead of 2) you probably need to specify their rules as 110 usually has an infinite tape. You should also definitely include an explanation of 110 in your post. I think it is possible that if you allow the IO to be anywhere you may wind up with weird solutions. Certainly you can't allow that for unary IO since then they could require the inputs interleaved and the output would immediately be available. I think what you suggest is ok as long as input 1 is entirely more left than input 2 (but I'm not sure). \$\endgroup\$ – FryAmTheEggman Oct 6 '19 at 15:27
  • \$\begingroup\$ I think your specification of the input looks good! I have somewhat minimal experience actually working with cellular automata so you probably want to run it past some other people before trusting me ;) Aside from that, I think you should specify the output a bit more (I assume it should be read on a certain generation? Or do you require steady state after a certain generation?). Then I think if you move the summary of 110 to your post (basically just copy the table) you just have some formatting / grammar issues until you are ready to post. \$\endgroup\$ – FryAmTheEggman Oct 7 '19 at 19:29
  • \$\begingroup\$ I think the question looks pretty good, the only thing left I think is using "bits" for unary. I think it might be good to explain even just with an example that zero is exactly 00000000 and two is exactly 00000011 etc. For more expert CA help try the nineteenth byte chatroom, or try to hunt down some of the users who got tetris working in GoL :) \$\endgroup\$ – FryAmTheEggman Oct 9 '19 at 20:07
  • \$\begingroup\$ Random weird question idea: "Now that we've done it in Life, create a game of Tetris in rule 110". \$\endgroup\$ – my pronoun is monicareinstate Oct 10 '19 at 11:34
1
\$\begingroup\$

Disconnect a social network

A version of this question was used in the 2019 International Mathematical Olympiad, which is now public. Modifications italicised.

A social network has n users, some pairs of whom are friends. Whenever user A is friends with user B, user B is also friends with user A. Events of the following kind may happen repeatedly, one at a time:

Three users A, B, and C such that A is friends with both B and C, but B and C are not friends, change their friendship statuses such that B and C are now friends, but A is no longer friends with B, and no longer friends with C. All other friendship statuses are unchanged.

Given the initial graph of users, find whether sequence of such events so that at the end of the sequence each user is friends with at most one other user exists, and if so output that sequence.

Test cases

These cases have n followed by a list of friendships in the graph, and output as a list of triples of people in order A-B-C (and 0 if no sequence of triples exists - note that this is different from [] in this particular output scheme, here [] means that the graph already satisfies the condition that each user is friends with at most one other user).

3, [[1,2], [2,3]]
[[1,2,3]]

3, [[1,3], [2,3]]
[[2,3,1]]

3, []
[]

3, [[1,2]]
[]

3, [[1,2], [1,3], [2,3]]
0

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

6, [[1,2], [1,6], [2,3], [3,4], [4,5], [5,6]]
0

7, [[1,2], [1,3], [1,4], [2,3], [5,6]]
[[2,1,4], [1,3,2], [1,2,4]]

4, [[1,2], [1,3], [1,4], [2,3], [2,4], [3,4]]
0

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

5, [[1,2], [1,3], [2,3], [2,4], [2,5], [3,4], [3,5]]
0

Input and output format are flexible as long as they conform to standard I/O requirements, and standard loopholes are forbidden. (In particular, for the impossible case, the output can be anything which is not an output from a possible graph, such as [[0,0,0]] or an additional 'success' boolean.)

This is , so the shortest code wins!

\$\endgroup\$
  • \$\begingroup\$ I suspect more answers will pretty much brute force the problem, trying all possible sequences. Are you OK with that? I don't know if there's a nice algorithm for this and you're hoping people make something like it. If you do want to restrict it, you could limit the run-time on test case or impose an algorithmic complexity ceiling. \$\endgroup\$ – xnor Oct 21 '19 at 5:12
  • \$\begingroup\$ Outputting either a list or 0 is not possible in strongly-typed languages. I'd suggest allowing some alternatives like [[-1, -1, -1]] or [[]] or a pair of a Boolean representing success and the list. \$\endgroup\$ – xnor Oct 21 '19 at 5:14
  • \$\begingroup\$ @xnor a) I don't know what the optimal algorithm is, so it'd be hard for me to set a limit (I heard that it could have potentially been a submission to the IOI but i don't know what form that would have taken) - do you have suggestions on how to make a reasonable restriction? b) I'm happy with any output format, as long as it distinguishes between the "already done" and "impossible" cases \$\endgroup\$ – boboquack Oct 21 '19 at 6:24
  • \$\begingroup\$ @xnor Do you think that a polynomial runtime bound would be interesting? Alternatively, would this make a good fastest-code question? If it becomes a fastest-code question, would I have to offer to test solutions on my machine? \$\endgroup\$ – boboquack Oct 27 '19 at 2:07
  • \$\begingroup\$ Do you know if there's a polynomial run-time algorithm? I think people usually test fastest code on their machines. Maybe you can test on TIO, but I think people said that might not be too consistent. \$\endgroup\$ – xnor Oct 27 '19 at 3:51
  • \$\begingroup\$ @xnor I believe I have a polynomial run-time algorithm - fastest-code is looking like probably a better challenge at this stage anyway... Since I don't have any idea what the best time-complexity is, should I make some large test cases of varying sizes to compare programs with? \$\endgroup\$ – boboquack Oct 27 '19 at 9:25
1
\$\begingroup\$

Shorthand Combined Functions

I was doing some investigation into trig functions using compound angles recently, and noticed that the results are really long and tedious to write: $$ cos(A+B) = cosAcosB - sinAsinB\\ cos(A-B) = cosAcosB + sinAsinB\\ sin(A+B) = sinAcosB + sinBcosA\\ sin(A-B) = sinAcosB - sinBcosA\\ $$ $$ tan(A+B) = \frac{tanA+tanB}{1 - tan A tan B} $$ $$ tan(A-B) = \frac{tanA-tanB}{1 + tan A tan B} $$

Realising this, I devised a shorter, golfier way, of writing such expressions:

<direction><operator>[functions](variables)

Where direction is either « or » and operator is in the string +-*/


When the direction is «, functions in functions are applied to variables in the following method (assuming functions is f, g, h and variables is x, y, z and the operator is +)

$$ f(x)f(y)f(z) + g(x)g(y)g(z) + h(x)h(y)h(z) $$

When there isn't a given operator, it is assumed that it is * (multiplication)

When the direction is », however, functions in functions are applied to variables in the following method (assuming functions is f, g and variables is x, y and the operator is +):

$$ f(x)g(y) + f(y)g(x) $$ Once again, when there isn't a given operator, it is assumed that it is * (multiplication)

The Challenge

Given a shorthanded string as described above, output the expanded expression

Test Cases

Input -> Output
«+[cos,sin](a,b) -> cos(a)cos(b) + sin(a)sin(b)
»+[cos,sin](a,b) -> cos(a)sin(b) + sin(a)cos(b)
«[f](x,y,z,n) -> f(x)f(y)f(z)f(n)
«+[f](x,y,z,n) -> f(x) + f(y) + f(z) + f(n)
«+[f,g]() -> 
»*[f,g]() ->
»-[f,g](a,b) -> f(a)g(b) - f(b)g(a)
»[g,f](a,b) -> g(a)f(b)g(b)f(a)
«+[tan](a,b) -> tan(a) + tan(b)
»+[](a,b) -> 
»-[f,g](x,y,z) -> f(x)g(y)z - f(y)g(z)x - f(z)g(x)y
«/[f,g](x,y,z) -> f(x)f(y)f(z) / g(x)g(y)g(z)
«[]() ->
»[]() -> 

Let it be known that:

  • The direction will always be given
  • The operator is optional
  • The [] denoting the functions will always be present, but will not always contain functions
  • The () denoting the variables will always be present, but will not always contain variables

Therefore, if no functions/variables are present, then an empty output is required. Whitespacing within the answer doesn't matter (i.e. newlines/extra spaces don't invalidate outputs).

Input can also be taken as:

[direction, operator, [functions], [variables]]

In which case, direction will be a string, operator will be either an empty string or an operator, functions will be a (sometimes empty) list of strings, as will variables.

As per usual, standard loopholes are forbidden, and, as this is code-golf, the shortest code (in bytes) wins.

Feedback

So what do you guys think? Do I need to add a more detailed explanation for how everything would work? Also, would it be requested to have input taken as [direction, operator, [functions], [variables]]?

\$\endgroup\$
1
\$\begingroup\$

This message is open for anyone to adopt and post to main. The full post can be found in the revision history. For more details, see the chat room or meta post.

\$\endgroup\$
  • \$\begingroup\$ "However, some walls will simply me holds, no rope or clip." what's me holds? \$\endgroup\$ – Rɪᴋᴇʀ May 15 '17 at 17:39
  • \$\begingroup\$ Also, I'd recommend making this a test-battery. (i.e. score is number of correct outputs / number of total inputs) \$\endgroup\$ – Rɪᴋᴇʀ May 15 '17 at 17:40
  • \$\begingroup\$ How else would you score it? It's not really plausible to specify any image should always give the right result. \$\endgroup\$ – Rɪᴋᴇʀ May 15 '17 at 18:28
  • \$\begingroup\$ @Riker changed! \$\endgroup\$ – caird coinheringaahing May 15 '17 at 18:48
1
\$\begingroup\$

It was found that this challenge is a duplicate. if you would like to see the challenge, please look in the revision history.

\$\endgroup\$
1
\$\begingroup\$

Follow the Path

Posted here.

\$\endgroup\$
1
\$\begingroup\$

Fermat's Last Theorem, mod n

It is a well known fact that for all integers \$p>2\$, there exist no integers \$x, y, z>0\$ such that \$x^p+y^p=z^p\$. However, this statement is not true in general if we consider the integers modulo \$n\$.

You will be given \$n\$ and \$p\$, which are two positive integers with \$n>1\$. Your task will be to write a function or program to compute all positive integers \$x, y, z<n\$ such that \$(x^p+y^p)\$ and \$z^p\$ give the same remainder when divided by \$n\$.

Input

Any reasonable method of input is allowed. E.g. two separate user inputs, ordered pair, two function parameters, etc.

Output

Any reasonable method of output is valid, it may be produced by a function or output to the screen. The order the triples are listed does not matter. Triples such as (1, 2, 3) and (2, 1, 3) are considered distinct, and all distinct triples should be listed exactly once. No invalid/trivial triples such as (0, 0, 0) should be output.

Examples

n p -> Possible Output
----------------------------------------------------------------
2 3 -> []
3 3 -> [(1,1,2),(2,2,1)]
3 4 -> []
4 3 -> [(1,2,1),(1,3,2),(2,1,1),(2,2,2),(2,3,3),(3,1,2),(3,2,3)]

Scoring

Shortest code in bytes with no standard loopholes wins.

\$\endgroup\$
  • \$\begingroup\$ I'd wager the average user of this site isn't particularly familiar with the mathematical notion of modulus, compared to the programming concept. I suspect some of them will find the last statement in the intro slightly confusing (my guess thinking that only the RHS is taken in modulus). Beyond clarifying that, I think you should specify in your test cases which parameter is which (i.e. n p -> result as the first line). \$\endgroup\$ – FryAmTheEggman Oct 31 '19 at 19:40
  • \$\begingroup\$ @FryAmTheEggman I have fixed those issues, is there anything else? \$\endgroup\$ – 79037662 Oct 31 '19 at 20:02
  • \$\begingroup\$ I don't see anything beyond adding some more test cases (particularly with larger n). Technically, this could be calculated for large p even if the intermediate results wouldn't work for a particular data type, but I assume you don't want to require that? Other than that it looks good to me, but of course I'm just one person, so I'd still wait a while. \$\endgroup\$ – FryAmTheEggman Oct 31 '19 at 20:22
1
\$\begingroup\$

Sort and Table a Sentence by Word Lengths

In as few bytes as possible, sort the input, a delimited string OR list/vector/array of words containing printable ASCII except space into a table (or something resembling a table). I tried to make the table rules as code friendly as possible to allow golfing and non-golfing languages alike to compete. Table rules are as follows:

  • optional order, shortest to longest or vice versa, letter counts are required
  • formatting is not the challenge, but to repeat the above rule, letter count is required. So as long as the output is some form of numerically labelled rows of words, a numbered list, or a list of lists, or similar output, then it is a satisfactory answer.

  • including/excluding gaps (NA values, see below examples for both methods of output)

  • Word case is untouched. How the word appears in input should be shown in output.

Input 1:

Code Golf and Coding Challenges Meta

Output 1:

 1. NA
 2. NA
 3. and
 4. Code Golf Meta
 5. NA
 6. Coding
 7. NA
 8. NA
 9. NA
 10. Challenges

or

3. and
4. Code Golf Meta
6. Coding
10. Challenges

or

[[3, ['and']], [4, ['Code', 'Golf', 'Meta']], [6, ['Coding']], [10, ['Challenges']]]

Input 2:

My very excellent mother just served us nine pizzas. #JusticeForPluto

Output 2:

1. NA
2. My us
3. NA
4. very just nine (alphabetized version: just nine very)
5. NA
6. mother served pizzas (mother pizzas served)
7. NA
8. NA
9. excellent
10. NA
11. NA
12. NA
13. NA
14. NA
15. NA
16. #JusticeForPluto

or

2. My us
4. very just nine
6. mother served pizzas
9. excellent
16. #JusticeForPluto

or

[[2, ['My', 'us']], [4, ['very', 'just', 'nine']], [6, ['mother', 'served', 'pizzas']], [9, ['excellent']], [16, ['#JusticeForPluto']]]

More examples can be provided if necessary but I think this should suffice for now. Please give me pointers, this is my second attempt at a challenge. (the first failed dramatically)

\$\endgroup\$
  • 1
    \$\begingroup\$ Are the letter counts a required part of the output? I would suggest removing the requirement of filtering punctuation and just allow input as a delimited string or array of words. \$\endgroup\$ – Shaggy Nov 10 '19 at 22:06
  • \$\begingroup\$ @Shaggy That is a very good suggestion. I think that that is a fantastic idea. I'll make the edit. \$\endgroup\$ – Sumner18 Nov 11 '19 at 13:39
  • \$\begingroup\$ @Shaggy I don't see why it would be difficult for letter counts to be required in the output. The idea is to place them in rows of a table that denote the word lengths within its row. \$\endgroup\$ – Sumner18 Nov 11 '19 at 14:04
  • 1
    \$\begingroup\$ I wasn't suggesting they shouldn't be included, but, if they must be included, that you make that clearer in the spec. \$\endgroup\$ – Shaggy Nov 11 '19 at 14:07
  • 1
    \$\begingroup\$ What constitutes a "table?" Is the formatting you've used required, or is something like this alright? If it isn't, it seems like around half the code in several golfing languages will be devoted to formatting. Is that the intent? \$\endgroup\$ – FryAmTheEggman Nov 11 '19 at 20:34
  • \$\begingroup\$ @FryAmTheEggman Thank you for the suggestion. I don't want formatting to be the focus of the challenge, but rather than just placing words in a list/array/vector with some form of label. Essentially a list of lists as you've done. I'll make the change \$\endgroup\$ – Sumner18 Nov 11 '19 at 22:26
  • 1
    \$\begingroup\$ Thanks for the edits, though I don't think you need to include the program I wrote (it may even be more confusing since not many people read Pyth). I'd also recommend including something saying what class of characters the words will be drawn from, like "printable ASCII except space" or something. \$\endgroup\$ – FryAmTheEggman Nov 12 '19 at 20:54
1
\$\begingroup\$

Solve a separable differential equation

A first order separable ordinary differential equation is (arguably) the easiest type of differential equation to solve, and takes the form of

$$N(y)\frac{dy}{dx} = M(x) \\ y(x_0) = y_0$$

For two given functions \$N(y)\$ and \$M(x)\$ and an initial condition \$y(x_0) = y_0\$.

Your task is to take \$N(y)\$, \$M(x)\$, \$x_0\$ and \$y_0\$ and output the solution to that differential equation.

How to solve a separable differential equation

The differential equation

$$f(y)\frac{dy}{dx} = g(x)$$

can be solved through the following method:

$$ \begin{align} f(y)\frac{dy}{dx} & = g(x) \\ \int{f(y)\frac{dy}{dx}dx} & = \int{g(x)dx} \\ \int{f(y)dy} & = \int{g(x)dx} \end{align} $$

Once the integrals have been calculated, we can remove one of the constants of integration, leaving the equation

$$F(y) = G(x) + c$$

where

$$ F(y) = \int{f(y)dy} \\ G(x) = \int{g(x)dx} $$

After this, \$c\$ can be calculated by applying the initial condition:

$$ c = F(y_0) - G(x_0) $$

and a final solution for \$F(y)\$ can be given.

Challenge

You are to take in four inputs:

  • The function \$N(y)\$
  • The function \$M(x)\$
  • \$x_0\$
  • \$y_0\$

Both \$x_0\$ and \$y_0\$ can be any real number, and can be taken as input in many reasonable manner (i.e. a list, tuple, two integers etc.). The functions, in order to avoid having to focus on parsing mathematical input, will be limited to a type of Laurent polynomials - i.e polynomials in the form

$$ p(x) = \alpha \cdot x^n + \beta \cdot x^{n-1} + \dots + \gamma + \delta \cdot x^{-2} + \epsilon \cdot x^{-3} + \dots + \zeta \cdot x^{-m+1} + \eta \cdot x^{-m} \\ \alpha, \beta, \dots, \eta \in \mathbb{R}, \:\: n, m \in \mathbb{N} $$

Notice that we'll never have \$x^{-1}\$ in the polynomial, and that because of this, the integrals will always be Laurent polynomials of the same form (with \$x^{-1}\$ included after integrating).

With inputs in this format, there are multiple ways you could represent them for input. As with the mapping, any reasonable representation is acceptable, and if you aren't sure, ask. However, here are some that are definitely allowed (for the example \$p(x) = 3x^2 + x + 6 - 2x^{-2} + 7x^{-5}\$):

  • Nested list: [[3, 2], [1, 1], [6, 0], [-2, -2], [7, -5]]
  • A pair of lists of coefficients: [3, 0, 1, 6] and [-2, 0, 0, 7]
  • A string representation: 3x^2 + x + 6 - 2x^-2 + 7x^-5
  • etc.

Given these four inputs, you are to output the solution to the differential equation they represent.

In order to avoid having to algebraically manipulate your solutions to get into the form \$y(x) = ...\$, you can output two Laurent polynomials, in the same form as the input; one representing \$y\$ and the other \$x\$.

This is so the shortest code wins!

Test cases

Both the MathJax and text-based inputs will be included for each example, where the text based will use the nested list input format above. In addition, I will walk through the first example for clarity.

In:
  N = [[1, -2]]
  M = [[6, 1]]
  1 -> 1/25 = 0.04
Out:
  y = [[-1, -1]]
  x = [[3, 2], [28, 0]]

$$ \begin{align} \frac{1}{y^2}\frac{dy}{dx} & = 6x \\ y(1) & = \frac{1}{25} = 0.04 \\ \\ \int{N(y)dy} & = \int{M(x)dx} \\ \int{\frac{1}{y^2}dy} & = \int{6xdx} \\ -\frac{1}{y} & = 3x^2 + c \\ -25 & = c + 3 \implies c = -28 \\ -\frac{1}{y} & = 3x^2 - 28 \end{align} $$

In:
  N = [[2, 1], [-4, 0]]
  M = [[3, 2], [4, 1], [-4, 0]]
  1 -> 3
Out:
  y = [[1, 2], [-4, 1]]
  x = [[1, 3], [2, 2], [-4, 1], [-2, 0]]

$$ N(y) = 2y - 4, \:\: M(x) = 3x^2 + 4x - 4 \\ y(1) = 3 \\ \:\\ y^2 - 4y = x^3 + 2x^2 - 4x + c \\ c = -2 \\ y^2 - 4y = x^3 + 2x^2 - 4x - 2 \\ $$

In:
  N = [[1, 0]]
  M = [[3, 2], [2, 0]]
  0 -> 0
Out:
  y = [[1, 1]]
  x = [[1, 3], [2, 1]]

$$ N(y) = 1, \:\: M(x) = 3x^2 + 2 \\ y(0) = 0 \\ \:\\ y = x^3 + 2x + c \\ c = 0 \\ y = x^3 + 2x \\ $$


Meta

  • Is this clear enough? I'm worried too much is spent on MathJax and may not be very clear
  • Is this a duplicate? I can't find anything, but you never know
  • Any nice edge cases to add for the test cases?
  • The tags are , and . Anything else?
  • Any further feedback?
\$\endgroup\$
  • \$\begingroup\$ "For two given functions" -- note that not even two integrable functions, the first being differentiable, meaning the ODE and 'solution' can be at least defined, necessarily lead to the above being a solution. \$\endgroup\$ – Jonathan Frech Sep 17 '19 at 7:36
  • \$\begingroup\$ @JonathanFrech I'm not sure I follow? \$\endgroup\$ – caird coinheringaahing Sep 18 '19 at 7:37
  • \$\begingroup\$ What I am trying to say is that I would expect there to be a condition on \$N,M\$ for them to be well-behaved in a sense. \$\endgroup\$ – Jonathan Frech Sep 18 '19 at 10:01
1
\$\begingroup\$

Sand timer puzzler (code-golf)

I was googling for a sand timer and found this little item: set of joined sand timers, for 3, 4, and 5 minutes each.

That of course reminded me of multiple puzzles about measuring X minutes using only M- and N-minute timers or whatever.

The mission then, if you choose to accept, is:

write a program that takes 3 integer inputs 0<A<B<C<100
and outputs list of all possible times that can be measured
using 3 joined sand timers A, B, and C up to 2 hrs

Test cases:

[in progress]

\$\endgroup\$
  • 1
    \$\begingroup\$ Isn't this basically any number that can be formed by some combination of multiples of A, B and C? Some test cases would be nice, and an objective winning criterion (such as code-golf) is mandatory \$\endgroup\$ – Jo King Nov 15 '19 at 0:23
  • 2
    \$\begingroup\$ I'm not clear what can be done with the timers. Can you flip any timer only when a timer runs out? Can you tell when two timers are the same level? Are the timers joined together like in the picture? If the answer turns out to be any multiple of the GCD of the numbers, I think that would make for a pretty boring challenge. Minor thing: I'd suggest writing "120 minutes" rather than 2 hours. \$\endgroup\$ – xnor Nov 15 '19 at 8:48
1
\$\begingroup\$

Guessing the subset.

Preface

I've never done a challenge before, so I'd appreciate some help to get this right. In particular, I'm not sure how much I should specify a (language-neutral) API. I'm also not sure how to implement time limits on computation time. (I want to be able to run a trial in seconds, not weeks.)


This challenge is based on Math Stack Exchange question "Guessing a subset of {1,...,N}".

In this challenge, the robber's job is to choose a subset \$R \subseteq \{1,\dots,N\}\$, kind of. Then the cop's job is to deduce the robber's subset by asking questions.


Robber

When I was growing up, I would sometimes play Twenty Questions with my brother. I would pick some sort of animal, and answer his questions about it. However, when he guessed the answer I had in mind, I would try to come up with another animal that satisfied all of the same answers to his questions—and if I could do it, I would tell him he was wrong.

The robber's job is similar to my strategy in Twenty Questions. The cop will ask the robber questions about the robber's chosen subset, but the robber can keep changing the subset as long as the answers are consistent. The robber's job is trying to answer the questions in such a way as to maximize the number of questions the cop needs to ask, always ensuring that the answers do not contradict each other.

Cop

The cop's job is to successively pick subsets starting with \$C_1 \subseteq \{1, \dots, N\}\$ and ask the question, "Does \$C_1\ = R\$, and if not how many elements do \$C_1\$ and \$R\$ have in common?" (That is, \$|C_1 \cap R|\$.)

If \$C_k = R\$, then the cop has finished the interrogation, and her score is \$k\$. Otherwise, the cop then can use this information to choose a new set \$C_{k+1}\$, and ask the same question for \$C_{k+1}\$.

Rules

Both the cop and robber will be given a number \$N\$, then the cop will go first outputting a subset \$C_1 \subseteq \{1,...,N\}\$. The robber will then take this as an input and output \$|C_1 \cap R|\$. The cop will take this number as an input and output \$C_2\$ and so on.

For a given interrogation both the cop's and robber's score is \$k\$ where \$C_k = R\$ is the last, correct guess. Naturally, the cop is trying to minimize her score while the robber is trying to maximize his.

Each cop will be tested against each robber (perhaps multiple times) with varying values of \$N \leq 1000\$. The score for the cop and robbers will be the sum of the scores over all interrogations.

\$\endgroup\$
  • \$\begingroup\$ I wish N was at most 24 so we can brute-force for 'giving the least information' answer as robber over 16M possible sets and then narrowing the set. Also consider this \$\endgroup\$ – Alexey Burdin Nov 26 '19 at 21:25
1
\$\begingroup\$

Name the hydrocarbon

A hydrocarbon is a chemical compound which consists of only hydrogen and carbon atoms. For this challenge, we will only consider the three simplest kinds of hydrocarbons: alkanes, alkenes, and alkynes with no branches.

An alkane with \$n\$ carbon atoms contains \$2n+2\$ hydrogen atoms. An alkene with \$n\$ carbon atoms contains \$2n\$ hydrogen atoms. An alkyne with \$n\$ carbon atoms contains \$2n-2\$ hydrogen atoms.

Each kind of hydrocarbon is named with a prefix indicating the number of carbon atoms it contains, followed by the suffix ane, ene, or yne if it is an alkane, alkene, or alkyne respectively. The numerical prefixes are as follows:

1  -> meth
2  -> eth
3  -> prop
4  -> but
5  -> pent
6  -> hex
7  -> hept
8  -> oct
9  -> non
10 -> dec

For example, we can see propane has 3 carbon and 8 hydrogen atoms, and heptyne has 7 carbon and 12 hydrogen atoms.

Challenge

Your task is to write a function or program that receives two integers, representing a number of carbon and hydrogen atoms, and produces or outputs the name of the corresponding hydrocarbon. Capitalization does not matter, and leading/trailing whitespace is allowed.

The input and output can be in any convenient format. You may assume the input will correspond to a valid hydrocarbon, and there are at most 10 carbon atoms.

Examples

Input -> Output
1 4   -> Methane
3 8   -> Propane
7 12  -> Heptyne
10 20 -> Decene

Rules

  • No standard loopholes.
  • Shortest code in bytes wins.

\$\endgroup\$
1
\$\begingroup\$

Numbers without 'E'

In this trial, I wish for us to think only of digits and digit compounds, from two to six trillion. If any in this group contains, in a plain Latin writing form, an indication of what our prompt prohibits, it is cast out of this group.

If a digit or digit compound contains 100, 1000, or similar, "1" is not a part of its plain Latin writing form. 1000 would simply boil down to "thousand", although 4000 is "four thousand".

What you must do:

Taking an input of N, in which N is not as high as 1000, nor as low as 0, (0 < N < 1000), and in which N is an ordinal, output what N points to in an array that follows our titular prompt.

Additionally, your solutions may contain only a solitary count of this cast out latin symbol (including diacritical marks and such, although this should not dismay you too much).

Your aim is to do this with a minimum bit count in your program.

This following portion is for clarification on what I am in pursuit of: 1 -> 2 (two) 3 -> 6 (six) 5 -> 32 (thirty two) 22 -> 1004 (thousand four) 100 -> 30 000 (thirty thousand)

Meta:

As you may have noticed, this is a little hard to read. I tried to spice it up by excluding any instance of the letter 'e' from the text description.

  • Should the challenge be changed to "evaluate if a number contains 'E'"? This is an alternative idea Id considered but Im not sure if it would make a better challenge
  • Does eliminating all instances of 'e' from the description make this challenge unreadable?
  • Does the additional challenge of only having 1 'e' in the solution add too much to the challenge?
  • Are the bounds too restrictive/not restrictive enough?
\$\endgroup\$
  • 3
    \$\begingroup\$ Hi there! These are called "Eban" numbers, and essentially has already been asked; the difference being you're asking for the nth number, while the linked question is asking for the first n. \$\endgroup\$ – AdmBorkBork Dec 2 '19 at 20:25
  • 1
    \$\begingroup\$ @AdmBorkBork I see, I had searched for similar questions but couldnt find anything. Thanks for letting me know. \$\endgroup\$ – frank Dec 2 '19 at 20:29
1
\$\begingroup\$

Can the statues be stacked?

Inspired by this stack of little statues that are currently on my desk at work, given to me by my colleagues from Sri Lanka when they visited The Netherlands:

enter image description here

Challenge:

Input:

\$statues\$: a multi-line string (or character matrix), containing only the characters \n|-# (where the # can be another character of your own choice)

Output:

Two distinct values of your own choice indicating truthy/falsey; so yes, 1/0 is allowed as output in languages like Java/C# .NET and such (relevant forbidden loophole). The output will be truthy if the statues can be stacked.

Statues input example:

      ##|
####    |
# ##
#  #  |##
----  |######
      |   ###
|##   |##   #
|## - |######
    # |####

The | and - represent the bases of the statues. So with the input above, we'll have the following statues:

       ####
       ## #
       ## ##
####   #  ##
# ##  ## ###  ##      #
#  #  ## ###  ##  #   #
----  ------  --  -  --

How can the statues be stacked?

When stacking statues, we can only stack statues with a width of the base that is \$\leq\$ the width of the top of the statue beneath it. So with the statues above, these are all possible pairs of how we could stack two statues on top of each other:

####
# ##    ##
#  #    ##      #        #
----    --      -       --
####    ####    ####    ####    ##
## #    ## #    ## #    ## #    ##    #      #
## ##   ## ##   ## ##   ## ##   --    -     --    #    #
#  ##   #  ##   #  ##   #  ##   ####  ####  ####  -   --   #
## ###  ## ###  ## ###  ## ###  # ##  # ##  # ##  ##  ##   -
## ###  ## ###  ## ###  ## ###  #  #  #  #  #  #  ##  ##   #
------  ------  ------  ------  ----  ----  ----  --  --  --

One possible complete stack keeping that in mind could therefore be:

 #
 -
 #
--
##
##
--
####
# ##
#  #
----
####
## #
## ##
#  ##
## ###
## ###
------

So in this case the result is truthy, since the statues can be stacked.

Challenge rules:

  • You can use a different consistent character other than # for the statue border if you want (other than |- \n). Please state which one you've used in your answer if it's different than #.
  • You are allowed to take the \$statues\$ input in any reasonable format. Can be a multi-line string, a list/array/stream of strings, a character matrix, etc.
  • You are allowed to pad the statues input with trailing spaces.
  • You can assume statues are always separated by at least one space/newline from one-another, so something like #|#| isn't possible.
  • You can assume the statues will only have a base at ones side, so a statue like this isn't possible:
##|
##|
--
  • It is possible that a smaller statue is within the rectangular boundaries of another oddly shaped statue. For example, this is possible:
# ##
- ##
  ##
####
# # 
----
  • Statues will never be inside of each other, though. So something like this isn't possible:
 #####
##   #
#  # #
# ## ##
# -- ##
#     #
##    #
-------
  • You can assume all statues will only be placed on top of each other, and never next to each other if the top of a statue is large enough to hold two adjacent statues with small bases, or if it could fit on a smaller ledge. For example, these towers of statues aren't possible:
                        #
  #                     # #
#--                     - -
####                    ###
----                    ---
Statue on lower ledge   Two statues next to each other on top of single statue
  • You can assume the top and base parts of a statue are always a single piece, without any gaps. So a statue like this wouldn't be possible:
#  #
----

But a statue like this is possible:

#
#  #
----
  • You can assume the base determines the width of a statue. So it's not possible to have statues like these:
#######
 #####
 ####     ###
  ---     --

General rules:

  • This is , so shortest answer in bytes wins.
    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
  • Default Loopholes are forbidden.
  • If possible, please add a link with a test for your code (i.e. TIO).
  • Also, adding an explanation for your answer is highly recommended.

Test cases:

Truthy test cases:

      ##|
####    |
# ##
#  #  |##
----  |######
      |   ###
|##   |##   #
|## - |######
    # |####

TODO: More to add

Falsey test cases:

|##
|   ##
|#  --

TODO: More to add


Sandbox questions:

  • Should I make the statues always solid without inner spaces, so it's slightly easier to parse?
  • Any edge cases I should think about in the rules/test cases?
  • Any suggested test cases?
  • Any additional rules I should add?
\$\endgroup\$
  • 1
    \$\begingroup\$ If the top of a statue is wide enough, can you put two statues on top of it? \$\endgroup\$ – Hiatsu Aug 30 '19 at 23:52
  • \$\begingroup\$ @Hiatsu Oh, that's a pretty good question. I think I will add a rule that will disallow it, to not complicate it too much. Thanks for asking though, hadn't considered that! :) \$\endgroup\$ – Kevin Cruijssen Aug 31 '19 at 9:20
  • \$\begingroup\$ Related \$\endgroup\$ – Shaggy Sep 1 '19 at 16:02
  • 1
    \$\begingroup\$ Another thing that should probably be cleared up: Can the base and top row/column consist of multiple parts? (e.g. is a 5x5 square with the top, bottom, left and right middle square respectively missing a valid statue?) \$\endgroup\$ – ar4093 Sep 4 '19 at 11:09
  • 1
    \$\begingroup\$ Hm, is there a possibility that a statue can "fall into" a bigger statue if the latter's top has a wide enough hole on it and there's no other place to put the smaller one on? \$\endgroup\$ – Erik the Outgolfer Sep 4 '19 at 12:36
  • \$\begingroup\$ @ar4093 & ErikTheOutgolfer Added some rules to prevent this. I have the feeling the rules are becoming a bit large with all this blacklisting of statues which aren't possible, though. \$\endgroup\$ – Kevin Cruijssen Sep 4 '19 at 12:49
  • \$\begingroup\$ This seems like two challenges now: sum of statue heights <= maximum height (trivial), and all statues can be stacked somehow (the fun part). Given the effort you've gone through to keep the first part trivial, you might just want to remove it. \$\endgroup\$ – Hiatsu Sep 4 '19 at 15:38
  • \$\begingroup\$ @Hiatsu You might be right. Will probably change it later on to actually stack the statues. Will the input format and irregular shapes be different enough from this challenge in that case? I personally think it will, but I'd like some other opinions before I change it. \$\endgroup\$ – Kevin Cruijssen Sep 4 '19 at 16:58
1
\$\begingroup\$

What's that frequency?

This is my first code-golf challenge, so apologies if it is a little unclear/already has been done. I gave the past challenges a good look over, but I may have missed something.

Create a function or a full program which accepts a frequency value, and then outputs the closest musical note, and the octave, this frequency corresponds to.

This function/program should support eight full octaves worth of notes, starting from C0 up to and including B8.

Test cases:

440.00 -> A4
466.16 -> A#4
466.20 -> A#4
261.63 -> C4
16.35 -> C0
0.00 -> C0
7902.13 -> B8
10000.00 -> B8

A full list of frequencies and notes they correspond to can be found here: https://pages.mtu.edu/~suits/notefreqs.html

This is a code golf, so shortest code wins!

\$\endgroup\$
  • 1
    \$\begingroup\$ Thanks for using the sandbox! :) I found the inverse challenge. I feel as though I've reviewed this version as well, but perhaps it never left the sandbox. In any case, you should include a method by which to classify the frequencies, and what precisely you mean by closeness in the body of your challenge. External links are nice but not enough! \$\endgroup\$ – FryAmTheEggman Dec 5 '19 at 14:58
  • \$\begingroup\$ Great idea! Just make sure to flesh out the rules: perhaps specify that A=440Hz and that each note is 2 ^ (1/12) times the note below it (if I'm remembering my music theory correctly). \$\endgroup\$ – FlipTack Dec 27 '19 at 14:18
  • \$\begingroup\$ You may also want to consider adding some tags: music, code-golf \$\endgroup\$ – FlipTack Dec 27 '19 at 14:19
1
\$\begingroup\$

plan an efficient finnish bus stop on a sphere

Apparently respecting personal space is very important at finnish bus stops. Now given some "minimum-personal-space-angle" \$\vartheta\$, your job is designing a bus stop on a sphere for as many people as possible respecting the "minimum-personal-space-angle".

Let us rephrase this a little bit more clearly: Let \$S^2 = \{x \in \mathbb R^3 \mid \Vert x \Vert_2 =1 \}\$ be the unit sphere in \$\mathbb R^3\$. Given the angle \$\vartheta \in (0,\pi)\$ you should find a set \$U \subset S^2\$ such that all pairs of vectors \$x,y \in U\$ (\$x \neq y\$) are at least an angle of \$\vartheta\$ apart, that is \$x \cdot y \leqslant \cos \vartheta\$.

And this set \$U\$ should be as large as possible - but this does not mean that your program needs to find the largest possible \$U\$ (this is a hard unsolved problem), but it should try to make it as large as possible as this will be part of the score.

Let us define \$a_\vartheta = \vert U \vert\$ as the number of vectors your program found for \$\vartheta\$.

The score \$s\$ of your submission will be

$$ s=\frac{1}{N}\sum_{n=1}^N a_{\vartheta_n} w_n$$

where \$\vartheta_n = 1/n\$, \$w_n = 1/n^2\$. And you can choose \$N \in \mathbb N\$ as large as you want.

Inspired by this reddit thread.

META:

I think the choice of \$\vartheta_n\$ and \$w_n\$ needs some fine tuning to make the challenge interesting. My thoughts so far: The idea is that \$a_{\vartheta} \leqslant c \frac{1}{\vartheta^2}\$ since every vector on the sphere needs a circle of a radius that is at least \$\vartheta/2\$, so the area of such a circle is about \$\pi (\vartheta/2)^2\$ which means we can fit at most \$\frac{4\pi}{\pi (\vartheta/2)^2} = \frac{1}{\vartheta^2}\$ (just as a rough estimate).

So I think with current choice of \$\vartheta_n\$ and \$w_n\$ the score should be bounded. But I fear that with the current choice of these sequences the greatest score will be achieved by a relatively simple solution where someone just chooses \$N=1,2\$ or so.

Can we alleviate this by adding a factor of \$\log n\$ to \$w_n\$? Unfortunately I think this would incentivise using very large \$N\$.


EDIT: Instead of using \$\log n\$ I think using a bounded increasing sequence would work. E.g. \$(1-1/n)\$ so \$w_n = \frac{1}{n^2}(1- \frac{1}{n})\$.


If you have any thoughts or ideas, please share!

\$\endgroup\$
  • \$\begingroup\$ I didn't have time to actually think about this challenge, but my first reaction is that it seems weird to let the solver choose N. Might balancing the scoring be easier if you pick some value high enough to be interesting and specify it in the challenge? \$\endgroup\$ – xnor Nov 30 '19 at 10:02
  • \$\begingroup\$ @xnor thanks for the feedback! I thought maybe some answers would include very inefficient algorithms. While I cannot directly prevent those, I thought it would be a nice idea to try to discourage them via the scoring method. So ideally you'd get the best solution every time, and if not, get solutions that are as good as possible for the most possible n. I know it looks quite convoluted:) \$\endgroup\$ – flawr Nov 30 '19 at 23:47
  • \$\begingroup\$ This seems neat, but I did stumble at one point in understanding. You say \$ a_{\vartheta} \$ is what the program found, which led me to believe this value was going to be fixed in the scoring. I think if you change it to "finds" it will be pretty immediately clear that what I thought isn't correct. Also, assuming I'm reading correctly we never consider angles greater than 1 radian, which is a tad surprising following the definition (not really a problem, just something I noticed). \$\endgroup\$ – FryAmTheEggman Dec 5 '19 at 18:54
  • \$\begingroup\$ @FryAmTheEggman Yes this is correct. For \$\vartheta=\pi/2\$ the optimal \$a_\vartheta\$ is 6 (octahedron). For \$\vartheta \approx 0.9680399...\$ the optimal number is \$a_\vartheta=12\$ (icosahedron), so \$\vartheta=1\$ must be somewhere in between, and my thinking was that for angles this large, optimal solutions can easily be found. But it would easily be possible to define a totally different sequence for \$\vartheta_n\$ - if you have a suggestion let me know! \$\endgroup\$ – flawr Dec 5 '19 at 20:06
1
\$\begingroup\$

Roll for Initiative!

Tags:

Introduction

In tabletop games like Dungeons and Dragons, when you begin a battle, all involved parties roll for initiative. In DnD 5e, this is 1d20 + DEX + Other bonuses, where DEX is the bonus given by your Dexterity stat. The characters that roll higher numbers go first. We'll use a similar, deterministic system in this challenge.

The Challenge

Write a program or function that, when given a list of characters, will output a list of characters in order of initiative.

A character is defined as this:

character = {
    name: "name" // a string
    statblock: [SPD, DEX, WHT] // a list of numbers
                               // DEX = dexterity, SPD = speed, WHT = weight
}

The formula for initiative is the following: $$\text{Initiative} = \left\lfloor{ \frac{\text{SPD}^2}{\sqrt{\lvert\text{DEX}\rvert}} }\right\rfloor - \text{WHT}$$

Input

A list of characters, unsorted. This can be a JSON object, a list of lists, a list of dictionaries, a series of strings etc.

It is guaranteed that all names will be unique.

Output

A list of characters, or character names, sorted by initiative order from highest to lowest, based on the above formula.

Rules

Sample IO

Input --> Output
[[Name, SPD, DEX, WHT], ...]
    --> [[Name, SPD, DEX, WHT], ...] (or [Name, Name, ...])
---------
[[Alice,1,2,3],[Bob,10,5,0],[Charlie,3,2,1]]
    --> [Bob, Charlie, Alice]
// Alice = -3, Bob = 44, Charlie = 5

[[Z,1,1,1],[B,1,1,1],[XY,5,1,1]]
    --> [XY, Z, B]
// Retain the order of characters from the input if they have the same initiative.
// Z = 0, B = 0, XY = 24

[[Neg,-3,-3,-1],[SomeNeg,5,-2,-4],[NoNeg,4,6,8]]
    --> [SomeNeg, Neg, NoNeg]
// Negative values are valid.
// Neg = 6, SomeNeg = 13, NoNeg = -2

[[Flo,1.5,2.5,3.5],[MoreFlo,2,2.5,3.5]]
    --> [[MoreFlo,2,2.5,3.5], [Flo,1.5,2.5,3.5]]
// Floats are also valid.
// Flo = -2.5, MoreFlo = -1.5

[[Lonely,1,2,3]]
    --> [[Lonely,1,2,3]]
// Input with 1 item.

[]
    --> []
// Empty input leads to empty output.
\$\endgroup\$
  • 1
    \$\begingroup\$ You can use \left and \right in mathjax to make your brackets the right size. I also think that the output format is a little pointlessly strict - why not also allow just the list of names (same with requiring stable sorts)? \$\endgroup\$ – FryAmTheEggman Dec 4 '19 at 23:11
1
\$\begingroup\$

Count the length of head movement

Moved here

\$\endgroup\$
1
\$\begingroup\$

Sort By the New Alphabet

The order of the alphabet is really quite arbitrary. I propose a new ordering of the alphabet, ordered so that adjacent letters (in capital form) are similar in shape. Here is the order:

JUOQGCDPRBEFTILVYXKHAMWNZS

Of course, this makes a lot of previously written code redundant. To fix this problem we will start re-implementing that code, in its updated form.

Your task is to create a program or function that takes a string or list of characters as input, and outputs that string/list sorted according to this new ordering.

You can assume that all input will contain only uppercase alphabetic characters.


I know it's similar to this and this, but this challenge has a fixed ordering, so I hope this allows for some more ingenuity as well as the requirement to store the ordering efficiently.

\$\endgroup\$
  • \$\begingroup\$ Is uppercase mandatory, or are we allowed to take both input and store the compressed alphabet as lowercase? \$\endgroup\$ – Kevin Cruijssen Dec 16 '19 at 9:36
  • \$\begingroup\$ You can store the alphabet however you want. You can accept input as upper or lowercase. \$\endgroup\$ – Matthew Jensen Dec 16 '19 at 20:42
1
\$\begingroup\$

edit: check it out live here!

Play Big 2 by yourself, as fast as you can

\$\endgroup\$
  • \$\begingroup\$ Seems a good first go. There is one major ambiguity I can find: You don't explain if aces are high or low. From your straight explanation, I guess they can be both, but you can't 'wrap' around. Please add an explanation about that. Also, the straight flush, while a Poker hand, isn't required algorithmically: It's a subset of both straights and flushes, so any algorithm detecting them will also catch the straight flush. \$\endgroup\$ – AlienAtSystem Nov 18 '19 at 8:01
  • \$\begingroup\$ Consider 3352 ['8C', '7C', '4C', '0C', 'AC'] 3966 ['4H', '6D', '3S', '5H', '2S'] 8063 ['AS', 'AH'] 8191 ['8D'] for the first test \$\endgroup\$ – Alexey Burdin Nov 18 '19 at 14:00
  • \$\begingroup\$ tinyurl.com/cgm-a18285-1 -- tio (may run more than \$1\$ min for \$hands\ge7\$) \$\endgroup\$ – Alexey Burdin Nov 18 '19 at 14:17
  • \$\begingroup\$ @AlienAtSystem you're right - aces can be used as a high or a low, but they can't appear in the 'middle' of a straight, so to say. I'll update the straight description. Re: the straight flush - yeah I figured this too, mostly adding it for the sake of completion. I'll also make a note about that. Thanks for reading through it! \$\endgroup\$ – aphrid Nov 18 '19 at 15:08
  • \$\begingroup\$ @AlexeyBurdin ack, you're right! I came up with the suiting on a whim and didn't really sit down to consider if it was possible to dump the hand faster. Oops. I meant to use the first test case as a general explanatory case, so I'll update my tests to reflect that. (Also, it seems like your tinyurl link is broken...) \$\endgroup\$ – aphrid Nov 18 '19 at 15:10
  • \$\begingroup\$ tinyurl.com/cgm-a18285-2 -- I use bfs with early exit if goal reached, so it can't be done faster(in words of move numbers, not computation time). ) \$\endgroup\$ – Alexey Burdin Nov 18 '19 at 16:22
  • \$\begingroup\$ @AlexeyBurdin Hmm, I still can't seem to use that link, but I appreciate your attempts nonetheless \$\endgroup\$ – aphrid Nov 18 '19 at 17:34
  • 1
    \$\begingroup\$ One more )) tiny.cc/cgm_a18285_2 \$\endgroup\$ – Alexey Burdin Nov 18 '19 at 18:33
  • \$\begingroup\$ That link works like a charm, great work! \$\endgroup\$ – aphrid Nov 18 '19 at 18:56
1
\$\begingroup\$

Challenge posted to Main here

\$\endgroup\$
  • \$\begingroup\$ I'd say this is very close to being a dupe of the Fibonacci challenge. Often one could pretty directly replace the (inc/dec)rement with a divisibility check. The specific nature of the Fibonacci challenge allows a lot of tricks that wouldn't work as well here, though. \$\endgroup\$ – FryAmTheEggman Dec 9 '19 at 20:48
  • \$\begingroup\$ Could you link to that challenge? \$\endgroup\$ – Don Thousand Dec 9 '19 at 20:50
  • \$\begingroup\$ Here you go. \$\endgroup\$ – FryAmTheEggman Dec 9 '19 at 20:51
  • \$\begingroup\$ Hmm, I see. Is there a way to modify this to invalidate more answers from that question? Maybe a new winning criterion? \$\endgroup\$ – Don Thousand Dec 9 '19 at 20:54
  • \$\begingroup\$ You could try something like scoring each submission by the sum of each byte's smallest Fibonacci multiple? That's kind of a lazy fix (and you need to deal with null bytes, lenguage, etc.) but it could work. You can try asking in chat for more ideas, and of course if I think of anything I'll let you know :) \$\endgroup\$ – FryAmTheEggman Dec 9 '19 at 20:56
  • \$\begingroup\$ @FryAmTheEggman How do you like the update? \$\endgroup\$ – Don Thousand Dec 9 '19 at 23:46
  • \$\begingroup\$ I don't think your precise method of scoring is ideal, it seems like it could be abused to get a score of zero too easily. I recommend scoring actual bytes, not the unicode characters they turn into. \$\endgroup\$ – FryAmTheEggman Dec 10 '19 at 5:55
  • \$\begingroup\$ @FryAmTheEggman Hmm, sorry for bugging you, but how would you suggest doing that? I'm not sure I see the picture. \$\endgroup\$ – Don Thousand Dec 10 '19 at 6:23
  • \$\begingroup\$ I guesss something like Lenguage could come in and have a program full of spaces, henceforth getting a score of 0. \$\endgroup\$ – Lyxal Dec 10 '19 at 10:30
  • \$\begingroup\$ @Jono2906 I don't know how to modify this to make this work, frankly. \$\endgroup\$ – Don Thousand Dec 10 '19 at 18:45
  • \$\begingroup\$ No worries, and I recommend not worrying too much about Lenguage and the like, they are often kind of impossible to fix. What I mean is, the characters used in code are ambiguous and not particularly meaningful. Instead, score based on the bytes of the program, which are clear and fixed. Then keep the part with the fib multiples, but add one to the bytes beforehand to avoid zero. \$\endgroup\$ – FryAmTheEggman Dec 10 '19 at 20:24
  • \$\begingroup\$ @FryAmTheEggman Makes sense! I'm pretty happy now with where this challenge is at. \$\endgroup\$ – Don Thousand Dec 10 '19 at 22:38
1
\$\begingroup\$

Expand a road network


You've been employed as a city planner (obligatory seinfeld clip) and you have been tasked with expanding the road system of Codegolfville. Here's a diagram of what Codegolfville could look like:

        | |
        | |
--------+ +-------
--------+ +-------
        | |
        | +-------
        | +-------
        | |
        | |

Your job is to expand the existing infrastructure \$n\$ blocks in a specific direction.

The Challenge

  1. Take two inputs - a direction to expand in, and the number of blocks to expand - through any reasonable input format.

  2. Expand the existing roadways in the ASCII map, in the direction specified.

    a. You must take into account the existing roadways - you can only expand on roads that are already there, and if there are no roads to expand, you won't expand anything.

    b. Your program must work for any example map, not just the one provided above.

  3. Show the output on STDOUT, if your language supports it.

Test Cases

        will be done soon

Other Rules

This is , so lowest score in bytes wins. Standard loopholes are forbidden. Have fun!

\$\endgroup\$
  • 1
    \$\begingroup\$ Are blocks a fixed dimension or is it based on the size of the input? Does it expand in only one direction or can it be multiple? Finally, what does expansion mean? Are we replicating the block n times? Merely extending the roads on the expanding edge (i.e. appending n*width - or |s)? \$\endgroup\$ – Veskah Dec 11 '19 at 14:21
1
\$\begingroup\$

Is it a Snake Cube?

A snake cube is a quite popular wooden puzzle. There are usually 27 cubes threaded on an elastic string. Each cube has a hole that either goes straight through from one face to the opposite face, or that makes a 90° bend, that means it exits through a face that is adjecent to the one it enters. (And the two end cubes into which this string enters. Two adjecent cubes on that string can rotate against eachother. The goal is rotating them all such that the whole "snake" forms a large 3x3x3 cube.

Images from Wikipedia (1)(2)

Obviously we cannot have any random sequence of the straight/90° pieces if we want to get a cube in the end. This leads us to the

Challenge

Given a sequence of the types of the inner 25 cubes of a "snake", determine whether it is possible to form a cube.

Example

I will here use the symbol T for a piece with a straight hole, and F for a piece with a 90° hole. The example in the image would be encoded (from the bottom left to the top right) as

TFFFTFFTFFFTFTFFFFTFTFTFT

Details

  • You can take the input as a string or list/array or any other type of sequence.
  • You can use different symbols for the two types, you could also take booleans or integers.
  • The output is also flexible: You're can have two distinct output, one for each case, but they must be consistent. If it is not obvious (e.g. True/False) please specify which one means what.

Examples

No cube possible:

TFTFTFTFTFTFTFTFFTFFFTFFF (we have 8 consecutive (overlapping) straight runs of length 3)
TFTFTFTFFFFTFTFFFTFFTFFTT (we have a straight run of four pieces at the end)

Cube possible:

TFFFTFFTFFFTFTFFFFTFTFTFT
TFTFTFTFFFFTFTFFFTFFTFFFT
\$\endgroup\$
  • 1
    \$\begingroup\$ Oh hey, I have that exact cube, but I forgot how to put it back together again \$\endgroup\$ – Jo King Dec 14 '19 at 2:44
  • \$\begingroup\$ @JoKing ...then I should maybe modify the challenge and ask for the solution as output :P \$\endgroup\$ – flawr Dec 14 '19 at 9:37
  • \$\begingroup\$ Don't worry, I dug it out of the drawer it was stuck in and finally solved it \$\endgroup\$ – Jo King Dec 16 '19 at 7:07
1
\$\begingroup\$

Union of Two Polygons

Given two intersecting polygons as input, output a third polygon that is the union of the two input polygons, that is to say, the perimeter that encloses all points present in at least one of the two input polygons.

Example polygon unions

Example inputs/outputs

2 Squares

  [(0, 0), (0, 2), (2, 2), (2, 0)]
| [(1, 1), (1, 3), (3, 3), (3, 1)]
==> [(0, 0), (0, 2), (1, 2), (1, 3), (3, 3), (3, 1), (2, 1), (2, 0)]

... more to come

Notes and Rules

  • Input will be two lists of at least 3 2d points each, taken in any convenient format.
  • Output should be a list of 2d points, in any convenient format.
  • It does not matter which point you list first.
  • It does not matter whether you output in clockwise or counterclockwise order.
  • Polygons may be concave
  • You may assume that both polygons are not self-intersecting
  • You may assume that the polygons overlap in at least two places exclusively via edge-edge crossings rather than vertex-edge intersections, vertex-vertex intersections, or flush edge-edge overlaps.
  • You may assume that the polygons do not overlap in such a way that the union would have at least one hole in it.
  • You must be accurate to at least 0.01 for all polygons between -100 and 100 units along each axis.
  • Standard rules apply. Shortest code wins.

\$\endgroup\$
  • \$\begingroup\$ Can you add some examples? \$\endgroup\$ – Carson Graham Dec 13 '19 at 16:01
1
\$\begingroup\$

Make an "implicit" parser

In this task, given an infix expression, fill in all of the implicit inputs and evaluate this expression with the other given input. (You only need to deal with (+, -, and ().)

Expressions are only allowed to be dyadic and not monadic. If an operator is monadic, prepend an input.

What do I do?

The rule is simple: if something is preceded with a nilad or a parenthesized expression, it is a dyad.

+ is a dyad here:

2 + 1
(5 + 2)
3 + ((2) + 4)

Otherwise, the operator is a monad.

+ is a monad here:

 +(2 - 2)
(+ 2)

If you find a monad in your code, immediately prepend it with the a character.

a +(2 - 2)
(a+ 2)

That's about it.

Examples

The input expression is guaranteed to not produce errors, such as the format 2- which is impossible to prepend an input.

"+++a",2 -> a+a+a+a = 2+2+2+2 = 8
"(+1)+(-1)",5 -> (a+1)+(a-1) = (5+1)+(5-1) = 10
"+(2-a)", 3 -> a+(2-a) = 3+(2-3) = 2
"(5+2)+2+1", 7 -> (5+2)+2+1 = 10
"--2", 2 -> a-a-2 = 0-2 = -2

Rules

  • This is , so the shortest code wins.
  • Standard loopholes are disallowed.
\$\endgroup\$
  • \$\begingroup\$ I've been thinking of making a challenge to parse a simple subset of APL e.g. numbers and + and - and /, but what does your challenge have to do with APL? APL doesn't have implicit arguments for nilads, and a+(2-) is a syntax error in most dialects. \$\endgroup\$ – Adám Dec 15 '19 at 9:16
  • \$\begingroup\$ @Adám (You said nilad, I assume you meant monad.) 1. I assume scanning for nilads was how APL was parsed. Correct me if I am wrong. 2. Although APL doesn't provide arguments, the only less trivial way I can think of compared to outputting how many arguments an operator has is to provide the arguments. Do you have a better way to do this? 3. To simplify the challenge, preventing syntax errors is unneccecary. \$\endgroup\$ – user85052 Dec 15 '19 at 9:43
  • \$\begingroup\$ Yeah, sorry about the "nilad" instead of "monad". 1. That's wouldn't work. 2. How about simply evaluating a given expression consisting of `[-+/ 0-9]? That's easy to verify against a real interpreter. 3. Just guarantee that the input expression has no errors. \$\endgroup\$ – Adám Dec 15 '19 at 9:48
  • \$\begingroup\$ What is the correct answer for "--2",2? \$\endgroup\$ – Adám Dec 15 '19 at 10:48
1
\$\begingroup\$

Asyncronous Breakfast

I haven't seen any asyncronous challenges here, even tho it's an important part of coding, so here's my idea, based on an example (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/) that explains asyncronous coding:

You are making breakfast. The things you want to serve are:
Cooked eggs, Bacon, Coffee, Orange Juice and Toast.

You start boiling the eggs, cooking the bacon, making coffee, and toasting toast. 
When everything is finished, you're serving the orange juice.

After every finished food, the console outputs "[Food] is ready."
\$\endgroup\$
  • 1
    \$\begingroup\$ I think you should generally only specify things about the input and the output, and not the program's internal behaviour ("do addition without the + operator"-like questions are now discredited). Can you define a required output in a way that the only way to produce it is for the program to run asynchronously? \$\endgroup\$ – KeizerHarm Dec 16 '19 at 14:29
  • 1
    \$\begingroup\$ How about checking the multi-threading tag? \$\endgroup\$ – Adám Dec 16 '19 at 22:03
1
43 44
45
46 47
92

You must log in to answer this question.

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