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

Sandbox FAQ


To post to the sandbox, scroll to the bottom of this page and click "Answer This Question". Click "OK" when it asks if you really want to add another answer.

Write your challenge just as you would when actually posting it, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

When you think your challenge is ready for the public, go ahead and post it, and replace the post here with a link to the challenge and delete the sandbox post.


The purpose of the sandbox is to give and receive feedback on posts. If you want to, feel free to give feedback to any posts you see here. Important things to comment about can include:

  • Parts of the challenge you found unclear
  • Comments addressing specific points mentioned in the proposal
  • Problems that could make the challenge uninteresting or unfit for the site

You don't need any qualifications to review sandbox posts. The target audience of most of these challenges is code golfers like you, so anything you find unclear will probably be unclear to others.

If you think one of your posts needs more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended!

It is recommended to leave your posts in the sandbox for at least several days, and until it receives upvotes and any feedback has been addressed.


Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]. To search for posts with a certain tag, include the name in quotes: "king-of-the-hill".

Get the Sandbox Viewer to view the sandbox more easily!


3624 Answers 3624

78 79
81 82

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\$ 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\$ 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\$ 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\$ 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\$ 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\$ 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\$ 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\$ Jan 13 '17 at 8:46
  • \$\begingroup\$ Also, string challenges should specify which characters can appear in the input. \$\endgroup\$ 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\$ Jan 13 '17 at 14:43
  • \$\begingroup\$ @Zgarb yes, you're right. \$\endgroup\$ 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\$ 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\$ 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\$ 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\$ 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\$ 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\$ 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\$ Jan 18 '17 at 20:09
  • \$\begingroup\$ Also, this is more or less "output the location of the users ISP"... \$\endgroup\$ 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\$ 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\$ 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\$ 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\$ Jan 20 '17 at 18:17
  • \$\begingroup\$ All of that needs to be in the in the post. \$\endgroup\$ 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\$ 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\$ Jan 20 '17 at 22:26
  • \$\begingroup\$ I vote no on $2 bills, that sounds like it doesn't add much. \$\endgroup\$ 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\$ Jan 20 '17 at 2:27
  • \$\begingroup\$ @ETHproductions that sentence doesn't end due to the ;, rather it ends due to the newline. \$\endgroup\$ Jan 20 '17 at 18:20
  • \$\begingroup\$ Coulda sworn at least one person would like this haha. \$\endgroup\$ 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\$ 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\$ 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\$ 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\$ 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\$ 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\$ 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\$ 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\$ Jan 23 '17 at 21:00

Compute the CYK-Table!

Context-Free Grammars

