571
\$\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\$
1
  • \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$
    – None1
    May 15 at 14:05

4689 Answers 4689

1
144 145
146
147 148
157
-1
\$\begingroup\$

Biggest 25 byte number

You are allowed 25 bytes of source code.

With these you have to calculate the biggest finite number possible, assuming infinite number precision[1], runtime and memory.

You will not be taking input and do not have to output the final result.

You are not allowed to use a String representation, so "9".repeat(BIG_NUMBER) is disallowed.

Scoring will be based of the final number, bigger numbers ranking higher.

[1]: This means that for example in java you do not need to use BigInteger to represent big numbers, but using an int would be sufficient. Over- and underflows are ignored as if the int had infinite precision.

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

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

Challenge:

The sequence starts with [1]

And multiply by the reversed indices plus one.

And make an extra list containing 0 length of the list times.

If the number is greater than reversed indice plus two, then modulo by indice plus two, add number integer divided by indice plus two to extra list (Previous indice).

Then the next list will be the list plus an extra list.

Example (step-by-step)

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

Test cases

TODO

Meta:

  • Suggestions?

  • Which test cases I should add?

\$\endgroup\$
2
  • \$\begingroup\$ Adding more step-by-step examples would be nice. After [3, 2], I can get to [9, 4], but I'm not sure what to do with [1, 0] ([9, 4] modulo 4) and [2, 1] ([9, 4] div 4). Also, test cases in a sequence challenge are just a list of first X terms (20 terms would be enough here I think). \$\endgroup\$
    – Bubbler
    Dec 28, 2021 at 1:51
  • \$\begingroup\$ I think a reference implementation (even in pseudocode) would be helpful. \$\endgroup\$ Jan 10, 2022 at 12:49
-1
\$\begingroup\$

Mahjong Checker

\$\endgroup\$
4
  • \$\begingroup\$ As a real mahjong player I can tell you that it may not be enoigh to have four sets and the eye pair – flowers and animals may be needed to win. \$\endgroup\$ Feb 6, 2022 at 9:48
  • \$\begingroup\$ flowers and animals are excluded in this case, makes it a little more tricky to add more possiblities to the challenge \$\endgroup\$
    – DialFrost
    Feb 6, 2022 at 9:53
  • \$\begingroup\$ I know, but this is just for your information. \$\endgroup\$ Feb 6, 2022 at 9:54
  • \$\begingroup\$ ah ok lol thx anyways i rarely play mahjong in the first place \$\endgroup\$
    – DialFrost
    Feb 6, 2022 at 10:15
-1
\$\begingroup\$

Zhiwei Sun Squares

Given a positive integer n, find the number of ordered tuples (a, b, c, d, e) over non-negative integers for which a² + b² + c² + d² = n and b + 3c + 5d = e².

Note: A conjecture by 孙智伟 (Sūn, Zhìwěi) states that this count is always at least 1.

For example, if n is 9, there are 3 solutions, namely:

(0, 0, 3, 0, 3)
(1, 0, 2, 2, 4)
(3, 0, 0, 0, 0)

Test cases:

9 -> 3
4 -> 2
24 -> 1
25 -> 5
144 -> 3
128 -> 1
365 -> 9
366 -> 21

Scoring:

This is code-golf, so shortest code wins!

Credits to this puzzle

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

The travelling sales man problem

The travelling salesman problem (TSP) asks the following question: "Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city?"

In this puzzle not necessarily the shortest route is the answer but an approximation using a greedy algorithm (which in fact could be the shortest route as well).

This greedy algorithm starts at the first input given and always chooses the nearest point from the current point. This continues until no points are left and the last point is connected to the first point.

Use the Euclidian distance, i.e. sqrt(deltaX^2 + deltaY^2), as the distance between two cities. If there are points with the same distance, always pick the one occurring first in the list.

In general, the greedy algorithm does not find the optimal solution, but nonetheless a greedy heuristic may yield locally optimal solutions that approximate a global optimal solution in a reasonable time.

Input & Output

  • You are given an integer n and on the next n lines, you are given the x and y coordinate of the city

Test cases

5
9 12
24 15
12 30
4 3
13 27
->
71

5
25 2
5 9
22 12
15 19
0 1
->
69

12
4 5
12 80
65 18
39 29
99 11
84 31
9 9
54 49
16 27
31 67
0 71
60 0
->
403

Others

  • You are allowed to take in the input as a list of n integers

Scoring:

This is code-golf, so shortest code wins!

Credits to this puzzle

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

Draw an Erlenmeyer flask

Given the level of liquid in the Erlenmeyer flask L in the range 0-6. Your program should draw the following ASCII art.

When L=0:

      __________
     |_        _|
       |      |
       |      |
       |      |
       |      |
       |      |
       /      \
      /        \
     /          \
    /            \
   /              \
  /                \
 /                  \
/                    \
\____________________/

When L=1:

      __________
     |_        _|
       |      |
       |      |
       |      |
       |      |
       |      |
       /      \
      /        \
     /          \
    /            \
   /              \
  /                \
 /  %%%%%%%%%%%%%%  \
/  %%%%%%%%%%%%%%%%  \
\____________________/

When L=6:

      __________
     |_        _|
       |      |
       |  %%  |
       |  %%  |
       |  %%  |
       |  %%  |
       /  %%  \
      /  %%%%  \
     /  %%%%%%  \
    /  %%%%%%%%  \
   /  %%%%%%%%%%  \
  /  %%%%%%%%%%%%  \
 /  %%%%%%%%%%%%%%  \
