572
\$\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".

\$\endgroup\$
0

4668 Answers 4668

-3
\$\begingroup\$

Create a "Transpiler"

for the purpose of this challenge, a transpiler is any program that takes valid source code from one language as input and produces a program valid in another language that performs the same actions. Calling the original languages interpreter is not banned.

Posts should start with "SRCLANG to DSTLANG in LANG; X bytes" as a heading.

Here's an example post:

Shell to Ruby in Ruby; 41 bytes

puts'`bash #{Data}`
__END__
'+STDIN.read

Here we use the somewhat obscure Data constant to embed arbitrary data in the program. this has the advantage of never having to escape anything.

Each "triple" of source, destination, and working language represents its own category, as this challenge varies greatly in difficulty depending on the languages used.

\$\endgroup\$
5
  • \$\begingroup\$ What is the winning criterion? Are there requirements for the languages used? \$\endgroup\$ Nov 6, 2020 at 23:09
  • \$\begingroup\$ @RedwolfPrograms lowest byte count, as usual. I guess no strict subsets as well, so you can't say cat is a sh to bash transpiler \$\endgroup\$
    – binarycat
    Nov 6, 2020 at 23:24
  • \$\begingroup\$ How would this be consistently graded? I don't get how this is fair to all answers. \$\endgroup\$
    – Razetime
    Nov 7, 2020 at 3:35
  • \$\begingroup\$ Is g++ a C++ to x86 assembly transpiler? "this challenge varies greatly in difficulty depending on the languages used" I'd say it varies in difficulty way too much. \$\endgroup\$ Nov 7, 2020 at 7:08
  • \$\begingroup\$ @thedefault. Yes, but it's far from trivial. As for variation, like I said, each "triple" of languages forms it's own category. If it's necessary to have 1 winner, I guess it could be popularity-contest. \$\endgroup\$
    – binarycat
    Nov 8, 2020 at 21:35
-3
\$\begingroup\$

I have the following code. Help me make it code shorter.

new Promise(r=>r(URL.createObjectURL(new Blob(['<h1>Example</h1>'],{type:'text/html'})))).then(u=>open(u)&&setTimeout(t=>URL.revokeObjectURL(u),2e3))

The Catch:

  • This has to be in JavaScript
  • It cannot contain semicolons
  • It must be a "one-liner"
  • It must have the same steps as the code above:
    1. Create a blob URL from a blob
    2. Open a browser window of the blob URL
    3. Revoke the blob URL

Extras

  • The winner will be decided by the shortest amount of bytes
  • If you try this in another language, you will still get an upvote
\$\endgroup\$
-3
\$\begingroup\$

Most digits of Pi in a hundred bytes

\$\endgroup\$
3
  • 4
    \$\begingroup\$ It's likely possible to output infinitely many. \$\endgroup\$ Jan 19, 2021 at 3:09
  • \$\begingroup\$ @thedefault. how? \$\endgroup\$
    – someone
    Jan 20, 2021 at 0:46
  • 2
    \$\begingroup\$ By using one of the many known formulas for pi. And if you do not use a formula for pi, you're compressing random digits (it's possible to store around 240 digits like this). codegolf.stackexchange.com/q/47808 has multiple answers below 100 bytes. \$\endgroup\$ Jan 20, 2021 at 1:52
-3
\$\begingroup\$

Reinvent math

The task is simple. Define the basic operators (+, -, *, /) without using them directly.

Also banned:

  • any add-assign (+=) and its equivalents
  • basically anything intended to be used as a basic arithmetic operation

Program should consist of at least 4 binary functions, one for each operation. they may call other functions defined in your program, including each other. The types of the arguments to the function may be any types that the basic arithmetic operators work on, except for types that are less than 3 bits in size.

Shortest code wins

\$\endgroup\$
17
  • \$\begingroup\$ Thank you for using the sandbox. Have you considered stating the required argument domain? And how should one answer? Using for functions/programs with the total length being the score? Can the four share code? \$\endgroup\$
    – Adám
    Feb 8, 2021 at 19:35
  • \$\begingroup\$ Also, what does "using them directly" mean? Does that mean we can't use those four symbols or their equivalents in whatever language we use? And do we implement them for integers or floating-point numbers? \$\endgroup\$
    – user
    Feb 8, 2021 at 19:43
  • 1
    \$\begingroup\$ If our language allows e.g. using _plus_ instead of +, is that allowed? \$\endgroup\$
    – Adám
    Feb 8, 2021 at 19:45
  • \$\begingroup\$ @user I feel like it it's fairly clear what "using them directly" means. I can't really think of an alternative interpretation. Any numeric type which the basic operators work on will do. For most c-derived languages, this will be floats and ints. \$\endgroup\$
    – binarycat
    Feb 8, 2021 at 19:54
  • \$\begingroup\$ @binarycat It's not clear to me - I can't tell if you're talking about those four specific symbols or the equivalent operators in the answer's language (if there is an equivalent operator). Also, could you add to the draft that any numeric type will do? \$\endgroup\$
    – user
    Feb 8, 2021 at 19:57
  • 1
    \$\begingroup\$ Are we allowed to use the basic operators in each others' definitions, e.g. plus(x,y)=x--y? \$\endgroup\$
    – Adám
    Feb 8, 2021 at 20:15
  • \$\begingroup\$ @Adám Ideally, the operator will behave the same as the builtin, but if that's not possible due to restrictions in the language, that's ok. Also, no _plus_ wouln't be allowed. That is still using the basic operator of addition. \$\endgroup\$
    – binarycat
    Feb 8, 2021 at 20:19
  • \$\begingroup\$ @binarycat OK, that's useful information (i.e. it should be included in the challenge specification). \$\endgroup\$
    – Adám
    Feb 8, 2021 at 20:29
  • \$\begingroup\$ Are we allowed to use the corresponding operations in a different language than the one we're answering in, i.e. to call out? \$\endgroup\$
    – Adám
    Feb 8, 2021 at 20:31
  • \$\begingroup\$ Pro-tip: I note that you have never posted any challenges. restricted-source challenges are notoriously difficult to get right. I'm not saying this is a bad challenge, not at all, but I highly recommend posting a few well-received standard code-golf challenges before attempting a restricted-source one. \$\endgroup\$
    – Adám
    Feb 8, 2021 at 20:33
  • \$\begingroup\$ @Adám the post has been updated to reflect the fact that the answer is no \$\endgroup\$
    – binarycat
    Feb 8, 2021 at 20:34
  • \$\begingroup\$ @Adám It's really not restricted source, just the "no using a builtin that does exactly what the challange says" loophole. \$\endgroup\$
    – binarycat
    Feb 8, 2021 at 20:36
  • 5
    \$\begingroup\$ This is a textbook example of a "do X without Y" challenge and simply isn't considered interesting on this site. \$\endgroup\$
    – Beefster
    Feb 8, 2021 at 20:48
  • 2
    \$\begingroup\$ @binarycat You seem very convinced that this isn't do-X-without-Y. I'd be very interested in hearing why you think so, especially considering that your text literally says "Define [=do] the basic operators (+, -, *, /) [=X] without using them directly [=Y]." \$\endgroup\$
    – Adám
    Feb 8, 2021 at 21:47
  • 1
    \$\begingroup\$ Essentially a duplicate of Add without addition, as the same techniques can be used to define all four operators. \$\endgroup\$
    – Bubbler
    Feb 8, 2021 at 22:54
