What is the Sandbox?

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

To post to the Sandbox, scroll to the bottom of this page or click on the "Add Proposal" link below, and click "Answer This Question". Click "OK" when it asks if you really want to add another answer. Write your challenge just as you would when actually posting it. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it. When you think your challenge is ready for the public, go ahead and post it, replace the post here with a link to the challenge and delete it.

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

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

Add Proposal

Search the Sandbox

Browse your pending proposals

Get the Sandbox Viewer to view the sandbox more easily

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

| |

2914 Answers 2914

63 64
66 67


Tic-Tac-Toe is a solved game. It is possible on current hardware to generate a complete game tree using the minimax algorithm. However, doing so is CPU and memory intensive. There are various ways of generating an incomplete game tree that will still solve the game using, for example, sorting, pruning, lookup tables and other means.


Your task is to code a function that, given a particular game state, will construct a game tree and "solve" the game. Your function is expected to return the best possible move given the current game state and also output the game tree, along with a total count of the nodes constructed, to the console. The objective is to generate the smallest tree, by node count, while still solving the game. The function must accept at least two arguments. 1) a string representing the game state. 2) an integer representing who's turn it is to play.

The winning entry will be the one that generates the least amount of nodes while still solving the game. If there is a tie, the function that was submitted first will win, unless the subsequent entry can be shown to run 25% faster. Scoring (number of nodes), will be done only with the input given in the input example below. Note that your function is still expected to work properly given any valid tic-tac-toe game state.

Example Input and Output

The first agument passed to the function is the game state. It is represented by a string of 9 comma seperated integers. Each integer represents the state of a square on the tic-tac-toe board sequentially. 0 reprensents an empty square, 1 a square with an X and -1 a square with an O.

The second argument is the player who's turn it is to make the next move. It is an integer where 1 means player X and -1 means player O.

Input example:

"0,0,0,1,0,0,-1,0,0", 1

This example input represents the following game sate, with player X making the next move: Tic-Tac-Toe board


The function will return an integer 0-8 representing the next move.


The function must also output the game tree to the console and how many nodes were created.


Final instructions

If you end up using look-up tables, they must be empty to begin with and be generated as the tree is being created/traversed.

Node values should be dependant on children terminal/leaf node actual values. Your are not allowed to use some kind of heuristic or simulation to evaluate a node. If a tree branch is not expanded all the way to terminal nodes, it must be because the algorithm figured out that it would be useless to do so or because it has already come across the same game state node elsewhere in the tree and can use that information instead of expanding further.

| |

What can I spell?

My mother-in-law has a set of wooden blocks that together spell out fRoSty The Snowman. Specifically, f, R, o, S, t, and y are all painted on separate blocks (note that R and S are capitalized). And then there's one longer block that says The Snowman.

However, each block also has a different letter on the reverse side. For example, if you flip the f block around, it shows a B. So you could instead spell out BRoSty The Snowman. (Sidenote: Googling Brosty the Snowman reveals several Twitter users with that alias. Those people are not me, and their opinions are their own. I do not endorse their comments.)

Similarly, the reverse side of the R is an e, and on the back of the t is a u.

Or actually, I'm not really sure if that's a u or an n on the other side of the t. So I guess it could really be either one!

So the full set of blocks is

f <--> B

R <--> e

o <--> M <--> W

S <--> i

t <--> u <--> n

y <--> E

The Snowman <--> xo xo xo <--> ox ox ox

Note that The Snowman has a space, and xo xo xo includes two spaces, as does ox ox ox.

Of course, when writing out a phrase you can re-order the blocks, you don't have to use every block, and you can't use a block twice. (If you like: from each block, either zero or one of the two or three options may be used.)

Finally, you can insert at most 1 space in between any two blocks. So both fRoSty The Snowman and fRoStyThe Snowman are possible, but fRoStyTheSnowman is not possible because the block with The Snowman includes a space.

So the question is, Given a phrase, can I spell it out using these blocks?


A string of printable-ASCII characters, of length 1 or more. If you like, you may assume the input has only letters (A-Z a-z) and spaces .

You may also assume that the input won't begin or end in a space, and will never have multiple spaces in a row.

You may take the input as a string or array of characters or whatever is convenient and conventional in your language.


You should output a Truthy value if the message can be spelled using the blocks, and a Falsey value otherwise.

Truthy Examples:

fRoSty The Snowman

fRoStyThe Snowman

SMuRfy The Snowman

fRy SuM ox ox ox

xo xo xo MRS BEn

