# What is the Sandbox?

This "Sandbox" is a place where Code Golf users can get feedback on prospective challenges they wish to post to the main page. This is useful because writing a clear and fully specified challenge on 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.

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

# The (All But) Quine challenge

Like a quine challenge, but the opposite. Print everything except source code

# Challenge

Write a program, which takes no input, and outputs all the strings of printable characters which are the same length as the source code of the program, except the source code of the program.

# Scoring

The shortest program (per language) to accomplish the above task, wins

• By 'printable characters' you mean printable ASCII characters (code-points [32,126])? What if I use a language that don't contain any ASCII characters in its source code? – Kevin Cruijssen Mar 20 '20 at 13:38
• If your program is in ASCII, then you would need to print all of the ASCII characters, if the program is in Unicode, then you would have to print all of the Unicode characters – Benji Mar 20 '20 at 14:40
• @Benji Would you consider a Python 3 source file as being "in Unicode"? – Jonathan Frech Mar 22 '20 at 17:49
• If there are any Unicode characters that are used in the file, then no. If Unicode characters are used, then I would consider it to be Unicode – Benji Mar 23 '20 at 14:47

## Numbers by index

Challenge

Print the numbers:

0
1
22
333
4444
55555
666666
7777777
88888888
999999999


In that order.

I/O

Takes no input. The numbers can have any delimiters desired (or none). Example outputs:

0122333444455555666666777777788888888999999999

[0,1,22,333,4444,55555,666666,7777777,88888888,999999999]

etc....


Code Example

This is an un-golfed example that may perhaps act as algorithm guide (or maybe not):

# Turing Machine Code, 553 bytes

0 * 0 r K
K * _ r 1
1 * 1 r L
L * _ r 2
2 * 2 r a
a * 2 r M
M * _ r 3
3 * 3 r b
b * 3 r c
c * 3 r N
N * _ r 4
4 * 4 r d
d * 4 r e
e * 4 r f
f * 4 r O
O * _ r 5
5 * 5 r g
g * 5 r h
h * 5 r i
i * 5 r j
j * 5 r P
P * _ r 6
6 * 6 r k
k * 6 r l
l * 6 r m
m * 6 r n
n * 6 r o
o * 6 r Q
Q * _ r 7
7 * 7 r p
p * 7 r q
q * 7 r r
r * 7 r s
s * 7 r t
t * 7 r u
u * 7 r R
R * _ r 8
8 * 8 r v
v * 8 r w
w * 8 r x
x * 8 r y
y * 8 r z
z * 8 r A
A * 8 r B
B * 8 r S
S * _ r 9
9 * 9 r C
C * 9 r D
D * 9 r E
E * 9 r F
F * 9 r G
G * 9 r H
H * 9 r I
I * 9 r J
J * 9 r halt


Try it online!

This prints out the numbers with a space delimiter:

0 1 22 333 4444 55555 666666 7777777 88888888 999999999


Challenge Type

, so shortest answer in bytes (by language) wins.

Edit: Link to the related challenge. Curiously, there is one answer on there where if it was by index, and the zero was included, it would be shorter.

• Nice challenge! Are preceding & trailing whitespace (during string output) permitted? – user92069 Mar 11 '20 at 3:22
• I think it should also be kolgomorov-complexity. – PkmnQ Mar 11 '20 at 5:19
• I don't like how the zero breaks the pattern of having the digit N appear N times -- it seems like an exceptional edge case. I think it would be better for 0 not to appear, so the numbers would just start from 1. – xnor Mar 11 '20 at 7:06
• @xnor, I knew you wouldn't like it (and probably a few other won't as well) That's on purpose. It just seems a little too easy otherwise. – ouflak Mar 11 '20 at 7:28
• @a'_', Yes. @ PkmnQ, Noted. – ouflak Mar 11 '20 at 7:29
• I don't really see how adding a fixed zero to the beginning makes the challenge harder in almost any language. In some, the empty string will actually convert to zero, which makes it more natural but still fairly trivial. I feel like you probably either want to go with omitting the zero, or finding a different way to make the challenge more complicated. – FryAmTheEggman Mar 11 '20 at 14:53
• @FryAmTheEggman, How can you have a challenge about indexes and not have zero? That just seems wrong. – ouflak Mar 11 '20 at 15:31
• Most people start counting from one - only people who use computers a lot default to starting at zero. And separately, I think finding another way to incorporate it is better than leaving it out (I just also think both are better than having an unexplained outlier). – FryAmTheEggman Mar 11 '20 at 15:40
• @FryAmTheEggman, But it's not really unexplained is it? It's the index of the first number. – ouflak Mar 11 '20 at 15:46
• As per what xnor said, it doesn't match the pattern of the others. That behaviour is not explained. Comments aren't really for a discussion like this; if you disagree that is fine. I've just given feedback on how I think you could improve the challenge. – FryAmTheEggman Mar 11 '20 at 16:15
• I do want to make sure that everyone knows that I am VERY grateful for the feedback! I also appreciate having a Sandbox where we can have this discussion here instead of on the main site. – ouflak Mar 11 '20 at 16:18
• @FryAmTheEggman, It's not that I disagree. I kind of agree. I like that leading zero in there to represent the index location of the initial value. I considered this when I thought of the question, before posting it here. It breaks up a trivial loop sequence answer a bit, or maybe even inspires a clever solution that nobody considered. I'd like to keep it because it stands out like that, not despite that. – ouflak Mar 11 '20 at 16:21
• I posted an example implementation above. The zero wasn't a big deal. – ouflak Mar 11 '20 at 16:31
• My guess is that you're excited about the arithmetic expression 10**n/9*n or similar. But I don't think that's much more interesting than the obvious loops that removing the zero would allow unmodified. – xnor Mar 11 '20 at 21:59
• @ouflak I contrast, I am very excited about arithmetic expressions :) – xnor Mar 12 '20 at 21:16