-3
\$\begingroup\$

Enumerate all possible IPv4 addresses

Title might make the challenge hard, but it's easy.

You have to print all the possible IPv4 addresses from 0.0.0.0 to 255.255.255.255

Standard loopholes apply, no internet usage for this

Tags: ,,

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

Google search

Challenge is very simple, you have to get a string as input and then launch the default web browser, and search for that string in Google.

Input string will have only characters a-zA-Z

Google search URL is google.com/search?q=querystring

Standard loopholes apply, Internet connection allowed, but only to google.com domain

Tags: ,


Author note: challenge title sucks, please improve it!

\$\endgroup\$
7
  • 1
    \$\begingroup\$ I suspect on many (older) systems the notion of a default browser does not exist. In addition, I think there are many other escape characters. Of course, you could allow the answers to fail - but without the encoding requirements this is probably a dupe of some old basic internet challenge. \$\endgroup\$ Feb 20, 2021 at 18:08
  • 1
    \$\begingroup\$ Also, %20 is not the right escape sequence for a + \$\endgroup\$
    – pxeger
    Feb 20, 2021 at 19:00
  • \$\begingroup\$ @FryAmTheEggman The first one is not really an issue, if the programming language doesn't have the thing then it can't have an answer. \$\endgroup\$
    – DELETE_ME
    Feb 24, 2021 at 3:55
  • \$\begingroup\$ For the challenge: it's best to specify which characters might appear in the input. \$\endgroup\$
    – DELETE_ME
    Feb 24, 2021 at 3:56
  • \$\begingroup\$ @FryAmTheEggman,user202729 edited, now input will only have a-zA-Z \$\endgroup\$
    – Wasif
    Feb 24, 2021 at 17:30
  • \$\begingroup\$ Most languages can't launch a browser. Also, there are dozens like this already, \$\endgroup\$
    – emanresu A
    Feb 25, 2021 at 4:04
  • \$\begingroup\$ Sorry, I missed your edit earlier. I think if you want to go ahead with this you need to define what the "default browser" is, and what to do if it isn't present. Depending on how you define it, this may not be a dupe, but I imagine you will have some trouble with different systems defining it differently. \$\endgroup\$ Mar 3, 2021 at 19:03
-3
\$\begingroup\$

Reverse error quine

,

Based on this

Write a quine that prints it own source code in reverse, but to STDERR.

Penalties

  • +200 using other files I.E. reverse.txt
  • +150 internet usage
  • +100 reading own source code

Rules

  • Minimum length of source is 2 bytes

  • Standard loopholes apply

, shortest code wins

\$\endgroup\$
6
  • 3
    \$\begingroup\$ As a reverse error quine, it will probably just be basically the same as a plain error quine, but with the creative solutions using syntax errors not valid. The things with penalties should probablly just be disallowed or someone will just do sh, 6 bytes + 20 penalty, tac $0. You can also add [tag:quine] \$\endgroup\$
    – Wezl
    Feb 24, 2021 at 17:45
  • 4
    \$\begingroup\$ But thanks for using the sandbox! \$\endgroup\$
    – Wezl
    Feb 24, 2021 at 17:46
  • \$\begingroup\$ Why the rule No palindromes? Aside from Stack Cats, there are pretty much no languages that print a palindromic error. \$\endgroup\$
    – emanresu A
    Feb 25, 2021 at 4:07
  • \$\begingroup\$ Changed the rules: 1) Increased penalty (None will not now dare to read own source code) 2) Palindromes allowed 3) Added the tag quine \$\endgroup\$
    – user101036
    Feb 25, 2021 at 7:45
  • \$\begingroup\$ Penalty in code golf is discouraged by itself, just like bonuses. Accessing the internet/other files/the source file itself to get the desired output is already considered a standard loophole, so you should just say they're not allowed, and remove the penalties altogether. \$\endgroup\$
    – Bubbler
    Feb 25, 2021 at 8:06
  • \$\begingroup\$ Also, another thing to avoid: using old challenges as a model. \$\endgroup\$
    – Bubbler
    Feb 25, 2021 at 8:11