xo xo xo MR BEn (don't need to use every block)

eW (Both e and E appear in the set of blocks)

WRiThe Snowman

R u The Snowman

y i M The Snowman Rn

BRThe Snowmano

Box ox oxy

xo xo xo

t o yS


Falsey Examples:

The Snowman BRoW (the o and W can't occur simultaneously)

TheSnowman (again, the block in question clearly reads The Snowman)

The snowman (input is case-sensitive)

The Snowmen

The SMuRfy Snowman



xo xo xo The Snowman



yo yo yo

Ho Ho Ho

xo xo xo MR bEn

More egg nog please

Invalid inputs (you are allowed to assume such inputs will not occur):

The Snowman (adjacent multiple spaces)

(has space at the beginning/end of the string)

fRo5ty (only letters and spaces allowed)

Is there any more egg nog left?

Should we make some more egg nog?

Is there any alcohol at all in the house?

I'll be back in a bit

`` (The empty string)

Other rules

My mother-in-law's Internet access is not the best, so the shorter your code, the better. Hence, this is . Shortest code wins! You may use any of the default input and output methods, and standard loopholes are forbidden.

If you have a built-in that will do this for you, then I guess this is your chance to use it! Please feel free!

Room for improvement

Obviously, let me know if this is too close to another question, or if it's unclear.

Please let me know if you'd rather see different rules. Please feel free to propose any suggestions that would improve the challenge.

Other test cases that I need to include?

Would different formatting be more convenient?

| |
  • \$\begingroup\$ "it could really be either one" What does that mean? \$\endgroup\$ – Buffer Over Read Dec 28 '16 at 1:56
  • \$\begingroup\$ I mean that the block could function as either a u or an n. (Because if you turn a u upside down, it becomes an n.) \$\endgroup\$ – mathmandan Dec 28 '16 at 13:37
  • \$\begingroup\$ Well, that's more clear now. \$\endgroup\$ – Buffer Over Read Dec 28 '16 at 13:41

Create an equation who's only solution is the numerical ASCII code of the equation itself

Your equation will be run as a Wolfram Alpha query with Solve prepended to it.

The equation must start with (spaces optional):

y = 

Output is considered to be the string in the second box of Wolfram Alpha, after your prefix (above) is stripped. If the string is not numerical, it is disqualified.

Only these functions are allowed.

| |
  • \$\begingroup\$ This is a duplicate of the standard quine challenge with a language restriction slapped on top. Its not uninteresting or boring but I and I would think others will vote to close this if it is posted as is. I don't have any recommendations for how to fix this, but if you want to see this answered I would suggest offering a bounty rather than posting a question. \$\endgroup\$ – Ad Hoc Garf Hunter Dec 27 '16 at 5:25

Golf a Sound Change Applier

(Snappier title suggestions appreciated)


The pronunciation of human languages changes over time. Often, sound changes follow discernable rules, with the same change applied consistently across many words in a language. For example, a lot of words that started with f in Latin now start with h in Spanish: facere -> hacer, fervere -> hervir, fīcus -> higo, and fīlius -> hijo.

Mark Rosenfelder, a well-known name in conlang circles, wrote a program called Sound Change Applier to help simulate this process. Actually, the SCA constitutes a small pattern-matching and substitution language. For this challenge, we're going to implement a pared-down version.

The language

An SCA program transforms a list of words according to a collection of sound change rules. It consists of two sections: category definitions and substitutions.

Category definitions are lines of the form V=aeiou, where V is the category name (must be a single character) and aeiou are the category entries. Categories define groups of similar speech sounds (we'll use the term "letters," though strictly speaking that's a bit misleading); for instance, the above example is the category of vowels.

Substitutions are where the magic happens. They take the form target/replacement/environment, where the constituent parts are as follows:

  • target and replacement are strings containing any number of letters and 0 or 1 category names, in any order. They represent the string to be replaced and the string to replace it with, respectively.
  • environment is a string containing exactly 1 underscore (_), representing the substitution, and any number of letters and category names, representing the required context for the substitution to take place. It can also contain the # character, representing the beginning or end of a word.

Some examples, assuming the V category from earlier:

ii/i/_    Change ii to i anywhere in a word
i/j/_V    Change i to j when followed by a vowel
u/o/_#    Change u to o at the end of a word
p//V_t    Delete p if preceded by a vowel and followed by t

Categories in substitutions

When category names are used in the environment, the environment matches if any member of the category is in the appropriate place. For example, the last rule above will delete the p from apt, opt, inept, or scripting, but not from thbpt.

The same is true when categories are used in the target but not the replacement. For example, the rule V/e/Vr_# will delete any vowel if it matches the environment: opera -> oper, sombrero -> sombrer, calamari -> calamar (but not cobra -> cobr because the environment vowel isn't matched).

However, if categories are used in both the target and replacement, the replacement letter must come from the same position in its category as the matched target letter does in its category.

For example, suppose we have these category definitions: S=ptc, Z=bdg. (These are unvoiced and voiced stops, respectively.) Then the substitution S/Z/V_V (changed unvoiced stops to voiced between vowels) represents three possible substitutions: p -> b, t -> d, and c -> g.


An SCA program accepts as input a list of words to be transformed. It goes down the list of substitutions in order, applying each one to all words in the word list. Each substitution is applied repeatedly until the environment and/or target no longer matches. Then the next substitution is applied. When all substitutions have completed, the program outputs the transformed list of words.

Miscellaneous rules

If a category is used in the replacement, a category must also be used in the target.

The replacement may be empty, but the target may not be empty.

Category names, letters, and words in the word list will never use the characters =/#_ or space.

The challenge

Write a program or function that takes an SCA program and a list of words and outputs/returns the result of running that program on those words.

You may assume that the SCA program is syntactically valid and that the words do not contain any forbidden characters. If these assumptions are broken, your code may do anything (handle it gracefully, crash, output gibberish).

I/O format

Input format is flexible. You may take the program as a multiline string or a list of strings. The category definitions and substitutions may be in the same string/list or two different strings/lists (or contained in a two-item list). The input words may be in a list or a space- or newline-delimited string. Similarly, output may be a list or a space- or newline-delimited string.

Any of the default I/O methods are acceptable. You may use different input methods for category definitions, substitutions, and input words if it makes the task easier in your language.

Linguists use many letter forms that are not present in ASCII. Therefore, your program must be able to accept Unicode characters up through U+1FFF (at least) in both the rules and the word list.


Adapted from Mark Rosenfelder's site, here is a simplistic Latin-to-Portuguese converter.





Given the following input list:


the output list should be as follows:


This is ; the shortest code wins.

| |
  • \$\begingroup\$ "Sound Change Applier" is so XKCD thing-explainer style! Although I admit it might not be a good fit here on PPCG. As for the challenge itself, I'd say, try to make it a bit more clear, have explicit definitions for all the important words you pick, so that there is no confusion on what counts as substitution and what doesn't, as an example. \$\endgroup\$ – Buffer Over Read Dec 28 '16 at 1:53

Output every string

Your task here is simple. Write a program, in as few bytes as possible, which prints every single possible string. Your program should, given infinite memory, never terminate, however for any given string there should be a finite time to be generated. (that is, a aa aaa aaaa ... Won't work as it will never generate b).

The strings to be generated should consist of all the characters in the same encoding as your answer, which you must specify if not utf-8.

The exception is that you must choose a character to exclude from your strings, which you will use to delimit strings. You may optionally have one leading delimiter.

Remember to include the empty string!

| |
  • 4
    \$\begingroup\$ I think this would be a duplicate of output all strings. \$\endgroup\$ – xnor Dec 28 '16 at 20:14
  • \$\begingroup\$ @xnor that one takes input, this one just encompasses every possible string. I think it's worth having a challenge for that. \$\endgroup\$ – Pavel Dec 28 '16 at 20:25
  • 1
    \$\begingroup\$ I disagree here: the new part is generating one of every character (except a separator), which I don't think merits a new challenge. \$\endgroup\$ – xnor Dec 28 '16 at 20:28

Arrange ranges of numbers in columns

Write a program to print from m to input n with step s, arranging the numbers in either horizontal or vertical columns.


  • You can use any two values, or kinds of values, for signifying horizontal and vertical columns, specifying these in your answer.

Test cases

m = 1, n = 15, s = 1, vertical columns

m = 1, n = 11, s = 2, horizontal columns

m = 1, n = 11, s = 2, vertical columns

Any more clarifications or test cases?

This challenge is based on a chat mini challenge by Helka Homba, which is allowed to be used in real challenges under the conditions of Calvin's Hobbies Public License.

| |

Natural Order Sorting

Goal :: Writing a sorting algorithm that doesn't need preceding zeroes to sort music files properly.

Natural Order Sorting will be defined in this way:

  • Consecutive Digits (ie [0-9]+) are considered one character and its value is the evaluation of those digits as an integer (eg int("0123"))
  • Uppercase Letters (ie [A-Z]) are each their own character and its value is the ASCII value of the letter
  • Lowercase Letters (ie [a-z]) are each their own character and its value is the corresponding uppercase value plus .5
  • Symbols (ie [^0-z]) are each their own character and its value is the ASCII value of the symbol
  • Symbols are always before Digits which are always before Letters
  • If two characters are in the same category, the one with the small value precedes the other


  • Input :: An unordered list of strings (flexible on how)
  • Output :: A list of strings that are naturally ordered (flexible on how)
  • Victory :: Shortest program/function in bytes, wins

Test Cases

Input                             Output
-----                             ------
10,11,8,9                      -> 8,9,10,11
appleA,CiderB,AppleC           -> AppleC,appleA,CiderB
File1,File12,File143A,File031B -> File1,File2,File031B,File143A

| |

Source code standard deviation

Your program should accept as input a string, convert it to a unsigned byte array using UTF-8 encoding and output the standard deviation of the n bytes.

Standard deviation is given by this formula, where x1...xn are the string's bytes:



Input hello:

  • UTF-8 encoding returns the list [104,101,108,108,111]
  • mean is 106.4
  • standard deviation is 3.49857113690718

More test cases:

  • ppcg: 5.678908345800274
  • aaaaa: 0
  • azazaz: 12.5
  • smiley☺: 41.12432220162674


Your score is the standard deviation of your source code, using the above algorithm, divided by the length of your source in bytes, using UTF-8 encoding. The higher the better.

For example, the score for the program hello is: 3.49857113690718 / 5 = 0.699714227381436

Related: Calculate Standard Deviation

| |
  • \$\begingroup\$ Programs can pad their standard deviation by including a huge number of the highest and lowest possible character in equal amounts in a comment. \$\endgroup\$ – xnor Jan 12 '17 at 6:18
  • \$\begingroup\$ @xnor yes, but after some time, the score decreases when adding these characters. For example, hello scores 0.69, hello ÿ scores 6.15, hello ÿ ÿ scores 5.31. \$\endgroup\$ – Arnaud Jan 12 '17 at 7:08
  • \$\begingroup\$ I see you now this doesn't raise your score arbitrarily, though the numbers I'm getting are different. \$\endgroup\$ – xnor Jan 12 '17 at 7:19
  • \$\begingroup\$ @xnor I think you need to use statistics.pstdev, not statistics.stdev \$\endgroup\$ – Arnaud Jan 12 '17 at 7:31
  • \$\begingroup\$ So an answer in Unary is guaranteed to score 0? \$\endgroup\$ – Peter Taylor Jan 12 '17 at 10:40
  • \$\begingroup\$ @PeterTaylor yes, an answer in Unary is guaranteed to lose, as the higher score the better. \$\endgroup\$ – Arnaud Jan 12 '17 at 10:42
  • \$\begingroup\$ @SuperChafouin I see. Putting in pstdev still gives different numbers from yours. \$\endgroup\$ – xnor Jan 12 '17 at 21:45
  • \$\begingroup\$ ÿ is interpreted by the python command ord as integer 255 - while it should be the two bytes 0xC3 0xBF. \$\endgroup\$ – Arnaud Jan 13 '17 at 4:09

The many errors of twin primes

Note: this is a repost of my earlier challenge, but with a different winning condition and better rules.


Bob was handed the following assignment for his programming class (this is not the actual challenge).

Homework assignment 11: Twin primes

Take as input an integer n ≥ 8 and print a single character, depending on n:

  • If n is not a prime number, print N for "Not prime".
  • If n is a prime number, but neither of n - 2 and n + 2 is, print I for "Isolated prime".
  • If n and n + 2 are both prime numbers, print L for "Lower twin prime".
  • If n and n - 2 are both prime numbers, print U for "Upper twin prime".

Bob tried hard to solve the assignment, but his program kept crashing, and in the end, he gave up and submitted it in hope of partial credit. Nevertheless, Bob's program has the curious property that even though it never does what it's supposed to, the input is still classified correctly depending on the program's behavior: non-primes result in no output, isolated primes in a crash, lower twin primes in an infinite loop with no output, and upper twin primes in an infinite loop that keeps printing the correct message.

The Task

Your task is to replicate the behavior or Bob's solution: you shall write a program or function that behaves as follows. Your input is a single integer n ≥ 8.

  1. If n is not a prime number, print nothing and exit gracefully.
  2. If n is a prime number, but none of n - 2 or n + 2 is, print nothing and exit with a runtime error of some kind (like stack overflow or division by 0).
  3. If n and n + 2 are both prime numbers, print nothing and keep running indefinitely (or until you run out of memory).
  4. If n and n - 2 are both prime numbers, repeatedly print the character U to STDOUT indefinitely (or until you run out of memory). The output can contain newlines, commas or other separators.

Input can be taken with any of our default methods, but all output must go to STDOUT (and STDERR in case of error) or closest alternative.

The lowest byte count wins.

Test cases

8 -> [no output]
9 -> [no output]
10 -> [no output]
11 -> [infinite loop]
12 -> [no output]
13 -> UUUUUUUUU[continues indefinitely]
14 -> [no output]
15 -> [no output]
16 -> [no output]
17 -> [infinite loop]
18 -> [no output]
19 -> UUUUUUUUU[continues indefinitely]
20 -> [no output]
21 -> [no output]
22 -> [no output]
23 -> [runtime error]
29 -> [infinite loop]
31 -> UUUUUUUUU[continues indefinitely]
37 -> [runtime error]

Sandbox notes

To keep the rules simple, I decided to only allow output to STDOUT.

| |
  • \$\begingroup\$ that's not really simplifying? couldn't you allow functions, but mandate output through stdout and stderr? \$\endgroup\$ – Destructible Lemon Jan 5 '17 at 9:30
  • \$\begingroup\$ @DestructibleWatermelon Yeah, that's actually much more reasonable. \$\endgroup\$ – Zgarb Jan 12 '17 at 7:49
  • \$\begingroup\$ Would it not be better to edit the previous question and try to get it reopened? \$\endgroup\$ – Peter Taylor Jan 12 '17 at 16:28
  • \$\begingroup\$ @PeterTaylor Ideally, yes. But it has existing answers, which are not competitive at all in a pure golf context. Won't that be an issue? \$\endgroup\$ – Zgarb Jan 12 '17 at 18:15
  • \$\begingroup\$ Hmm. I noticed that golfing was taken into account in the previous scoring system, but I didn't notice that 2 out of the 3 answers didn't golf. I retract my previous suggestion. \$\endgroup\$ – Peter Taylor Jan 12 '17 at 19:47

Prime Factors that Weren't there Before

Given a list of integers a, calculate the prime factorization for each integer in the array. Then, return a list of factors that do not appear in the original input, even as part of another number. For instance, if you were given:

a = [1243,11311]

The prime factors would be calculated as:

a' = [[11, 113], [11311]] = []

Because 11 appears in 11311, and 113 appears in 11311, the result would be [], an empty set.

Lets look at another example:

a = [270,325,192] = [[2, 3, 3, 3, 5], [5, 5, 13], [2, 2, 2, 2, 2, 2, 3]] = [13]

Another example:

a = [27072,32585,19296] a' = [[2, 2, 2, 2, 2, 2, 3, 3, 47], [5, 7, 7, 7, 19], [2, 2, 2, 2, 2, 3, 3, 67]] a'' = [47,67]

A bigger example:

a = [56,3924,10000,1240124]
a' = [[2, 2, 2, 7], [2, 2, 3, 3, 109], [2, 2, 2, 2, 5, 5, 5, 5], [2, 2, 31, 73, 137]]
a'' = [7,109,31,73,137]

This is code golf, lowest byte-count wins.

| |

Play time

Hello. It is time to play the most popular portuguese card game: Sueca! So for people who does not know the game, it is needed to print a wall poster to make them know the power and the points each card has.

So, the job is to print an ASCII art wall as:

    11        10        4         3         2        ———       ———       ———       ———       ———
╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ 
|A     A| |7     7| |R     R| |V     V| |D     D| |6     6| |5     5| |4     4| |3     3| |2     2| 
|♥     ♥| |♥     ♥| |♥    /♥| |♥    /♥| |♥    /♥| |♥     ♥| |♥     ♥| |♥     ♥| |♥     ♥| |♥     ♥| 
|       | |  ♥ ♥  | | ♔ /  | | ♗ /  | |  ♕ /  | |  ♥ ♥  | |  ♥ ♥  | |  ♥ ♥  | |       | |   ♥   | 
|   ♥   | |   ♥   | |   /   | |   /   | |   /   | |  ♥ ♥  | |   ♥   | |       | |  ♥ ♥  | |       | 
|       | |  ♥ ♥  | |  / ♔ | |  / ♗ | |  / ♕  | |  ♥ ♥  | |  ♥ ♥  | |  ♥ ♥  | |   ♥   | |   ♥   | 
|A     A| |7 ♥ ♥ 7| |R/    R| |V/    V| |D/    D| |6     6| |5     5| |4     4| |3     3| |2     2| 
|♥     ♥| |♥     ♥| |♥     ♥| |♥     ♥| |♥     ♥| |♥     ♥| |♥     ♥| |♥     ♥| |♥     ♥| |♥     ♥| 
╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ 
╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ 
|A     A| |7     7| |R     R| |V     V| |D     D| |6     6| |5     5| |4     4| |3     3| |2     2| 
|♦     ♦| |♦     ♦| |♦    /♦| |♦    /♦| |♦    /♦| |♦     ♦| |♦     ♦| |♦     ♦| |♦     ♦| |♦     ♦| 
|       | |  ♦ ♦  | | ♔ /  | | ♗ /  | |  ♕ /  | |  ♦ ♦  | |  ♦ ♦  | |  ♦ ♦  | |       | |   ♦   | 
|   ♦   | |   ♦   | |   /   | |   /   | |   /   | |  ♦ ♦  | |   ♦   | |       | |  ♦ ♦  | |       | 
|       | |  ♦ ♦  | |  / ♔ | |  / ♗ | |   / ♕ | |  ♦ ♦  | |  ♦ ♦  | |  ♦ ♦  | |   ♦   | |   ♦   | 
|A     A| |7 ♦ ♦ 7| |R/    R| |V/    V| |D/    D| |6     6| |5     5| |4     4| |3     3| |2     2| 
|♦     ♦| |♦     ♦| |♦     ♦| |♦     ♦| |♦     ♦| |♦     ♦| |♦     ♦| |♦     ♦| |♦     ♦| |♦     ♦| 
╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯
╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ 
|A     A| |7     7| |R     R| |V     V| |D     D| |6     6| |5     5| |4     4| |3     3| |2     2| 
|♣     ♣| |♣     ♣| |♣    /♣| |♣    /♣| |♣    /♣| |♣     ♣| |♣     ♣| |♣     ♣| |♣     ♣| |♣     ♣| 
|       | |  ♣ ♣  | | ♚ /  | | ♝ /  | |  ♛ /  | |  ♣ ♣  | |  ♣ ♣  | |  ♣ ♣  | |       | |   ♣   | 
|   ♣   | |   ♣   | |   /   | |   /   | |   /   | |  ♣ ♣  | |   ♣   | |       | |  ♣ ♣  | |       | 
|       | |  ♣ ♣  | |  / ♚ | |  / ♝ | |  / ♛  | |  ♣ ♣  | |  ♣ ♣  | |  ♣ ♣  | |   ♣   | |   ♣   | 
|A     A| |7 ♣ ♣ 7| |R/    R| |V/    V| |D/    D| |6     6| |5     5| |4     4| |3     3| |2     2| 
|♣     ♣| |♣     ♣| |♣     ♣| |♣     ♣| |♣     ♣| |♣     ♣| |♣     ♣| |♣     ♣| |♣     ♣| |♣     ♣| 
╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ 
╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ ╭───────╮ 
|A     A| |7     7| |R     R| |V     V| |D     D| |6     6| |5     5| |4     4| |3     3| |2     2| 
|♠     ♠| |♠     ♠| |♠    /♠| |♠    /♠| |♠    /♠| |♠     ♠| |♠     ♠| |♠     ♠| |♠     ♠| |♠     ♠| 
|       | |  ♠ ♠  | | ♚ /  | |  ♝/  | |  ♛ /  | |  ♠ ♠  | |  ♠ ♠  | |  ♠ ♠  | |       | |   ♠   | 
|   ♠   | |   ♠   | |   /   | |   /   | |   /   | |  ♠ ♠  | |   ♠   | |       | |  ♠ ♠  | |       | 
|       | |  ♠ ♠  | |  / ♚ | |  / ♝ | |  / ♛  | |  ♠ ♠  | |  ♠ ♠  | |  ♠ ♠  | |   ♠   | |   ♠   | 
|A     A| |7 ♠ ♠ 7| |R/    R| |V/    V| |D/    D| |6     6| |5     5| |4     4| |3     3| |2     2| 
|♠     ♠| |♠     ♠| |♠     ♠| |♠     ♠| |♠     ♠| |♠     ♠| |♠     ♠| |♠     ♠| |♠     ♠| |♠     ♠| 
╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯ ╰───────╯
| |
  • \$\begingroup\$ You should specify which specific characters should be used. Of note, several of the ones you used don't appear to fall in the ASCII range. \$\endgroup\$ – FryAmTheEggman Jan 13 '17 at 0:51
  • \$\begingroup\$ @FryAmTheEggman: Should I call it Unicode Art? \$\endgroup\$ – sergiol Jan 13 '17 at 1:30
  • \$\begingroup\$ @FryAmTheEggman If you know better chars than ♔♗♕ ♚ ♝ ♛ for me to put in the question, please tell me. I don't like the effect they have on the white space width after them. \$\endgroup\$ – sergiol Jan 13 '17 at 1:33
  • \$\begingroup\$ I'm afraid I don't know of any better characters, but yes, that would be less confusing. I still think adding the exact character codes would be a good idea. \$\endgroup\$ – FryAmTheEggman Jan 13 '17 at 1:47
  • \$\begingroup\$ The "ascii-art" looks aweful in my browser (firefox on win): i.stack.imgur.com/keYgN.jpg \$\endgroup\$ – flawr Jan 13 '17 at 14:48
  • \$\begingroup\$ @flawr: In mine (Vivaldi on Windows) they look better: i.imgur.com/OIILDbB.png but not perfectly drawn; it is due to the chess Unicode characters. I am waiting for opinions on better characters, please. The queen card (D) seems a lot the King card! The Jack (V) doesn't even seem to be a Jack! And the King (R) also does not seem the King! \$\endgroup\$ – sergiol Jan 13 '17 at 19:42

Left-to-Right calculator

Given the opinion I posted on https://ux.stackexchange.com/a/99984/51560 , I want to have a calculator where the least-significant least digits are placed on the left.

The input must come from stdin. It only needs to support non-negative integers. Additions must support any number of parcels, and to end the input of parcels input an empty line. In every example, all above the first ——— line is input, the first ——— line itself and the lines below are output.



Subtractions input is always composed by two operators:


Multiplications input is also two operands.Must support at multiplications where the second operator is < 100 and output the auxiliary addition like the way it is done by hand.

| |

Contiguous Palindromic Subsequencing

Given a word a, perform the following operations:

  1. Group string into palindromic subsequences of length > 2 and non-palindromic subsequences. (You should prioritize partition length over partition index, for instance esse shouldn't result in ['e','ss','e'], it should be ['esse']. However, if the lengths are the same for two subsequences, use index to prioritize which you choose).
  2. Make all non-palindromic subsequences palindromic (single characters are palindromic here).
  3. Put it back together.

You may assume only printable ASCII characters are used.


raggamuffin -> ['r','agga','muffin'] -> ['r','agga','muffiniffum'] -> raggamuffiniffum

bananaracecar -> ['b','anana','racecar'] -> ['b','anana','racecar'] -> Unchanged.

(Since each palindrome grouping would be the same length, use the first one).
abaca -> ['aba', 'ca'] -> ['aba','cac'] -> abacac

(Always choose the bigger palindrome, THEN go by index)
cheesewheels -> ['che','ese','wh','ee','ls'] -> ['chehc','ese','whw','ee','lsl'] -> chehcesewhweelsl

(Always choose the bigger palindrome, THEN go by index)
1223224 -> [1,22322,4] -> Unchanged.

abbabbababbababba -> ['a', 'bb', 'abbababbababba'] -> Unchanged.

abcdefg -> ['abcdefg'] -> ['abcdefgfedcba'] -> abcdefgfedcba

slammedintoacardoor -> ['sla', 'mm', 'edinto', 'aca', 'rd', 'oo', 'r'] -> ['slals', 'mm', 'edintotnide', 'aca', 'rdr', 'oo', 'r'] -> slalsmmedeintotniacardroor

eeefffgegffhi -> ['eee','f','ffgegff','hi'] -> ['eee','f','ffgegff','hih'] -> eeefffgegffhih

This will be , lowest byte-count wins.

| |
  • \$\begingroup\$ The term "subsequence" doesn't usually imply that they are contiguous. ac is a subsequence of abc. You should either use "substring" or "contiguous subsequence" to avoid confusion. \$\endgroup\$ – Martin Ender Jan 13 '17 at 8:42
  • \$\begingroup\$ I can't tell whether this is covered by any of your test cases, but it's also not explicitly mentioned in the rules, what about a test case like abaca. Is it ab,aca or aba,ca, since the palindromes have the same length? What about abacada? aba,c,ada? ab,aca,da? \$\endgroup\$ – Martin Ender Jan 13 '17 at 8:46
  • \$\begingroup\$ Also, string challenges should specify which characters can appear in the input. \$\endgroup\$ – Martin Ender Jan 13 '17 at 8:46
  • \$\begingroup\$ In test case slammedintoacardoor, shouldn't ed and into be combined into one substring? \$\endgroup\$ – Zgarb Jan 13 '17 at 12:09
  • \$\begingroup\$ @MartinEnder I worded it wrong, you should be prioritizing length of substring, THEN position. So it would be aba,ca. \$\endgroup\$ – Magic Octopus Urn Jan 13 '17 at 14:43
  • \$\begingroup\$ @Zgarb yes, you're right. \$\endgroup\$ – Magic Octopus Urn Jan 13 '17 at 14:43
  • \$\begingroup\$ @MartinEnder aba,c,ada because aba is before both aca and ada using index. Then ada and c are what would be prioritized to be grouped next. \$\endgroup\$ – Magic Octopus Urn Jan 13 '17 at 15:49

1 line ASCII Domino play

The game is described on my own question I posted on Domino game maximum achievable points.

The rules for scoring are on the link, and I am reposting them here:

The rules for scoring are: every time a part is placed, if the sum of both ends of the dominoes chain is a multiple of 5, you add it to you current score.

example: [4|2] [2|1] makes 5 points

A double (every part where the two halfes are equal) is always placed rotated by 90º; so for accounting purposes, unlike other pieces, both sides ot the part are taken into account.


___       ___
|6|       |4|
——— [6|4] ———  
|6|       |4|
———       ———

makes for 20 points.

One single part placed accounts as the two tips.

Example [2|3] accounts as 5 points


———  accounts as 10 points.

The challenge is to write a game that is an ASCII one line domino game for me to play.


  • You must output to stderr/stdout
  • Line Width is 80 chars
  • The first two chars are reserved for displaying points, aligned at right. By definition, it will always be a multiple of 5; and the third is always a space
  • Given space is limited:

    • Every join of two parts will conjoin and they will be separed by a | they will share instead of ][
    • Double parts (those where the two halves are equal) will be represented abbreviate:

      • [ | ] => [ ]
      • [1|1] => [=]
      • [2|2] => [+]
      • [3|3] => [*]
      • [4|4] => [&]
      • [5|5] => [X]
      • [6|6] => [%]
    • Except for white double, all whites are represented by only the other half
    • Every other part is represented by [NM], where N and M are the number of each half
  • The ends of the whole dominoes chain are always terminated by []
  • The initial state is an empty table. First piece placed will be at the center
  • When chain begins to not fit, at one of the ends, it must be adjusted to fit by pushing the whole placing a little bit to the left or the right.
  • The last 3 chars of the line are reserved for user input. User can only input a piece not yet placed. User input is NM which is displayed; and a keypress of + or - which will NOT be displayed to avoid a newline feed. The key press tells what side of the chain will the new piece will be snapped:
    • - to left
    • + to right
    • It also must validate the snapping. If user snaps to a non-matching piece, just do nothing. The program will NOT be smart enough to make guesses; so it will NOT make a piece to snap on the other side if piece does not match user specified side
    • And after each valid placing of a piece, must update the points display if there are some to score.

Example of an INVALID placed chain, containing a sequence which would not be possible, because there are pieces snapped to not-matching pieces.

  5 [ |=|+|*|&|X|%|1|2|3|4|5|6|12|13|14|15|16|23|24|25|26|34|35|36|45|46|56] 12{+}

The {+} is not displayed, it is there just to illustrate the input:

| |
  • 1
    \$\begingroup\$ I find this rather confusing. After reading it three times I think I begin to understand the spec, but 1. Why those random characters for the doubles? IMO !@#$%& would be preferable: it's easy to refer to for people with a US-layout keyboard, and it corresponds to the ASCII characters at an offset of 32 from the digits. 2. What's all that about ][? The question should be self-contained: don't confuse things by assuming that people have read another related question. 3. Following on from that, you should explain the scoring. \$\endgroup\$ – Peter Taylor Jan 13 '17 at 13:30
  • 2
    \$\begingroup\$ 4. Don't give an example of an invalid chain: the example which would be actually useful is a valid chain. 5. Doesn't the abbreviated form for 0s create ambiguities? If the board is currently [6] then which is valid out of 46-, 46+, 64-, 64+, 4-, 4+? 6. What's the initial state? Empty board, and either of - or + does the same thing? \$\endgroup\$ – Peter Taylor Jan 13 '17 at 13:31
  • \$\begingroup\$ @PeterTaylor: Those chars have been decided on the appearance they have. = seems [11] rotated vertically; + being a four-point star is the most similar I get to [22]; the same goes for * as it is a 6 point star; & seems an 8, which are the points of [44]; X is an way to say 10, which are the number points of a [55]; % seems to have a 10 and a 2 number implicit on it, as the slash and final ball seem a 10, and the existent balls are two, then twelve which are the points of [66]. \$\endgroup\$ – sergiol Jan 14 '17 at 12:04
  • \$\begingroup\$ Given the space is limited, the joining of two pieces must conjoin, so ][ becomes | to save space. Example: [23][34] becomes [23|34] \$\endgroup\$ – sergiol Jan 14 '17 at 12:09
  • \$\begingroup\$ Reproduced ipsis verbis from the link the rules for scoring. \$\endgroup\$ – sergiol Jan 14 '17 at 13:29
  • \$\begingroup\$ @trichoplax: It is clearly stated: "User can only input a piece not yet placed". There are only 28 dominoes and the statement makes clear there are no repetitions. I am already getting issues trying to put the whole chain in only one line and you want to make the problem even worse?! \$\endgroup\$ – sergiol Jan 14 '17 at 14:48
  • \$\begingroup\$ @PeterTaylor :Just made clear The initial state is an empty table \$\endgroup\$ – sergiol Jan 14 '17 at 15:02
  • \$\begingroup\$ @trichoplax: I upvoted your comment: Is there a missing second half of sentence after "When chain begins to not fit"?.Sentence is now fixed! \$\endgroup\$ – sergiol Jan 14 '17 at 15:03
  • \$\begingroup\$ My apologies for overlooking "User can only input a piece not yet placed". I've deleted both my comments now that they have been addressed. \$\endgroup\$ – trichoplax Jan 14 '17 at 17:41
  • \$\begingroup\$ @trichoplax: I made now clear the program will not have any kind of "smartness". So if user specifies 64- and left side is not a 4, placing is simply rejected. \$\endgroup\$ – sergiol Jan 14 '17 at 18:32

Graphical Borromean Rings

Here is an SVG rendering of the Borromean Rings:

<svg xmlns="http://www.w3.org/2000/svg" height="200" width="200">
    <radialGradient id="green">
      <stop stop-color="transparent" offset="70%"/>
      <stop stop-color="#0F0" offset="75%"/>
      <stop stop-color="#CFC" offset="85%"/>
      <stop stop-color="#0F0" offset="95%"/>
      <stop stop-color="transparent" offset="100%"/>
    <radialGradient id="blue">
      <stop stop-color="transparent" offset="70%"/>
      <stop stop-color="#00F" offset="75%"/>
      <stop stop-color="#CCF" offset="85%"/>
      <stop stop-color="#00F" offset="95%"/>
      <stop stop-color="transparent" offset="100%"/>
    <radialGradient id="red">
      <stop stop-color="transparent" offset="70%"/>
      <stop stop-color="#F00" offset="75%"/>
      <stop stop-color="#FCC" offset="85%"/>
      <stop stop-color="#F00" offset="95%"/>
      <stop stop-color="transparent" offset="100%"/>
    <mask height="100" width="100" y="0" x="0" id="back">
      <rect fill="#FFF" height="100" width="50" y="0" x="0"/>
      <rect fill="#FFF" height="50" width="50" y="25" x="50"/>
    <mask height="100" width="100" y="0" x="0" id="front">
      <rect fill="#FFF" height="25" width="50" y="0" x="50"/>
      <rect fill="#FFF" height="25" width="50" y="75" x="50"/>
  <circle mask="url(#back)" fill="url(#green)" r="50" cy="50" cx="50"/>
  <circle fill="url(#blue)" r="50" cy="93.3" cx="75"/>
  <circle fill="url(#red)" r="50" cy="50" cx="100"/>
  <circle mask="url(#front)" fill="url(#green)" r="50" cy="50" cx="50"/>

Please write a full program to generate a which resembles the above rendering reasonably well. In particular:

  • Solid colours, aliased pixels or overlap artefacts are not acceptable
  • Your colours should contrast with each other
  • Your circles must default to at least 100px in diameter (I wanted larger circles in my snippet but I get a scroll bar if I try)
  • Your circles must have the appearance of overlapping impossibly
  • Rotations and reflections are perfectly acceptable

Output is via any generally acceptable output format e.g. writing to vector or raster image format or displaying directly to the screen. This is , so the shortest program wins.

Related: ASCII Borromean Rings

| |
  • \$\begingroup\$ Related. Related. \$\endgroup\$ – DLosc Jan 19 '17 at 10:35
  • \$\begingroup\$ @DLosc Well, those are interlocking rings... Borromean rings don't interlock in pairs ;-) \$\endgroup\$ – Neil Jan 19 '17 at 16:25

Number that includes the amount of digits of itself

Create a number where each digit represents the amount of this digit the number itself contains. Maybe my english is too bad to describe it clearly so here is an example:

6               -> this number contains 6 times '0'
 2              -> this number contains 2 times '1'
  1             -> this number contains 1 time  '2'
   0            -> this number contains 0 times '3'
    0           -> this number contains 0 times '4'
     0          -> this number contains 0 times '5'
      1         -> this number contains 1 time  '6'
       0        -> this number contains 0 times '7'
        0       -> this number contains 0 times '8'
         0      -> this number contains 0 times '9'

We will call those numbers self-describing. Each self-describing number must be 10 digits long to be able to represent all digits from 0 to 9.

I have two possible goals for this challenge:

  1. Create a program which prints out all self-describing numbers in the range 0000000000 < X < 99999999999
  2. For a given integer in the range 0000000000 < X < 99999999999 print out true if it's a self-describing number, else false.

I can add further examples and rules if i move it out of the sandbox.

| |
  • \$\begingroup\$ @Fatalize Yes my bad i will search for a correct number \$\endgroup\$ – izlin Jan 16 '17 at 15:52
  • 3
    \$\begingroup\$ "I can add further examples": no, you can't. That's the only one. If you want to get an interesting question out of this you're going to have to open it up to other bases. \$\endgroup\$ – Peter Taylor Jan 16 '17 at 17:11
  • \$\begingroup\$ Related. Also related. \$\endgroup\$ – user62131 Jan 18 '17 at 19:45

Digit stream with no 42

You should write a program or function which receives no input and outputs a stream of digits.

  • The stream should contain at least once every positive integer number which does not contain the digit sequence 42. E.g. The string 1231 contains the integers 1 12 123 1231 2 23 231 3 31 (and 1 again)

  • The stream should not contain the digit sequence 42.

  • If your interpreter can't handle infinite output gracefully you can add code to only print the first n digits. This added code does not count to your score.

  • Note that the stream 203204205... contains 42.

  • No randomness should be used.

This is code-golf so the shortest entry wins.

Do we have infinite output tag?

| |
  • \$\begingroup\$ I think you need to say something about random numbers. Either require that the program always outputs the same stream or be very specific about requirements on the RNG for an answer which outputs random digits avoiding 2 when the previous one was a 4. \$\endgroup\$ – Peter Taylor Jan 18 '17 at 12:30
  • \$\begingroup\$ @PeterTaylor Right, forbidding randomness is probably the cleanest solution. Showing whether an RNG-using code solves the problem seems pretty complex. \$\endgroup\$ – randomra Jan 18 '17 at 15:13
  • \$\begingroup\$ So a program that always prints 1234567890 will satisfy this, or am I missing something? \$\endgroup\$ – Magic Octopus Urn Jan 18 '17 at 20:33
  • \$\begingroup\$ @carusocomputing The stream should contain every integer not just every digit. E.g. 1234567891011121314... fulfills this point. \$\endgroup\$ – randomra Jan 18 '17 at 23:29

Where am I?

(Some other tags pls help)

Your task in this challenge is to output the location of the user. This may be done by means of GeoIP, a builtin GPS device, or any other means. Output should either be in the format (latitude, longitude) accurate to at least one degree, or (City, [optional state/province/etc], Country). Errors due to the GPS device being inaccurate or similar which are not the fault of your code are allowed. Fewest bytes wins.

| |
  • \$\begingroup\$ Accurate to one degree? Holy hell, do you know how much one degree is? google.com/maps/dir/11.00000,+2.000000/10,1/… \$\endgroup\$ – Magic Octopus Urn Jan 18 '17 at 20:09
  • \$\begingroup\$ Also, this is more or less "output the location of the users ISP"... \$\endgroup\$ – Magic Octopus Urn Jan 18 '17 at 20:10
  • \$\begingroup\$ @carusocomputing one degree of Latitude/Longitude. That's just 11, 2. \$\endgroup\$ – Pavel Jan 18 '17 at 20:16
  • \$\begingroup\$ I was just pointing out that if you look at 10,1 compared to 11,2 it's in a different country. If you say closest to the nearest degree the answers will not be constant. \$\endgroup\$ – Magic Octopus Urn Jan 18 '17 at 20:31
  • \$\begingroup\$ @carusocomputing Oh, I misunderstood. I know 1 degree is a lot, but I think it's good enough. It requires actually finding the location rather than relying on other information, which is all that's really needed. This way could cut out some code necessary for formatting which isn't part of the challenge. \$\endgroup\$ – Pavel Jan 18 '17 at 20:36
  • \$\begingroup\$ Ping the router. Ask the router where it is. Done. (No idea if this would work) \$\endgroup\$ – SIGSTACKFAULT Jan 22 '17 at 15:49

Do you accept me?


Being accepted is very important to people. But words are also people (right!?). So they also want to be accepted. However most people work non-deterministically and as such it's only fair to transfer that into our decision whether we accept a word. Of course, because a stupid human can't remember much the instructions to decide whether to accept a word must be short...


Your input will be

  • a list of non-negative integers - the "word" (this is easier than using strings and actual alphabets)
  • a list of triples of non-negative integers - the transitions, you may also use unordered data structures here
  • an integer - the starting state
  • a list of non-negative integers - the accepting states, you may also use unordered data structures here

You may use any other object or whatever than integers if it pleases you.


A truthy or a falsey value.

What to do?

Basically implement an NFA.
That is, read every single character (ie every number) from left to right and for each one of them look whether there exist a transition from your current state using this character. If so follow it and repeat the process for the next letter. If you face an empty list, your current state must be in the list of accepted states if it is output true and stop examining other paths if it isn't continue examining the other options. If you get stuck (ie the word isn't empty but there's no way to continue), output false.

Who wins?

This is so the shortest answer in bytes wins.


For the following examples I'm going to use this automaton: Example NFA

which has starting state 10, accepting states [13] and transitions


These three parameters are assumed to be also passed in the examples. Word examples for this automaton are:

[1,2,3,4] -> false
[4,1,3,4] -> false
[4,1,3] -> true
[4,1,3,3,3] -> true
[2,1,3,4,3,2] -> false
[4,1,4] -> false
[4,3,1] -> false
[4,3,3] -> true
| |
  • \$\begingroup\$ I'm aware of this other challenge but truly believe that mine is different enough because a) it uses relations instead of a function b) it only asks for NFAs and not for three different automatons c) it asks for truthy / false instead of hard-coded strings d) it's not limited to strings e) it doesn't assume an implicit starting state. \$\endgroup\$ – SEJPM Jan 19 '17 at 11:24

Simulate a vibrating string

Vibrations are an integral part of physics. In this challenge, you will be implementing a simulation of a vibrating string.

This is actually rather easy to do as a result of the Huygens–Fresnel principle, which allows us to use a simulation process similar to cellular automata.

(don't have time to write a full spec right now. Also, I have a 2D version working but figured 1D was enough for a challenge)

Below is an example of a string vibrating at its second harmonic, with each row being 1 tick of the simulation.

  1.00  2.00  1.00 -1.00 -2.00 -1.00
  0.95  1.90  0.95 -0.95 -1.90 -0.95
  0.85  1.70  0.85 -0.85 -1.70 -0.85
  0.71  1.42  0.71 -0.71 -1.42 -0.71
  0.54  1.07  0.54 -0.54 -1.07 -0.54
  0.33  0.67  0.33 -0.33 -0.67 -0.33
  0.11  0.23  0.11 -0.11 -0.23 -0.11
 -0.11 -0.22 -0.11  0.11  0.22  0.11
 -0.33 -0.66 -0.33  0.33  0.66  0.33
 -0.53 -1.07 -0.53  0.53  1.07  0.53
 -0.71 -1.42 -0.71  0.71  1.42  0.71
 -0.85 -1.70 -0.85  0.85  1.70  0.85
 -0.95 -1.90 -0.95  0.95  1.90  0.95
 -1.00 -2.00 -1.00  1.00  2.00  1.00

This challenge is based off the math found on this website.

| |

Task Scheduling

Given as input:

  • A unix time at which to first run the program
  • Delay between runs (can be 0)
  • Number of times to run the program (-1 if infinite)
  • A program to be run through the console when triggered

Run the program under specified conditions.

  • You can assume your program will always be running
  • Run the equivalent of nohup <command> &.
| |
  • \$\begingroup\$ What happens if the unix time is before now? What is the delay measured in? What should I do if the delay is 0? What do you mean by "You can assume your program is always running?" Isn't the ability to keep my program running up to my program?. nohup is not a command I'm familiar with, so I'd definitely explain that. \$\endgroup\$ – Nathan Merrill Jan 20 '17 at 17:05
  • \$\begingroup\$ @NathanMerrill 1. undefined behavor, ie do whatever you want 2. seconds 3. undefined behavior 4. if you want to 5. it isn't? \$\endgroup\$ – noɥʇʎԀʎzɐɹƆ Jan 20 '17 at 18:17
  • \$\begingroup\$ All of that needs to be in the in the post. \$\endgroup\$ – Nathan Merrill Jan 20 '17 at 18:19

The many names of Túrin

Tolkien's character Túrin had a multiple personality disorder and consequently needed to change name on a regular basis to be called by something fitting its current mood. He has been known as Turambar, Mormegil, Gorthol, Adanedhel, Dagnir Glaurunga, the Wildman of the Woods, Neithan and some other unofficial nicknames alluding to his tenderness for his sister.

This must have been a real headache for the author: not only had he to find the new names but he also had to remember the translation in English1, since every new name is introduced along the lines of "From this day he was known as [Compound_Elvish_word], that is [Word of word]"

Your task is to automatize the production of epithets to help Tolkien finish his Unfinished Tales.

Given a list of Sindarin2 substantives and their English translations (see list below) as an external file, a list or any reasonable format, randomly take two Sindarin substantives (repetition is possible) and print "From this day he was known as Sindarin1sindarin2, that is English2 of English1"

(Note the inversion of words in the translation, and the capitalisation)

Input: none

Output: A string

The list: (names can be capitalized in your own list, but the formatting must be consistent. The order of the couples can also be changed)

Sindarin    English
amarth      fate
ang         iron
aur         morning
brethil     birch
carch       fang
celeb       silver
draug       wolf
galad       glittering
glor        light
gwathel     sister
manadh      doom
megil       sword
melethron   lover
mor         darkness
naur        flame
taur        forest


  • From this day he was known as Galadaur, that is Morning of Glittering
  • From this day he was known as Mormelethron, that is Lover of Darkness
  • From this day he was known as Draugdraug, that is Wolf of Wolf

Hobbits played golf and Codë was the Vala of challenges in the Silmarillion, so this is .

1 Sorry, Tolkien specialists, I'm probably massacring Quenya, Sindarin and many other concepts

2 I think

| |
  • \$\begingroup\$ Children do visit this website, so if you consider something unsuitable for them, do not mention it at all, even to hint at avoiding mentioning it. \$\endgroup\$ – trichoplax Jan 20 '17 at 15:32
  • \$\begingroup\$ Changed as asked, the example as well. \$\endgroup\$ – drolex Jan 20 '17 at 15:48
  • \$\begingroup\$ 1. Substantives are far more commonly called nouns in English. 2. This would be a more interesting challenge if the word list had a lot of common substrings to exploit for compression. Maybe it would work better with a fictional language rather than Sindarin? \$\endgroup\$ – Peter Taylor Jan 20 '17 at 22:32

Minimum exchange of bills

You're at the supermarket, buying groceries for the week. At the end, the cashier rings up your cart and declares that your total cost is exactly $76. You reach into your wallet, and find a $50, four $20s, and a $1, for a total of six bills.

We consider a transaction to be you paying money to the cashier, and the cashier giving you your change (if applicable). Your total for a transaction is the net amount of money you owe the cashier, which is calculated by the amount you pay less the amount of change you get. We can think of a transaction as adding the bills you pay to the cashier, and subtracting the bills you get in return. Thus, the following is a non-exhaustive list of possible transactions in this scenario:

$50 + $20 + $20 - $10 - $1 - $1 - $1 - $1 (8 bills)
$20 + $20 + $20 + $20 - $1 - $1 - $1 - $1 (8 bills)
$20 + $20 + $20 + $20 + $1 - $5           (6 bills)
$50 + $20 + $20 + $1 - $10 - $5           (6 bills)

Given a total of $76, and having 1 $50, 4 $20s, and 1 $1, the minimum exchange of bills comes out to 6 bills.


Given an integer Bill and a list of bills in your wallet [Ones Fives Tens Twenties Fifties Hundreds], calculate the number of bills in a minimum exchange of bills between you and the cashier.


  1. Your program can accept your input in any reasonable way. You can accept an integer followed by a list of six integers separated by reasonable means. You can accept seven integers separated by any reasonable means. If your language cannot accept input in any reasonable form, you may, at no penalty, hardcode the input into your program. You may only hardcode input if your language cannot reasonably accept meaningful input.
  2. Your program must output the number of bills in the minimum exchange transaction. Your program may not print any of the possible transactions themselves.
  3. You may assume that you will always have enough money to cover your bill, possibly requiring some change from the cashier.
  4. You may assume that the cashier has an unlimited number of all bills at their disposal.
  5. You may assume that all inputs are non-negative integers. It is possible that your bill comes out to $0. No integer input will ever be greater than 1000. That's too many bills and quite frankly, too many groceries.
  6. This is , so fewest bytes wins.

Test cases

Input                        Output
[76,1,0,0,4,1,0]              6

I'll come up with and post some more test cases if people think this is a good challenge.

Possible bonus challenge:

In the United States, a $2 is a rare, but legal, bill issued by the treasury. If you wish, you can have your program accept another integer, between the number of Ones and Fives, representing the number of $2-bills you have in your wallet, which you can use to pay for your groceries. However, since such bills are so uncommon, the cashier will not have any on-hand to give to you as change.

| |
  • \$\begingroup\$ Never allow arbitrary separators in the input, at least without some length limit; some languages may be able to slip the entire program in there. The easiest method is normally to say that the program takes a list of integers as input via any reasonable means; we have various rulings on Meta about which means are reasonable, and that saves you having to duplicate it in your challenge. I'd recommend against the bonus challenge, by the way; it just makes entries harder to compare. \$\endgroup\$ – user62131 Jan 20 '17 at 17:24
  • \$\begingroup\$ Essentially the making change problem ( codegolf.stackexchange.com/q/70847/194 and probably others) but adding negative value coins (bills). There's a risk it will be closed as dupe; it's borderline enough that I wouldn't cast a supervote. One thing I will suggest, as I have in the past on this type of question, is making the coin (bill) system be input rather than hard-coded. That way you can forget about the bonus challenge and the question feels a bit less culture-specific. \$\endgroup\$ – Peter Taylor Jan 20 '17 at 22:26
  • \$\begingroup\$ I vote no on $2 bills, that sounds like it doesn't add much. \$\endgroup\$ – Magic Octopus Urn Jan 23 '17 at 19:39


The purpose of this challenge is to emulate the functionality of the loripsum.net website. This website takes in a "number of paragraphs" and a list of randomized HTML5 stylizations and outputs a pre-formatted HTML5 lorem ipsum text that is REALLY good for placeholders on a prototype website. Your code, however, will focus more on the stylization aspect of this website.

Given a block of lorem ipsum text in the following format:

<segment> := <paragraph> | <paragraph><new-line><segment>

<paragraph> := <sentence> | <sentence><paragraph>

<sentence> := <character_run><sentence_end>

<character_run> := <printable_ascii_without_newline_or_period>|<pawnop><character_run>

<sentence_end> := \n | . | ? | !

Here's an example of a possible input:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quonam, inquit, modo? Progredientibus autem aetatibus sensim tardeve potius quasi nosmet ipsos cognoscimus. Quod non faceret, si in voluptate summum bonum poneret. Duo Reges: constructio interrete.

Tubulo putas dicere? Cum salvum esse flentes sui respondissent, rogavit essentne fusi hostes. Dat enim intervalla et relaxat. Satisne ergo pudori consulat, si quis sine teste libidini pareat? Negare non possum. An hoc usque quaque, aliter in vita? Plane idem, inquit, et maxima quidem, qua fieri nulla maior potest. Quid ei reliquisti, nisi te, quoquo modo loqueretur, intellegere, quid diceret?

Itaque ad tempus ad Pisonem omnes. Universa enim illorum ratione cum tota vestra confligendum puto. Haec dicuntur inconstantissime. Dicimus aliquem hilare vivere; Qui non moveatur et offensione turpitudinis et comprobatione honestatis? Sed quot homines, tot sententiae; Quippe: habes enim a rhetoribus; Omnes enim iucundum motum, quo sensus hilaretur. Tria genera bonorum; Profectus in exilium Tubulus statim nec respondere ausus;

Certe non potest. Dempta enim aeternitate nihilo beatior Iuppiter quam Epicurus; Graece donan, Latine voluptatem vocant. Itaque a sapientia praecipitur se ipsam, si usus sit, sapiens ut relinquat. Quid est igitur, inquit, quod requiras? Atque haec coniunctio confusioque virtutum tamen a philosophis ratione quadam distinguitur. Ego vero volo in virtute vim esse quam maximam;

Verum hoc idem saepe faciamus. Huic mori optimum esse propter desperationem sapientiae, illi propter spem vivere. Si enim ita est, vide ne facinus facias, cum mori suadeas. Indicant pueri, in quibus ut in speculis natura cernitur. Apparet statim, quae sint officia, quae actiones. An est aliquid per se ipsum flagitiosum, etiamsi nulla comitetur infamia? Non autem hoc: igitur ne illud quidem. Res enim se praeclare habebat, et quidem in utraque parte.

Your task, given the input t from above, is to apply one formatting operations at random once per paragraph, defined by the following list of operations:

  • Character Run Operations (Should be performed on 1-5 word runs chosen at random. This should NEVER cross sentence boundaries (\n|.|?|!))
    • Bold <b></b>
    • Italic <i></i>
    • Underline <u></u>
  • Sentence Operations (Should be performed on 1-2 sentences in the paragraph)
    • Block Quote <blockquote></blockquote>
    • Preface <pre></pre>
    • Heading <h1></h1> ... <h6></h6> (Chosen at random)
  • Paragraph Operations (Should turn entire paragraph into this format, separated by sentences if the operation is segmented (like a list)).
    • Unordered List <ul><li>Sentence 1</li>...<li>Sentence n</li></ul>
    • Ordered List <ol><li>Sentence 1</li>...<li>Sentence n</li></ol>

So, here is one possible random output:

[1:HEADING(h1 chosen),2:BOLD(4 times),3:PREFACE(1 sentence),4:UNORDERED-LIST,5:BLOCKQUOTE(2 sentences)]

Applied to the input from above (t):

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Quonam, inquit, modo? Progredientibus autem aetatibus sensim tardeve potius quasi nosmet ipsos cognoscimus. Quod non faceret, si in voluptate summum bonum poneret. Duo Reges: constructio interrete.

Tubulo putas dicere? Cum salvum esse flentes sui respondissent, rogavit essentne fusi hostes. Dat enim intervalla et relaxat. Satisne ergo pudori consulat, si quis sine teste libidini pareat? Negare non possum. An hoc usque quaque, aliter in vita? Plane idem, inquit, et maxima quidem, qua fieri nulla maior potest. Quid ei reliquisti, nisi te, quoquo modo loqueretur, intellegere, quid diceret?

Itaque ad tempus ad Pisonem omnes. Universa enim illorum ratione cum tota vestra confligendum puto. Haec dicuntur inconstantissime. Dicimus aliquem hilare vivere; Qui non moveatur et offensione turpitudinis et comprobatione honestatis?

Sed quot homines, tot sententiae;
Quippe: habes enim a rhetoribus; Omnes enim iucundum motum, quo sensus
Tria genera bonorum; Profectus in exilium Tubulus statim nec respondere ausus;

  • Certe non potest.
  • Dempta enim aeternitate nihilo beatior Iuppiter quam Epicurus; Graece donan, Latine voluptatem vocant.
  • Itaque a sapientia praecipitur se ipsam, si usus sit, sapiens ut relinquat.
  • Quid est igitur, inquit, quod requiras? Atque haec coniunctio confusioque virtutum tamen a philosophis ratione quadam distinguitur.
  • Ego vero volo in virtute vim esse quam maximam;

Verum hoc idem saepe faciamus. Huic mori optimum esse propter desperationem sapientiae, illi propter spem vivere.
Si enim ita est, vide ne facinus facias, cum mori suadeas. Indicant pueri, in quibus ut in speculis natura cernitur. Apparet statim, quae sint officia, quae actiones. An est aliquid per se ipsum flagitiosum, etiamsi nulla comitetur infamia? Non autem hoc: igitur ne illud quidem. Res enim se praeclare habebat, et quidem in utraque parte.

Wow! Isn't that much prettier? Here's the code view:

<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h1> Quonam, inquit, modo? Progredientibus autem aetatibus sensim tardeve potius quasi nosmet ipsos cognoscimus. Quod non faceret, si in voluptate summum bonum poneret. Duo Reges: constructio interrete.

Tubulo <b>putas dicere</b>? Cum salvum esse flentes sui respondissent, rogavit <b>essentne fusi</b> hostes. Dat enim intervalla et relaxat. <b>Satisne ergo pudori consulat, si quis sine</b> teste libidini pareat? Negare non possum. An hoc usque quaque, aliter in <b>vita</b>? Plane idem, inquit, et maxima quidem, qua fieri nulla maior potest. Quid ei reliquisti, nisi te, quoquo modo loqueretur, intellegere, quid diceret?

Itaque ad tempus ad Pisonem omnes. Universa enim illorum ratione cum tota vestra confligendum puto. Haec dicuntur inconstantissime. Dicimus aliquem hilare vivere; Qui non moveatur et offensione turpitudinis et comprobatione honestatis? <pre>Sed quot homines, tot sententiae; Quippe: habes enim a rhetoribus; Omnes enim iucundum motum, quo sensus hilaretur.</pre> Tria genera bonorum; Profectus in exilium Tubulus statim nec respondere ausus;

<ul><li>Certe non potest.</li><li>Dempta enim aeternitate nihilo beatior Iuppiter quam Epicurus; Graece donan, Latine voluptatem vocant.</li><li>Itaque a sapientia praecipitur se ipsam, si usus sit, sapiens ut relinquat.</li><li>Quid est igitur, inquit, quod requiras? Atque haec coniunctio confusioque virtutum tamen a philosophis ratione quadam distinguitur.</li><li>Ego vero volo in virtute vim esse quam maximam;</li></ul>

<blockquote>Verum hoc idem saepe faciamus. Huic mori optimum esse propter desperationem sapientiae, illi propter spem vivere.</blockquote>Si enim ita est, vide ne facinus facias, cum mori suadeas. Indicant pueri, in quibus ut in speculis natura cernitur. Apparet statim, quae sint officia, quae actiones. An est aliquid per se ipsum flagitiosum, etiamsi nulla comitetur infamia? Non autem hoc: igitur ne illud quidem. Res enim se praeclare habebat, et quidem in utraque parte.

Take note specifically of how I split the sentences on the paragraph operators, you delimit by ONLY periods and NEWLINES, nothing else ends a sentence. Also, make not of how the character run operators can span multiple words, BUT NOT MULTIPLE SENTENCES, you must stop before the next sentence begins (EXCLUDING THE ENDING NEWLINE OR PERIOD). As in, it's only applicable to the <character_run> language definition.

This is lowest byte-count will be declared the winner.

| |
  • \$\begingroup\$ I think you're missing ; from <sentence_end>. I also don't see any sentences ending in \n, but perhaps you were referring to the end of a paragraph? Also, I think the <paragraph> rule should be <sentence> | <sentence><paragraph>. \$\endgroup\$ – ETHproductions Jan 20 '17 at 2:27
  • \$\begingroup\$ @ETHproductions that sentence doesn't end due to the ;, rather it ends due to the newline. \$\endgroup\$ – Magic Octopus Urn Jan 20 '17 at 18:20
  • \$\begingroup\$ Coulda sworn at least one person would like this haha. \$\endgroup\$ – Magic Octopus Urn Jan 26 '17 at 14:55
  • \$\begingroup\$ Are you sure about character runs including any ASCII char except newline or period? I would restrict it to [A-Za-z ], at least for the most part. \$\endgroup\$ – ETHproductions Jan 26 '17 at 16:41

Find square sum products

It's possible to find sets of three numbers whose product including their sum is a square number. Examples:

  • (3 + 2 + 1) * 3 * 2 * 1 = 6²
  • (3 + 3 + 2) * 3 * 3 * 2 = 12²
  • (4 + 4 + 1) * 4 * 4 * 1 = 12²
  • (9 + 8 + 1) * 9 * 8 * 1 = 36²
  • (8 + 5 + 5) * 8 * 5 * 5 = 60²
  • (8 + 7 + 6) * 8 * 7 * 6 = 84²
  • (9 + 8 + 8) * 9 * 8 * 8 = 120²

Please write a program or function to find square sum products for me.

Since there are an infinite number of square sum products, even excluding trivial multiples, you should limit your output to depend on a characteristic number N. Your program should always output the same square sum product(s) for a given N, and there should be at least one value of N for each possible square sum product that will cause your program to output that product. However, I will be flexible in what N actually represents, as long as you describe it in your answer. Here are some examples:

  • N is one sixth[citation needed] of the square root of the square sum products. For example, an N of 2 would find the second and third of my examples.
  • N is the upper bound of the largest summand. For example, an N of 9 would find all of my examples and then some.
  • N is the number of square sum products to be found. For example, an N of 12 would find all of my examples and then some.

For the output, I don't actually want the summands or the square root. Instead, please output the pairwise sum of the summands. Please also exclude duplicates (i.e. reorderings) from your answer.

This is , so the shortest program wins!

| |
  • \$\begingroup\$ You can drop the first [citation needed]: if (a, b, c) is a valid triple, then so is (a*k, b*k, c*k) for k integral. \$\endgroup\$ – Sp3000 Jan 21 '17 at 11:43
  • \$\begingroup\$ @Sp3000 Sure, but that's a trivial case. I'm pretty sure there are infinite nontrivial cases too. \$\endgroup\$ – Neil Jan 21 '17 at 11:48
  • \$\begingroup\$ My point was just that an infinite number do exist, so you can drop the superscript. I'm sure you could come up with something less trivial if you really wanted, like (2*k*k+4*k+2, 2*k*k+4*k+3, 1) \$\endgroup\$ – Sp3000 Jan 21 '17 at 12:03
  • \$\begingroup\$ @Sp3000 Indeed, you can generate a subset by multiplying a triangular number by 4, and taking that number twice with a final 1. \$\endgroup\$ – Neil Jan 21 '17 at 13:28
  • \$\begingroup\$ I find the proposed relationship between input and output too vague, and also open to abuse. For example, I could say that every single N outputs 6^2 unless N is of the form 2^a 3^b 5^c where a,b,c generate a square sum product. Why not just pick a spec, for example, that N is the upper bound of the largest summand? \$\endgroup\$ – Greg Martin Jan 26 '17 at 8:36
  • \$\begingroup\$ @GregMartin I didn't want to be overly restrictive because on other sandbox posts I atttracted comments complaining about what I chose to spec, but I guess some sort of restriction is necessary, sigh... \$\endgroup\$ – Neil Jan 27 '17 at 0:33
  • \$\begingroup\$ I agree that it's not always clear what will make the best challenge...! \$\endgroup\$ – Greg Martin Jan 27 '17 at 0:38

Dual Kimian (Error) and Regular Quine Polyglot

Create a program that is

  • a non-erroring proper quine in one language...
  • ...and a proper quine that produces its own source code through an error in another language

What is an error quine?

The compiler/interpreter/runtime to produce error output when compiling/running your program which is identical to your program's source code.

  • Your program may be specific to a particular version or implementation of your language's compiler/interpreter/runtime environment. If so, please specify the particulars.
  • Only standard compiler/interpreter/runtime options are permitted. You cannot pass some weird flag to your compiler to get a specific result.
  • The program does not need to be syntactically or semantically valid.
  • The program must not produce any output of its own (e.g. by calling print or an output function). All output generated upon attempting to compile/run the program must originate from the compiler/interpreter/runtime.
  • The complete output of the compiler/interpreter/runtime must be exactly identical to your program source code.
  • The compiler/interpreter/runtime must generate at least one error message when invoked with your program.

(adapted from nneonneo's "Make an error quine!" challenge)

  • Polyglots from different versions of the same language or similar languages are allowed
| |
  • \$\begingroup\$ Related. \$\endgroup\$ – user62131 Jan 22 '17 at 2:40
  • \$\begingroup\$ I fear the spec here isn't clear enough to prevent people using absurd definitions of what counts as an error, like happened in my attempt. (For example, what happens if you throw a string, and the runtime's unhandled-exception handler prints it? Some people consider that to be an error, and it's printed by the runtime, but the text is entirely under user control.) \$\endgroup\$ – user62131 Jan 22 '17 at 2:45

Sandbox Questions

  • Is it a good idea to post this as a separate challenge? This one is significantly easier and I fear that posting it would take too much attention away from the original challenge.

Detect if your program has been bit-flipped

Write a program that outputs


If any single bit is substituted by the alternate bit the program should output

  • Do not read your source code from a file
| |
  • \$\begingroup\$ Isn't this already a question? If so why not just replace it with a link to the question? \$\endgroup\$ – user63571 Jan 22 '17 at 17:52

Binary beads clock

The challenge is dedicated to pseudo-graphical representation of objects, e.g. like by ascii-art. Puzzle is geometrical: to represent bistrings as beads using tiles. The result must be beads-like strings where one is more like a bead and zero is more like a stem (or smaller bead). The solution can result in wide variety of visual concept but there are specific guides, see below.

A simple example of binary beads using single tiles, here standard characters:
Input: 1001, 0101, 0011.


or e.g. PETSCII console:

enter image description here

So these are only example form, but now you must "upscale" it, but since you are not in graphical mode, the resulting image must be structure of source units, i.e. it must be a rectangular tiling. In other words. it is not allowed just to draw sprites for each next upscale step. So the whole must be a real console app or code which emulates the console behaviour itself within the guidelines. So you can draw any tiles and use them also. Solution should show some reference to console output, e.g. if using graphical lib, a "print" function should be made which takes the data.


The task is to write an application or function wich draws scalable yet visually consistent beads with efective usage of tiles. Tilesets with least amount of tiles and yet with outstanding rich beads look must win. In other words, one should find good relation between tiles amount and good possibility to present different sizes.

One can present different length strings, but the whole layout must be of adequate size. Multiple words on line is allowed and even welcome especially if shows interesting use case.
Usage of graphical libs is welcome, e.g. to emulate a simple console-like output.
All tiles can be custom, i.e. this should not be necessarily standard characters of console. In real console any characters possible can be used or patched with custom tiles if possible. Any OS can be used.


Final image:

  • must include at least 2 different types of beads (different sizes), i.e. interesting scalability example
  • each bead type must share some tiles with other beads
  • structures should be good visible from various distance and contiguos as possible
  • "zero=stem, ones=bead" rule is not strict, creativity is very welcome but it should be not too far from rule to compare results
  • artiscism in forms is always bonus points!


  • maximal amount of tiles in the tileset : 16
  • are rectangular, e.g 16x8, 8x8 pixels ...
  • minimal size: 6x6, maximal size: 24x24 pixels
  • only two-color but the whole image can have more colors.


  • Non-cryptic plain code: C, Python, Basic, Fortran and those not too far from it
  • hacks (e.g. for old platforms) should be documented somehow and reproducable in theory

Points given for:

  • less unique tiles yet with rich possibilities
  • visual consistence by each beads type presented, but two types must not necesserily have same style
  • Hint: even within one type, the look of one bead can vary but the whole string easily decodable
  • interesting scaling possibilities, e.g. parametric scaling
  • fullfill the restrictions
  • less operations and minimalistic code
  • working application, e.g. interactive counter or a micro-game is welcome

Solution publishing:

  • title: amount of tiles used and pixel sizes info
  • visual examples easy to follow
  • notes about interesting sides of solution
  • code and some explanation

Sandbox note: If there are unclear point, free to point to corrections. Please suppose better tags if needed.


| |
  • \$\begingroup\$ I really like this challenge, though I'd remove the "only monochrome mode is allowed" rule to give the designers more freedom. I'd also include only the first primitive output example, and add a line stating that users are free to format this, since all these examples might push all answers roughly in the same direction. Maybe you can make an answer as well, since the PETSCII example looks great! \$\endgroup\$ – Luke Jan 20 '17 at 10:59
  • \$\begingroup\$ I fear that this question is too broad for a popularity-contest. There are two primary problems: 1. The judgement criterion (which clock is most useful to low-sighted people) does not naturally gather votes. You are far more likely to get upvoted answers that are funny and interesting. 2. The challenge isn't really about programming, but about design. \$\endgroup\$ – Nathan Merrill Jan 20 '17 at 17:00
  • \$\begingroup\$ If you are wanting design help, ux.stackexchange is great for that. If you want people to implement a specific clock, then make objective requirements, and change the challenge type :) \$\endgroup\$ – Nathan Merrill Jan 20 '17 at 17:01
  • \$\begingroup\$ Hi @NathanMerrill, thanks for input. The aim is not for people with low vision, it is just background, I will make that point more clear. And do you mean design challenge is not welcome here? My idea was exactly to challenge different designs with few restrictions. \$\endgroup\$ – Mikhail V Jan 20 '17 at 17:50
  • \$\begingroup\$ Right. Design questions aren't a good fit for this site. \$\endgroup\$ – Nathan Merrill Jan 20 '17 at 17:55

Rainbow Cat Program

Recently, I remembered a program I'd written in C# a while back for fun. It takes a string as input, then outputs that same string, cycling through a rainbow of colours. I now realize that this is basically a cat program, but with the added complexity of the output changing colour every 100ms. So I figured it would make an interesting challenge.

The aim is to make your own "rainbow cat program", taking a string as input, and outputting that same string cycling through the following colours in sequence: red, yellow, green, blue, purple, and pink. Not quite a proper rainbow, but close enough. The colours must change every 100ms (or as close to 100ms as your chosen language will allow).

For reference, here's an extremely badly-golfed version of my original C# program (370 bytes):

using System;using System.Threading;class P{static void Main(){var a=Console.ReadLine();for(;;){L(a,ConsoleColor.Red);L(a,ConsoleColor.Yellow);L(a,ConsoleColor.Green);L(a,ConsoleColor.Blue);L(a,ConsoleColor.DarkMagenta);L(a,ConsoleColor.Magenta);}}static void L(string a,ConsoleColor b){Console.Clear();Console.ForegroundColor=b;Console.WriteLine(a);Thread.Sleep(100);}}

And a gif of it in action!

Other Rules

  • Trailing whitespace/newlines are allowed; printing so many newlines that you push the text off the screen, then writing it again in the next colour, is not allowed. You must physically clear the screen and rewrite the text rather than writing it out over and over.
  • Once the cycle starts, it should continue indefinitely without any user input.
  • Standard golfing loopholes apply.
  • This is , so shortest program wins. Feel free to compete for the shortest program in any given language, though: don't feel put off by the golfing languages!
| |

Avoiding Averages

Given a non-empty list of positive integers, reorder the list such that for every pair of indices, the average of the values at those indices is not contained in any index between them.


  • This is so the shortest code wins.

Work in-progress

| |
  • 2
    \$\begingroup\$ Maybe add some sample input->output? \$\endgroup\$ – Leo Jan 23 '17 at 15:41
  • 1
    \$\begingroup\$ I like this, but there's also not much here. Maybe add a picture of a kitten or some I/O like Leo said. \$\endgroup\$ – Magic Octopus Urn Jan 23 '17 at 19:33
  • \$\begingroup\$ Can we expect the input to be valid, or if not, what should be done if such an ordering does not exist? (e.g. [1,1,1]). \$\endgroup\$ – flawr Jan 23 '17 at 20:22
  • \$\begingroup\$ @flawr I'm wondering the same thing, should the input always have a possible solution. If multiple solutions exist, return only one or all of them? I'm still ironing out the details. \$\endgroup\$ – miles Jan 23 '17 at 20:40
  • \$\begingroup\$ I'm struggling to think of a set of numbers that doesn't have a possible ordering (where each number occurs once). I think returning only 1 is sufficient. \$\endgroup\$ – Nathan Merrill Jan 23 '17 at 21:00
63 64
66 67

You must log in to answer this question.

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