# A malbolge interpreter

The challenge today is to write a Malbolge interpreter.

## Specification

Malbolge

I hereby relenquish any and all copyright on this language,
documentation, and interpreter; Malbolge is officially public domain.

------------------------------------------------------------------------

Malbolge

Introduction
^^^^^^^^^^^^

It was noticed that, in the field of esoteric programming languages,
there was a particular and surprising void: no programming language
known to the author was specifically designed to be difficult to program
in.

Certainly, there were languages which were difficult to write in, and
far more were difficult to read (see: Befunge, False, TWDL, RUBE...).
But even INTERCAL and BrainF***, the two kings of mental torment, were
designed with other goals: INTERCAL to have nothing in common with any
major programming language, and BrainF*** to be a very tiny, yet still
Turing-complete, language.

INTERCAL's constructs are certainly tortuous, but they are all too
flexible; you can, for instance, quite easily assign any number to a
variable with a single statement.

BrainF*** is lacking the flexibility which is INTERCAL's major weakness,
but it fails in that its constructs are far, far too intuitive.
Certainly, there are only 8 instructions, none of which take any
arguments--but it is quite easy to determine how to use those
instructions.  Subtract 8 from the current number?  With a simple
'--------' you are done!  This kind of simple answer was unacceptable to
the author.

Hence the author created Malbolge.  It borrows from machine, BrainF***,
and tri-INTERCAL, but put together in a unique way.  It was designed to
be difficult to use, and so it is.  It is designed to be
incomprehensible, and so it is.

So far, no Malbolge programs have been written.  Thus, we cannot give an
example.

"Malbolge" is the name of Dante's Eighth Circle of Hell, in which
practitioners of deception (seducers, flatterers, simonists, thieves,
hypocrites, and so on) spend eternity.

Environment
^^^^^^^^^^^

In many languages, the environment is easy to understand.  In Malbolge,
it is best to understand the runtime environment before you ever see a
command.

The environment is, roughly, that of a primitive trinary CPU.  Both code
and data share the same space (the machine's memory segment), and there
are three registers.  Machine words are ten trits (trinary digits) wide,
giving a maximum possible value of 59048 (all numbers are unsigned).
Memory space is exactly 59049 words long.

The three registers are A, C, and D.  A is the accumulator, used for
data manipulation.  A is implicitly set to the value written by all
write operations on memory.  (Standard I/O, a distinctly non-chip-level
feature, is done directly with the A register.)

C is the code pointer.  It is automatically incremented after each
instruction, and points the instruction being executed.

D is the data pointer.  It, too, is automatically incremented after each
instruction, but the location it points to is used for the data
manipulation commands.

All registers begin with the value 0.

When the interpreter loads the program, it ignores all whitespace.  If
it encounters anything that is not one of an instruction and is not
whitespace, it will give an error, otherwise it loads the file, one non-
whitespace character per cell, into memory.  Cells which are not
initialized are set by performing op on the previous two cells
repetitively.

Commands
^^^^^^^^

When the interpreter tries to execute a program, it first checks to
see if the current instruction is a graphical ASCII character (33
through 126).  If it is, it subtracts 33 from it, adds C to it, mods it
by 94, then uses the result as an index into the following table of 94
characters:

+b(29e*j1VMEKLyC})8&m#~W>qxdRp0wkrUo[D7,XTcA"lI
.v%{gJh4G\-=O@5_3i<?Z';FNQuY]szf$!BS/|t:Pn6^Ha It then checks it against the characters listed below, and performs an appropriate action. If the result is not one of the characters listed below, it is treated as a nop. If the original character is not graphic ASCII, the program is immediately ended. When the interpreter parses the input file, it checks each non- whitespace character with the process above. If any result is not one of the eight characters below, the file will be rejected. After the instruction is executed, 33 is subtracted from the instruction at C, and the result is used as an index in the table below. The new character is then placed at C, and then C is incremented. 5z]&gqtyfr$(we4{WP)H-Zn,[%\3dL+Q;>U!pJS72FhOA1C
B6v^=I_0/8|jsb9m<.TVacuY*MK'X~xDl}REokN:#?G"i@

j
sets the data pointer to the value in the cell pointed to by the
current data pointer.

i
sets the code pointer to the value in the cell pointed to be the
current data pointer.

*
rotates the trinary value of the cell pointed to by D to the right 1.
The least significant trit becomes the most significant trit, and all
others move one position to the left.

p
performs a tritwise "op" on the value pointed to by D with the
contents of A.  The op (don't look for pattern, it's not there) is:

| A trit:
________|_0__1__2_
0 | 1  0  0
*D  1 | 1  0  2
trit 2 | 2  2  1

Di-trits:
00 01 02 10 11 12 20 21 22

00  04 03 03 01 00 00 01 00 00
01  04 03 05 01 00 02 01 00 02
02  05 05 04 02 02 01 02 02 01
10  04 03 03 01 00 00 07 06 06
11  04 03 05 01 00 02 07 06 08
12  05 05 04 02 02 01 08 08 07
20  07 06 06 07 06 06 04 03 03
21  07 06 08 07 06 08 04 03 05
22  08 08 07 08 08 07 05 05 04

<
reads an ASCII value from the stdin and converts it to Trinary, then
stores it in A.  10 (line feed) is considered 'newline', and
2222222222t (59048 dec.) is EOF.

/
converts the value in A to ASCII and writes it to stdout.  Writing
10 is a newline.

v
indicates a full stop for the machine.

o
does nothing, except increment C and D, as all other instructions do.

Turing-Completeness
^^^^^^^^^^^^^^^^^^^

Though I have not proven it, I _think_ Malbolge to be Turing-complete.
To be Turing-complete, there must be some data construct which can be
used to do any mathematical calculation.  I believe that using *p in
various clever ways on the tritwords can fulfill this requirement.

Turing-completeness also requires three code constructs: sequential
execution (which Malbolge obviously has), repetition (provided by the
i and, indirectly, j instructions), and conditional-execution (provided,
I believe, by self-modifying code and altering i destinations).

I do have my doubts, particularly about data constructs, but I *think*
this works...

Appendix: Trinary Conversion Table
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Trinary to ASCII to decimal to hex table, provided, strangely enough,
for the convenience of Malbolge programmers.

00000 NUL 000 00    01012   032 20    02101 @ 064 40    10120  096 60
00001 SOH 001 01    01020 ! 033 21    02102 A 065 41    10121 a 097 61
00002 STX 002 02    01021 " 034 22    02110 B 066 42    10122 b 098 62
00010 ETX 003 03    01022 # 035 23    02111 C 067 43    10200 c 099 63

# Find the nth positive integer m for which $$\\tan(m) > m\$$code-golfmath

Write a program/function that when given an integer $$\n\$$ as input outputs the $$\n\$$th positive integer $$\m\$$ for which $$\\tan(m) \gt m\$$.

Note: $$\m\$$ is in radians

## Scoring

This is so shortest bytes wins.

## Sample Testcases

# n -> m
1   -> 1
2   -> 260515
3   -> 37362253
5   -> 534483448
9   -> 214112296674652
10  -> 642336890023956
16  -> 4285797387061825747646013


Find more at A249836

Inspired by What is the biggest tangent of a prime?

• +1 for referencing a MegaFavNumbers video. – Razetime Aug 20 '20 at 3:24
• I don't understand the point. Are you asking us to find the nth number such that tan(x) > x? Is there any approach that will be shorter than iterating over all numbers until you find the nth number such that tan(x) > x? – the default. Aug 20 '20 at 3:33
• Where is n in the equation? I'm lost. – V. Courtois Aug 20 '20 at 9:07
• @Razetime On the channel Stand-up Maths, right? – Rosie F Aug 20 '20 at 18:49
• replace "nth" with "first" "second" etc -> "first/second/etc number m for which ..." i.e. n is not in the equation @V.Courtois – golf69 Aug 20 '20 at 20:30
• @Mukundan314 maybe indicate that n is the input? – golf69 Aug 20 '20 at 20:31
• @golf69 oh! So it has to be an integer, not a number. I see now :) And yes, indicating n is the input would be nice. – V. Courtois Aug 21 '20 at 6:50
• I don't really see this being solved any way that taking the generic golfiest code for "find the n'th number meeting [predicate]", of which there's plenty of challenges, and sticking in tan(m)>m for the predicate. – xnor Aug 22 '20 at 7:04
• Solutions relying on floating-point arithmetic will get the wrong answer starting around the 11th term. You’ll need to clarify whether that’s acceptable. – Anders Kaseorg Aug 22 '20 at 22:14