/  %%%%%%%%%%%%%%%%  \
\____________________/

You can change the character % to any other (excluding space), it's up to you. Trailing spaces are allowed.

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

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

Implement a complex search engine


Your job is to implement a search engine. The search engine should come with a few extra features to ensure that users can obtain the most relevant results.

Input, part 1

Your program will take a string as input. The string is composed of a bunch of words separated by spaces. Parsing the string is part of the task, so inputting as a list of words will not be allowed.

What's a word?

A word is composed of one or more lowercase letters. There may be a minus at the start of the word. If there is no minus, then there can be a double-quote at the beginning and/or end of the word. Double-quotes are closed, so "abc de is not a valid input because the double-quote is never closed, but "abc def" is valid because the double quote is closed.

The minus

A minus at the beginning of a word tells the search engine to not return results that contain that word.

Double-quotes

Double-quotes around strings tell the search engine to only return results that contain that string exactly.

Extra rules

There will never be any minus words contained within a quoted string. The minuses and quotes will never contradict, so -abc "abc" will never be given (it tells the search engine to exclude results containing abc while telling it to return only results containing abc).

The string contains only minus signs, quotes, spaces, and lowercase letters. There is at least one word that is not excluded by means of a minus.

Input, part 2

The second input will be a list of strings from which the search engine will search. The strings contain only lowercase letters and spaces. You may take a newline-separated list of strings or a list of strings in your language's native input format, or any other reasonable method to input strings. (Lists of words are not allowed.)

Output

Return all results matching the input. Your output format can be a newline-separated list of strings, or a list of strings in your language's list format. Lists of words are forbidden.

Any results that it returns must:

  • contain all of the unquoted words that do not have a minus, but not necessarily in the given order;
  • contain all quoted strings exactly;
  • not contain any excluded words indicated by a minus.

Testcases

Search query: abcdefg
List of strings: [abcdefg, abcdef, bcdefg, abcd efg]
Output: [abcdefg]

Search query: blah blah blah
List of strings: [blah, blah blah, blah blah blah, bla hbla h]
Output: [blah, blah blah, blah blah blah]

Search query: "blah blah" blah
List of strings: [blah, blah blah, blah blah blah, bla hbla h]
Output: [blah blah, blah blah blah]

Search query: my name is -not ophact
List of strings: [my name is ophact, my name is not ophact, my name is op, ophact is indeed my name]
Output: [my name is ophact, ophact is indeed my name]

Search query: "oh please help" me or "otherwise someone else"
List of strings: [oh please help me or otherwise someone who is else, oh please otherwise someone else, help me or otherwise oh someone else, or]
Output: []

Search query: -remove -all -the -most -common -words but keep "everything else"
List of strings: [guide how to remove an item from a list, words are the rest, keep everything else but not that, remove all the most common words but keep everything else]
Output: [keep everything else but not that]

This challenge is , so the shortest code, measured in bytes, wins.


Any feedback? Clarification needed? Other tags are suitable? Wrong testcase?

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

Fort-Defense KoTH

There are two teams, red and blue. Each team has a fortress, and if one team's fortress is destroyed, (health reaches zero) the other team wins.

The red team attacks the blue team first, blue attacks red, red attacks blue, and so on until one team's fortress is destroyed. Every team has half of the total number of bots. (For an odd number of bots, one team has one more bot.)

The grid looks like this:

FBBBBB|BBBBF
FBBBBB|BBBBF
FBBBBB|BBBBF
FBBBBB|BBBBF

where B is a bot, F is the fort, and | as the border between the two teams.

\$\endgroup\$
9
  • \$\begingroup\$ What would the attacks be like? Right now it doesn't seem like much strategy is involved. \$\endgroup\$ Apr 26, 2022 at 19:14
  • \$\begingroup\$ @RadvylfPrograms i know, it isn't finished yet. \$\endgroup\$ Apr 26, 2022 at 19:16
  • \$\begingroup\$ Are you planning on a 2D grid or for attacks to just be an action? If the first option, it would probably make sense for the defenders to be able to "send out" some bots to fight the attackers while others man the fort. If not, the strategy probably has to come from designing your team to work together well and to decide how many resources to allocate to fighting vs. how many for defense. \$\endgroup\$
    – Romanp
    Apr 26, 2022 at 19:20
  • \$\begingroup\$ @Romanp 2d grid \$\endgroup\$ Apr 26, 2022 at 19:26
  • \$\begingroup\$ You also can choose between real-time and turn-based strategy. There haven't been many RTS KoTHs that I have seen, but it seems like an interesting idea. \$\endgroup\$
    – Romanp
    Apr 26, 2022 at 19:35
  • \$\begingroup\$ @Romanp Ooh yeah, RTS would mean writing performant bots is a major goal, something that hasn't really been explored. I've proposed an RTS KotH before, but never really did anything with the idea. \$\endgroup\$ Apr 26, 2022 at 19:45
  • \$\begingroup\$ Now I want to make a RTS game, but I'm still running my current KoTH and am planning on a fix/reboot of King of the Ziggurat (if I can get permission)... \$\endgroup\$
    – Romanp
    Apr 26, 2022 at 20:01
  • \$\begingroup\$ @Romanp whats a RTS? \$\endgroup\$ Apr 26, 2022 at 20:57
  • \$\begingroup\$ Real time strategy. Pretty much, all the bots are moving at once (probably with floating point numbers) and everything is continuous. The bots probably have position/velocity values which automatically move them every tick, that sort of thing. \$\endgroup\$
    – Romanp
    Apr 26, 2022 at 20:59
