555
\$\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 requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

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

3928 Answers 3928

1
116 117
118
119 120
131
0
\$\begingroup\$

Return shortest integer-is-one-of function

This is a challenge, where you'll ...

Given a number of integers as input, your task is to write a function in JS, which returns a function that checks if an inputted integer is any of those. For example, f([1, 2, 4]) would return a function which would return true if given 1, 2, or 4, and false for any other inputs.

Task:

Your function will take any nonzero number of integers. There will not be any duplicates. This should return either a function, or a string containing the function's code.

The returned function should take a single integer as input. If the input is one of the integers inputted into the original function, it should return a truthy value, and a falsy one otherwise. You may also choose to return any two consistent values, or a consistent value for one possiblity (such as 0 for truthy) and any other value for the other.

Scoring:

This is metagolf, meaning the average of the byte counts of the returned programs for a certain set of inputs will be your score. This set of inputs will consist of:

  • All combinations one to four integers from -10 to 10
  • A random group of 2000 inputs consisting of between five and ten integers between -100 and 100
  • A random group of 1000 inputs consisting of between two and six integers between -10000 and 10000

Optimizing your solution for these specific test cases is disallowed.

Meta

  • I will generate a random list of test cases that will be used for scoring when I post this
  • This is my first time writing a metagolf challenge. Any improvements y'all can think of?
  • I think the number of bytes should be limited in the submitted function (not the generated ones). Suggestions?
  • Too many test cases? Too few?