# Is it a Pythagorean triple? code-golfdecision-problemgeometrymathnumber-theory

Given three numbers, determine whether they form a primitive Pythagorean triple. Here is the definition:

• all three numbers are positive integers
• they represent the side lengths of a right-angled triangle, that is, $$\a^2 + b^2 = c^2\$$ for any ordering of $$\a\$$, $$\b\$$, and $$\c\$$
• no other primitive Pythagorean triple exists with the same ratio of side lengths, that is, they are coprime. For example, $$\[6, 8, 10]\$$ is not a primitive Pythagorean triple, even though it satisfies the above conditions, because the simper $$\[3, 4, 5]\$$ exists.

## Rules

• Unless your language doesn't support them, you must accept floating-point numbers (even though Pythagorean Triples use, by definition, integers)
• meta: Is this necessary? Is it too restrictive?
• You may be given negative numbers, $$\0\$$, or numbers that cannot form any triangle (right-angled or not, i.e. $$\a + b \le c\$$), in which cases you must return false.
• meta: Is this necessary? Does it make it too difficult?
• You can return any two distinct individual values, or any typical truthy/falsey values for your language.
• Standard I/O and loophole rules apply.
• This is , so shortest function or full program in bytes wins.

## Test Cases

[0, 3, 3] => false
[3, 4, 5] => true
[5, 3, 4] => true
[3, 4, 6] => false
[3, 4, 10] => false
[6, 8, 10] => false
[3.0, 4.0, 5.0] => true
[3.1, 4.0, 5.0] => false
[-3, -4, -5] => false
[3, 4, -5] => false
[4.5, 6, 7.5] => false
[91, 60, 109] => true
[264, 265, 23] => true
[81, 210, 184] => false
[140, 221, 83] => false


## Meta

• Are the first two rules necessary, or do they restrict it too much?
• Is it clear enough? Are there any additional rules I need to add? Are more test cases needed?
• Does this suit the and tags? It's kind of tangential to both areas.
• Is this too similar to the existing questions that want you to generate triples?
• possible duplicate of this challenge – Razetime Oct 18 '20 at 13:38
• @Razetime that challenge appeared on the front page today and inspired me to make this one. I thought it was different enough because of the coprime requirement and I added the extra rules about invalid values/floats to make it more interesting as well – pxeger Oct 18 '20 at 14:32
• Input validation tends to make for a challenge that is less fun. The coprime requirement is nice, but I'm not sure if it completely changes the challenge. – Razetime Oct 18 '20 at 15:04
• This seems to me to be too much a combination of two separate generic tasks, checking that a^2+b^2=c^2 when sorted, and that a and b are relatively prime. – xnor Oct 19 '20 at 9:40

# Am I A Perfect Two Integer?

A “perfect two integer” is an integer that works as x in the following equations:

Let i = integer, j = integer, x = perfect two integer:
2^i = x
j^2 = x