A context-free grammar is a grammar consisting of rules from one variable to a list of variables and symbols. Every string purely consisting of symbols that can be produced using these rules is said to be accepted by the language. For the purpose of this challenge we're only going to consider grammars in CNF which means that on the right side there's either two variables or one symbol (we're gonna ignore the empty language for this challenge).

The CYK-Algorithm

The CYK-Algorithm is a method to check whether a given word is recognized by a context-free language in CNF. For doing this it iterates over the word and applies all possible rules on all substrings and writes them down in a nice table. This table can then be used to successively find variables generating larger substrings until you (don't) hit the word.

The Input

Your input will be

  • A list of strings representing the word
  • A list of triples of strings, representing the rules from one variables (the first in the triple) to two variables
  • A list of pairs of strings, representing the rules from one variable to a symbol
  • A string, representing the starting variable

You may replace the above input format with your favorite input format, as long as you can encode the same amount of information.

The output

The output will be three-dimensional: A list of rows consisting of a list of "candidates" which is a list of strings representing a list of variables. An illustration of this is on Wikipedia.

You may replace the above output format with your favorite output format, as long as you can encode the same amount of information.

Who wins?

This is so the shortest code in bytes to solve the challenge wins!


Start Symbol: "X"
Word: ["b","a","c","b"]
Rules #1: [("X","X","Y"),("X","Z","Z"),("Y","W","Z"),("Z","X","Y"),("W","Y","W")]
Rules #2: [("X","a"),("Y","a"),("Z","b"),("W","c")]

We're gonna do this step-by-step:

The substrings of length 1 first (this is your first row):

b    , a       , c   , b

Now for the substrings of length 2 (this is your second row):


(because there's no way to get ZX or ZY, but W -> YW and Y -> WZ)

Now for the substrings of length 3 (this is your third row):


(because there's no rule to get ZW, but X->XY (1+2), Y->WZ (2+1), Z->XY (1+2) where the sum denotes the lengths of of the used substrings)

Finally for the substrings of length 4 (this is your fourth row):


(because X->ZZ(1+3))

So in total your final table for this example is gonna look like this:


where the first index increases as we go downwards, the second increases as we go to the right an dthe third denotes the variable within the "cell".


Physical String Length

Given the following information:

  • (String) s - A string to be printed.
  • (String) f - The font in which it is to be printed.
  • (int) pt - The size of the font in which it is to be printed in pts (no decimals).
    • Note that the input units are in pt (1/72 inch).
    • The output unit should be pixels, rounded to the nearest integer.
    • Use 96 PPI in your conversion.


  • The physical length of the string (how many pixels wide the final string is).

Below are a few examples and a piece of code that will let you test arbitrary combinations.

import java.awt.Canvas;
import java.awt.Font;
public class F {
    public static void main(String[]args){
        System.out.println(physicalStringLength("What?", "Calibri", 12));
        System.out.println(physicalStringLength("What?", "Calibri", 24));
        System.out.println(physicalStringLength("What?", "Calibri", 36));
        System.out.println(physicalStringLength("What?", "Calibri", 72));
        System.out.println(physicalStringLength("What?", "Helvetica", 12));
        System.out.println(physicalStringLength("What?", "Times New Roman", 12));
        System.out.println(physicalStringLength("What?", "Courier New", 12));
    public static int physicalStringLength(String s, String f, int pt) {
        System.out.print(s + "@[" + f + "," + pt + "]=");
        return new Canvas().getFontMetrics(new Font(f,0,pt)).stringWidth(s);

Here's some base-line examples, the output has be created using the above piece of Java code:

What?@[Times New Roman,12]=31
What?@[Courier New,12]=35

If you want to see the length of any other strings, use the code provided as a base-line. Using a Java has been banned due to the usage of the example unless you'll be providing a different methodology (kinda sucks, cause Java may be one of the few with a built-in).

This is , lowest byte-count wins.

  • 2
    \$\begingroup\$ The font is an integer? \$\endgroup\$
    – Poke
    Jan 24 '17 at 21:25
  • \$\begingroup\$ Yep, no float font sizes. \$\endgroup\$ Jan 24 '17 at 21:26
  • 2
    \$\begingroup\$ Sorry, I mean the second parameter "f" \$\endgroup\$
    – Poke
    Jan 24 '17 at 21:26
  • \$\begingroup\$ Nope, that's a typo. \$\endgroup\$ Jan 24 '17 at 21:26
  • \$\begingroup\$ It's a little strange to ask for the width in px but input the font size in pt. Pixels are can vary in physical size while points are fixed at 1/72 inches. \$\endgroup\$
    – Poke
    Jan 24 '17 at 21:29
  • \$\begingroup\$ @Poke I guess I could state that Java is using a default PPI is 96. \$\endgroup\$ Jan 24 '17 at 21:31
  • \$\begingroup\$ Because I like answering challenges in java I'd be remiss if I didn't suggest adding more to this challenge such as height and other things found here but that's likely not as fun for other languages. I think the challenge does contain enough by itself. \$\endgroup\$
    – Poke
    Jan 24 '17 at 21:41
  • \$\begingroup\$ 1. I don't think this is well defined. Different applications using the same typeface and the same point size will produce strings of slightly different widths because e.g. they don't interpret the hints in the same way. 2. Why ban Java and not e.g. the .Net languages, which have very similar library support? \$\endgroup\$ Jan 24 '17 at 22:31
  • \$\begingroup\$ Adding to Peter's point, different rendering engines display fonts differently. The default Windows GDI renderer alone knows 5 different types of anti-aliasing, any of which can be the system standard, not counting fonts rendered by Direct2D, OpenGL or GDI+. It's very easy to just render and measure a string with GDI+, but the length might be different across systems by one or two pixels because of AA. Would that be acceptable? \$\endgroup\$
    – user42643
    Jan 24 '17 at 23:48
  • \$\begingroup\$ @PeterTaylor Maybe adding in a clause about acceptable standard deviations? \$\endgroup\$ Jan 25 '17 at 15:28

Binary Grids

Consider the N-dimensional binary grid, with dimensions {d1,d2,...,dN}. Here are a few examples:

6 (N=1): 100101

3x7 (N=2):


3x3x3 (N=3):

010   001   100
100   011   110
011   110   001

What each of these example grids have in common is: they do not contain any consecutive sequences of the same digit longer than 2.

The Challenge

Write a program or function which, given a list of dimensions, outputs the number of binary grid configurations with the given dimensions that satisfy this condition.


A list of positive integers (>1), either via stdin or passed as an argument. Example: 3 2 6, [3,2,6], etc.


The number of valid configurations, either as a returned value or printed to stdout, or something similar.


  • While brute-force solutions can work, their time complexity is O(2^N), which is way too long for anything but the smallest grids. Write something which will complete before my computer becomes obsolete, please!
  • Standard loopholes are forbidden, not that I think very many of them would apply here anyway.
  • This is code-golf, so the shortest code wins, with tiebreakers going to the fastest code.

Sandbox Questions

  1. Is this interesting?
  2. Is this doable?
  3. What's a better way to word the time complexity restrictions?
  4. The only example for which I actually know the answer is for [6]... do I need more? I'd have to solve this myself first...
  • \$\begingroup\$ 1. I think "consecutive" needs clarification. I'm guessing that it's talking about horizontal and vertical lines but not diagonal ones. 2. Re whether it's doable: in 1D it's oeis.org/A128588 which is easy to calculate. In general it can be done in n-D by calculating all of the acceptable values in some (n-1)-D projection and then taking the power of an incidence graph, but I doubt that scales well beyond 3D. It may be possible with some investigation to get an n-D generating function, but it's hard to tell without spending a couple of hours on the problem. \$\endgroup\$ Jan 27 '17 at 16:25
  • \$\begingroup\$ In terms of complexity restrictions, asking the program to run in polynomial time in the number of cells in the grid seems reasonable (because exponential time is enough to brute-force it and it's very rare (impossible?) for a program to have a complexity in between). I don't know whether that's possible, though (although even if there's a chance that it isn't, it may still be worth asking the question). \$\endgroup\$
    – user62131
    Jan 27 '17 at 22:31

Golf Me a Bubble Sort

Your task is to create a program that performs a bubble sort.
For those who don't know, a bubble sort is a simple sorting algorithm where two adjacent items are taken & swapped if they are in the wrong order until all values are in the correct order.


  1. You must provide an explanation for how your answer does a bubble sort.
  2. You may not use built-in or standard library sorting algorithms. You must make your own code.
  3. Your program should take a group of numbers as input and output them in the correct order.
    • Input format: 10 5 9 2 . . . (and so on)
    • Output can be an array returned by the program when run.
    • Output can also be the correctly ordered values separated by whitespace.
  4. Speed does not matter as much as of the program functions.

Test Cases

  • 10 5 9 2 1 6 8 3 7 4 (you can format it differently depending on your language)
  • 1 2 5 4 3

This is , so the shortest answer in bytes wins.

  • 1
    \$\begingroup\$ It may be a better idea to have entries do only a single iteration of bubble sort; that way it will be easy to verify their correctness. \$\endgroup\$ Jan 29 '17 at 20:52

Find fixed points of the Logistic Map


Logistic Map

A logistic map is defined as the following equation:


Where the next value in the map (on the left) is determined by a function of the current value (on the right), where the constant lambda represents a set constant between zero and four (non-inclusive, along the reals).

Stable Point

A "stable point" in relation to a map is a point which is approached repeatedly by iterating the logistic map. They are distinct, and there are one to many for any given lambda.

The Task

Write a function or program which, given an input real value n between zero and four (non-inclusive), returns the number of stable points for a map where lambda is n.


Soon to be added


Main problem: Defining "stable point". Is this definition sufficient?

  • \$\begingroup\$ The definition is wrong. A fixed point of a map is a point which is mapped to itself. For the logistic map the fixed points are 0 and 1-1/x. \$\endgroup\$ Jan 31 '17 at 8:45
  • \$\begingroup\$ If you instead look for points in stable cycles, you need to also specify that the domain is the real numbers, because stable cycles correspond to roots in the polynomial obtained by iterating the map, and over the complex numbers a polynomial always has as many roots as its order. If you specify distinct points in stable cycles of any length, that becomes a real challenge. \$\endgroup\$ Jan 31 '17 at 8:55
  • \$\begingroup\$ @PeterTaylor The second one was what I was going for. :P Got my terminology wrong. \$\endgroup\$ Jan 31 '17 at 9:40
  • \$\begingroup\$ @PeterTaylor Just to verify, I'm looking for the number of distinct stable points for specific values of lambda along this graph. \$\endgroup\$ Jan 31 '17 at 9:49
78 79
81 82

You must log in to answer this question.

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