\$\endgroup\$
7
  • \$\begingroup\$ The option to return a function is only available in JS, I'm assuming? I think you should disallow it, because it's unclear how you measure the size of a function object. \$\endgroup\$ May 21, 2021 at 14:22
  • \$\begingroup\$ Maybe you should include test cases with more than six integers? If not, is it allowed for a solution to be optimized for small sizes? (given that it's a a minority in the input space) \$\endgroup\$ May 21, 2021 at 14:23
  • \$\begingroup\$ @CommandMaster Oh, I meant to restrict this to JS anyway, wasn't sure if I was going to do that or not. It should be possible in any language with first class functions, though. If I open it up to any language I'll allow returning a string with a program. I'll add some test cases with more items. \$\endgroup\$ May 21, 2021 at 14:56
  • \$\begingroup\$ If you return a function, how do you count the byte count of it? \$\endgroup\$ May 21, 2021 at 15:14
  • \$\begingroup\$ .toString() (plus it's pretty likely they'll return a string form of the function anyway) \$\endgroup\$ May 21, 2021 at 15:28
  • 2
    \$\begingroup\$ .toString() doesn't work for that, for example in function f(i) { var l = a=>a+i return x=>l(x) } f().toString() is just x=>l(x), while that's clearly not the length of the code you want to count (it's also unclear what code you do want to count in such a case) \$\endgroup\$ May 21, 2021 at 15:39
  • 1
    \$\begingroup\$ @CommandMaster The functions will need to be independent from the meta function. As in, no closures/accessing variables in the above scope. \$\endgroup\$ May 21, 2021 at 15:55
0
\$\begingroup\$

Will the dominoes topple?

Your input contains a list of positive integers representing the height of a row of dominoes. As many of us know, when you have a row of dominoes and push the first one, the rest will topple in a chain reaction. But if the next domino is too big, it will not fall. This depends on the shape of the domino, so in addition to the list, your program will also receive a positive rational number \$r\$, so that domino \$n\$ will topple domino \$n+1\$ iff \$h_n\cdot r>h_{n+1}\$, where \$h_n\$ is the height of a domino.

Your task is to decide if all the dominoes topple or if the chain reaction stops before the end.

Your input is a non-empty list of positive integers (the height of the dominoes) and the rational number \$r\$.

You must use exact (integer) math, fp math is not allowed (though languages like Javascript and C can assume that the integer types are bigints).

Use standard output rules. This is , so shortest code per language wins.

Examples

[1,2,3], 5/2 -> True
[1,2,3], 3/2 -> False
[23,11,5,1], 1/2 -> True
[1,3,9,29], 10/3 -> True
[5,10,9,11], 2/1 -> False
[1,1], 1/1 -> False
[1], 1/1 -> True
\$\endgroup\$
0
\$\begingroup\$

Output up to n sets of n characters randomly

Given a positive integer n>1, output a random number of n-character strings, ranging from 1 to n strings.

Rules

  • Each string must differ from eachother by at least 1 char
  • Each string must be n chars long
  • Other than that, output strings do not have to be consistent in any way
  • However, our strings must be clearly delimited
  • A "random number" of strings means that each time the program is run with input n, non-deterministically, either 0, 1, 2, 3... up to n strings will be output
  • For smaller inputs, each possible number of strings should be displayed within a reasonable number of trials (to avoid cheesy solutions where one number gets chosen with probability ~1)

Examples

These are examples of valid outputs:

input => output
2 => af 4b
2 => 12 22
2 => ba
3 => WTF TL; VMB
3 => 0l3
3 => 04t <V<
3 => bop bAm
3 => AAA,AAB,AAC
3 => 
000
001
002
4 =>
w la
    
a,v 
 i  
3 => [tip, wor, kf3]

These would be invalid:

input => output
explanation of invalidity

2 => Ca Sa Da
too many strings output for this input

2 => asd sd mo
too many chars in a string for this input

3 => a Bad
too few chars in a string for this input

4 => 1234567890123456
strings are not clearly delimited

3 => 1   2   3   
strings are not clearly delimited

3 => A,B,BCD
strings are not clearly delimited

3 => CO CO LA
two or more strings are identical

Scoring

This is , so shortest code in bytes wins.

Meta

Is this too trivial? Also, can anything be phrased clearer (including the title)?

\$\endgroup\$
0
\$\begingroup\$

Weekday celebration with Doomsday

With the help of the Doomsday rule you can always calculate the day of the week for any date given. It includes any digit year.

Your code should determine which day of the week will be on the Valentine's Day of the given year.

The input is an integer representing the year, and the output is a number representing the day (1 - monday, 2 - tuesday, etc).

Test cases

2001 -> 3
1916 -> 1
41373 -> 7
312631 -> 1
71254065 -> 6
512836172 -> 5
-2735263 -> 3

This is code-golf, so shortest code wins.

\$\endgroup\$
0
\$\begingroup\$

Challenge: Create a program that plays the game of the goose

In this golfing challenge, write a program that simulates the game of the goose. If you don't know how it works, here's a rough explanation of it:

The game takes place on a grid of 63 cells: grid

Each turn, the first player rolls two dice and will *advance (number rolled) cells. Then the second player will roll two dice and do the same as player 1.

If a player lands on a goose, he will move again by the same number of cells.

If a player lands on the bridge, he will move to cell 12.

If a player lands in the tavern, he will skip 2 turns.

If a player's first rolls are 6 & 3, he will go to cell 26.

If a player lands in the well or the prison, he will wait until the other player lands in the same cell. Then the player goes to the other player's former cell.

If a player lands in the maze, he will go to cell 30.

If a player's first rolls are 4 & 5, he will go to cell 53.

If a player lands on death, he will go to the start.

Implementing it

Randomness

The dice rolls represent random numbers; the programming language you use needs to have a way to output (Any output method) and a way to generate random numbers.

Output

The program should output each iteration of the game; Each turn, it should output the player's position. Like this:

Turn 1: 16, 4

The first and second numbers represent each player respectively. When a player wins or after a certain maximum number of turns, the program will stop.

General Rules

  1. The player must be able to win.
  2. Making up your programming language is allowed, provided you made an interpreter available to the public for your programming language.
  3. Don't exploit standard loopholes.
  4. Make sure your code runs in at most 10 seconds.

Recommendations

  1. You should include a link to a website (for example https://tio.run) so that your code can be easily run.
  2. If you're using a compiled language, say which compiler you're using.

It's code golf, so the shortest code wins!

\$\endgroup\$
3
  • \$\begingroup\$ I have no idea why the grid didn't work. I tried to fix it in this edit. \$\endgroup\$
    – kevidryon2
    Feb 11 at 19:27
  • 1
    \$\begingroup\$ I'm too lazy to recreate the grid so here is an image of the grid. \$\endgroup\$
    – kevidryon2
    Feb 11 at 19:43
  • 3
    \$\begingroup\$ You should specify what kind of input/output the answers should have. For example, should the programs output the positions of the players every round until one player wins? \$\endgroup\$
    – AnttiP
    Feb 12 at 18:11
0
\$\begingroup\$

Mountain mapper

\$\endgroup\$
0
\$\begingroup\$

Uncountably long chain of subsets

A chain of subsets (a chain from now on) is a sequence of sets, so that every set is a (strict) superset of every preceding set. For example, here is a chain of length 3:

\$\{1,2\}\subset\{1,2,4,5\}\subset\{1,2,3,4,5\}\$

Chains can also be infinitely long. Here is a countably infinite chain:

\$\{2\}\subset\{2,4\}\subset\{2,4,8\}\subset\{2,4,8,16\}\subset\ldots\subset\{2,4,8,16,32,...\}\$

Your task is to make an uncountably infinite chain, consisting of sets of positive numbers.

Your gut reaction might be that this is impossible. But it's not. For example, consider the real numbers. We can define them as Dedekind cuts (meaning every real number is defined as the set of rational numbers that are smaller than it). Next we can associate every rational number with a positive integer. Now, under the standard ordering of the real numbers, we have a chain of subsets of the positive integers that is uncountably long.

Now that you've picked your favorite uncountably long chain of subsets of the positive integers, it's time to make a program that encodes it.

Your program will recieve two natural numbers. Your program will simply tell whether the first natural number appears before or at the same time as the second one in the chain. Or in other words: for inputs \$a\$ and \$b\$ return true iff \$b\in S\Rightarrow a\in S\$ for all sets \$S\$ in the chain. Your chain must contain every positive integer (however, this doesn't mean that it must contain the set of positive integers).

Bonus points if you achieve a cardinality different from \$2^{\aleph_0}\$

Edit:

Probably not gonna post this challenge as is, because of a rather trivial solution (lexicographic ordering)

\$\endgroup\$
0
\$\begingroup\$

Grid Aligned (Quad?) Linked List

Fluff

I was recently thinking about 2-dimensional linked lists, and realized that they could potentially become unaligned to a grid, unlike a singly linked list. To combat that, I need a program that checks if a quad-list is grid aligned or not, and it needs to be done as short as possible.

Challenge

Given a quad linked-list, return true or false (or any other 2 consistent values) whether or not the 2d list is grid aligned.

Input

Since linked lists can be implemented a variety of different ways in different languages, I'll keep the input format fairly simple. An input consists of tuples (or 4-lists, you can decide) which contain indices that refer to the input. Each tuple contains the indices of the node above, below, left, and right in that order. For nodes where not all directions are connected, the value will be -1.

Note: "above", "below", "left", "right" should be connected in that direction, but may not necessarily do so.

Examples

[(-1, 1, -1, -1), (0, -1, -1, -1)] -> true

0
|
1

[(-1, 1, -1, 3), (0, -1, -1, 2), (-1, -1, -1, -1), (-1, 2, 0, -1)] -> true

0---3
|   v
1 > 2

[(-1, 1, -1, 2), (0, -1, -1, 2), (0, -1, 1, -1)] -> false

0
| \
1--2

[(-1, 1, -1, -1), (-1, 2, -1, -1), (-1, -1, -1, 3), (4, -1, -1, -1), (-1, -1, 0, -1)] -> false

0 < 4
v   ^
1   |
v   |
2 > 3

[(0, -1, -1, -1)] -> false

0
^
0

This is , so the shortest code wins, good luck.

\$\endgroup\$
0
\$\begingroup\$

Determine if a number is base n heavy

Given a positive integer \$n\$ and a base number \$b\$, determine if the number is heavy in that base. A number is heavy if when converted to base \$b\$, has at least \$ \lfloor \log_{10}(n) \rfloor \$ \$b-1\$s on one end. (The left or right.)

Examples

When we convert 100 to base 2 (binary), we get

1100100

\$\log_{10}(100) = 2\$, and there are at least 2 ones (the max number in the base) on one end (the left side).

Scoring

Shortest code in bytes wins!

Test cases

Coming soon.


Feedback?

\$\endgroup\$
2
  • \$\begingroup\$ What do you mean by \$\lfloor \log_{10}(n) \rfloor b - 1 \$? Is this base \$n\$ or base \$b\$? \$\endgroup\$
    – tsh
    Feb 18 at 2:18
  • 1
    \$\begingroup\$ The base 10 logarithm feels a bit arbitrary. This also means that there are no heavy numbers if \$b>9\$ \$\endgroup\$
    – AnttiP
    Feb 18 at 9:10
0
\$\begingroup\$

Posted here

\$\endgroup\$
4
  • \$\begingroup\$ Question: is Python a valid language for this challenge? \$\endgroup\$ Feb 15 at 11:52
  • \$\begingroup\$ At first I wasn't going to allow other languages, but I think I can whip up a command line interface ;) \$\endgroup\$
    – Seggan
    Feb 15 at 15:46
  • \$\begingroup\$ @StackMeterPlus added a protocol \$\endgroup\$
    – Seggan
    Feb 15 at 20:59
  • \$\begingroup\$ you can clear this post now, by adding the link of the question here and deleting everything else \$\endgroup\$
    – DialFrost
    Feb 20 at 1:32
0
\$\begingroup\$

Ragged index of

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

Draw a battery indicator

Posted here

\$\endgroup\$
0
\$\begingroup\$

Implement Scordle

Background

TODO: Explain what Wordle and Scordle are

Challenge

Your task is to implement a modified version of Scordle with lists of numbers.

The input contains the following:

  • The possible numbers 1 to n that can be contained in a guess (think of this like there are 26 letters that can be used in regular Wordle)
  • The number sequence that represents the correct answer (assume that the answer contains only numbers between 1 and n)
  • Optional: the length l (at least 1) of the correct answer
  • The list (length 1 to 6) of the guesses (unlike Wordle, the list doesn't have to end in the correct answer, even if the length of the list is less than 6). Assume all guesses are valid.

Output a list of numbers that represent the number of possible number sequences that conform to all the clues at and before that point.

Example

Let's say that the answer is [3,2,1] and the possible numbers are from 1 to n=3. Before any guesses, there are \$3^3=27\$ possible number sequences that can potentially be the answer:

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

Let's say that the list of guesses is:

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

After the first guess [2,1,3], all of them are yellow. Based on these clues, the remaining possible sequences are listed below:

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

Because there are 2 possibilities remaining, the first element in the output list will be 2.

In the second guess [2,2,2], the middle 2 will be green while the other two 2's are black. This eliminates [1,3,2] and leaves the only possibility [3,2,1]. So the second element in the output list will be a 1.

Any subsequent guesses will not affect the number of possibilities, so for the rest of the guesses, put 1 in the output list.

Scoring

This is , so the shortest code in byte count wins!

Test Cases (TODO)

answer, n, list of guesses, l
--> list of possibilities
--------------------------------
[3,2,1], 3, [[1,2,3],[2,2,2],[3,3,3],[3,2,1]], 3
--> [2,1,1,1]

Meta

  • Suggestions for tags?
  • I haven't put in the Background yet, but for people who already know what Wordle and Scordle are, is the task clear?
  • Suggested test cases?
  • Should I make it so that the guesses always have to end in the correct answer?
\$\endgroup\$
4
  • \$\begingroup\$ I think your list of guesses needs [2,1,3] in the first place. \$\endgroup\$
    – pajonk
    Feb 25 at 19:37
  • \$\begingroup\$ @pajonk "(unlike Wordle, the list doesn't have to end in the correct answer, even if the length of the list is less than 6)". Should I make it so that it has to end in the correct answer? \$\endgroup\$
    – Aiden Chow
    Feb 26 at 5:07
  • \$\begingroup\$ After the fix the part "After the first guess [1,2,3], all of them are yellow" is not true (2 is green). Re: ending in correct answer - I don't have a strong opinion either way. \$\endgroup\$
    – pajonk
    Feb 26 at 6:35
  • \$\begingroup\$ @pajonk oops I meant to keep [2,1,3] as the first guess, not [1,2,3]. As for ending in the correct answer, I think I'll just keep it as is, because if it always end in the correct answer, the last element of the output list will always be 1, but if it doesn't always end in the correct answer, the last element is not always 1, which is more interesting (I think?) . \$\endgroup\$
    – Aiden Chow
    Feb 26 at 7:09
0
\$\begingroup\$

Is it irrational?

Your task is to make a program that decides if a real number is irrational or not. As stated, this is obviously impossible, so instead we will use the following definition:

p is your program, which takes in a decimal expansion of a number (list of integers), and returns 0 or 1. If x is an irrational number, then \$\limsup\limits_{n\rightarrow\infty}p(x[:n])=1\$, and if x is rational the limit superior has to be 0. \$x[:n]\$ means the truncated decimal expansion, which is just the first n digits after the decimal point (the integer component obviously doesn't change the irrationality).

This is , so shortest code wins. Also, standard rules apply, so instead of outputting 0 or 1, you can output true,false, "Yes", "no", etc. As we know, \$0.999...=1\$, so you can assume that the decimal expansion doesn't contain a trail of repeating 9s. Instead of decimal, you can use binary.

\$\endgroup\$
0
\$\begingroup\$

Pick the best seat in a vehicle

We have eight seats in a vehicle, represented by numbers:

1  2  3  4
5  6  7  8

Two people get in. First person will pick the seat X. Number X will be inputted to the program. The second person will pick the furthest seat from the first person. Output (or return, if a function) the seat number which person B will take.

All seats are on the same elevation, and can be represented with two integers in a coordinate grid. The difference between two adjacent seats (horizontally or vertically) is the same between every seat.

For example, if person A chose seat number 7, person B will sit on 1.

1 <= X <= 8

All possible combinations: (the output for specific input is shown directly underneath the input) Input:

1   2   3   4   5   6   7   8

Output:

8   8   5   5   4   4   1   1
\$\endgroup\$
5
  • 1
    \$\begingroup\$ Related: codegolf.stackexchange.com/questions/162337/… \$\endgroup\$
    – tsh
    Mar 8 at 3:29
  • 5
    \$\begingroup\$ Welcome to Code Golf and thanks for using the Sandbox! Could you please add some more test-cases? Please also specify what distance metric are you looking for (I suppose Euclidean distance). You may also explicitly specify what the output is (the seat for person B I presume). \$\endgroup\$
    – pajonk
    Mar 8 at 8:28
  • \$\begingroup\$ Can we take input 0 <= X <= 7 instead? \$\endgroup\$
    – pxeger
    Mar 8 at 17:34
  • \$\begingroup\$ @pxeger That would not make sense as in real life you will never find seats labeled starting from zero \$\endgroup\$ Mar 9 at 14:11
  • \$\begingroup\$ As the input is constrained between 1 and 8, I suggest providing output for all inputs in the test-case section. \$\endgroup\$
    – pajonk
    Mar 9 at 16:29
0
\$\begingroup\$

All empty cells are neighbours

Task

Given dimensions of a 2D grid \$n>1,m>1\$, output the size (number od cells) of the minimal connected region, so that every empty cell is its neighbour.

Cells are neighbouring (or connected) when they share a side, so no diagonal connections.

Background

When putting together jigsaw puzzles with my son, I always try to reach a single connected region of solved pieces such that empty places have at least one piece to connect to. This way he can test every loose piece one place after another, and always find a spot to fit it.

Details

  • You may take \$n\$ and \$m\$ in any reasonable format and output corresponding region size.
  • You may also output as an infinite sequence, as long as you use a bijection of \$\{2,3,\ldots\}\times\{2,3,\ldots\}\$ into \$\mathbb{N}\$ (and provide it in your answer).

Test cases

n=2, m=3 -> 3
Example grid (you don't need to output that):
###
...
n=3, m=4 -> 4
....
####
....
n=4, m=4 -> 8
....
####
####
....
n=4, m=5 -> 9
....
####
...#
####
....
n=2, m>1 -> m
n=3, m>1 -> m

Meta

  • Better title?
  • Better tags?
  • Is the output as infinite sequence well defined?
  • Any mistakes in the examples?
\$\endgroup\$
1
  • \$\begingroup\$ n=2, m=3 -> 2 (.#. \ .#.) \$\endgroup\$
    – att
    Mar 15 at 18:10
0
\$\begingroup\$

Finding an element in an array

Please tell me whether this challenge has been created or is in the sandbox! I tried searching for it, but with thousands of pages, I easily could have missed one.

Your task:

Given an input of an array, and a certain element found in that array, output the coordinates of the element. Output a falsey value if the element cannot be found in the array.

Rules:

  • The array will be made of single (non-space) ASCII characters. The element to be found in the array can be input either before or after the array
e3R5     e
p10-     e3R5
.v!x     p10-
0>3v     .v!x
e        0>3v
  • You must output the coordinates of the element found in the list. The top left corner is (0,0)
(0,0)  (1,0)  (2,0)
(0,1)  (1,1)  (2,1)
(0,2)  (1,2)  (2,2)
(0,3)  (1,3)  (2,3)
  • Keep the x and y coordinates separate. (0,1) and 0 1 and 0,1 are all valid outputs, but 01 is not.
  • You can assume there will not be more than one of the specified element in the array, but other elements may appear more than once.
  • This challenge is case-sensitive!

Test Cases:

e3R5
p10-
.v!x
0>3v
e

Result:(0,0)

43T0*x
\@.2,c
''b%gP
5qQ}#m
q

Result:(1,3)

mW(
iMz
EA/
$"t
a]:
7

Result: (falsey)

-c2?08r,TZTj
"^9LT^*`LFu2
^"~l6-PiyPo8
,f=[aOv50ZnO
`

Result: (7,2)

\$\endgroup\$
0
\$\begingroup\$

Sandbox overflow

\$\endgroup\$
2
  • \$\begingroup\$ It seems awfully similar to your chained compound challenge: here you simply add slashes instead of spaces, and dots instead of spaces, and draw only one "circle". \$\endgroup\$
    – ophact
    Mar 18 at 6:32
  • \$\begingroup\$ hmm ill try to change that. didnt realise it was so similar :/ @ophact \$\endgroup\$
    – DialFrost
    Mar 18 at 6:35
0
\$\begingroup\$

Deterministic oozes

Task

Output the next generation of the input.

These conversions happen if there is food . or : next to them:

"o" → "O"
"O" → "8"
"8" → "oo"

^ These are called oozes.

Rules for eating

  • The food should disappear if it gets eaten.
  • If there is a single food ., with oozes on both sides, the left one eats it.
  • If there is a double food :, with oozes on both sides, both eat one.
  • If there is a double food : with only one ooz beside it, the ooz eats the entire food and advances 2 generations.
  • A food with no oozes on the either side, stays the same.
  • Spaces between oozes should be preserved.

Scoring

Number of bytes, shortest code wins!

Test Cases

"o. o" → "O o"
"oooo.8" → "oooO8"
"8:8" → "oooo"
":8" → "Oo"
"8:" → "oO"
"o:o.o" → "O8o"
"ooo" → "ooo"
"o.o.o" → "OOo"
"o:8:o" → "OoOO"
" .  o o 8." → " .  o o oo"

Meta:

  • Tags?
  • Clear?
\$\endgroup\$
8
  • \$\begingroup\$ There's a lot still missing here. It seems like most the challenge has to be guessed from a handful of test cases. \$\endgroup\$
    – Wheat Wizard Mod
    Jan 24 at 14:54
  • \$\begingroup\$ @WheatWizard ok ill add more test cases tomorrow. \$\endgroup\$
    – PyGamer0
    Jan 24 at 14:55
  • \$\begingroup\$ No that is the opposite of what I am saying. You need to specify the challenge not just add more test cases. \$\endgroup\$
    – Wheat Wizard Mod
    Jan 24 at 14:56
  • \$\begingroup\$ The challenge should be completely understandable with the test cases removed. \$\endgroup\$
    – Wheat Wizard Mod
    Jan 24 at 14:56
  • \$\begingroup\$ @WheatWizard ok i see, will do that tomorrow \$\endgroup\$
    – PyGamer0
    Jan 24 at 14:59
  • \$\begingroup\$ Having multiple generations happen at a time seems contrary to "output the next generation" \$\endgroup\$ Jan 25 at 20:41
  • 1
    \$\begingroup\$ Suggested testcase: "o:o.o" \$\endgroup\$
    – tsh
    Jan 26 at 5:43
  • \$\begingroup\$ Will the input have leading/trailing spaces? How to handle them? Also, the o:8:o test-case is not covered by your specs (or anything like .o.). \$\endgroup\$
    – pajonk
    Mar 23 at 12:27
0
\$\begingroup\$

Given a current page number (p), pages to show (s), and max pages (m), create the classic pagination, marking the current page as active (*) and using ...'s for any outside the range.

For example:

p = 1, s = 5, m = 15

Should output:

1* 2 3 4 5 ... 15

Or

p = 7, s = 5, m = 15 

should output

1 ... 5 6 7* 8 9 ... 15

and

p = 2, s = 5, m = 4 

Should output

1 2* 3 4

It can be assumed that pages to show (s) is always odd, so the active page is often in the middle of the set of numbers.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome and thanks for using the Sandbox! I feel this challenge may be a duplicate of codegolf.stackexchange.com/q/243701/55372 \$\endgroup\$
    – pajonk
    Mar 24 at 14:09
  • \$\begingroup\$ Oh yes... it has some confusion over what the correct output should be for the edge cases as well. Ah well! \$\endgroup\$
    – Djave
    Mar 24 at 15:58
0
\$\begingroup\$

Integer divisors of a decimal number

The input is a decimal number larger than zero, given in decimal form. You can use any unambiguous printable character(s) to enclose or separate a possible repeating part in the input, such as 0._3_, 0.(3) or 0.(3 for \${0.\overline{3}}\$ to represent an exact third.

The output is the pair of the smallest integer dividend and divisor that give the exact value represented by the input. The output format doesn't matter, 1/3, 1 3 and (1,0b011) are all valid for an input value representing an exact third.
Examples:

Input:  1
Output: 1 / 1

Input:  0.(3)
Output: 1 / 3

Input:  1.234
Output: 617 / 500

Input:  1.1(3)
Output: 17 / 15

Input:  3.454(54)
Output: 38 / 11

Input:  3.14159
Output: 314159 / 100000

Input:  3.(142857)
Output: 22 / 7

Input:  12.345(6789)
Output: 10287037 / 833250

Input:  9.(9)
Output: 10 / 1

Reference implementation in Python 3

It does \$12.345\overline{6789} = \frac{12345}{1000} + \frac{6789}{9999*1000} = \frac{123444444}{9999000} = \frac{10287037}{833250}\$

def greatest_common_denominator(a, b):
	while b:
		a, b = b, a%b
	return a

def r(inp):
	x, _, repeating = inp.rstrip(')').partition('(')
	x = x.split('.')
	dividend = int(''.join(x))
	divisor = 10**(len(x[1]) if len(x) == 2 else 0)
	if repeating:
		repeating_nines = 10**len(repeating) - 1;
		dividend = int(repeating) + dividend*repeating_nines
		divisor *= repeating_nines
	d = greatest_common_denominator(dividend, divisor)
	return dividend//d, divisor//d

Try it online!

  • This is , so the lowest byte count wins!
\$\endgroup\$
2
  • \$\begingroup\$ I recommend the title "Integers divided to obtain a decimal number" \$\endgroup\$
    – ophact
    Apr 2 at 6:23
  • \$\begingroup\$ Unfortunately this is a duplicate of Convert a repeated decimal to a fraction. \$\endgroup\$
    – pxeger
    Apr 2 at 11:02
0
\$\begingroup\$

Generate a clue for an arbitrary MultiSoft URL

Here is the program that will verify your output (transcripted into javascript, and modified for my own ease)

Sheet of paper containing a small program in python. Javascript version below

let s = '';
const a = 'your output here'
for(const i = 1; i < a.length; i+=1){
  if (a[i] % 2 === a[i-1] % 2) {
    s = `${s}${Math.max(a[i], a[i-1])}`;
  }
}
if ('your program input' === `www.multisoft.se/${s}`){
   return true;
}

Where you're given 'your program input', which will look like www.multisoft.se/9109382911 and you need to generate an a ('your output here') that generates that URL.

Test cases:

// TODO make test cases

\$\endgroup\$
0
\$\begingroup\$

Wordle but Harder

If you've been online in the last year, you probably know the rules of Wordle. I was implementing a (very bad) Wordle algorithm, when I thought of another game:

Task

One 5-letter word from wordle's answer list is randomly selected. Your task is to guess the word.

Each failed guess gives you one piece of information - the amount of letters in your guess that are also in the word.

For example, if the answer was hello and you guessed loser, you would get 2, because 2 of your letters are in the answer. Conversely, if the answer was loser and you guessed hello, you would get 3, as 3 of the letters in your guess are in the answer.

Scoring

Each guess must be made within 10 seconds. Separate categories for lowest average and lowest worst-case scenario.

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

Draw my shower curtain

I got a shower curtain and it looks cool, so today you get to draw it.

But how do we do this?

I'm glad you asked.

Part 1: the shape

circles

The image shows a blue, red, and green circle. This is a subsection of the pattern. The actual pattern of circles can be imagined by placing a circle of radius 4 at (8i, 8j) and (8k + 4, 8l + 4) for all (i, j, k, l) in the integers.

sectors

This image shows the three circles from the first image, but with two sectors coloured in. These sectors are defined as the area in at least two circles, or the area in a circle centred at (8i, 8j) and in on at (8k + 4, 8l + 4), for (i, j, k, l) in the integers. I would provide a closed form for this, but I don't know one.

more circles and sectors

The above image shows more circles and sectors. In this image, you can begin to see how the pattern fills an infinite grid. For this challenge, you will take two integers as input and output a grid with that many of the pattern on each side. For example, this (specifically the intersections between two circles because I was too lazy):

(3, 1) pattern

is the output for (3, 1), and this (again I didn't mark the sectors because there were too many of them):

(2, 2) pattern

is the output for (2, 2).

As well as this, your image must be at least 800 pixels on each side.

Part 2: the color

shades of grey: #0B, #22, #37, #4E, #66, #7F, #98, #B3, #CF and #EB

The above shows some examples of shades of grey. All of them have the values of their red, blue and green component set to be the same. For your program, you must use all 256 possible shades of grey, with a non-zero chance of each occurring. You may not use any other colours than these.

Since this is , shortest answer wins.

NBs

You may assume both numbers are greater than 0.

You can take width or height first (examples take width first), but say which in your answer.

You are allowed to be +/- 0.1% off.

Meta

Is this well specified?

Anything to change?

\$\endgroup\$
2
  • \$\begingroup\$ 1. What is to be "coloured" with the 256 shades of gray? The circles, the areas, both? What if there are less circles/areas than 256? Nevertheless, I suggest just letting the golfers to choose two distinct colours for background and objects; or three for background, circles and areas. 2. Could you please add at least one test-case that will fully comply with the specs? \$\endgroup\$
    – pajonk
    Apr 7 at 13:25
  • \$\begingroup\$ Ok - on hiatus now, but will fix this later. \$\endgroup\$ Apr 9 at 15:13
0
\$\begingroup\$

Construct integers from 1, -, and (

In this answer, I used only 1, -, and ( to construct any integer (although ( is technically unnecessary) in TI-Basic. Your task is to make a program or function that takes an integer (or a different convenient format to represent it) as input and output the shortest possible string made from 1, -, and ( that will evaluate to the integer in TI-Basic. If there are multiple possible outputs, then choose the one with the least amount of (. If there are still multiple left, then any one of them is valid as an output.

Some things to note:

  • - is the subtraction symbol, not the negative sign.
  • TI-Basic automatically closes all ( at the end.
  • ( can also be used for implied multiplication (e.g. 11(11 is 121)

Rules

  • It should work for numbers from -128 to 127.
  • Standard loopholes apply.
  • This is , so the shortest code in bytes in each language wins.

Test cases

Input    | Possible Output

-128     | 1-(11-1-1-(1-11(11
-124     | 1-111-11-1-1-1
-44      | 11(1-1-1-1-1-1
-5       | 1-1-1-1-1-1-1
-3       | 1-1-1-1-1
-1       | 1-1-1
0        | 1-1
1        | 1
2        | 1-(1-1-1
3        | 1-(1-1-1-1
5        | 11-1-1-1-1-1-1
8        | 11-1-1-1
10       | 11-1
11       | 11
14       | 11-(1-1-1-1-1
18       | 11-1-1-1-(1-11
19       | 11-1-1-(1-11
21       | 11-(1-11
22       | 11-(1-11-1
33       | 11-11(1-1-1-1
43       | 11-(1-11-11-11
78       | 111-11-11-11
123      | 111-(1-11-1-1
127      | 11-1-1-1-1-(1-11(11

If your output is different from the one listed, then it should have the same length and the same amount of (.

Meta

  • Is anything unclear?
  • Are any of the outputs for the test cases incorrect?
\$\endgroup\$
6
  • \$\begingroup\$ Are there any inputs for which there is more than one ( in the output? If that's false, maybe specifying that at most one ( is permissible would make the rules simpler? Or that's just me? \$\endgroup\$
    – pajonk
    Apr 3 at 18:30
  • \$\begingroup\$ @pajonk 127 becomes 11-1-1-1-1-(1-11(11 and -128 becomes 1-(11-1-1-(1-11(11. I suppose I will add those as test cases. \$\endgroup\$
    – Yousername
    Apr 3 at 19:08
  • \$\begingroup\$ Ok, thanks for clarification. \$\endgroup\$
    – pajonk
    Apr 3 at 19:47
  • \$\begingroup\$ But 127 can be done with 1-(-111-11-1-1-1-1? Any nonnegative integer can be made with 1-(1-1-1-1-1-1-1-1-1-1-1-1-... with at most one (, and any negative integer can be made with -1-1-1-1-1-1-... with no (s. \$\endgroup\$
    – pxeger
    Apr 5 at 19:31
  • \$\begingroup\$ @pxeger As stated in the beginning, - is the subtraction symbol, not the negative sign (TI-Basic makes a distinction between the two). The main priority is to make the shortest possible string with 1, -, and ( to represent the number, then to have it have the least amount of ( possible. \$\endgroup\$
    – Yousername
    Apr 5 at 21:45
  • \$\begingroup\$ Maybe you should either move "shortest" to the "Rules" section, or move "If there are multiple possible outputs, then choose the one with the least amount of (. " tie-breaker into the header. Currently, it placed in different places and may be confuse. \$\endgroup\$
    – tsh
    Apr 18 at 8:46
0
\$\begingroup\$

Make a PDF look scanned

META: This challenge still needs more work, including some examples - if you already have suggestions and hints feel free to post them, but due to the nature of popularity contests I definitely want to discuss it again when I added the missing part.

Do you know the situation where you have to print some document, scan it and send the scan back? Let's automate that! Your task is making a program that, given some input, makes it believably look like it was scanned.

A few people have done that before (links see 1 2 3) which inspired this challenge, but they all still look too uniform and pristine in my opinion.

Here some examples of the test file, a real scan and the output of (TODO: use one of these tools):

TODO: add examples of scan artifacts, compare real scan with examples.

Details

  • Validity Criterion: The input and output are raster images of any resolution (they should have the same resolution).
  • For simplicity you can assume that both the input and output are grayscale images.
  • You can assume that the input - no matter the resolution - has roughly the size of an A4 or Letter page.
  • You should run your program on the test image below, and include it in your submission using <img src="[image ]" width="400" alt="processed" /> (TODO: determine exact format), but you can also include other examples to illustrate the inner workings.
  • You are encouraged to explain how your program processes the image.

TODO: Add test image.

\$\endgroup\$
2
  • \$\begingroup\$ IMHO, It's going to be difficult to specify well, but sincerely: good luck. I think it might be worth adding some suggested requirements (see comment below your link 2). \$\endgroup\$
    – pajonk
    Apr 20 at 9:27
  • \$\begingroup\$ Thanks:) I intend to add some images that actually show examples of artifacts like the ones you mentioned (I'm planning to actually make some prints/scans). But only as suggestions, as in my experience for this kind of challenge compulsive requirements really must be measurable objectively to work well. And thanks for your input, I'll let you know if/when I update the draft! \$\endgroup\$
    – flawr
    Apr 20 at 10:05
0
\$\begingroup\$

Heapify a List into a Binary Max Heap

Given a list of integers, write the shortest program or function that will heapify the list into a binary max-heap, and return the heap as a list of integers.

Additional Resources

Additional Rules

Tags:

\$\endgroup\$
2
0
\$\begingroup\$

Multiples Game

Given an array of divisors A, loop n from 1 to infinity and do one of the following:

  • If n is divisible by an even number of divisors of A, print out n
  • If n is divisible by an odd number of divisor(s) of A, print out * (clap)

Examples

Input:

A = [3, 5]

Output:

1
2
*
4
*
*
7
8
*
*
11
*
13
14
15
16
17
*
19
...

Input:

A = [2, 3, 5]

Output:

1
*
*
*
*
6
7
*
*
10
11
12
13
*
15
*
17
18
19
...

Input:

A = [3, 6]

Output:

1
2
*
4
5
6
7
8
*
10
11
12
13
14
*
16
17
18
19
...

Rules

  • Fetching outer sources are forbidden
  • UTF-8 encoding
  • A newline count as 1 byte (UNIX newline)
  • The answer with the least bytes wins
\$\endgroup\$
0
\$\begingroup\$

Shift a string gradually

\$\endgroup\$
12
  • \$\begingroup\$ Surely the output for the first test case should be bdf. \$\endgroup\$
    – chunes
    Apr 21 at 22:02
  • \$\begingroup\$ @chunes fixed.. \$\endgroup\$
    – Bgil Midol
    Apr 22 at 0:08
  • \$\begingroup\$ I suggest adding a test case that requires wrapping. \$\endgroup\$
    – chunes
    Apr 22 at 20:28
  • \$\begingroup\$ @chunes implemented \$\endgroup\$
    – Bgil Midol
    Apr 22 at 20:30
  • \$\begingroup\$ Suggested test cases of length other than 3. How to treat empty string? \$\endgroup\$
    – pajonk
    Apr 23 at 15:17
  • \$\begingroup\$ @pajonk done, i hope i didn't write the wrong result \$\endgroup\$
    – Bgil Midol
    Apr 23 at 15:24
  • \$\begingroup\$ Last test case output should be "bdfhjlm" right? \$\endgroup\$
    – ophact
    Apr 25 at 14:39
  • \$\begingroup\$ @ophact fixed it \$\endgroup\$
    – Bgil Midol
    Apr 25 at 15:08
  • \$\begingroup\$ Wait actually it's bdfhjln \$\endgroup\$
    – ophact
    Apr 25 at 15:10
  • \$\begingroup\$ @ophact fixed it \$\endgroup\$
    – Bgil Midol
    Apr 25 at 15:13
  • \$\begingroup\$ You should remove all but the title, which should be linked to the posted challenge. Then delete this post. \$\endgroup\$
    – Adám
    Apr 26 at 6:47
  • \$\begingroup\$ @Adám fixed it. \$\endgroup\$
    – Bgil Midol
    Apr 26 at 13:03
0
\$\begingroup\$

Split given integer into a given number of integers, each within given bounds

Input variables:

(Names are just examples, they don't need to be named like this)

  • GrandTotal - integer to divide
  • SplitCount - number of output integers required
  • UpperLimit - highest valid value for any one output integer
  • LowerLimit - lowest valid value for any one output integer

There must be SplitCount values returned, each of which is a uniformly random integer between UpperLimit and LowerLimit (your language's RNG is fine), the sum of which is GrandTotal.

Also, the order of the output matters: 5,8,7 is not an equal set to 5,7,8. Both outputs must be equally likely if either is possible.
(This does mean that output where all three integers are the same is less likely output to one where all three are different: Given GrandTotal=6, SplitCount=3, UpperLimit=4, LowerLimit=1, a set including 1, 2 and 3 can appear in 6 different configurations, while a set of all 2s can only appear in one, making it 6 times as likely that one of the varied sets will appear, rather than the set of 3 2s.)

Assumptions:

Any input variables should work, assuming that the following is true

  1. UpperLimit * SplitCount >= GrandTotal
  2. LowerLimit * SplitCount <= GrandTotal
  3. all input variables are positive integers.

Sample in-out range

GrandTotal SplitCount UpperLimit LowerLimit Possible Output Range
11 2 10 2 10,1;9,2
8 3 11 2 2,3,3;3,2,3;3,3,2;2,2,4;2,4,2;4,2,2
13 2 8 4 8,5;7,6;6,7;5,8
16 2 8 4 8,8
16 2 10 4 10,6;9,7;8,8;7,9;6,10
16 4 10 4 4,4,4,4

\$\endgroup\$
13
  • \$\begingroup\$ I don't think I've ever seen a question that specifies language, but couldn't see anything in the help that said it shouldn't... \$\endgroup\$ Apr 28 at 4:14
  • \$\begingroup\$ Language-specific challenges are technically allowed, but make sure that this challenge utilizes some language-specific feature, and that it's not just arbitrarily restricting to this one language. I don't know enough about SQL to fully judge this challenge, so you will have to make your own judgement call on this. \$\endgroup\$
    – Aiden Chow
    Apr 28 at 4:28
  • \$\begingroup\$ @AidenChow Practically, it's SQL because I have a yucky version of this I'm using at the moment in a SQL environment, and I want to see just how un-yucky it can get, but it did seem like a reasonably valid code-golf idea based on my limited experience of this stack, so thought I'd give it a bash. Given that there are some limitations on the specific built-in functions you have in SQL that other languages don't share, opening up the languages to other ones would be less useful for me... \$\endgroup\$ Apr 28 at 4:48
  • \$\begingroup\$ @AidenChow also I'd be very interested to see if anyone has really simple/fast ways of adding other language-code in, like a shortcut CLR function (a concept I definitely need to become more familiar with...) \$\endgroup\$ Apr 28 at 4:51
  • \$\begingroup\$ Code golf isn't really the place to go to if you are looking for "un-yucky" code; code golfers will do any atrocity you can think of in order to shorten the length of their code, most times sacrificing readability and actually making "yuckier" code in most cases. Though if you are fine with that, then I don't see anything inherently wrong with this challenge. You could definitely add some test cases though. \$\endgroup\$
    – Aiden Chow
    Apr 28 at 4:54
  • 1
    \$\begingroup\$ Actually now that I'm looking at it, there are some things wrong with this post. First, you need to indicate what the winning criterion is, whether that be code-golf, code-challenge, or something else entirely; this is required for ALL code golf challenges. Second, as I stated in my comment above, you definitely should add some test cases, so that people attempting this challenge can easily test their code. Third, it is recommended that you add a short worked example for an example test case. Just a short explanation would suffice. \$\endgroup\$
    – Aiden Chow
    Apr 28 at 5:02
  • \$\begingroup\$ Oh wait sorry, I didn't read the challenge fully; it's random, so there are no set test cases. In that case, just include an example input and a possible output, and a short explanation. \$\endgroup\$
    – Aiden Chow
    Apr 28 at 5:12
  • \$\begingroup\$ @AidenChow better or worse? \$\endgroup\$ Apr 28 at 9:07
  • \$\begingroup\$ It's better, though I fear that with a scoring system with that many rules, there is bound to be some ambiguity that's going to arise when people actually start attempting the challenge and scoring their programs. I don't know enough about this particular language though, so I will leave it up to others to give a better judgement on this. My gut feeling is that there are just way too many rules for scoring; I haven't seen a scoring system in a challenge with quite as many rules as this before. \$\endgroup\$
    – Aiden Chow
    Apr 28 at 9:13
  • 1
    \$\begingroup\$ Also, it is pretty standard to include the tags you are going to apply to this challenge when you are going to post it to the main website. You can add a tag like so: [tag:(tag name)]. With a complex scoring system like your challenge, I think you may want to add the code-challenge or maybe the atomic-code-golf tag (I'm not too sure how applicable this tag is to your challenge, though; as I said, I'm not entirely familiar with SQL). \$\endgroup\$
    – Aiden Chow
    Apr 28 at 9:19
  • \$\begingroup\$ @AidenChow thanks, was wondering how to add that. \$\endgroup\$ Apr 28 at 9:21
  • \$\begingroup\$ Good as a language-agnostic solution? \$\endgroup\$ Apr 28 at 10:59
  • \$\begingroup\$ You may also like to add [tag:random]. Also, consider specifying what kind of randomness are you looking for (be it uniform, any other or leave it to the golfers). \$\endgroup\$
    – pajonk
    Apr 28 at 19:40
1
116 117
118
119 120
131

You must log in to answer this question.

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