Example “perfect two integers”: 4, 16, 64, 256, 1024 (see a pattern here?)

Your answer should take a number from stdin or an argument. This should be relatively easy, but this is , so the shortest answer wins. (Note: there are ways to simplify these equations that aren’t listed here).

## Sandbox Questions:

1. Is this a duplicate?
2. Is this too easy?
3. Any other thoughts?
• My personal feeling is that this is too easy. There's not really much scope for golfing the answer once you find the pattern. – Sisyphus Oct 28 '20 at 0:25
• Yeah, you're probably right. It's kind of just like if it's a power of 4. I somehow didn't think about this while making the question. – nthnchu Oct 28 '20 at 0:34

Find out if a function returns its input.

# Input Format

Input is a math expression as a string with operators + - * /. Whitespace can be ignored. For more info, check the examples.

# Example Input/Output

Input: n /3 + 2*n/3 + 175 - 175x(n+ 1-n)
Output: true
Explain: Simplifies to "n".

Input: f
Output: true
Explain: Any variable is allowed.

Input: j*(j-3)/(j-   3)
Output: false
Explain: When j is 3, evaluates to an error.

Input: 1j
Output: anything or error
Explain: Use "1*j".


# Scoring

This is , so lowest amount of bytes wins!

## Sandbox Questions

I posted because of reputation limit, but was too unclear, any suggestions please?

• There's some inconsistency in the examples: the first one is being treated as if it's a maths expression whereas the third one is not. Suppose the input is n/2 + n/2. Should the output be true? In some languages the output will not necessarily be the same as the input: / might get you floor division or conversion to a float. You can avoid these issues by treating the input as maths. But in that case, example 3 should simplify to j. – Dingus Jan 5 at 9:38

# Undecidable halting set

Write a program such that the set of natural numbers on which it halts is not recursive.

Shorter is better.

You may assume natural numbers in your language are unbounded.

## Example: Python 3 (52 chars)