-1
\$\begingroup\$

Roman Numerals... But With A Twist

I'm assuming you have some knowledge of roman numerals, but more is at Appendix A.

Fine. What's the twist?

I want it short

So, I don't want to express 1 as IIIIIIIIIX, I want it I.

And we are not Romans, come on...

Instead, you will create a program that takes in, either as a function parameter or from STDIN:

  • A dictionary to represent Roman Numerals. You can take it in any (reasonable) format, for instance: {"I":1,"V":5,"X":10,"L":50,"C":100}, "I1 V5 X10 L50 C100", or even "0111 1011 0010 0010 0100 1001 0010 0010 0011 1010 0011 0001 0010 1100 0010 0010 0101 0110 0010 0010 0011 1010 0011 0101 0010 1100 0010 0010 0101 1000 0010 0010 0011 1010 0011 0001 0011 0000 0010 1100 0010 0010 0100 1100 0010 0010 0011 1010 0011 0101 0011 0000 0010 1100 0010 0010 0100 0011 0010 0010 0011 1010 0011 0001 0011 0000 0011 0000 0111 1101". You may cast any assumption on the input format, for instance, the letters must be in increasing order, or the odd numbers come first (even though, come on, why?) Assume all numbers to be positive.

  • The number to represent. For instance, 128724235. Assume all numbers to be positive. The number will be guaranteed to be accomplishable. For instance, for the dict {"A":10,"B":58}, 2 might be given (which your program should output).

Your output would be the shortest Roman Numeral representation for the given numeral and mapping.

Example Program:

Up later...

Appendix A

  • The mapping of letters to characters is {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}

  • Every letter is added or subtracted from a total

  • The total is the value of the numeral

For the adding or subtracting, we create the following standards:

  • If there is a character that stands for a higher value at the right, for instance an X on the right of the V, the value of V will be subtracted.

  • Else, it will be added. for instance, VV is 10 and V is 5, as there are no higher numbers at the right.

Let's just keep things clear by giving an example:

10 is X, 5 is V, 1 is I, 6 is VI, 4 is IV, 2 can be IIIV, 19 is XIX, 4 can also be expressed as IVX. Note the last three.

To make things even clearer this is a decoder:

def roman_to_integer(numeral,mapping=None):
 if not mapping: mapping = {'I':1, 'V':5, 'X':10, 
  'L':50, 'C':100, 'D':500, 'M':1000}
 result = 0
 for index, character in enumerate(numeral):
  if index+1==len(numeral) or \
   mapping[character]>=max(map(lambda x: 
   mapping[x], numeral[index:])): 
    result+=mapping[character]
  else: result-=mapping[character]
 return result
\$\endgroup\$
2
  • \$\begingroup\$ I suggest specifying clearly with some words (maybe in several bullet-points) the algorithm you use for your definition of Roman numerals. \$\endgroup\$
    – pajonk
    Jun 6, 2022 at 6:37
  • \$\begingroup\$ Oh OK good point \$\endgroup\$ Jun 6, 2022 at 6:39
-1
\$\begingroup\$

Left and Right, Spsp Style

WARNING