-3
\$\begingroup\$

“Simple” Programming Homework


Your friend has been caught sleeping in class again! As punishment, his computer science teacher has assigned him homework, knowing that he will not be able to solve it due to not having paid any attention.

The assignment seems deceiving simple at first; all that is required is to output the string:

John Doe

Unfortunately, the teacher is intent on making the simple assignment much more difficult. Since your friend was not listening when the teacher explained the concept of strings and numbers, the teacher forbids him from using any number character (0-9) or the quotes (", ', `).

Can you help your friend solve this problem with the shortest code possible, and save his computer science grade in the process?

Try to find the shortest code in each language!

Note: it is encouraged to try to solve this problem in languages where string/character literals exist but cannot be used due to the restrictions (most mainstream languages are like this, e.g. C++).

\$\endgroup\$
5
  • \$\begingroup\$ Better leaving it here for a while (and ask in chat often) to see if people mostly agree that what "literal" means is obvious. (see, bash have echo John Doe and BF has +++something+++., and most languages doesn't have a formal specification to define English names for the components of the language) \$\endgroup\$
    – DELETE_ME
    Feb 27, 2021 at 12:18
  • \$\begingroup\$ Other than that (huge) point it is clear enough. [please review other sandbox posts] \$\endgroup\$
    – DELETE_ME
    Feb 27, 2021 at 12:19
  • \$\begingroup\$ @user202729 Ask which chat? \$\endgroup\$
    – user101295
    Feb 27, 2021 at 22:14
  • \$\begingroup\$ @user202729 I thought this would be interesting for most languages that do use quotes for string and character literals like C, but I do see how it might be too easy in some languages. \$\endgroup\$
    – user101295
    Feb 27, 2021 at 22:54
  • 1
    \$\begingroup\$ chat.stackexchange.com/rooms/240/the-nineteenth-byte \$\endgroup\$
    – DELETE_ME
    Feb 28, 2021 at 6:13
-3
\$\begingroup\$

Geometry Dash Clone in a weird Way?

Try to make a functional clone of Geometry Dash in the shortest time.

How GD Works.

  • You have a cube. In the clone, it can be as small as you want, but no bigger than 2x2.
  • You have to jump over spikes. The key to do this is (preferably) the up arrow key, but can be any option you want (simply tell me in your answer what key is it.
  • If you touch the spikes, the screen says "Game Over." and exits in 3 seconds.
  • There are blocks! You can jump on them, but touching them from the left side results in the same thing that happens if you touch the spikes.
  • A song plays in the background. How you do this is up to you.

Rules:

  1. 3 Extra points for working forwards and backwards.
  2. Must have the letter a 5-7 times and no q at all!
  3. Allows ascii art type output and text input (standard input)!

Sandbox Questions

How is this even going to work?

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to codegolf! I don’t really recommand to compare how fast submit time after question release, since there maybe someone out there already holding an answer, and it also really timezone dependent. \$\endgroup\$
    – okie
    Dec 2, 2021 at 5:41
  • \$\begingroup\$ But it could be one of the code-golf problem, and allowing ascii art type output and text input (standard input) could allow more language to compete. \$\endgroup\$
    – okie
    Dec 2, 2021 at 5:42
  • \$\begingroup\$ also the flawless limit is kinda weird, extra point for certain language is not suggested, if you still want to give extra point, you may want to say how much extra point is. \$\endgroup\$
    – okie
    Dec 2, 2021 at 5:48
-3
\$\begingroup\$

Get Floor of N ^ (3 / 2)

Your task is very simple:

Get The Floor of N ^ (3 / 2)

OEIS

This is Code Golf so the winner wins

Test Cases

0 => 0
1 => 1
2 => 2
3 => 5
4 => 8
5 => 11
10 => 31
13 => 46
27 => 140
33 => 189
49 => 343
68 => 560
89 => 839
98 => 970
100 => 1000
136 => 1586
256 => 4096
500 => 11180
147385 => 56582212

Meta

  • Any feedback?
\$\endgroup\$
-3
\$\begingroup\$

Who Loses The number guessing game?

You are playing a number guessing game. You know everyone's guesses, and who won, and want to figure out who was in last place.

Task

Your task is to take a dictionary of guesses as input, along with the name of the winner. You should then return the name of the player whose guess was the farthest from the winner's, or if there are multiple, the lowest.

A input:

[{"Joe": 800, "Mama": 1000, "Biden": 1200}, "Joe"]

Means that the aproxximate score winner is Joe, The next is Mama, Mama is greater than Joe and Mama is greater than Biden.

So the loser is Biden.

All guesses are guaranteed to be unique

Test cases

[{"A": 100, "B": 200, "C": 300}, "A"] => "C"
[{"Hello": 200, "World": 201}, "World"] => "Hello"
[{"Blah": 210, "Bruh": 984, "Boo": 314}, "Boo"] => "Bruh"
[{"A": 6, "B": 7, "C": 666, "D": 1000}, "C"] => "A"
[{"AC": 100, "BE": 200, "CE": 300}, "B"] => "CE"

Meta

  • Any feedback?

  • Dupe?

\$\endgroup\$
1
  • \$\begingroup\$ What's the point of having this weird input format? Why not just take and return indices? \$\endgroup\$
    – ophact
    Jan 23, 2022 at 10:36
-3
\$\begingroup\$

Convert decimal to unary in fewest regex codes

Your task is to Convert decimal to undary in fewest regex codes

Every regex code is substitution mode.

The regex code counts the regex code, without test string and Substitution code

A example

^2, |11
^3, |111
^4, |1111
...
\|, <empty>

This scores infinity, But don't try this.

Rules

  • Your score is always non-infinity

  • Any flavor is allowed.

  • Your score is the number of regex codes

  • every length of regex code is non-infinite

Meta

  • Any feedback?
\$\endgroup\$
1
  • 2
    \$\begingroup\$ Can you add an explanation of what exactly a "regex code" is? \$\endgroup\$
    – AnttiP
    Jan 23, 2022 at 17:30
-3
\$\begingroup\$

Nth Eights Challenge

Inputs:

There are 2 inputs: The amount of eights to be used in the calculation, and the number to solve for.

What to solve:

The program needs to insert operators in between each eight, so when the newly created equation is calculated, the answer is the number that was trying to be solved for. When the equation is calculated, there is no operator priority.

Rules:

The only operators allowed are:

+
-
*
/
(And parentheses)

You may insert multiple operators between each number. No extra numbers are allowed. There must be an operator inserted in between each 8. The answer must be displayed when the program finishes.

Examples:

#User inputs
Amount of eights: 4
Solve for: 15

#Answer
8+8-8/8
#User inputs
Amount of eights: 4
Solve for: 10

#Answer
(8+8)/8+8

Winning Criteria:

The winning criteria is for the program written in the least amount of characters.

\$\endgroup\$
3
  • \$\begingroup\$ 0. What is winning criteria for this question? Code-golf or fastest code? 1. What operators are allowed? May I insert multiple operators between two 8s or may concatenation two 8s without any operator? 2. Is operator priority considered? 3. How fast should it be? Define by time usage on specified (batch of) testcases? Or defined by algorithm time complexity? 4. Language specified challenges are generally unwelcome on this site. \$\endgroup\$
    – tsh
    Jan 27, 2022 at 8:56
  • \$\begingroup\$ Related, related. \$\endgroup\$
    – Dingus
    Jan 29, 2022 at 1:35
  • \$\begingroup\$ Do you mean "characters" or "bytes"? \$\endgroup\$
    – ophact
    Jan 31, 2022 at 12:46
-3
\$\begingroup\$

Get the Nth line

Challenge

Let's have a file f and a number n. Your task is to get the nth line from the file.

Constrains

  • file f exists and has at least n lines
  • you can index lines from 0 or 1, whichever you prefer

Example

  • input: n = 2 (indexing from 1) and content of file f is:
foo
bar
baz
  • output: bar

Rules

\$\endgroup\$
2
  • 2
    \$\begingroup\$ I thought the entire point of this sandbox was to get feedback. Down-votes without any comment is the complete opposite. \$\endgroup\$
    – matusf
    Feb 18, 2022 at 15:28
  • 1
    \$\begingroup\$ I think the downvotes here are just because it's not a very interesting challenge. There are no comments because there's nothing actually wrong with your post, so no feedback to really give, but people just don't think it's interesting for code-golf. You could post it and I don't think it would get closed or anything, but it wouldn't get many upvotes. Thank you for using the sandbox nonetheless. \$\endgroup\$
    – pxeger
    Feb 19, 2022 at 9:35
-3
\$\begingroup\$

Knight mover

Your task is to move a chess knight between the points B and E.

A chess knight moves in an L shaped pattern, like so:

.X.X.
X...X
..B..
X...X
.X.X.

The Xs mark where the knight in position B can move.

There may be other chess pieces on the board, blocking the knight's movement, but for clarity, you will only be notified of where you cannot go by # characters. You cannot land on these marked spaces, but you can go over them. You also cannot go outside of the board.

Your goal is to find how many turns N are needed to go from B to E, or return -1 if it can't be done.

Input & Output

  • You are given 2 integers W and H giving the width and height of the board
  • For the next H lines, you are given a row of the board, containing the characters B, E, . and #
  • You are allowed to take in the input as a WxH board as a list of strings or a character matrix

Test case

3 2
..E
B..
->
1


5 5
B...E
..#..
.....
.....
.....
->
4


7 5
B..###.
####.##
...###E
..#.#.#
.#..#..
->
4


8 8
....#...
....##..
..E..#..
#...##..
.###....
........
........
.....B..
->
6

This is code-golf, so shortest code wins!

Credits to this puzzle

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

Game of GO

Go is an abstract strategy board game for two players, in which the aim is to surround more territory than the opponent.

Given a board (where some stones are already added) and a list of moves to be executed next, check whether the moves are valid and (if they are valid) execute them.

After executing all moves in the list the expected output is either not valid if at least one of the moves is invalid, or the new state of the board after all moves were executed.

Rules of Go:

  • Two players place stones of their color (by turns)
  • If a stone is completely surrounded by stones of the other player (or by the edge of the field) this stone is beaten and is removed from the board
  • If stones of the same color are placed next to each other they build a group
  • If the group is completely surrounded by stones of the other player (or by the edge of the fields) this group is beaten and all of its stones are removed from the board
  • A stone can be placed on every free field on the board except for:

A position in which it would be completely surrounded by the stones of the other player (no suicidal moves allowed). Except this move beats some other stones which leads to it not being surrounded anymore

A position that would create the same board that was there before the other player made his move (to prevent an infinite loop of killing stones) which is named KO-rule (see a test case for an example)

  • Points (which are not important for this puzzle) are made by empty fields that are surrounded by the stones of a player or by enemy stones that are beaten

For a more detailed description please visit here

Input & Output

  • You are first given an integer S for the size of the field (the field is a square of S×S)
  • You are then given an integer M for the number of moves that are to be made on the board
  • You are then given a line of the board where . is an empty field, B is a field with a black stone and W is a field with a white stone on it (each line contains S characters) for the next S lines
  • You are then given a move that is described by the player color, and the position (separated by a space character)
  • Output the expected output, else output any character you want
  • You are allowed to output the board as a matrix/list
  • You may assume the initial board state in the input is always valid
  • You are allowed to take in the input as a list/array of lines and moves

Testcases

5
5
.....
.....
.....
.....
.....
B 2 2
W 2 3
B 3 2
W 3 4
B 4 3
->
.....
.....
..BW.
..B.W
...B.


5
7
BB...
B....
.....
...W.
.....
B 3 2
W 0 2
B 3 4
W 2 0
B 2 3
W 1 1
B 4 3
->
..W..
.W...
W..B.
..B.B
...B.


5
1
.....
.....
..B..
.....
.....
B 2 2
->
0


5
5
.BW..
BW...
.W...
.....
.....
B 3 4
W 4 4
B 3 3
W 2 0
B 0 0
->
0


5
3
..B..
.B.B.
.WBW.
.BW..
.....
B 3 3
W 1 2
B 2 2
->
0


5
7
.B...
BW...
WB..W
...W.
...BW
B 3 4
W 0 2
B 0 3
W 0 0
B 1 2
W 0 1
B 1 0
->
...B.
B.B..
WB..W
...WB
...B.

This is code-golf, so shortest code wins!

Credits to this puzzle

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

Beaker drawing

Your task is to output the following beaker with the volume n:

_
 %      %
%       %
%       %
%       %
%       %
%%%%%%%%%

You are the fill n spaces of the beaker above, so n=5 looks like this

_
 %      %
%       %
%       %
%       %
%-----  %
%%%%%%%%%

Even though this defies the law of physics, you are to output the beaker with the liquid of n volume. The volume of the beaker is 35. The first 4 layers have a volume of 7 and the top has a layer of 6, and the _ represents an additional volume of 1 if the beaker overspills.

Test cases

34
->
_
 %------%
%-------%
%-------%
%-------%
%-------%
%%%%%%%%%

35
->
-
 %------%
%-------%
%-------%
%-------%
%-------%
%%%%%%%%%
(Note the `_` becomes a `-`)

15
->
_
 %      %
%       %
%-      %
%-------%
%-------%
%%%%%%%%%

You may assume n is positive (can be 0)

You may assume the beaker can overspill

You may perform the "flood fill" from left to right bottom to top or right to left bottom to top.

This is code-golf, so shortest code wins!

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

Play an audio file

Challenge

Your challenge is simple: play an audio file at a given path. Your program will take the file path as input and will play it once and quit.

To make this harder, however, you are not allowed to use external libraries, but modules that are part of your language's standard library (such as ctypes below) are allowed.

Rules

  • Standard loopholes are forbidden.
  • You may assume (a) specific operating system(s) and/or (a) specific file format(s).
  • You may assume an absolute path.
  • You do not have to hear the sound every time; you are not expected to unmute muted speakers, and you can play through whichever audio device is the most convenient. However, it must be possible to hear it every time you run it with certain settings. A window such as Control Panel -> Sound -> Playback on Windows must always be able to "show" the sound being played under at least one audio device. You are allowed to play the file under a different device each run.
  • Your program must be able to play at least one of the audio file formats listed on Wikipedia. Other formats are allowed, as long as one of the formats listed there is supported.
  • Outputting any content to any stream, file, etc. is allowed, but the sound must be played.
  • Please explain your answer. This is not necessary, but it makes it easier for others to understand.
  • Languages newer than the question are allowed. This means you could create your own language where it would be trivial to do this, but don't expect any upvotes.
  • This is , so shortest code in bytes wins!

Reference implementaion (ungolfed, Python 3, Windows only, .wav only)

# -*- coding: utf_8 -*-

from ctypes import windll

winmm = windll.winmm
audio_file = input('Audio file path: ').encode('utf_8')

winmm.PlaySound(audio_file, 0, 131072)

Golfed reference implementation

import ctypes;ctypes.windll.winmm.PlaySoundW(input(),0,131072)
\$\endgroup\$
6
  • \$\begingroup\$ "To make this harder, however, you are not allowed to use external libraries."...and then you use a library in the reference implementation? \$\endgroup\$ Feb 25, 2022 at 19:29
  • \$\begingroup\$ Does "external libraries" mean libraries not coming with the standard library of the language of choice, or all libraries for that language? \$\endgroup\$
    – Ginger
    Feb 25, 2022 at 19:34
  • \$\begingroup\$ I said external libraries, not libraries in general. ctypes is built-in, so it's not an external library. \$\endgroup\$
    – Makonede
    Feb 25, 2022 at 19:35
  • \$\begingroup\$ @Makonede But winmm is not built-in. \$\endgroup\$
    – wizzwizz4
    Feb 26, 2022 at 0:51
  • \$\begingroup\$ @wizzwizz4 It is in Windows. \$\endgroup\$
    – Makonede
    Feb 26, 2022 at 1:20
  • \$\begingroup\$ @Makonede “External libraries” is unclear, then. External to what? Can I make raw calls to the hardware interface, and say that those particular drivers are part of my operating system and so not external? etc, etc.. We already have rules and conventions about all of this; trying to forbid “external libraries” won't make it more fun. \$\endgroup\$
    – wizzwizz4
    Feb 26, 2022 at 1:28
-3
\$\begingroup\$

Visualize tag progress

Task is pretty simple. Given non-negative positive integers 0 ≤ s ≤ 1000 and 0 ≤ a ≤ 200, your code should draw following progress bars.

Examples

When s ≤ 100 or a ≤ 20:

Input:15 12
Output: 
15/100 score
++++++------------------------------------
12/20 answers
+++++++++++++++++++++++++-----------------

Input:3 1
Output: 
3/100 score
+-----------------------------------------
1/20 answers
------------------------------------------
  
Input:85 35
Output: 
85/100 score
+++++++++++++++++++++++++++++++++++-------
35/20 answers
++++++++++++++++++++++++++++++++++++++++++

When (s > 100 and a > 20) and (s ≤ 400 or a ≤ 80):

Input:156 43
Output: 
156/400 score
++++++++++++++++--------------------------
43/80 answers
++++++++++++++++++++++--------------------
  
Input:666 66
Output: 
666/400 score
++++++++++++++++++++++++++++++++++++++++++
66/80 answers
++++++++++++++++++++++++++++++++++--------

When (s > 400 and a > 80) and (s ≤ 1000 and a ≤ 200):

Input:999 85
Output: 
999/1000 score
+++++++++++++++++++++++++++++++++++++++++-
85/200 answers
+++++++++++++++++-------------------------

Input:666 194
Output: 
666/1000 score
+++++++++++++++++++++++++++---------------
194/200 answers
++++++++++++++++++++++++++++++++++++++++--

The number of +'s in each bar is equal to the value of a or s divided by its max value (max values for s are 100, 400, 1000 and for a are 20, 80, 100, the choice of max values ​​depends on the ranges in which the values ​​of a and s fall.), multiplied by 42 and rounded down. This number cannot be more than 42.
The number of -'s is equal to 42 minus the number of +'s.

End etc. Trailing spaces are allowed. Additional newlines are not allowed.

This is a code-golf challenge so the shortest solution wins.

Meta

I realized that I myself got confused in my task :) ... so this task will be in completion until this text is deleted.

\$\endgroup\$
3
  • \$\begingroup\$ "progress bars are built according to the same rules" - what are those rules? Please describe them, so that we don't need to infer them from examples. \$\endgroup\$
    – pajonk
    Mar 2, 2022 at 7:14
  • \$\begingroup\$ Why should we have to "output nothing" when s>1000 and a>100? The challenge would, in my opinion, be much better if we were allowed to assume that s<=1000 and a<=100. \$\endgroup\$
    – ophact
    Mar 2, 2022 at 9:12
  • \$\begingroup\$ Please, describe the rules governing drawing the bars. Also, "s = 666 and a = 66" appears twice with two different outputs. \$\endgroup\$
    – pajonk
    Mar 3, 2022 at 7:32
-3
\$\begingroup\$

Your task is to create an approximation for sin(x) in the fewest characters possible.

  • Given the approximation s(x), it must satisfy 0.95 * sin(x) <= s(x) <= 1.05 * sin(x)

The entry with the fewest characters wins.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Most languages already have a built-in for the sine function, so I think this would not be an interesting challenge at all. Also, FYI, code-golf challenges (if that is what you are going for) usually score submissions by byte count, not character count. \$\endgroup\$
    – Aiden Chow
    Mar 15, 2022 at 23:01
-3
\$\begingroup\$

Longest Possible Pythagorean Triple Triangle

A Pythagorean triple is a set of 3 integers \$\{a, b, c\}\$ where \$a^2 + b^2 = c^2\$. Your task is to, given an integer \$n\$ where \$3 ≤ n ≤ 15\$, output a Pythagorean triple using these rules:

  • If \$n\$ is odd, output \$\{n, \frac{n^2-1}{2}, \frac{n^2+1}{2}\}\$.
  • If \$n\$ is even, output \$\{n, \frac{n^2}{4}-1, \frac{n^2}{4}+1\}\$.

With these rules, the difference between the lengths of the longest leg and the hypotenuse is minimized.

Rules

Test cases

Input | Output
------+-------
3     | 3 4 5
4     | 4 3 5
5     | 5 12 13
6     | 6 8 10
7     | 7 24 25
8     | 8 15 17
9     | 9 40 41
10    | 10 24 26
11    | 11 60 61
12    | 12 35 37
13    | 13 84 85
14    | 14 48 50
15    | 15 112 113

See A055523 and A055524.

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

Repeat Hello World according to another string's length

\$\endgroup\$
5
  • \$\begingroup\$ I think arbitrarily overriding the scoring defaults is not very well received... \$\endgroup\$
    – Seggan
    Jul 25, 2022 at 18:14
  • \$\begingroup\$ Which part? The "This is code-golf, so shortest answer wins!"? I've seen it in many questions, so I thought I would have to add it here. Is there a problem with it, or were you talking about something else in the question? \$\endgroup\$ Jul 26, 2022 at 5:37
  • 2
    \$\begingroup\$ "Please write how many bytes it is in UTF-8". A lot of languages have ther own scoring systems \$\endgroup\$
    – Seggan
    Jul 26, 2022 at 14:57
  • \$\begingroup\$ So what you are suggesting is to remove the UTF-8 option? \$\endgroup\$ Jul 29, 2022 at 9:53
  • \$\begingroup\$ Alright then. I've added it. \$\endgroup\$ Jul 29, 2022 at 9:56
-3
\$\begingroup\$

Do you trust this site?

title is a work in progress

This challenge is simple. Your program must take a URL (which will always exist) as input, download the file, and execute its contents as a program in the language your answer is in. The file will always be a valid program in your language.

Example

Language: Python
Input: https://gist.githubusercontent.com/GingerIndustries/d6f25007b45071e901b2b9057388d8f8/raw/25f838879fdc93f07394afc080eeef0993f55cbe/helloworld.py
Result: Program should print "Hello World!"
\$\endgroup\$
3
  • \$\begingroup\$ It'd probably benefit from more test cases; and how is it guaranteed that the webpage is a file? \$\endgroup\$ Oct 12, 2022 at 12:17
  • 1
    \$\begingroup\$ @py3programmer All webpages are files. \$\endgroup\$
    – Ginger
    Oct 12, 2022 at 15:25
  • \$\begingroup\$ As in, the URLs will have an extension in the end? \$\endgroup\$ Oct 12, 2022 at 16:33
-3
\$\begingroup\$

This is a famous mathematical problem, Named as Bridges of Königsberg

Task

The bridges of Königsberg is a problem in mathematics which states that the path required for crossing each bridge exactly once without using a boat

Bridges of https://cdn.britannica.com/77/74877-050-F5DD4C34/Leonhard-Euler-route-each-question-bridges-Swiss.jpg

You have to find out if there is any path which uses each bridges exactly once without using a boat, if the time exceeds 36000 seconds or 10 hours the program should print no path found yet

Rules

Standard rules of fastest-code

Expected Output: Paths possible: [7, 2, 3, 1, 5, 6, 4], [2, 1, 7, 3, 4, 6, 5], etc.

This is fastest-code so the answer with shortest time is accepted, Even if the code will take a many days without a Quantum Computer

\$\endgroup\$
7
  • 1
    \$\begingroup\$ I'm really confused by the "programing languages starting from b" rule. What does it even mean? And what a extremely arbitrary restriction \$\endgroup\$
    – mousetail
    Nov 29, 2022 at 14:55
  • \$\begingroup\$ Thanks, @mousetail I mean unofficial languages which is not included in the Wikipedia Article \$\endgroup\$
    – user115781
    Nov 29, 2022 at 14:59
  • 1
    \$\begingroup\$ What does it mean for a language to be unofficial? See codegolf.meta.stackexchange.com/a/8058/91213 our guidelines for arbitrary restricting languages. \$\endgroup\$
    – mousetail
    Nov 29, 2022 at 15:02
  • \$\begingroup\$ Thanks @mousetail, For the guidelines link \$\endgroup\$
    – user115781
    Nov 29, 2022 at 15:26
  • \$\begingroup\$ This question isn't very specific. What exactly are we supposed to do? \$\endgroup\$
    – Ginger
    Nov 29, 2022 at 18:09
  • \$\begingroup\$ Thanks, @Ginger, You have to find out if there is any path which uses each bridges exactly once without using a boat, if the time exceeds 36000 seconds or 10 hours the program should print no path found yet \$\endgroup\$
    – user115781
    Nov 30, 2022 at 6:44
  • \$\begingroup\$ What is input and what is output? Without input, how can you prevent someone write a program which simply print "[7, 2, 3, 1, 5, 6, 4]"? \$\endgroup\$
    – tsh
    Dec 15, 2022 at 7:21
-3
\$\begingroup\$

Take one of two distinct, consistent values of your choice. For one input, check if the input is prime. For another input, check if the input is a square.

Standard loophole apply except input complete or partial functions, which is replaced with

No input results in an infinite loop.

\$\endgroup\$
3
  • \$\begingroup\$ This challenge is pretty easy to solve in most languages, many have builtins for both parts \$\endgroup\$
    – noodle man
    Jan 19, 2023 at 23:52
  • \$\begingroup\$ Why it get -3 vote and don't turn grey? \$\endgroup\$
    – l4m2
    Jan 20, 2023 at 7:16
  • \$\begingroup\$ ok b/c grey is loaded earlier, and it later get vote \$\endgroup\$
    – l4m2
    Jan 20, 2023 at 7:18
-3
\$\begingroup\$

Munge my Text

Inspired by this example in the Python documentation.

Write a program that takes as input a string of arbitrary length and returns a version of that string with every letter, except the first and last, of every word randomly shuffled. "Word" is defined here as a contiguous set of alphabetical characters separated by one or more spaces or punctuation marks (!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~).

Examples

Input: Professor Abdolmalek, please report your absences promptly.
Possible output: Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.

META TODO: Add more examples

This is , so shortest answer wins!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ dupe \$\endgroup\$
    – emanresu A
    Feb 16, 2023 at 22:58
-3
\$\begingroup\$

Fibonacci before the zero - Dublicate of Negative Fibonacci Numbers

\$\endgroup\$
2
  • 3
    \$\begingroup\$ very closely related \$\endgroup\$
    – math scat
    Feb 18, 2023 at 15:25
  • 1
    \$\begingroup\$ I would consider this a duplicate of the challenge @mathcat linked to. Although your version just says to output 50, this is basically just overwriting the default sequence rules \$\endgroup\$
    – noodle man
    Feb 18, 2023 at 15:48
-3
\$\begingroup\$

See Those Sorts

Using shapes or Unicode, show how some array of numbers is sorted with a particular sorting method. You should include selection sort, merge sort, bubble sort, quick sort, bogo sort, and at least one other sort you find interesting (maybe try one of these).

Make sure that the speed of the sort corresponds to the actual performance on your computer. You can try adding a constant multiplier to the speed if you want.

Someone watched sort videos :)

\$\endgroup\$
1
  • \$\begingroup\$ Please note that popularity-contest challenges are not so well received any more. Read more here \$\endgroup\$
    – The Thonnu
    Mar 3, 2023 at 18:21
-3
\$\begingroup\$

\$n\$ bottles of beer!

You want to recreate the song "99 Bottles of Beer", but you don't have 99 bottles!


Given an input non-negative integer \$n\$, output the lyrics to the song "99 Bottles of Beer" but starting from \$n\$ instead. For a few examples:

Input: 10

Output: 

10 bottles of beer on the wall,
10 bottles of beer.
Take one down, pass it around,
9 bottles of beer on the wall.

9 bottles of beer on the wall,
9 bottles of beer.
Take one down, pass it around,
8 bottles of beer on the wall.

8 bottles of beer on the wall,
8 bottles of beer.
Take one down, pass it around,
7 bottles of beer on the wall.

7 bottles of beer on the wall,
7 bottles of beer.
Take one down, pass it around,
6 bottles of beer on the wall.

6 bottles of beer on the wall,
6 bottles of beer.
Take one down, pass it around,
5 bottles of beer on the wall.

5 bottles of beer on the wall,
5 bottles of beer.
Take one down, pass it around,
4 bottles of beer on the wall.

4 bottles of beer on the wall,
4 bottles of beer.
Take one down, pass it around,
3 bottles of beer on the wall.

3 bottles of beer on the wall,
3 bottles of beer.
Take one down, pass it around,
2 bottles of beer on the wall.

2 bottles of beer on the wall,
2 bottles of beer.
Take one down, pass it around,
1 bottle of beer on the wall.

1 bottle of beer on the wall,
1 bottle of beer.
Take one down, pass it around,
0 bottles of beer on the wall.
Input: 1

Output:

1 bottle of beer on the wall,
1 bottle of beer.
Take one down, pass it around,
0 bottles of beer on the wall.

This is , so shortest answer wins!



Meta:

  • Any more tags?
  • Is this a duplicate?
  • Is the song formatted correctly in the example?
  • Any more test cases?
\$\endgroup\$
3
  • \$\begingroup\$ I think the “{n} bottles of beer on the wall. {n} bottles of beer.” should be “{n} bottles of beer on the wall, {n} bottles of beer.” with a comma. At the end of the song, it’s supposed to go “1 bottle of beer on the wall, one bottle of beer. Go to the store and buy some more, {n} bottles of beer on the wall.” Also, what is the expected output for n=1 ? \$\endgroup\$
    – noodle man
    Jul 13, 2023 at 12:49
  • \$\begingroup\$ @noodleman fixed. In the original version, I don't think you go to the store for more. \$\endgroup\$ Jul 13, 2023 at 15:03
  • \$\begingroup\$ Wikipedia cites several variations of the final lyric, but that’s how I’ve always sung it. Consider choosing one of those variations. (p.s. this challenge pretty trivial and is likely to be marked as a dupe of the regular 99 bottles of beer question, though I’m not one of the downvoters) \$\endgroup\$
    – noodle man
    Jul 13, 2023 at 17:15
-3
\$\begingroup\$

Square decomposition

Inspired by silly ideas for answers to this CMC.


Given a perfect square, take the square root of it. NO NO NO NOT THAT CHALLENGE


Explanation

Given a square in Unicode art, output the characters that compose the square.

Rows are separated by newlines, so they cannot appear in the square. Therefore, contrary to I/O defaults, you cannot output leading or trailing whitespace unless it is in the square. You may also output in any order. Remember, this is , so shortest code wins!

Test cases

Input Unordered Output
aaa
aaa
aaa
a
1234
4567
7890
0123
1234567890
"
"
🟥🟨🟩
🟩🟥🟨
🟨🟩🟥
🟥🟨🟩




Meta

  • Is this a duplicate?
  • Is this clear enough?
  • Should I add more test cases?
  • Should I add or remove any tags?
  • Anything else?
\$\endgroup\$
9
  • \$\begingroup\$ So it's just printing the unique characters in a string? \$\endgroup\$
    – mousetail
    Aug 26, 2023 at 18:46
  • \$\begingroup\$ @mousetail No, you must not print newlines. It is printing the unique elements that make up the square. \$\endgroup\$ Aug 26, 2023 at 18:49
  • 1
    \$\begingroup\$ Yea so extremely trivial and not related to the title at all. Try to title your challenges what they actually are \$\endgroup\$
    – mousetail
    Aug 26, 2023 at 18:54
  • \$\begingroup\$ @mousetail Square decomposition is not finding what makes a square!?! \$\endgroup\$ Aug 27, 2023 at 7:59
  • \$\begingroup\$ Not at all, it's just removing duplicate items from a string \$\endgroup\$
    – mousetail
    Aug 27, 2023 at 8:16
  • \$\begingroup\$ @mousetail which happen to be part of the square. Also, newlines may be part of the string, but you may not print them. \$\endgroup\$ Aug 27, 2023 at 8:27
  • \$\begingroup\$ That doesn't make any difference for the challenge \$\endgroup\$
    – mousetail
    Aug 27, 2023 at 8:31
  • \$\begingroup\$ while it is a funny idea and i do appreciate the title, it is a bit too trivial to have as a challenge, as currently posed. I think this could be improved if you actually had to find the exact string that was made to wrap to a square, like for example, abcb made into a 5x5 square becomes abcba\nbcbab\ncbabc\nbabcb\nabcba, and you have to somehow reverse that, maybe find the minimal string which could be turned into a square like that. Still might be seen as trivial to some but idk thats my suggestion :o \$\endgroup\$ Aug 28, 2023 at 1:59
  • \$\begingroup\$ @thejonymyster that would be a separate challenge. \$\endgroup\$ Aug 28, 2023 at 8:13

You must log in to answer this question.

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