lambda n:eval(n.to_bytes(n.bit_length()//8+1,'big'))

• This boils down to "emulate a Turing-complete language", which is the same as eval in any Turing-complete language that supports the feature (as you already showed in the example). I don't think it's an interesting challenge. – Bubbler Jan 19 at 6:37
• @Bubbler Eval is only half the battle (assuming the language has eval in the first place). You still need to handle the fact that the inputs are natural numbers, not arbitrary strings. That is, you need to surject the natural numbers onto a set of strings sufficient to get the undecidable behavior under eval. – user76284 Jan 19 at 7:08
• @Bubbler I'd consider an eval-free version of the challenge though, if you have any suggestions. Not sure how that restriction is usually phrased/enforced. – user76284 Jan 19 at 7:09
• Eval is half of the battle, but the other half is converting a natural number to a string, which is just a matter of base conversion (which gives ALL strings, maybe except strings starting with null bytes, which doesn't matter in most languages). Unfortunately, banning built-ins is discouraged, and we already had a challenge about simulating a different Turing-complete language, so I don't think banning eval will make the challenge better. – Bubbler Jan 19 at 7:36
• @Bubbler Is banning eval not an objective restricted-source criterion, as opposed to “no built-ins”? – user76284 Jan 19 at 19:28
• Banning built-ins means banning a specific feature of a language, like some old challenge banned exponentiation. It is different from restricted source, which is about restrictions in the source code as text, not looking at the features it uses. There are various classes of eval, e.g. interpret the whole language (Python's exec), interpret the subset of the language (Python's eval and ast.literal_eval), interpret a different language (you can't even count how many Turing-complete mini languages are out there; if Perl regex is Turing-complete, would you ban it?), etc. – Bubbler Jan 21 at 0:53

Here is the problem, for which I can only think of an iterative solution and have not found a closed formula.

This problem was found on : https://www.codingame.com/ in the shortest codemode.

You need to paint a house with R rooms.

For each room there are four walls and one ceiling, which all have the same dimensions and need C coats of paint.

You can't paint the next coat until the previous one has dried. You're finished when every wall is dry. Time taken to move between walls, ceilings, rooms is negligible.

It takes you M1 minutes to paint each coat, and M2 minutes for the paint to dry on each. You must finish in the least possible time, otherwise they will not pay you.


NOTE DON'T FORGET, THE PAINT MUST ALL BE DRY BEFORE YOU CAN RECEIVE YOUR PAYMENT!

In :

Line 1: R, C, M1, M2 separated by spaces.
R: Number of rooms in the house
C: Coats of paint needed for each wall/ceiling
M1: Minutes taken to paint each coat
M2: Minutes taken for paint to dry on each coat (measured from when you've finished the entire coat)


Out :

The time taken to paint the entire house in the format H:MM


Contraints

1 ≤ R ≤ 10
1 ≤ C ≤ 20
1 ≤ M1 ≤ 10000
1 ≤ M2 ≤ 10000


Dataset:

input: 1 1 12 0

output: 60

input: 5 2 5 30

output: 280

input: 1 5 5 200

output: 1045

• Is this a problem from another site? If so, you need to state where the problem comes from. Also, unlike other online judge sites, we tend to allow submissions to be functions or full programs, and allow a wide range of I/O methods for both. Having to convert the minutes to hours/minutes and format as h:mm is not so related to the core (and requiring such formatting is discouraged on our site), so I suggest to simply output a number in minutes. – Bubbler Jan 28 at 0:16
• @Bubbler I have taken your remarks into consideration. I hope it's what you expected. – Simon Rochwerg Jan 28 at 9:31
• Do you have permission to repost this challenge? CodinGame's rules state (Article 9): 'The reproduction, representation or use of all or part of the components proposed in the CodinGame Contests is strictly prohibited.' – Dingus Jan 28 at 12:15
• Posting a challenge from elsewhere so that you can be shown an answer is engaging with this community in bad faith. You can ask for programming help in places such as SO, but this isn't intended to be one of them. – xnor Jan 28 at 17:05
• @xnor I am not acting in bad faith or such. I found this problem interesting and I wanted to share with the community to find an optimal answser. There is nothing for me it this except extending my own knowledge as well as community knowledge – Simon Rochwerg Jan 29 at 9:00

# Hello World! - Generation 3392

Your job is to create a genetic algorithm that slowly evolves and mutates its string until the output is equivalent to "Hello World!".

The genetic algorithm should start with a random string generated, and continue for generations, making random mutations to its code, like this:

Gen 3393 - Hemmo World!


To:

Gen 3394 - Hemko World!


# Heres how the randomization algorithm works:

1. Create a function named randint(n), import the time module.
# Written in Python 3.8
import time # imports time
def randint(n): # create function

1. Get the current time since Jan 1. 1970, multiply by n and assign it as var "t". Make t an integer not a float.
t=int(time.time()*n) # Set time, and multiply by n.

1. Use the "%" operation on var "t" (var t is the first argument), with var n as the second argument, assign it as "rand". Code in python should look like this:
rand=t%n #setup a psuedorandom number, since you already have a counter, use n as the limit number, and reset the counter once the counter reaches the limit number. This generates a psuedorandom number within n.

1. Return rand.
return int(rand) #return results as integer.


# Your program should have:

• A randomized start string (using the rand_int algorithm)
• A point it reaches "Hello World!"
• Mutation, using "parents". You are not allowed to completely change a string, only modify 1 character each generation.
• Mutations are not allowed to be repeated twice/No mutation backtracking.
• Once a genetic algorithm has a correct letter in its correct position (such as "e" in "reJ" and "Hes"). It is forced to stay as that letter in that position and the genetic algorithm is forced with that string forever, this repeats for all other positions. This way the time increases additionally instead of exponentially. So you cannot do this: ["Hlllr" -> "Hellr" -> "Hfllr"]

So I can do this:

Herlo Wcrld

Herlo Wrrld


But you cannot change >1 character/byte at a time:

Herto Wcrld

Heflo World


You can do whatever else you want with it if it satisfies those requirements.

# Scoring:

This is , so the answer with the least amount of bytes wins.

• For code golf to work, the rules must be very clearly defined. At the current state people will do do (s:=randomString()); while(s!="Hello world!"); print(s);  (pseudocode): (you can make this a popularity contest, but that's even harder to get right. I don't know why) – user202729 Feb 6 at 13:46
• @user202729 I want the person to make a genetic algorithm, where it starts with a random string. mutates the previous string randomly by 1 character during each generation, and eventually outputs "Hello World!" – fr4cew Feb 6 at 13:55
• Besides being poorly-defined, it is also an non-observable behavior. – user202729 Feb 6 at 14:02
• No, (hey, that's a link. Read it.) – user202729 Feb 6 at 14:09
• Wait, that's not what I mean. I'll explain it later. – user202729 Feb 6 at 14:47
• @user202729 Right... – fr4cew Feb 6 at 14:53
• But if the mutations between generations are random, there's no guarantee that the program will ever generate a specific string. You have to add a constraint like "the program should not generate a given string twice" – Sheik Yerbouti Feb 6 at 17:11
• @Davide I think that rule already existed in the "A point it reaches 'Hello World!'" but I'll add that anyway. – fr4cew Feb 6 at 19:26
• A few things that I find missing from the rules: How long is the string? How do you mutate space/punctuation marks? I agree that is has non-observable behavior, because you can't see it mutating the string. Does the code have to be in python? Why should it randomize its input and why should it be random during the process? Wouldn't it be better if you get a string from user input (defined length) and then transform it to "Hello World!" (because that would allow bf and other languages to work) – Deadbeef Feb 7 at 6:37
• @Deadbeef 1. The length of hello world, 2. It works with base 64, 3. No, 4. Because I liked it that way. 5. I do not know. – fr4cew Feb 7 at 15:22
• Okay, about the unobservable behavior, what I mean is... – user202729 Feb 7 at 15:59
• It's relatively hard to define what exactly "having a string stored internally" means (what if the string is stored as a list of int values (char codes)? What about encoded in the exponent like in FRACTRAN?) Instead, you can require the programs to output the generations (i.e., print the random strings, each subsequent string has one character changed, etc.) [please review other sandbox posts] – user202729 Feb 7 at 16:02

# Return all elements around an index forming sun

Define a function that takes in a 2D array and a 2D index, and return all the elements of the 2D array that are directly vertical to, horizontal to, and diagonal to the given index, and the returned list must omit the index itself.

External modules, like numpy, as allowed. The most efficient program wins.

• ... while we do have [fastest-code] on this site, there are specific requirements; restricting allowed programming languages is another problematic thing; – user202729 Feb 8 at 14:38
• besides, this definitely sounds like that you're outsourcing your homework to this site. – user202729 Feb 8 at 14:38
• @user202729 I already have a numpy solution... this is definitely not homework XD – Accept one day later Feb 8 at 15:34
• @user202729 Okay, removed language restriction. – Accept one day later Feb 8 at 15:35
• Okay, the other problem is with "most efficient code win". Code golf is popular around here because it's easy to measure, but with this you have to install all sort of weird programming languages on a test machine. – user202729 Feb 9 at 2:07
• I don't think this is very interesting to do fastest code anyway, because it can be done in linear time anyway (with the array given); besides the general consensus is to allow "full program or function" [please review other sandbox posts] – user202729 Feb 9 at 2:11
• @user202729 Okey. – Accept one day later Feb 9 at 2:27

# Create a Screw

There are a variety of code cad languages, as well as other 3d API's that allow you to define shapes with code. Some of these are limited, while others are Turing complete and/or use a popular programming language such as Python or JavaScript.

# The Challenge

Output a 3d model of a screw. Acceptable formats include .stl files and .obj files. A screw is defined as a shorter, wider cylinder on top of a taller, thinner cylinder, which should be threaded at least 5 times. Winner is whoever has the shortest code by two weeks after this question is posted. Standard rules and loopholes apply, with the exception that anything that allows you to programmatically define a 3d object is treated as a program language.

# Changes

Should I add a spot for the screw driver to my definition of a screw? On the one hand, that would be more realistic, but on the other, it might just add bloat to answers, since I don't think there's anything interesting you can do with it.

I plan to include an example of a minimal screw under whatever definition I end up using, with pictures and outputs in every allowed format.

For the purpose of sorting and answer headers, should each langauge/framework combo be treated as a separate language? I'm leaning towards this, since It would be cool to have an easily searchable set of code for a bunch of different frameworks.

• While the challenge is probably clearly defined enough, it might not allow solutions more interesting than hardcoding compressed output. – user202729 Feb 15 at 2:04
• How could I make sure that it does without fundamentally changing it? Or do you think that's not possible? I feel like there might be some potential for interesting ways of doing the threading, but I haven't used very many of these languages.. – import huh Feb 15 at 2:40
• No idea... I think that (1) if there's a lot of boilerplate in the file format, using a library might be shorter (2) if the structure of the output file is not very repetitive, computing the coordinates might be shorter than hard coding + compressing it. I'm not familiar with either file format so I can't tell. -- -- nevertheless the challenge is on-topic; what I've said only concerns whether it's interesting [please review other sandbox posts] – user202729 Feb 15 at 2:46
• I think both formats basically just contain the points for every triangle used to represent the 3d object. To be honest I didn't really think about directly creating the file. Compared to using a library, it seems incredibly inefficient. That could make for an interesting challenge on it's own, though... – import huh Feb 15 at 2:58
• You should probably add a specific diagram with the proportions for the screw, or maybe ask the program to take it as input – Razetime Feb 15 at 2:58
• @Razetime There's no specific proportion, just "larger" and "smaller". – user202729 Feb 15 at 3:06

# Print your PPCG avatar

This is a graphical output question.

You have to connect to the codegolf.stackexchange.com in your homepage, scrape and download your avatar and show it in your default image viewer or some other way.

Standard loopholes apply, connections only allowed to codegolf.stackexchange.com

One language can be only used once, but a user can post multiple answers in different language

• This is probably a dupe of this. Finding the avatar instead of the id wouldn't affect most of the code. Your final line is odd, do you mean that if I answered in a language it would prevent anyone else from using that language? That seems like a bad rule - what if I started on my answer and someone posted while I was working? I can't see any benefit, but perhaps I am not understanding. – FryAmTheEggman Feb 20 at 18:10
• I think it would be interesting if you have to print the ascii representation of the user before you , without scraping. With a standard way to produce the ascii image so people can't differ. i.e. img to ascii – Alex bries Feb 20 at 21:13

See who can write the longest code in order to print "Hello World!". The rule is that if you remove any single character from the code, it should NOT run.

• I think we have a similar challenge already. It's pretty easy to get an infinite score with these rules. – Redwolf Programs Feb 25 at 1:23
• It is a weaker version of Programming in a Pristine World and a different variant of Biggest Irreducible Hello World. But note that, in many languages, it is possible to add arbitrarily long no-op code that breaks when exactly one char is removed. For example, Python's ''+''+''+... causes syntax error when any of ' or + or a newline surrounding it is removed. – Bubbler Feb 25 at 1:41

# Output function from one to another

I tried to post this twice and I gained negative feedback, so I will put what I have in mind here if anyone is interested.

Get a certain output function from one programming language and transfer to another. You'll be recreating an output function that came from a different programming language. There is a certain criteria in order for the answer to be valid:

1. It should function the same way as the original function. All things that function can do should be applied to the recreated one. For example, Python's print() has certain keywords like end.
2. Syntax doesn't matter. Example, if you can't use the << for cout, don't use it. Use what's available.
3. The function should be able to output the same errors like the original. Replicate the same errors from the original function. If impossible, leave it out.

An answer example would be making printf() from C using Python or making Console.WriteLine() (or just WriteLine() if incapable) from C# using Ruby. Any output functions that are already similar to 2 languages don't need to be replicated in any of them.

• "Get a certain output function from one programming language and transfer to another." To clarify, is the challenge to write source code which works in two different languages and does the same thing? What's the winning condition because this sounds very trivial. For example, print does the same thing in many languages. – 79037662 Feb 24 at 20:25
• Actually that doesn't mesh with "syntax doesn't matter". The point of this challenge is completely unclear, could you please clarify it? – 79037662 Feb 24 at 20:26
• I see you edited this post but the point of the challenge is still completely unclear. What exactly would a valid submission look like? – 79037662 Feb 25 at 20:56
• I don't really get the point of this task. Sure, someone could write code that does this, it might take some work to get exactly right, but is there a challenge underneath it? Is it code golf? – xnor Feb 26 at 3:08
• @xnor It isn't code golf, nor king of the hill. It's an ordinary coding challenge if they can replicate a function from one language to another. – Mark Giraffe Feb 26 at 5:53
• @MarkGiraffe That's not really a thing on this site -- challenges need to have an objective winning criterion. From the close reason: "Questions without an objective primary winning criterion are off-topic, as they make it impossible to indisputably decide which entry should win." – xnor Feb 26 at 8:13

# Random Roman Numerals

Printing a random number is easy, but what about roman numerals? Your task is to output a random roman numeral from 1 to 1000, both inclusive.

Requirements:

• Each number has to have the same chance of appearing
• The program should use the language's random module or other random algorithm

Remember, I is 1, II is 2, III is 3. V is 5, X is 10, L is 50, C is 100, D is 500, and M is 1000. Also note that IV is 4, IX is 9, XL is 40, XC is 90, CD is 400, and CM is 900. For more information see the Wikipedia page.

This challenge is , so try to have the shortest program possible!

• I'd really recommend loosening the restrictions for the random numbers. What if the language's random module doesn't guarantee exactly equal chances? Can we assume it does? What about an implementation of an algorithm typically used by language's random modules, like xorshiro or the mersenne twister? A much better restriction in my opinion would be requiring that every result is possible, and it's unlikely people will deviate too far from a uniform distribution anyway. – Redwolf Programs Mar 10 at 5:43
• Sounds like you're combining two or more unrelated core challenges into one ― consider splitting the challenge up into separate challenges ― or dropping unnecessary parts. Just watch out for duplicate challenges: random number generation and Roman numeral conversion are popular tasks. – Adám Mar 10 at 6:01

# Is this an one-one function?

Two sets given as input, one is the domain of a function, and other one is the co-domain of a function. As an example

$$\{1,2,3,4\}$$ $$\{5,6,7,8,9\}$$

Now if the range set of the function, i.e. set of each element in the co-domain set which maps to the domain set (1 -> 5, 2 -> 6, ......) is equal to the co-domain set, then it is a one-one function.

For the above example, the range set is

$$\{5,6,7,8\}$$

So the range set is not equal to co-domain set, the function is not a one-one function.

# Challenge

Inputted two domain and co-domain set of function, output a truthy value if the function is one-one or falsey if not.

# Test cases

{1,2,3,4} {5,6,7,8,9} -> Falsey
{a,b,c} {b,c,d} -> Truthy
{4,8,2} {3,4} -> Falsey


Standard loopholes apply, , so shortest code wins

Pre-defining the input sets in the header section of TIO is not allowed.

• Is this challenge simply asking if the two sets have equal length? If not, can you include counterexamples? – water_ghosts Mar 21 at 18:03
• @water_ghosts yes i feel it is like that – Wasif Mar 22 at 5:14
• not particularly interesting – rak1507 Mar 22 at 12:11

# Remaking Kernel code-golf

I made a program as a final project in the main CS50 Harvard course, and it was named Kernel, written in C alsongside CS50's library.

## Functions

It has 7 functions: 4 main (talk, count, calculate, build) and 3 advice functions (error, feedback, help).

What each function does:

• Talk asks for a prompt to the user and outputs the same thing.
• Count asks for a number to count from 1 to there. If the number is bigger than 50, it will lead to an error.
• Calculate asks for 2 numbers and an operator (must be either +, -, * or /) then will calculate the value. If the result is a number is greater or equal to 999999999, it leads to an error. However, 0 / 0 = 0 and other division rules still apply.
• Build asks for a size and something that it can build, which could be either a line, tower, wall, or pyramid. If the size is more than 20, it leads to an error. It would then ask for the character you want to use to build it, then it will be used to build the final product. There are multiple errors here, which is explained at the Error function.
Disappointed that I can't make a proper pyramid.
• Error is a library that shows all 14 errors, which is listed in the Error page of this post.
• Feedback asks for feedback from the user and they can type whatever they want. The input will then be transferred in a new file called Feedback.list.

Inside Feedback.list:

• Help displays the info of the entire app.

## Errors

There are 14 written errors to prevent writing the real errors.

1. NO_FUNCTION_ADDED: When asking for which function to use, entering a non-existent one will result to this error.
2. ERROR_CLASS_NONE: In Error, entering a number which doesn't have its error will pop this up.
3. COUNT_MAX: Well, typing a number greater than 50 won't put up the error, but counting up to 50 will.
4. INVALID_DIVIDE: Anything divided by 0 in Calculate (except 0 / 0) will put up this error.
5. ExTREME_VALUE: In Calculate, earning a final number of 999,999,999 or more will result to this error.
6. OVERSIZE_CHUNK: Entering a size larger than 20 in Build will result to this error.
7. UNKNOWN_STRUCTURE: Also in Build, inputting a structure unavailable will pop this up.
8. UNCLEAR_INSTRUCT: If the input for Build's line is not vertical, horizontal or diagonal, they wouldn't know what it is.
9. OVERWIDTH_COUNT: Building a tower with a width of 20 or more is invalid.
10. INVALID_PYRAMID: Similar to Build's line, inputting a pyramid unavailable pops this up.
11. OPERATE_BAD: Inputting an operator unavailable in Calculate is invalid.
12. MORE_NAMES: If you didn't know, to run Kernel, you need to add your name alongside running it. Me, I use ./Kernel MarkGiraffe. If I use Mark Giraffe instead, it is invalid.
13. SECRET_USER: Even NOT putting a name is not allowed.
14. BAD_ALIGNMENT: Not choosing left or right for a diagonal line in Build is invalid.

For this challenge, I want you to remake the program the most designed way, while still keeping low bytes.

In case you are interested, I will post the source code somewhere where you can view it.

• This has LOTS of quality issues. 1) Being a multipart challenge with unrelated subtasks. 2) Rigid I/O (command line arguments AND interactive stdin/stdout AND file output). 3) Input validation and error handling in arbitrary ways. 4) Lack of specification in certain cases. 5) Putting I/O examples in images instead of code blocks. – Bubbler Mar 23 at 4:10
• I think the outstanding question is, why would people want to code and golf here? Like, it's cool that you wrote a thing, but it seems like a lot of work for someone to re-do on a recreational programming site without a really compelling reason. – xnor Mar 26 at 3:29

Given a program as input. If the program ever output a '1', output a truthy value and halt; if it halts without ever outputting a '1', output a falsy value and halt; if it falls into infinite loop without outputting a '1', fall into infinite loop.

• This is unclear, for example: what language will the program be in? Do we take it as a string? And for a turing-complete language, this is impossible (at least if it can take input). – Wzl Apr 2 at 15:45
• @Wezl Why not?? – l4m2 Apr 2 at 16:09
• You didn't specify the above ^ points, which are important. – Wzl Apr 2 at 16:17

# Poly-functional Polyglots

I don't have a ton of time to work on this, so I decided to remove it temporarily while I rework the scoring.

• I think the scoring system is too convoluted. Optimizing for the bonuses seems like more of a challenge than completing the core task. And if number of languages is the denominator, it’s hard to know how to calculate that upfront. How many shells does echo “Hello World” work in? If I later learn about another one, does that retroactively lower my score? – water_ghosts Apr 2 at 16:53
• @water_ghosts thanks for saying so. I was worried that that would be the case, especially after reading the discussion on things to avoid in questions. I'm going to try and rework this. – Aaron Miller Apr 8 at 19:26

# Unlock Tim Cook’s iPhone

This is Tim Cook, CEO of Apple. Your challenge is to write a program to output a picture that will be recognized as the same person by a facial recognition model.

Test your picture using the face_recognition package—we’ll use the current version as of this challenge’s release, face_recognition 1.3.0 with face_recognition_models 0.3.0:

mkdir known
wget https://i.stack.imgur.com/owjG4.jpg -O known/tim_cook.jpg
face_recognition known YOUR_OUTPUT.png


If successful, this will output a line like YOUR_OUTPUT.png,tim_cook indicating a match.

See our default rules for allowed image output methods. (Since face_recognition loads the image using Pillow, if your chosen output format is not one of Pillow’s supported formats, you’ll need to convert it to run this test.)

Your program may not use any data about faces from libraries or external sources without including it in your byte count. Shortest program wins.

# Every number is interesting

We know that every number is interesting but how?

You should write a program or function which:

• takes a list of N positive integers (>0 and <2^31)
• outputs N lines each of them showing how the corresponding input number is interesting
• is not longer than 1024 bytes
• uses no more than 1 second per number
• doesn't use external sources

## Examples

172: 444 in base6
5776: 76*76
9801: 9 * 1089 (reverse)
68101: no 11 in base2 (10000101000000101)
491033: 317 * 1549 (product of 2 big primes)
467808816: no digit 5 from base6 to base10


## Inputs

You should include the output for the following input in your post:

58 92 120 224 358 490 912 1578 7812 222008 1645060 19796411 550453633


If you care to run your program on a bigger sample and share the result with us use this input data (2500 numbers). (You can upload your output to e.g. pastebin.)

This is a popularity-contest so highest voted answer wins.

Tags: popularity-contest, number

• What sort of criteria are necessary for defining a number as 'interesting'? I see things like square numbers, other bases, etc. But are there any specifics? I'm interested in this challenge (but worried it might be closed as too broad). – ASCIIThenANSI Apr 7 '15 at 13:18
• @ASCIIThenANSI There wasn't a clear definition. That's part of the reason why I abandoned the challenge. – randomra Apr 8 '15 at 1:55
• Would you mind if I tried taking it up? I would have to post as a new answer, because I can't directly edit. – ASCIIThenANSI Apr 8 '15 at 2:00
• @ASCIIThenANSI Not at all. – randomra Apr 8 '15 at 2:01
• @ASCIIThenANSI Where did you post it? – wizzwizz4 Jul 24 '19 at 13:33
• @ASCIIThenANSI I am also curious – MilkyWay90 Aug 27 '19 at 23:41

# Create a Drawing Guide for a Polygram

Poor old Jim, he's just terrible at drawing polygrams, and he's asked you to create a "drawing guide" for him - an ascii polygram with numbered edges, so he can follow the instructions.

## Challenge

Write a program to produce an ascii polygram with P <= 10; each edge of the polygram should be made of a single digit 0-9, showing the order in which the edges should be drawn.

## Input

Your program should receive (via STDIN, as function arguments, or some other language-appropriate method): P, the number of edges/vertices of the polygram, and Q, the spacing. In the notation as per the Wikipedia link, you'll be drawing a {p/q} polygram.

## Output

Either print to STDOUT or return (or something else language-appropriate) a multiline string showing the drawing guide for the given polygram. The string can be any size you like, as long as it's large enough to display a clear polygram.

## Notes

Your code should be able to handle compound regular polygons as well as regular regular polygons, and also inputs of q > p/2 (poor old Jim doesn't realize that the polygram for {p/q} is the same as for {p/p-q}).

## Example Output for {10,3}

              5
5 4
4
21     5        888
2 11115     8888  7
2    5111888 4    7
2     888111  4   7
2  888      111   7
8885           4117
8882               4 711
8   2 5               7  111
25               47
9   5                 7    0
9  2                 74  0
52                 7  0
9 2                 7 4
5 92                 7 04
9                 70  4
5   2                 7
5    29                7    4
6666 2 9              07   33
666              0 7333
2 696           337
2   9666     333  7
2    9  66633 0   7
2      333 666    7
2   339       666 7
2333   9    0    67
9  0
0
`

## Scoring

This is code-golf, so shortest in bytes wins. Tiebreaker goes to the most votes.

• I have a python solution to this which is ~600 bytes, so it's definitely doable, and it's not easy... – sirpercival Apr 27 '15 at 4:31
• I think the spec needs to be more prescriptive for this to make a good question, especially since the example seems to indicate that you're not currently even prohibiting the lines from having gaps. At a minimum I would say that you should require the lines to be equivalent to those produced by Bresenham's algorithm, and specify how overlaps should be handled; at the extreme, you could tie it down so tightly that it becomes a parameterised kolmogorov-complexity. – Peter Taylor Apr 27 '15 at 9:34