This question is written by the Spsp language creator TvoozMagnificent` and might includes severe advertising.

Spsp

What's Spsp? Spsp is designed to be a 2D fourth generation golfing language.

What are the commands?

Good question, it is in developement, and if you want to help me, come (here)[https://chat.stackexchange.com/rooms/136645/superior-simple]. Thank you.

But three commands have been kept in Spsp and is likely to stay that way. For the Spsp in this challenge, we have simplified things.

The commands are L, R, and S, which stand for left, right, and stop. You will be given a program, for instance this: (You would probably take it as a list instead, for instance [[' ','R','S'],[' ','L','S'],['L','S',' ']]) Assume the lines to be padded to the same length.

+-+-+-+
| |R|S|
+-+-+-+
| |L|S|
+-+-+-+
|L|S| |
+-+-+-+

The IP, which stands for the Instruction Pointer, Starts out at the top left cell, pointing right, so let's draw it as >. Thus, the current map looks like this:

+-+-+-+
|>|R|S|
+-+-+-+
| |L|S|
+-+-+-+
|L|S| |
+-+-+-+

Now the IP tries to advance. It hits an R block, so it doesn't advance, and turns right. Now it points down:

+-+-+-+
|v|R|S|
+-+-+-+
| |L|S|
+-+-+-+
|L|S| |
+-+-+-+

Now the IP can advance:

+-+-+-+
| |R|S|
+-+-+-+
|v|L|S|
+-+-+-+
|L|S| |
+-+-+-+

Now the IP can't advance again, so it turns left. This is because it points towards an L, the L at the side has no effect:

+-+-+-+
| |R|S|
+-+-+-+
|>|L|S|
+-+-+-+
|L|S| |
+-+-+-+

And turns left again to point upwards:

+-+-+-+
| |R|S|
+-+-+-+
|^|L|S|
+-+-+-+
|L|S| |
+-+-+-+

It advances:

+-+-+-+
|^|R|S|
+-+-+-+
| |L|S|
+-+-+-+
|L|S| |
+-+-+-+

If the IP hits a wall, it raps. (Pun Intended) So if the IP advances, he would end up on the L marked X on this map:

+-+-+-+
|^|R|S|
+-+-+-+
| |L|S|
+-+-+-+
|X|S| |
+-+-+-+

And thus the pointer turns left:

+-+-+-+
|<|R|S|
+-+-+-+
| |L|S|
+-+-+-+
|L|S| |
+-+-+-+

And the pointer advances and hits the S:

+-+-+-+
| |R|X|
+-+-+-+
| |L|S|
+-+-+-+
|L|S| |
+-+-+-+

Thus the pointer stops. Your chllenge is to output the ending coordinate in some way, whether it is the mathematical coordinate system (2,2) or the index [1,3] or [0,2].

There's a small twist however. What does this program do?

+-+-+
| |R|
+-+-+
|L|S|
+-+-+

Well, the IP turns right, and then turns left, and then... yikes, that's an infinite loop! What do we output then? Well, don't output anything, but terminate the program instead of running forever. It is easy to know that if the same IP state is achieved twice, then a loop will happen.

Or, take this:

+-+
| |
+-+
|S|
+-+

The IP just wraps around and loops on the first line.

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

Minimal number of moves needed by a knight


Given an \$N × N\$ board, what is the minimum number of moves needed by a knight to reach every square (on any given square)?

In other words, the A232007 sequence from OEIS.

Input/Output can be taken in any reasonable format, taking the size of the board and returning the number of moves (you don't need to handle 2, and 3 because the knight can't travel all of the \$2 × 2\$ and \$3 × 3\$ board)

Testcase:

8 -> 6
5 -> 4

This is , so shortest answer (in bytes) wins!

\$\endgroup\$
3
  • 2
    \$\begingroup\$ I'd suggest removing the -1 output, and not requiring answers to handle those inputs. Adding edge cases like this tends to make the challenge quite boring to golf, because a lot of the code gets taken up by them \$\endgroup\$
    – pxeger
    Jun 6, 2022 at 17:43
  • \$\begingroup\$ Do you mean minimum or maximal? \$\endgroup\$
    – tsh
    Jun 7, 2022 at 10:31
  • 2
    \$\begingroup\$ I think this may be too simple, as it is just ceiling(2n/3) per the OEIS page. \$\endgroup\$
    – pajonk
    Jun 8, 2022 at 9:04
-1
\$\begingroup\$

The prime frog 🐸 -- Integrated.

From the original question, we make the following changes:

The "prime frog" is a strange animal that jumps between integers*, until it arrives on 3 or 19...


Your program should accept an integer n as input and output the result of the below algorithm (3 or 19).

For a given integers n > 1 and b > 1:

  1. Let f be the position of the frog. It is initially set to n
  2. if f has been hopped on: return the smallest lilypad hopped after and including the f hopped on last time
  3. if f is prime : the frog jumps to the position b×f+1. Go back to step 2.
  4. if f is composite : let d be f's biggest prime divisor. The frog jumps to the position f-d. Go back to step 2.

Examples:

An example with n = 5, b = 4:

5 > 21 > 14 > 7 > 29 > 117 > 13x8 > 13x7 > 13x6 > 13x5 > 13x4 > 13x3 > 13x2 > 13 (I'm a bit lazy there) > 53 > 213 > 142 > 71 > 285 > 14x19 > 13x19 > snip > 38 > 19 > 77 > 66 > 55 > 44 > 33 > 22 > 11 > 45 > 40 > 35 > 28 > 21 (loop), returns 7. 

Thus the program should output 7.

Another example with n = 23, b = 3:

 23 > 70 > 63 > 56 > 49 > 42 > 35 > 28 > 21 > 14 > 7 > 22 > 11 > 34 > 17 > 52 > 39 > 26 > 13 > 40 > 35 (loop), returns 7. 

Again, the program should output 7.

Test cases:

Coming up later

Meta: is it possible for a number to go up infinitely?

\$\endgroup\$
1
  • \$\begingroup\$ Downvoters, why? \$\endgroup\$ Jun 17, 2022 at 1:14
-1
\$\begingroup\$

Build a file/directory tree

Task

In this challenge, your task is to write a program or function which takes an array of paths with an additional boolean indicating it is a file or directory and outputs a file/directory tree in any reasonable format.

Remarks

  • Some directories can end with a forward slash ("/") but this is not always the case
  • A parent directory is not always explicitly defined but should be in the tree
  • "." and ".." as file name or directory name are not allowed
  • Standard loopholes are not allowed

Input

An unsorted array of paths. Each item is a tuple of path and a boolean which is True for a file and False for a directory.

[
    ['Root Folder/Sub Folder/', False],
    ['Root Folder/Sub Folder/hello.txt', True],
    ['Root Folder/Sub Folder/SubSub Folder/SubSubSub Folder/', False],
    ['Root Folder/Sub Folder/world.txt', True],
    ['Root Folder/Sub Folder 2', False],
]

Output

Any output which shows or defines a tree based upon input is valid.

Text formatted example

[D] Root Folder
    [D] Sub Folder
        [D] SubSub Folder
            [D] SubSubSub Folder
        [F] hello.txt
        [F] world.txt
    [D] Sub Folder 2

Data structure formatted example

[
    'Root Folder',
    [
        [
            'Sub Folder',
            [
                [
                    'SubSub Folder',
                    [
                        [
                            'SubSubSub Folder', [], []
                        ]
                    ],
                    []
                ]
            ],
            ['hello.txt', 'world.txt']
        ],
        [
            'Sub Folder 2',
            [],
            []
        ]
    ],
    []
]

This is a code golf. Shortest code in bytes wins.

Meta

  • Is this an interesting question?
  • Is this question clear enough?
  • Anything i can do to improve this question?
\$\endgroup\$
2
  • \$\begingroup\$ I think it would be good to simplify input and output as much as possible. For example the input being just list of strings and directories identified by ending with slash. And also specifying list of characters which can/can't appear in path would allow to use some of those as string separator (perhaps best as separator would be space and newline). This would mean that data can be easily read from STDIN. \$\endgroup\$
    – Jiří
    Jul 8, 2022 at 19:52
  • \$\begingroup\$ You should also write a bit about how the algorithm generating the tree works. For example: "You split all paths by character /, which gives you list of directories and possibly file. The you choose first part of any path and output this, then you have to find all paths which begin with the same directory..." (I think it can be written a bit better than I did and also I didn't described it fully) Also then the output can be maybe a bit simplified or a bit better defined too, but I am not sure how (maybe not differentiating between directories and files). \$\endgroup\$
    – Jiří
    Jul 8, 2022 at 19:57
-1
\$\begingroup\$

Write a program on any language that accepts some input and give some different output. The challenge is that the text of the program must form a square: all rows must be the same length and the number of rows must equal the number of columns (ie length of rows). Adding extra spaces or comments to pad lines is not allowed.

This is Code Golf so the one with the shortest functioning program (ie smallest square) wins!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to the site! To edit your post there is edit button. You have posted two similar versions of same post, so I recommend deleting the older (this one). I will post further recommendations under your new post. \$\endgroup\$
    – Jiří
    Aug 7, 2022 at 20:03
-1
\$\begingroup\$

Convert English to integer

When saying a number out loud in English, or writing it out in words, speakers use a certain method.
Since there's lots of variations from person to person on the specific method, I'll define the format I'm using here:

  • [TODO]

Some things to note about the format:

  • There are no commas, only lowercase letters and spaces.
  • There is no "and" separating the hundreds and tens.
  • 1234 is described as "one thousand two hundred thirty four", not "twelve hundred thirty four".

Here's some rather sloppy code that, given a number, generates the associated English phrase.

The challenge

Taking an input \$s\$ which a string describing some integer \$n\$ written using the format above, output \$n\$. In other words, convert from an English description of a number back to its integer form. Your code should be able to handle string associated with non-negative integers up to but not including a quadrillion (i.e. \$0 \leq n \leq 999,999,999,999\$), or the maximum value that an integer can have in your programming language. You can assume the input will always follow the format above.

Test cases

Input Output
zero 0
eight 8
ten 10
sixteen 16
twenty 20
thirty five 35
one hundred 100
four hundred nine 409
five hundred thirteen 513
seven hundred seventy seven 777
six thousand five hundred thirty four 6534
one hundred thousand ten 10010
twenty four thousand three hundred sixty five 24365
eighty eight million two hundred twenty thousand one hundred 88222100
seven hundred million eleven thousand ninety nine 700011099
eight hundred ninety four billion three hundred twelve million five hundred sixty seven thousand eight hundred ninety one 894312567891
one trillion 1000000000000
five hundred trillion one 500000000000001

Standard I/O rules apply, standard loopholes are forbidden. The shortest program wins.

Questions

Do I need to describe the format besides saying how it deals with the major variants (e.g. including/excluding "and")? I really don't want to formally write out all that stuff. I also don't like the wording of the first sentence at all, but I feel like I need some introduction.

\$\endgroup\$
2
-1
\$\begingroup\$

find overlap between 2 grids

You have 2 grids with numbers inside, and you want to find the overlapping parts.

For example
The firdst grid

1 2 3 4
1 2 3 4
1 2 3 4

The second grid

2 3 4 1
2 3 4 2
9 8 6 4

This part is the overlapping part:

2 3 4
2 3 4

And when you combine, you sould get this:

1 2 3 4
1 2 3 4 1
1 2 3 4 2
  9 8 6 4

Rules

  • The grids are minimum 2*2 and MUST be a rectangle or a square.
  • The input can be the size of the grids (and random generated content), or the content of the grids itself (your choice)
  • The output can be visual just like my example or sommerhing else (but explain how to read it).
  • If there is no overlap you output what you want but it needs to be clear.

goal It is code golf so the byte size is important.

\$\endgroup\$
8
  • \$\begingroup\$ What do we output if there is no common part, like 1 2 3 newline 4 5 6 and 7 8 9 newline 4 8 3 where newline is a grid row separator? \$\endgroup\$ Sep 9, 2022 at 10:10
  • \$\begingroup\$ Or is the input guaranteed to have at least one overlapping value? \$\endgroup\$ Sep 9, 2022 at 10:19
  • \$\begingroup\$ It needs to be clear, I wouls say domething like "-1" or can be tex or so. \$\endgroup\$
    – Bjop
    Sep 9, 2022 at 10:33
  • \$\begingroup\$ Won't it be more sensible to output truthy/falsey values for whether there exists overlapping values? That way you can account for all possible inputs. \$\endgroup\$ Sep 9, 2022 at 10:41
  • \$\begingroup\$ Like I statet in the question, "find the overlapping parts", not if there is overlap or not. \$\endgroup\$
    – Bjop
    Sep 9, 2022 at 10:52
  • 1
    \$\begingroup\$ I only suggested it; it's up to you if you want to modify the challenge. \$\endgroup\$ Sep 9, 2022 at 11:06
  • \$\begingroup\$ Do you think it is better to change it? To my logic you have to know if there is overlapping before you know where. So it is part of it. \$\endgroup\$
    – Bjop
    Sep 9, 2022 at 11:47
  • 1
    \$\begingroup\$ So include the expected output for not having overlapping grids \$\endgroup\$ Sep 9, 2022 at 11:50
-1
\$\begingroup\$

Find all matrices whose sliding sums are the input

Like this, but

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

Posted on main: Make a Compiler or Interpreter for any Turing-complete language in another language

\$\endgroup\$
4
  • \$\begingroup\$ Welcome to Code Golf Stack Exchange, and thank you for using the sandbox. Wouldn't any language that has an evaluate command perform this task in very few bytes? \$\endgroup\$
    – Adám
    Oct 22, 2022 at 23:01
  • \$\begingroup\$ Edited, thanks! \$\endgroup\$
    – Unresolved
    Oct 23, 2022 at 12:36
  • \$\begingroup\$ I generally recommend leaving challenges in the sandbox for a week, especially if the author is new to writing challenges. \$\endgroup\$
    – Adám
    Oct 23, 2022 at 13:22
  • \$\begingroup\$ Anyway, when posting to main, edit the sandbox post to just a link, and delete it. \$\endgroup\$
    – Adám
    Oct 23, 2022 at 13:29
-1
\$\begingroup\$

RGB to Hexadecimal

\$\endgroup\$
3
  • \$\begingroup\$ Instead of 0 < r < 255 (both inclusive), which is a bit of a nonstandard way to write that, why not MathJax: \$0\lex\le255|$ \$\endgroup\$ Nov 2, 2022 at 13:05
  • \$\begingroup\$ Added it, but there was an escaping error where the $ had to be escaped to end the MathJax. Fixed it by changing | with \, and it worked. \$\endgroup\$ Nov 2, 2022 at 13:13
  • \$\begingroup\$ Oh oops, that was a typo on my part. Yeah, backslash is correct. \$\endgroup\$ Nov 2, 2022 at 13:27
-1
\$\begingroup\$

LS, Part 2: Sebald Code

WARNING: You still not gonna answer a challenge about ponies?


Sebald code is a code developed by Dr. Gustav Sebald purely for communication through movies. It is decoded like this:

  1. We look for an instance of "ring" case-insensitive
  2. Starting from the word just after the "ring" we add this to an empty string
  3. We jump 11 words and add the next word after that
  4. Repeat 2 and 3 until we pass one of the words "ring"
  5. The string we've been adding to is the plaintext.

Note that if the string doesn't contain "ring", just return an empty string ''.

Testcases (TODO)

This is , so shortest answer wins!

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

Output your Votes

The challenge is simple: Print to stdout the current total score (upvotes minus downvotes) of your answer.

For obvious reasons, you do not have to include the ID of your answer in the program; you may take it from stdin or specify a place in the code where the ID must be inserted. Your program may assume that the computer it is running on has internet access and isn't restricted by SE API ratelimiting. Your program does not need to use the SE API to get the vote count, but that's probably the easiest way to do it.

This is , so shortest code wins.

Meta

Is this a dupe? I wouldn't be surprised if it is.

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

Help Santa Rest

Santa has finally delivered presents to everyone at the stroke of midnight in a day, and now he wants some well-deserved rest. He is just about to sit down when the present managing computer suddenly calls out: "ME NEED REST." Now he is asking you to write him a program that does... nothing.

You will be given command line args, you will be given STDIN input. You must swallow/ignore the input and after some length of time, quit the program. You may have no externally visible effects (other than RAM/CPU usage obviously), and the program must not hang.

Testcases

NullPointerException

Scoring

Santa wants to type this in as quickly as possible so he can rest, so this challenge is scored in bytes, as standard .

\$\endgroup\$
8
  • \$\begingroup\$ So, what should the program do? Quit? Probably loads of 0-byte solutions to this. \$\endgroup\$
    – Adám
    Dec 8, 2022 at 17:14
  • \$\begingroup\$ @Adám the program should do nothing and exit. true, but 0 byters are not possible in quite a few languages (i.e. Java, golflangs that implicitly print the input, C(++)(#), Kotlin) \$\endgroup\$
    – Seggan
    Dec 8, 2022 at 18:04
  • \$\begingroup\$ Wouldn't it be more fun to have to swallow all input? \$\endgroup\$
    – Adám
    Dec 8, 2022 at 18:12
  • \$\begingroup\$ @Adám isn't that what I'm describing? \$\endgroup\$
    – Seggan
    Dec 8, 2022 at 18:13
  • 1
    \$\begingroup\$ Well, if the program quits immediately, it won't have a chance to swallow any input. \$\endgroup\$
    – Adám
    Dec 8, 2022 at 18:52
  • \$\begingroup\$ @Adám not quit immediately. i meant do nothing from an outside perspective, as in no STDOUTput or alert boxes or whatever \$\endgroup\$
    – Seggan
    Dec 8, 2022 at 21:57
  • \$\begingroup\$ Then it is still unclear to me. How long should the program run and swallow input before quitting? \$\endgroup\$
    – Adám
    Dec 9, 2022 at 12:16
  • \$\begingroup\$ @Adám as long as it does not hand (i.e. enter into an infnite loop) \$\endgroup\$
    – Seggan
    Dec 9, 2022 at 16:22
-1
\$\begingroup\$

Print my Country

This challenge is simple: Your program must output the two-character country code of the computer it is currently being run on, according to the computer's locale settings. (Capitalization doesn't matter.) For example, were I to run your program on a computer with a location set to the United States, your program should output US. You may assume that your program is running on the latest version (Bullseye, if I'm not mistaken) of Debian Linux. This does not need to be accurate; I could easily set the locale to Antartica while being in Britain.

This is , so shortest program wins!

\$\endgroup\$
3
  • \$\begingroup\$ Is this even possible? How can the computer possibly know where it is physically? And who says it even is in a country? \$\endgroup\$
    – Adám
    Dec 13, 2022 at 14:34
  • \$\begingroup\$ @Adám The program only needs to print the system's locale, which may or may not be accurate. I could easily set my location to Antartica while actually being in Britain. I have clarified some of the language. \$\endgroup\$
    – Ginger
    Dec 13, 2022 at 15:48
  • 1
    \$\begingroup\$ Removing the restriction of system could make it more interesting. Answers should specify what system / environment they are running on. \$\endgroup\$
    – tsh
    Dec 15, 2022 at 7:13
-1
\$\begingroup\$

Generate 3d Christmas tree using "3d pixel art"

Imagine you are building Christmas tree from 1x1x1 sized cubes that can be attached just by sharing a side. At least one input - size, but can be more granular (height, bottom_width, etc.).

Any kind of algorithm you like, data representation should be set of 3d int vectors containing positions of each cube.

The more natural looking, the better.

If you want to visualize it too, even better. But it's not essential (I may try to visualize some of your creations).

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

Halting detector (Archived)

Choose a Turing complete language and write a program in this language that, given a program in 1TB, decide whether it halts.

Your program would likely be more than 1TB, which results in transferring difficulty1. Therefore, you only need to show your construction and prove your code length.

Shortest code in each language win. A Turing complete language which write 2TB of program to do a loop would make short submission but that won't be fun (and I don't think such language exist now)

1 Yeah it isn't the main point

\$\endgroup\$
8
  • 3
    \$\begingroup\$ This is literally impossible, due to the halting problem. Also how are we to submit an entire terabyte of code? \$\endgroup\$
    – Seggan
    Dec 18, 2022 at 19:53
  • \$\begingroup\$ @Seggan I'm not the OP, but the problem specifies the program is less than 1 TB, so in principle you could solve it with a very large lookup table. And it says "you only need to show your code construction and prove your code length". \$\endgroup\$ Dec 18, 2022 at 22:27
  • 1
    \$\begingroup\$ There are so many unsolved conjectures in mathematics that may impact the halting or non-halting of a program. For example, if you can express Collatz conjecture (specifically, an infinite loop that stops when a nontrivial Collatz loop is found) in 1TB of code in language X, you can't solve this challenge in X. \$\endgroup\$
    – Bubbler
    Dec 18, 2022 at 23:13
  • \$\begingroup\$ @Bubbler True, I suppose whether you can solve it depends on what counts as a solution. Like could you just say "this solution exists, but you would need to solve a lot of conjectures to actually construct it"? \$\endgroup\$ Dec 18, 2022 at 23:55
  • \$\begingroup\$ @Seggan For example, you can just create a language called PythonAfter1TB which simply ignore first 1TB source and interpret following source as Python 3.10 (or do nothing and halt if your source is less than 1TB). \$\endgroup\$
    – tsh
    Dec 19, 2022 at 9:23
  • \$\begingroup\$ @tsh "but that won't be fun (and I don't think such language exist now)" \$\endgroup\$
    – l4m2
    Dec 19, 2022 at 9:46
  • \$\begingroup\$ @tsh and what would that achieve? besides, it doesn't change the fact that this problem is impossible \$\endgroup\$
    – Seggan
    Dec 19, 2022 at 14:05
  • \$\begingroup\$ @l4m2 I don't think there is some language (defined by implementation) support a single file with 1TB content as its source code currently. \$\endgroup\$
    – tsh
    Dec 20, 2022 at 6:09
-1
\$\begingroup\$

Character Values Quine

Write a program that prints out a sequence of integer values corresponding to the character codes in the source code.

For example, the program:

print("Hello, World!")

has a valid corresponding integer sequence of:

112 114 105 110 116 40 34 72 101 108 108 111 44 32 87 111 114 108 100 33 34 41

Rules

  • You may use a non-numerical sequence delimiter of your choice.
  • The order of values in the sequence must be maintained for this challenge.
  • The integers may be in any numerical base with a radix of 2 or larger. (binary or up). All the integers must have the same base.
  • Code comments are permitted.
  • The program may not read from its own source code.
  • Standard loopholes apply.
  • This is , so the shortest-length solution wins.
__

My first question, so please let me know what could/should be changed. Thanks!

\$\endgroup\$
7
  • \$\begingroup\$ Why the arbitrary restriction to ASCII? \$\endgroup\$
    – Adám
    Jan 5, 2023 at 18:49
  • \$\begingroup\$ @Adám That might be unecessary, but I was mainly thinking that a mixture of unicode and ascii characters wouldn't be great. Is that a concern? \$\endgroup\$
    – Bob th
    Jan 5, 2023 at 18:51
  • \$\begingroup\$ @Adám Okay, after thinking about I believe you're right in that it's rather arbitrary so I've removed it. \$\endgroup\$
    – Bob th
    Jan 5, 2023 at 19:18
  • \$\begingroup\$ Welcome to Code Golf SE and thanks for using the Sandbox! You may want to think though the allowed encodings - some languages use special code pages (not Unicode nor ASCII, see 05AB1E or Nibbles). I suggest allowing them and even allowing code pages specifically crafted for this challenge (eg. program adcbd returning 1 2 3 4 2 with encoding a:1 b:4 c:3 d:2). But that's up to you. \$\endgroup\$
    – pajonk
    Jan 6, 2023 at 14:08
  • \$\begingroup\$ This seems to fall under generalized quines, a type of challenge we'd rather avoid \$\endgroup\$
    – mousetail
    Jan 7, 2023 at 16:03
  • \$\begingroup\$ @mousetail I think that allowing custom encodings may result in some clever solutions that don't use the standard quine approach. I don't know however if the probability is high enough to post it against the generalized quine discouragement. \$\endgroup\$
    – pajonk
    Jan 8, 2023 at 8:30
  • \$\begingroup\$ I really don't see how using a different base could ever lead to a different approach to the standard quine \$\endgroup\$
    – mousetail
    Jan 8, 2023 at 9:19
-1
\$\begingroup\$

Generate a random halting Brainfuck code

Generate a random valid halting brainfuck program using []+-<>. Every halting program should be possibly outputted.

Sandbox Notes:

  • What should I add?
  • Is it a duplicate?
\$\endgroup\$
3
  • \$\begingroup\$ I would add "Every halting program should be possibly outputted with nonzero probability." Also, I don't think there is any other viable approach than implementing this and randomly quitting when a program halts, which makes your challenge a possible duplicate. \$\endgroup\$
    – Bubbler
    Jan 19, 2023 at 6:52
  • \$\begingroup\$ @Bubbler They can be wrapped into each other(this+loop outputting unseen entries=that,that+random output then halt=this), if these two wrappers treated non-trivial then it's not a dup \$\endgroup\$
    – l4m2
    Jan 20, 2023 at 0:07
  • \$\begingroup\$ This is impossible, since you can't determine if a program halts. Should it generate a program that solves the colatz conjecture or not? \$\endgroup\$
    – mousetail
    Jan 20, 2023 at 8:38
-1
\$\begingroup\$

Sum of numbers of arbitrary length

\$\endgroup\$
2
  • 1
    \$\begingroup\$ This seems like it would be fairly trivial in most languages. Maybe add a restriction that there shouldn't be floating point errors (e.g. in many languages, 0.2 + 0.3 = 0.30000000000000004) \$\endgroup\$
    – noodle man
    Feb 5, 2023 at 20:13
  • \$\begingroup\$ @Jacob If there will be floating point errors then it will not meet the condition "summarize them as normal numbers" \$\endgroup\$
    – EzioMercer
    Feb 5, 2023 at 20:54
-1
\$\begingroup\$

Route Planning for a delivery driver

There is a town that consists of a single long road with evenly spaced houses. Each house either needs rice, represented with a negative number, or can provide rice, represented with a positive number.

[-1, 50, -1, -1, -1, -50, 3, 1]

Here, the first house needs one grain of rice, the second can provide 50 etc.

Your delivery truck starts at the very left edge of the town, and must end on the very right edge. It has a infinite capacity, but you can't deliver if it's empty.

The sum of the input list is guaranteed to be 0.

Given a list of requirements, output the shortest possible path that can deliver to every address.

Test cases

Test Case Output
5, -5 3
-5, 5 5
2, -5, 3 6
-1, -1, 1, 1, 1, -1 12
\$\endgroup\$
-1
\$\begingroup\$

Paint you a Picture for Piet Perfection

Make a Piet program that does whatever you want—but make it pretty.

Your goal is to paint a beautiful picture with an interesting function.

Your program may do anything, but your submission is much more likely to gain upvotes if it is interesting or related to the content of the picture. Likewise, your program could be incredibly interesting but look very ugly and thus receive few upvotes.

This is a , so the submission with the highest score wins.


Meta sandboxing: This might be too vague, should the program guidelines be more specific?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Unfortunately, this kind of popularity contest ("do whatever you want but make it pretty") is exactly the kind that we've decided isn't a good fit for the site. \$\endgroup\$
    – DLosc
    Mar 10, 2023 at 16:38
  • \$\begingroup\$ @DLosc Booooooo \$\endgroup\$
    – noodle man
    Mar 10, 2023 at 22:13
  • \$\begingroup\$ Yeah, I understand the reasons, but I'm not entirely happy with the outcome. Tweetable Mathematical Art was one of my favorite questions. Popularity contests and what to do with them have been one of the site's most vexing questions for a lot of years. We still discuss the issues in chat from time to time. \$\endgroup\$
    – DLosc
    Mar 11, 2023 at 16:20
  • 1
    \$\begingroup\$ Improvement idea: Create a Piet program that describes what it does in the picture itself. \$\endgroup\$
    – Bubbler
    Mar 17, 2023 at 1:07
1
144 145
146
147 148
157

You must log in to answer this question.

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