What is the Sandbox?





Add Proposal

Search the Sandbox

Browse your pending proposals

Get the Sandbox Viewer to view the sandbox more easily


| |

2916 Answers 2916

45 46
48 49

Count the length of head movement

Moved here

| |

Sort By the New Alphabet

The order of the alphabet is really quite arbitrary. I propose a new ordering of the alphabet, ordered so that adjacent letters (in capital form) are similar in shape. Here is the order:


Of course, this makes a lot of previously written code redundant. To fix this problem we will start re-implementing that code, in its updated form.

Your task is to create a program or function that takes a string or list of characters as input, and outputs that string/list sorted according to this new ordering.

You can assume that all input will contain only uppercase alphabetic characters.

I know it's similar to this and this, but this challenge has a fixed ordering, so I hope this allows for some more ingenuity as well as the requirement to store the ordering efficiently.

| |
  • \$\begingroup\$ Is uppercase mandatory, or are we allowed to take both input and store the compressed alphabet as lowercase? \$\endgroup\$ – Kevin Cruijssen Dec 16 '19 at 9:36
  • \$\begingroup\$ You can store the alphabet however you want. You can accept input as upper or lowercase. \$\endgroup\$ – Matthew Jensen Dec 16 '19 at 20:42

edit: check it out live here!

Play Big 2 by yourself, as fast as you can

| |
  • \$\begingroup\$ Seems a good first go. There is one major ambiguity I can find: You don't explain if aces are high or low. From your straight explanation, I guess they can be both, but you can't 'wrap' around. Please add an explanation about that. Also, the straight flush, while a Poker hand, isn't required algorithmically: It's a subset of both straights and flushes, so any algorithm detecting them will also catch the straight flush. \$\endgroup\$ – AlienAtSystem Nov 18 '19 at 8:01
  • \$\begingroup\$ Consider 3352 ['8C', '7C', '4C', '0C', 'AC'] 3966 ['4H', '6D', '3S', '5H', '2S'] 8063 ['AS', 'AH'] 8191 ['8D'] for the first test \$\endgroup\$ – Alexey Burdin Nov 18 '19 at 14:00
  • \$\begingroup\$ tinyurl.com/cgm-a18285-1 -- tio (may run more than \$1\$ min for \$hands\ge7\$) \$\endgroup\$ – Alexey Burdin Nov 18 '19 at 14:17
  • \$\begingroup\$ @AlienAtSystem you're right - aces can be used as a high or a low, but they can't appear in the 'middle' of a straight, so to say. I'll update the straight description. Re: the straight flush - yeah I figured this too, mostly adding it for the sake of completion. I'll also make a note about that. Thanks for reading through it! \$\endgroup\$ – aphrid Nov 18 '19 at 15:08
  • \$\begingroup\$ @AlexeyBurdin ack, you're right! I came up with the suiting on a whim and didn't really sit down to consider if it was possible to dump the hand faster. Oops. I meant to use the first test case as a general explanatory case, so I'll update my tests to reflect that. (Also, it seems like your tinyurl link is broken...) \$\endgroup\$ – aphrid Nov 18 '19 at 15:10
  • \$\begingroup\$ tinyurl.com/cgm-a18285-2 -- I use bfs with early exit if goal reached, so it can't be done faster(in words of move numbers, not computation time). ) \$\endgroup\$ – Alexey Burdin Nov 18 '19 at 16:22
  • \$\begingroup\$ @AlexeyBurdin Hmm, I still can't seem to use that link, but I appreciate your attempts nonetheless \$\endgroup\$ – aphrid Nov 18 '19 at 17:34
  • 1
    \$\begingroup\$ One more )) tiny.cc/cgm_a18285_2 \$\endgroup\$ – Alexey Burdin Nov 18 '19 at 18:33
  • \$\begingroup\$ That link works like a charm, great work! \$\endgroup\$ – aphrid Nov 18 '19 at 18:56

Challenge posted to Main here

| |
  • \$\begingroup\$ I'd say this is very close to being a dupe of the Fibonacci challenge. Often one could pretty directly replace the (inc/dec)rement with a divisibility check. The specific nature of the Fibonacci challenge allows a lot of tricks that wouldn't work as well here, though. \$\endgroup\$ – FryAmTheEggman Dec 9 '19 at 20:48
  • \$\begingroup\$ Could you link to that challenge? \$\endgroup\$ – Don Thousand Dec 9 '19 at 20:50
  • \$\begingroup\$ Here you go. \$\endgroup\$ – FryAmTheEggman Dec 9 '19 at 20:51
  • \$\begingroup\$ Hmm, I see. Is there a way to modify this to invalidate more answers from that question? Maybe a new winning criterion? \$\endgroup\$ – Don Thousand Dec 9 '19 at 20:54
  • \$\begingroup\$ You could try something like scoring each submission by the sum of each byte's smallest Fibonacci multiple? That's kind of a lazy fix (and you need to deal with null bytes, lenguage, etc.) but it could work. You can try asking in chat for more ideas, and of course if I think of anything I'll let you know :) \$\endgroup\$ – FryAmTheEggman Dec 9 '19 at 20:56
  • \$\begingroup\$ @FryAmTheEggman How do you like the update? \$\endgroup\$ – Don Thousand Dec 9 '19 at 23:46
  • \$\begingroup\$ I don't think your precise method of scoring is ideal, it seems like it could be abused to get a score of zero too easily. I recommend scoring actual bytes, not the unicode characters they turn into. \$\endgroup\$ – FryAmTheEggman Dec 10 '19 at 5:55
  • \$\begingroup\$ @FryAmTheEggman Hmm, sorry for bugging you, but how would you suggest doing that? I'm not sure I see the picture. \$\endgroup\$ – Don Thousand Dec 10 '19 at 6:23
  • \$\begingroup\$ I guesss something like Lenguage could come in and have a program full of spaces, henceforth getting a score of 0. \$\endgroup\$ – Lyxal Dec 10 '19 at 10:30
  • \$\begingroup\$ @Jono2906 I don't know how to modify this to make this work, frankly. \$\endgroup\$ – Don Thousand Dec 10 '19 at 18:45
  • \$\begingroup\$ No worries, and I recommend not worrying too much about Lenguage and the like, they are often kind of impossible to fix. What I mean is, the characters used in code are ambiguous and not particularly meaningful. Instead, score based on the bytes of the program, which are clear and fixed. Then keep the part with the fib multiples, but add one to the bytes beforehand to avoid zero. \$\endgroup\$ – FryAmTheEggman Dec 10 '19 at 20:24
  • \$\begingroup\$ @FryAmTheEggman Makes sense! I'm pretty happy now with where this challenge is at. \$\endgroup\$ – Don Thousand Dec 10 '19 at 22:38

Expand a road network


        | |
        | |
        | |
        | +-------
        | +-------
        | |
        | |

Your job is to expand the existing infrastructure \$n\$ blocks in a specific direction.

The Challenge

  1. Take two inputs - a direction to expand in, and the number of blocks to expand - through any reasonable input format.

  2. Expand the existing roadways in the ASCII map, in the direction specified.

    a. You must take into account the existing roadways - you can only expand on roads that are already there, and if there are no roads to expand, you won't expand anything.

    b. Your program must work for any example map, not just the one provided above.

  3. Show the output on STDOUT, if your language supports it.

Test Cases

        will be done soon

Other Rules

This is , so lowest score in bytes wins. Standard loopholes are forbidden. Have fun!

| |
  • 1
    \$\begingroup\$ Are blocks a fixed dimension or is it based on the size of the input? Does it expand in only one direction or can it be multiple? Finally, what does expansion mean? Are we replicating the block n times? Merely extending the roads on the expanding edge (i.e. appending n*width - or |s)? \$\endgroup\$ – Veskah Dec 11 '19 at 14:21

Is it a Snake Cube?


Images from Wikipedia (1)(2)










No cube possible:


Cube possible:

| |
  • 1
    \$\begingroup\$ Oh hey, I have that exact cube, but I forgot how to put it back together again \$\endgroup\$ – Jo King Dec 14 '19 at 2:44
  • \$\begingroup\$ @JoKing ...then I should maybe modify the challenge and ask for the solution as output :P \$\endgroup\$ – flawr Dec 14 '19 at 9:37
  • \$\begingroup\$ Don't worry, I dug it out of the drawer it was stuck in and finally solved it \$\endgroup\$ – Jo King Dec 16 '19 at 7:07

Union of Two Polygons

Given two intersecting polygons as input, output a third polygon that is the union of the two input polygons, that is to say, the perimeter that encloses all points present in at least one of the two input polygons.

Example polygon unions

Example inputs/outputs

2 Squares

| [(1, 1), (1, 3), (3, 3), (3, 1)]
==> [(0, 0), (0, 2), (1, 2), (1, 3), (3, 3), (3, 1), (2, 1), (2, 0)]

... more to come

Notes and Rules

  • Input will be two lists of at least 3 2d points each, taken in any convenient format.
  • Output should be a list of 2d points, in any convenient format.
  • It does not matter which point you list first.
  • It does not matter whether you output in clockwise or counterclockwise order.
  • Polygons may be concave
  • You may assume that both polygons are not self-intersecting
  • You may assume that the polygons overlap in at least two places exclusively via edge-edge crossings rather than vertex-edge intersections, vertex-vertex intersections, or flush edge-edge overlaps.
  • You may assume that the polygons do not overlap in such a way that the union would have at least one hole in it.
  • You must be accurate to at least 0.01 for all polygons between -100 and 100 units along each axis.
  • Standard rules apply. Shortest code wins.

| |
  • \$\begingroup\$ Can you add some examples? \$\endgroup\$ – Carson Graham Dec 13 '19 at 16:01

Make an "implicit" parser

In this task, given an infix expression, fill in all of the implicit inputs and evaluate this expression with the other given input. (You only need to deal with (+, -, and ().)

Expressions are only allowed to be dyadic and not monadic. If an operator is monadic, prepend an input.

What do I do?

The rule is simple: if something is preceded with a nilad or a parenthesized expression, it is a dyad.

+ is a dyad here:

2 + 1
(5 + 2)
3 + ((2) + 4)

Otherwise, the operator is a monad.

+ is a monad here:

 +(2 - 2)
(+ 2)

If you find a monad in your code, immediately prepend it with the a character.

a +(2 - 2)
(a+ 2)

That's about it.


The input expression is guaranteed to not produce errors, such as the format 2- which is impossible to prepend an input.

"+++a",2 -> a+a+a+a = 2+2+2+2 = 8
"(+1)+(-1)",5 -> (a+1)+(a-1) = (5+1)+(5-1) = 10
"+(2-a)", 3 -> a+(2-a) = 3+(2-3) = 2
"(5+2)+2+1", 7 -> (5+2)+2+1 = 10
"--2", 2 -> a-a-2 = 0-2 = -2


  • This is , so the shortest code wins.
  • Standard loopholes are disallowed.
| |
  • \$\begingroup\$ I've been thinking of making a challenge to parse a simple subset of APL e.g. numbers and + and - and /, but what does your challenge have to do with APL? APL doesn't have implicit arguments for nilads, and a+(2-) is a syntax error in most dialects. \$\endgroup\$ – Adám Dec 15 '19 at 9:16
  • \$\begingroup\$ @Adám (You said nilad, I assume you meant monad.) 1. I assume scanning for nilads was how APL was parsed. Correct me if I am wrong. 2. Although APL doesn't provide arguments, the only less trivial way I can think of compared to outputting how many arguments an operator has is to provide the arguments. Do you have a better way to do this? 3. To simplify the challenge, preventing syntax errors is unneccecary. \$\endgroup\$ – user85052 Dec 15 '19 at 9:43
  • \$\begingroup\$ Yeah, sorry about the "nilad" instead of "monad". 1. That's wouldn't work. 2. How about simply evaluating a given expression consisting of `[-+/ 0-9]? That's easy to verify against a real interpreter. 3. Just guarantee that the input expression has no errors. \$\endgroup\$ – Adám Dec 15 '19 at 9:48
  • \$\begingroup\$ What is the correct answer for "--2",2? \$\endgroup\$ – Adám Dec 15 '19 at 10:48

Asyncronous Breakfast

I haven't seen any asyncronous challenges here, even tho it's an important part of coding, so here's my idea, based on an example (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/) that explains asyncronous coding:

You are making breakfast. The things you want to serve are:
Cooked eggs, Bacon, Coffee, Orange Juice and Toast.

You start boiling the eggs, cooking the bacon, making coffee, and toasting toast. 
When everything is finished, you're serving the orange juice.

After every finished food, the console outputs "[Food] is ready."
| |
  • 1
    \$\begingroup\$ I think you should generally only specify things about the input and the output, and not the program's internal behaviour ("do addition without the + operator"-like questions are now discredited). Can you define a required output in a way that the only way to produce it is for the program to run asynchronously? \$\endgroup\$ – KeizerHarm Dec 16 '19 at 14:29
  • 1
    \$\begingroup\$ How about checking the multi-threading tag? \$\endgroup\$ – Adám Dec 16 '19 at 22:03


This is kept fairly simple, compared to a real Blackjack-Game:

Write a program that creates a blackjack game, where the input "h" means "hit" and "s" means "stand". Everything else outputs nothing, it just waits for the right input.

- You can draw as many cards as you want, also to make it easier, there is no card limit.
  This means you could draw more than 4 Asses.
- The cards you can get are
  standard-cards (2-10, J, Q, K, A) where the Values are the default ones:

2-9 = 2-9,
10, J, Q, K = 10

- A is a special card. So to make it easy, the default value is 11.
  If a player gets over 21, the value gets reduced to 1.
  In the case that a player has two or more A-Cards, all but one A
  reduces to 1, giving a total value of 14 for 4 Asses. (11+1+1+1)

- The dealer needs to get in between 18-21. If the bank has reached a value in 
this radius,
it can't draw another card (For example: Bank reached 18.
                          It can't get another card to get closer to 21)

- The game runs forever
- hit means „draw another card“, stand means „stop with cards and wait for 
the dealer to reach his limit“


- The player gets 2 cards at the beginning, shown by "Player:" in the console 
  (Example: Player gets 2 and 5 at the beginning. 
  Console output: "Player: 2, 5").

- The cards can be shown in the console by their values
  (For example: 2, 10, 1 | No need for: 2, K, A), but you can also use 
  the card-names instead. Your choice. But you need to show the maximum
  value you have
  (for example:
  first draw console output "Player: 2, 4, 5 = 11",
  second draw console output "Player: 2, 4, 5, 7 = 18")

- The input by the player is "h" for "hit" and "s" for "stand". Also allowed 
  is 1 and 0

- In the console, the player is displayed by "Player:"
- In the console, the dealer is displayed by "Dealer:"

- After the player got two cards, the dealer gets one card.
  Then the player can hit or stand.
  After every card drawn from the player,
  the dealer gets another card until he reaches his limit. (18-21)

  If the dealer reaches 21 before the player does, the dealer wins.
  If the Player reaches 21 first, the player wins.
  If the dealer reached his limit, and the player stands on the same value, it's a draw.
  If the dealer is over 21 first, the player wins.
  If the player is over 21 first, the dealer wins.

- At the end you get the output "Win", "Lose", "Draw",
  or "Blackjack", depending on the game

This game is a challenge, even the smallest result won'tbe under 150 bytes at least

| |
  • \$\begingroup\$ @Noodle9 1. If you want to write 'h' and mistype, then you basically ruined your win 2. Blackjack rules: win = more points than dealer or Blackjack | lose = less points than Dealer | draw = same points as dealer | Blackjack = 21 points straight | 3. As it's the easy version there is only one hand, will add that \$\endgroup\$ – DudeWhoWantsToLearn Dec 16 '19 at 18:14
  • \$\begingroup\$ Do you know blackjack? You draw cards and try to get as close to 21 as possible. If you get 21 you already have won the game. if you get 20 you could still draw a card, maybe it's an Ass. But you still need to get higher points than the dealer, but not more than 21 \$\endgroup\$ – DudeWhoWantsToLearn Dec 16 '19 at 18:37
  • \$\begingroup\$ if you play with 52 cards you could draw up to 7 cards (4*Ass+ 3*2 = 20) \$\endgroup\$ – DudeWhoWantsToLearn Dec 16 '19 at 18:38
  • \$\begingroup\$ Yes I've played the game T_T But questions/challenges need to be self-contained with a full explanation for anyone who's doesn't know the game. Also you should edit your sandbox to include the things above. \$\endgroup\$ – Noodle9 Dec 16 '19 at 19:59
  • \$\begingroup\$ If a player gets over 21, the value gets reduced to 1. this contradicts the bit below of all but one A reduces to 1, giving a total value of 14 for 4 Asses. (11+1+1+1) \$\endgroup\$ – Corsaka Dec 20 '19 at 22:36
  • \$\begingroup\$ @Corsaka It doesn't. First ace you have 11, second ace makes that 22 so it gets reduced to 12, third ace makes that 23 so it gets reduced to 13, forth ace makes that 24 so it gets reduced to 14. \$\endgroup\$ – Noodle9 Jan 3 at 21:48
  • \$\begingroup\$ Ah, I misread that. Apologies. \$\endgroup\$ – Corsaka Jan 5 at 13:20

Decorate the Christmas Tree



It's a week before Christmas and the your family just bought a Christmas tree. Your little sister has a box of ornaments which she wants you to decorate the tree with.


Write a function or program to randomly decorate the tree with all the ornaments from the box. All possible arrangements of ornaments on the tree must have a non-zero probability of occurrence.


  1. height of the tree n
  2. 'box' of ornaments (a string of printable ascii characters where each character represents an ornament) in which order doesn't matter. Also, you can assume that '#' will not show up as an ornament since it is used to draw bare branches.

Given the number of branches on a tree of size n is (n-1)^2 you can assume that the number of ornaments in the box will be less than or equal to the number of branches on the tree.

Example of a box of ornaments: o = '**@@***@@$$**OOOO....'. Since this string is 21 characters long it can only be valid input for n > 5.


Print out the tree with its decorations

The tree is the following structure of ascii characters where n specifies the height of the tree:

//Tree where n=9                         //Tree where n=6
        #                                        #
       ###                                      ###
      #####                                    #####

Bare branches will always be represented with '#' and the bottom trunk is always ||| while centered with center character of each row.

Examples of output with ornaments:

//n=9, o='X@@X%%%**&&'                   //n=6, o='OO*X*X'
        #                                        O
       ##%                                      O##
      #X###                                    #X#*#
     ###@##%                                  *######
   #@######X##                                  |||



  • Is this too close to a duplicate?
  • Are there any improvements or clarifications required?
| |
  • 2
    \$\begingroup\$ By random, do you mean that every possible distribution of decorations should be equally likely? Or just that the distribution changes with each run? \$\endgroup\$ – frank Dec 17 '19 at 20:10
  • 1
    \$\begingroup\$ What does the tree look like if n is even? That is, how does the trunk center? \$\endgroup\$ – AdmBorkBork Dec 17 '19 at 20:14
  • \$\begingroup\$ Every level of the tree will have an odd number of characters, no matter what the value of n is, so the trunk should remain centered with the top level of the tree. \$\endgroup\$ – Grumpy_Boy Dec 17 '19 at 21:09
  • \$\begingroup\$ What can you put in the box of ornaments? Printable ascii characters? Unicode? Also, what if there's more ornaments than there is area of tree to put them on? \$\endgroup\$ – KeizerHarm Dec 17 '19 at 22:41
  • 1
    \$\begingroup\$ To add to frank's comment: codegolf.meta.stackexchange.com/a/10909/36398 \$\endgroup\$ – Luis Mendo Dec 17 '19 at 23:14
  • 1
    \$\begingroup\$ Regarding "a string of printable ascii and/or unicode characters" You should know that handling unicode (millions of possible characters, from Urdu اُردُو‎ to cuneiform 𒀣) is a lot harder in many golfing languages than printable ascii (which is mostly just the Latin alphabet and some punctuation marks) - to the point where using the tag unicode is advisable if you want the solution to handle unicode characters. If you want the possibility to handle every conceivable tree decoration, you should be more explicit about it than use an and/or construction. \$\endgroup\$ – KeizerHarm Dec 18 '19 at 9:20
  • 1
    \$\begingroup\$ Fair enough. Sticking to printable ascii should be fine then. \$\endgroup\$ – Grumpy_Boy Dec 18 '19 at 22:44
  • \$\begingroup\$ This feels very familiar; I think we may have had it before but, maybe, without the inputs. \$\endgroup\$ – Shaggy Dec 18 '19 at 23:54

For any integer a and any positive odd integer n the Jacobi symbol is defined as follows: $$ \left(\frac{a}{n}\right) = \left(\frac{a}{p_1}\right)^{\alpha_1} \left(\frac{a}{p_2}\right)^{\alpha_2} \cdots \left(\frac{a}{p_k}\right)^{\alpha_k} $$ where $$n = p_1^{\alpha_1}p_2^{\alpha_2}\cdots{p_k^{\alpha_k}}$$ is the prime factorization of n. The Legendere symbol is defined for all integers a and odd primes p as $$\left(\frac{a}{p}\right) = \begin{cases} 0 & \text{if $a \equiv 0 \pmod{p}$},\\ 1 & \text{if $a \not\equiv 0 \pmod{p}$ and for some integer $x$: $a \equiv x^2 \pmod{p}$},\\ -1 & \text{if $a \not\equiv 0 \pmod{p}$ and there is no such $x$}. \end{cases} $$

Your task is to write a function that will take two parameters: a and v, where a is a positive integer, and v is a list of n values. The function should return the index of the first value in v for which the Jacobi symbol is -1. For this challenge, you may assume that all values in the v array are odd primes, and are greater than or equal to a. The length of v will be between 4 and 100 values. If no value in v produces a -1 result for the Jacobi symbol, simply return the length of v.

Because each invocation of the function will execute very quickly, your function will be tested against a wide variety of inputs and the execution time will be summed. This process will be repeated 50 times and the best execution time will serve as your score. My machine is a 2018 Macbook Pro, with the following specs:

CPU: Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
GPU: Intel UHD Graphics 630 1536MB
RAM: 32GB 2400MHz DDR4

| |

Even-Odd chunks

(Inspired by the Keg utility of this challenge)

Given an input string, e.g. s c 1= e(a"E"), split the input into even-odd chunks.


This input string, when mapped to its code points, yields the list [115, 32, 99, 32, 49, 61, 32, 101, 40, 97, 34, 69, 34, 41]. When applied modulo-2 for every item, this returns [1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1].

In this list let's find the longest possible chunk that is consistent with even and odd code points:

[1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1]

For the first chunk, this yields [1, 0, 1, 0, 1] because this is the longest chunk that follows the pattern

Odd Even Odd Even Odd Even ...


Even Odd Even Odd Even Odd ...

. Adding another codepoint into [1, 0, 1, 0, 1, 1] breaks the pattern, therefore it is the longest possible even-odd chunk that starts from the beginning of the string.

Using this method, we should split the input into chunks so that this rule applies. Therefore the input becomes (the ; here is simply a separator; this can be any separator that is not an empty string):

s c 1;= e(a"E")


  • This is so the shortest solution wins. Let it be known that flags don't count towards being in the pattern. They also don't count towards byte count in this challenge.
| |
  • \$\begingroup\$ Right now, the output specified in the introduction (Longest even-odd chunk) doesn't agree with the example, where you have instead the string split into even-odd chunks. Both would work as challenge, but you have to choose which. \$\endgroup\$ – AlienAtSystem Dec 21 '19 at 12:24
  • \$\begingroup\$ I chose the latter because it is easier to specify. \$\endgroup\$ – user85052 Dec 21 '19 at 12:30

Convert Character Substrings to Numeric

I often have to take character data and categorize it numerically. A common thing I do is to take character type variables and convert them to numeric type characters, keeping same categories according to the level of work I'm doing. (The longer the substring, the more in depth, shorter substrings for broad level). Enough backstory...

The challenge: In as few bytes as possible, convert the input part A, a vector/list of unique strings, into the output, a vector/list of numbers, keeping unique categories within the length of substrings the same length, which is input part B.


  1. w, Vector/list of unique strings of equal character length. n <= 10

    • These strings may be any combination of uppercase letters and numbers. Sorry if it seems my examples follow a pattern, I just created them after a similar pattern I see in the data I work with.
  2. s, where 1 <= s <= n

Output: May take input and output in the same order, or you can convert alphabetically, but output in the same order. See example 2. (I've included comments in my output to clarify, this is not required)

Example Input 1:

#Already alphabetized, but this input is not always guaranteed

s = 3, w = 

Example Output 1:

[1, #ABC
 2, #ABD
 3, #ABE
 4, #ACA
 5, #ACB

Example Input 2: s = 4, w =


Example 2 Output:

#Categorize by order
[1, #X1Z1
 2, #X1Y1
 3, #X1X1
 4, #X1X2
 5, #X2Z1
 6, #X2Z2

OR if conversion follows alphabetical formatting,

#Categorize alphabetically, but output in same order as input.
[6, #X1Z1
 5, #X1Y1
 3, #X1X1
 4, #X1X2
 1, #X2Z1
 2, #X2Z2
| |
  • \$\begingroup\$ I'm a little confused; the input matches the regex [A-Z]+[0-9]+ and the task is to replace the inputs with unique integer identifiers based on the first s letters? Something like as.integer(as.factor(substring(w,1,s)))? I think it's a good challenge but needs a little more clarification. \$\endgroup\$ – Giuseppe Dec 23 '19 at 19:58
  • \$\begingroup\$ Sorry, I suppose I didn't specify how the input will appear. The input is not supposed to follow any specific regex pattern, but some inputs will be similar enough. It could be all uppercase letters or all numbers. \$\endgroup\$ – Sumner18 Dec 23 '19 at 20:24

Partial tq interpreter

In this task you are expected to provide a list output given an input tq program. The tq programs will not contain whitespace inside them. (I find tq extremely difficult to implement within a short time, therefore I consider it to be a nice challenge.)

What is tq, in the first place?

tq is a lazy-evaluated language that is designed with the idea that array items should be accessable during the definition of them. In tq, there is no explicit separator of an array, only special arrangements of monadic/dyadic functions and nilads.

The following program is a program printing [123] (Pretend that tq doesn't support strings because we aren't dealing with them in this case):


This defines a list with the first item being the number 123, after which all items in the list will be outputted inside a list.

In tq, numbers are supported to allow multiple-digits. So this defines a list with 2 items:


In this test case, you are expected to output the list [24,5]. Let's explain it step by step.

12+12   # This evaluates 12 + 12 in the current item in the list, returning 24
     ,  # A separator. This separates two items when they could be potentially
        # ambiguous when they are applied without a separator.
      5 # This evaluates 5 in the current item in the list, returning 5
        # The comma is simply a no-op that doesn't require parsing.

So you think that tq is not hard at all to implement? Well, remember that tq also has a special feature of accessing the items in an array before the array is defined!


We introduce two new atoms:

  • t (tail) means access the last item in the list
  • h (head) means access the first item in the list

Therefore our list is going to yield:


Now take a look at this program:


We introduce 2 more atoms:

  • p Yield the next item before (previous) the current position
  • s Yield the next item after (succeeding)the current position

This yields the list:


A quick reference of the tq language

Just assume that you only have two operands for the operators.

  • [0-9] starts a number. Numbers will only be positive integers, i.e. no decimals and negative numbers.
  • , This is a separator of different items when it is given that two consecutive indexes will be ambiguous with each other without a separator. In tq all of the remaining characters can act as a separator, but in this case it is a good idea to implement only , for the ease of your implementation.
  • + and * These are arithmetic operators. Usually in tq, they may be applied multiple times, e.g. 1+2+3, but in your implementation, input will be provided so that this will not happen and only 1+2 will happen (there will not be applications multiple times).
  • t return the last item in the list. If the code is t1,2,3 it shall return [3,1,2,3].
  • h return the first item in the list. If the code is 1,2,3h it shall return [1,2,3,1].
  • p returns the item before the current item. If the code is 0,1,p,3,4 the code shall return [0,1,1,3,4].
  • s returns the item after the current item. If the code is 0,1,s,3,4 the code shall return [0,1,3,3,4].

More test cases

  • 4p*p will yield [4,16]
  • 1p+s2 will yield [1,3,2]
  • 1,2,3h+t4,5,6 will yield [1,2,3,7,4,5,6]
  • 3ppss6 will yield [3,3,3,6,6,6]
  • You also have to implement multiple hops. E.g. 1th should yield [1,1,1]
  • If you know that something is going to form a loop, e.g. 1sp2, the cells that form the loop should be removed. Therefore the previous example will yield [1,2].
  • Out of bounds indexing will yield the closest index of the indexed item that is a number. E.g. 1,2s should yield [1,2,2]
| |

Internal Truth Machine

It's a normal truth machine but instead of taking input, it uses the first character of the program. Thus, internal.

Example: 0abcd prints 0 and halts, and 1abcd prints 1 infinitely.

| |

Balanced interval tree

You will write a balanced, online interval tree.

  • A function, method, or procedure that performs insertion into a query of intervals that overlap with an interval over a, b in O(log n) time, given that a is less than b, including:
    • intervals that fully enclose a, b
    • intervals fully within a, b
    • intervals that start to the left of a but end before b
    • intervals that start to the right of a but end after b
  • A function, method, or procedure that performs insertion ov an arbitrary interval a,b into a data structure in O(log n) time
  • Both O-bounds must hold after arbitrary series of insertions and queries


If you write non-method functions, your submission may take the data structure as a global variable or receive the data structure as the first parameter.

You must informally prove your submission falls within the required O-bounds or name the data structure your program implements. If the name of the data structure you are implementing is obscure, you may name the paper of the data structure.

This is , so the submission with the shortest length in bytes wins.

| |

Posted: Find the Inverse Neighbor Pairs

| |

Recolour my Table (WIP)

I have an oak table. It's a very nice oak table. But recently, I've noticed that my table has been getting some sort of white patches on it:

Insert picture of my table here.

Now, I like my table, and I don't want my table getting all dirty. I'm asking y'all to fix this for me, so that my table will once again be clean.

The Challenge

Given a picture of the table in question, replace all pixels that are white with the correct table colour. I know I'll need to specify this area better, but I don't know how to. Suggestions are welcome.




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

| |
  • \$\begingroup\$ Maybe try limiting the table format. Is it top down or sideways? Also can we assume that the original table color (or slight variation to a certain HSL difference, maybe) is the majority of the image? \$\endgroup\$ – Roman Gräf Feb 6 at 19:50

floating-point error matters

Write a expression of floating-point numbers in any languages. When calculating the expression without floating-point errors (as what a human do), it should be 0. But with floating-point errors (as what happened in your language), it yield 1 instead.

  • Floating-point numbers are some numbers which store a finite number digits (binary or decimal or in any other bases) of fraction, plus an exponent in computer. It may be IEEE 754, but not must be.
  • Loss of precision due to integer types (which do not has a exponent) are not allowed in the expression. You are still allowed to include integers (or even other types) in your expression as long as operations such as rounding into an integer are not the root of errors.

Shortest codes win as code-golf.


  • Is there any duplicates here?
  • Is asking for an expression instead of full program allowed?
| |
  • \$\begingroup\$ Yes, you can allow expressions. Good fit for this one, imho. \$\endgroup\$ – Adám Feb 6 at 11:33

No title yet.

By Zekendorf's theorem every non-negative integer has a unique representation as the sum of Fibonacci numbers where no two numbers coincide or are adjacent.

In The minimum fibonacci challenge! the challenge was to output the list of Fibonacci numbers. However, you can instead consider the list of coefficients of the sum \$ \small x_0F(2) + x_1F(3) + x_2F(4) + \ldots \$ (since \$ \small F(0) = 0 \$ and \$ \small F(1) = F(2) \$ never appear in the Zekendorf representation) and represent that as a binary number \$ \ldots x_2 x_1 x_0 \$, e.g. \$ \small 67 = \small 1F(2) + 0F(3) + 1F(4) + 0F(5) + 1F(6) + 0F(7) + 0F(8) + 0F(9) + 1F(10) \$ which we can represent using the binary number \$ \small 100010101 \$ or \$ \small 277 \$ in decimal.

We can readily convert the binary representation back into the original integer by calculating the sum of the relevant Fibonacci numbers. However, I would like you to, given an input integer \$ \small n \$, output the decimal integer whose binary representation encodes the Zekendorf representation of \$ \small n \$ in this way.

This is , so the smallest function or program that breaks no standard loopholes wins!

| |
  • 1
    \$\begingroup\$ I would clarify that your binary representation is "flipped", i.e. 0-extends infinitely to the left. \$\endgroup\$ – Jonathan Frech Feb 8 at 18:32
  • \$\begingroup\$ @JonathanFrech flipped in comparison to what? \$\endgroup\$ – RGS Feb 10 at 20:18
  • \$\begingroup\$ @RGS I wrote the Fibonacci coefficients from left to right but the bits in the binary number from right to left and it wasn't so clear before. \$\endgroup\$ – Neil Feb 10 at 21:15
  • \$\begingroup\$ Oh ok, but that still matches what we don in binary. I can also write 11 = 1 + 2 + 8 and \$11 = 1011_2\$ :) but sure, going for perfect clarity is better than trusting other people's common sense \$\endgroup\$ – RGS Feb 10 at 21:54
  • 2
    \$\begingroup\$ @RGS Having to guess the specifications from a single example is not really common sense as it is annoying. \$\endgroup\$ – Jonathan Frech Feb 11 at 21:41

Calculate Mahjong points

Introduction to Mahjong tiles

Mahjong (麻雀) is a board game that originates from China. Mahjong tiles used in this challenge are in Unicode points U+1F000 – U+1F021:


They are categorized as:

  • Winds (風牌): 🀀(East Wind), 🀁(South Wind), 🀂(West Wind), 🀃(North Wind)

  • Dragons (三元牌): 🀄(Red Dragon), 🀅(Green Dragon), 🀆(White Dragon)

  • Ten Thousands (萬子): 🀇(One of the Ten Thousands) through 🀏(Nine of the Ten Thousands)

  • Bamboos (索子): 🀐(One of the Bamboos; note that it depicts a bird) through 🀘(Nine of the Bamboos)

  • Circles (筒子): 🀙(One of the Circles) through 🀡(Nine of the Circles)

  • Winds and Dragons are together called Honors (字牌).

  • Ten Thousands, Bamboos and Circles are each called a suit and together called Numbers (数牌). They have ranks from 1 to 9.

  • Among Numbers, the Ones and the Nines are called Terminals (老頭牌). The Twos through the Eights are called Simples (中張牌).

  • Honors and Terminals are together called Orphans (幺九牌).

Every Mahjong tiles have 4 copies of themselves.

Mahjong Hand

A legal Hand will be given as the input. It consists of:

  • A Head, which is 2 identical tiles.

  • 4 Bodies, each which is either:

    • A Sequence, which is 3 consecutive Numbers of the same suit.

    • A Triplet, which is 3 identical tiles.

Hence, a Hand consists of 14 tiles.

There are exceptions. See "Seven Heads" and "Thirteen Orphans" below.


The objective is to calculate how many points a Hand has. Points are gained by having Yakus (役), which are cumulative.

Also I apologize that I named these Yakus to be more intuitive for the code golf, making them differ from the 'usual' names. Sorry!

1 Point Yakus

  • Menzen Tsumo (門前清自摸和), which is worth 1 point, will always be assumed.

  • Pinfu (平和): Get a non-Dragon Head and 4 Sequences.

    • Example: 🀃🀃🀇🀈🀉🀑🀒🀓🀔🀕🀖🀟🀠🀡
  • One Pair (一盃口): Get 2 identical Bodies.

    • Example: 🀂🀂🀂🀇🀇🀇🀈🀉🀓🀓🀔🀔🀕🀕
  • Dragon Triplet (役牌): Get a Triplet of Dragons. Multiple Dragon Triplets are cumulative.

    • Example: 🀆🀆🀆🀇🀈🀉🀊🀊🀒🀓🀔🀛🀜🀝
  • All Simples (断幺九): Let the Hand consist only of Simples.

    • Example: 🀈🀉🀊🀓🀓🀓🀚🀛🀛🀜🀜🀝🀠🀠

2 Points Yakus

  • Seven Heads (七対子): Get 7 Heads. It cannot contain 2 identical Heads.

    • Example: 🀀🀀🀂🀂🀆🀆🀈🀈🀊🀊🀐🀐🀛🀛
  • Colorful Sequences (三色同順): Get a sequence for each suit, consisting of the same set of ranks.

    • Example: 🀀🀀🀁🀁🀁🀉🀊🀋🀒🀓🀔🀛🀜🀝
  • Full Sequence (一気通貫): Get 3 sequences of the same suit, consisting of ranks of 123, 456, and 789.

    • Example: 🀀🀀🀁🀁🀁🀇🀈🀉🀊🀋🀌🀍🀎🀏
  • Semi-Orphans (チャンタ): Let all Heads and Bodies have at least 1 Orphan.

    • Example: 🀀🀀🀁🀁🀁🀇🀈🀉🀐🀑🀒🀡🀡🀡
  • Concealed Three (三暗刻): Get 3 Triplets.

    • Example: 🀀🀀🀁🀁🀁🀊🀊🀊🀋🀋🀋🀑🀒🀓
  • Colorful Triplets (三色同刻): Get a Triplet for each suit, consisting of the same rank.

    • Example: 🀀🀀🀉🀊🀊🀊🀊🀋🀓🀓🀓🀜🀜🀜
  • Dragons Minor (小三元): Let the Head and 2 Bodies consist of Dragons. Cumulative with the 2 Dragon Triplets.

    • Example: 🀄🀄🀅🀅🀅🀆🀆🀆🀊🀋🀌🀒🀓🀔
  • All Orphans (混老頭): Let the Hand consist only of Orphans. Supersedes Semi-Orphans. Cumulative with Seven Heads.

    • Example: 🀁🀁🀂🀂🀃🀃🀆🀆🀇🀇🀏🀏🀘🀘
  • Three of a Kind (一色三順): Get 3 identical Bodies. Supersedes One Pair.

    • Example: 🀅🀅🀇🀇🀇🀈🀈🀈🀉🀉🀉🀙🀚🀛 (Note that this example also presents Semi-Orphans, which makes it supersede Concealed Three.)

3 Points Yakus

  • Two Pairs (兩盃口): Get 2 pairs of identical Bodies. Supersedes One Pair and Seven Heads.

    • Example: 🀃🀃🀇🀇🀈🀈🀉🀉🀑🀑🀒🀒🀓🀓
  • Semi-Terminals (純チャンタ): Let all Heads and Bodies have at least 1 Terminal. Supersedes Semi-Orphans.

    • Example: 🀇🀇🀇🀈🀉🀍🀎🀏🀏🀏🀏🀙🀙🀙
  • Semi-Flush (混一色): Let the Numbers consist of a single suit.

    • Example: 🀂🀂🀇🀈🀉🀉🀉🀉🀊🀋🀌🀌🀍🀎

6 Points Yaku

  • Flush (清一色): Let the Hand consist of a single suit of Numbers. Supersudes Semi-Flush.

    • Example: 🀇🀇🀇🀈🀉🀉🀉🀉🀊🀋🀌🀌🀍🀎


Yakumans (役満) worth 13 points, and supersede all Yakus above. Multiple Yakumans are cumulative.

Without Yakumans, the points are capped at 13.

  • Concealed Four (四暗刻): Get 4 Triplets.

    • Example: 🀀🀀🀉🀉🀉🀌🀌🀌🀒🀒🀒🀞🀞🀞
  • Thirteen Orphans (国士無双): Collect all 13 Orphans, plus an additional Orphan.

    • Example: 🀀🀁🀂🀃🀄🀅🀆🀇🀇🀏🀐🀘🀙🀡
  • Nine Gates (九蓮宝燈): Get Flush of ranks of 1112345678999, plus an additional Number of the same suit.

    • Example: 🀇🀇🀇🀈🀉🀊🀋🀋🀌🀍🀎🀏🀏🀏
  • All Greens (緑一色): Let the Hand consist only of Green Dragons and the Twos, Threes, Fours, Sixes, and Eights of the Bamboos.

    • Example: 🀅🀅🀅🀑🀑🀒🀒🀓🀓🀕🀕🀕🀗🀗
  • All Honors (字一色): Let the Hand consist only of Honors. Cumulative with Concealed Four.

    • Example: 🀀🀀🀀🀁🀁🀂🀂🀂🀅🀅🀅🀆🀆🀆
  • All Terminals (清老頭): Let the Hand consist only of Terminals. Cumulative with Concealed Four.

    • Example: 🀇🀇🀇🀏🀏🀏🀐🀐🀐🀘🀘🀙🀙🀙
  • Dragons Major (大三元): Get a Triplet for each of Dragons.

    • Example: 🀄🀄🀄🀅🀅🀅🀆🀆🀆🀇🀈🀉🀑🀑
  • Winds Minor (小四喜): Let the Head and 3 Bodies consist of Winds.

    • Example: 🀀🀀🀁🀁🀁🀂🀂🀂🀃🀃🀃🀖🀗🀘
  • Straight Flush (連七対): Get Seven Heads with Numbers with consecutive ranks of the same suit.

    • Example: 🀚🀚🀛🀛🀜🀜🀝🀝🀞🀞🀟🀟🀠🀠
  • Four of a Kind (一色四順): Get 4 identical Bodies.

    • Example: 🀃🀃🀓🀓🀓🀓🀔🀔🀔🀔🀕🀕🀕🀕
  • Winds Major (大四喜): Worths 2 Yakumans. Get a Triplet for each of Winds. Cumulative with Concealed Four.

    • Example: 🀀🀀🀀🀁🀁🀁🀂🀂🀂🀃🀃🀃🀖🀖
  • The Septentrions (大七星): Worths 2 Yakumans. Get a Head with each of Honors. Supersedes All Honors.

    • The only example: 🀀🀀🀁🀁🀂🀂🀃🀃🀄🀄🀅🀅🀆🀆

Other rules about Mahjong

When a Hand can be interpreted as different combinations of Heads and Bodies, the combination with the most points will be chosen. (See Three of a Kind and Two Pairs above)


🀅🀅🀋🀋🀌🀌🀍🀍🀑🀒🀓🀟🀠🀡 : Menzen Tsumo + One Pair = 2 points.

🀉🀊🀋🀌🀍🀎🀑🀒🀓🀔🀔🀞🀟🀠 : Menzen Tsumo + Pinfu + All Simples = 3 points.

🀀🀀🀀🀁🀁🀁🀂🀂🀂🀃🀃🀃🀆🀆 : Winds Major + Concealed Four + All Honors = 52 points. (Most points possible)

Rules about code golf

  • Input type and format doesn't matter, but it must consist of the Unicode characters above. In C++, valid examples include std::u8string (sorted or not) and std::multiset<u32char_t>.

  • Output type and format doesn't matter either.

  • Invalid Hands (not exactly 14 tiles, contains 5 copies of the same tile, etc) fall into don't care situation.

  • If and only if your language doesn't support Unicode, use the following table to parse Mahjong tiles:

| |
  • \$\begingroup\$ A related, more golfable challenge posted here: codegolf.stackexchange.com/q/199202/89459 \$\endgroup\$ – Dannyu NDos Feb 10 at 6:30
  • \$\begingroup\$ Maybe you need more testcase. At least one per yaku. \$\endgroup\$ – tsh Feb 10 at 14:40
  • \$\begingroup\$ Should output for 11112233778899m be 13 or 14? \$\endgroup\$ – tsh Feb 16 at 7:02
  • \$\begingroup\$ @tsh Since it has no Yakuman, its point is capped at 13. \$\endgroup\$ – Dannyu NDos Feb 16 at 7:06
  • \$\begingroup\$ Is Straight Flush (連七対) required to be All Simples (断幺九)? \$\endgroup\$ – tsh Feb 16 at 7:15
  • \$\begingroup\$ @tsh No. 小車輪, 大車輪, and their correspondent to other suits are all Straight Flush. \$\endgroup\$ – Dannyu NDos Feb 16 at 7:17

Be second to last

This is a challenge with a game with a clear winning strategy, but the winner is not the one who comes in first, but the one who comes in second to last! While losing is easy (just throw every game), just barely not losing is quite a task.

The Game

The bots will be made to play games of normal Nim against each other. The rules are as follows:

  • The board consists of a list of unsigned integers
  • In alternating turns, the players reduce one non-zero element by an amount of their choosing, as long as the element is not negative afterwards
  • The player who reduces the list to all entries being 0 wins

The length of the Nim list and its entries will be randomly determined for each game.

The Tournament

All bots will compete against each other in a Danish-Style tournament:

  • Initially, players are assigned positions in a list randomly
  • After each round, the list is sorted by the amount of wins with an order-preserving method
  • In each round, the players with the odd numbers play against those with the following even numbers (so 1st against 2nd, 3rd against 4th, and so forth)
  • If the number of players is odd, the one in the middle position has a bye and is given 1 win without playing.
  • The tournament ends after \$\lceil \log_{2}(N_{Players}) \rceil\$ (Binary logarithm of the number of players, rounded up) rounds.

The player in the second to last position of the list counts as the total winner of the tournament.

King of the Hill

Each time the contest is run, 100 tournaments are played. The bots with the highest number of being second to last is the overall winner.

Challenge Rules

  • Each bot is a Python 3 class implementing the following functions:
    • __init__(ID, n) passes the bot its randomly assigned ID for this tournament, and the total number of players.
    • nim(self,list) which takes in the Nim board state and returns a tuple (index, amount), specifying from which list index to subtract what number. This function is repeatedly called during each game of Nim played, until a winner has been determined.
    • rank(self,IDs,scores) which takes in the current order of ranking in the tournament, and the list of scores of each bot, ordered by ID. It returns nothing. This will be called for each bot after each round of tournament, as well as before the first round, to provide the ranking information if the bot requires it.
  • Bots are explicitly allowed to implement further functions and store data for private use. Bots will only be deleted and re-initialized after each full tournament.
  • Programming meta-effects are forbidden, meaning any attempts to directly access other bots' code, the Controller's code, causing Exceptions or similar. Any bot doing so is disqualified until fixed.
  • The following will also be set up to cause Exceptions:
    • nim returning an index of which the element is already 0
    • nim return an amount larger than the element at that index
  • Other languages are allowed only in case they can be easily converted to Python 3.
  • Class names have to be unique
  • Multiple bots per person are allowed, but only the latest version will be taken of iteratively updated bots.
  • As per Standard Loopholes, copies of bots are not allowed. This includes bots who differ from other bots only by a trivial change in strategy (e.g. a change in the pseudorandom seed).

Controller and Examples

Watch this space.

| |
  • \$\begingroup\$ this sounds fun! I have no idea how it fits this community, but I can't wait to see this in the main site! \$\endgroup\$ – RGS Feb 11 at 16:04
  • \$\begingroup\$ @RGS king-of-the-hill challenges are common -- not all challenges have to be code-golf. \$\endgroup\$ – S.S. Anne Feb 11 at 23:55
  • \$\begingroup\$ @S.S.Anne I know not everything has to be code golf, I'm just saying that in the little time I've been active, I've never seen a KotH challenge \$\endgroup\$ – RGS Feb 12 at 7:01
  • \$\begingroup\$ Me neither. This sounds great! \$\endgroup\$ – PkmnQ Mar 11 at 5:21

Find the most important character

The challenge is to write a program that outputs the most occurrent non-trivial* character in the input string, excluding these bracketing characters ()[]{}. A solution is scored by feeding the program's source into its input. Bracketing characters are allowed in the program, but may not be selected by the program as the most occurrent character. In cases where letters have the same percentile score, any of the characters can be returned, or all of them.

Write a program that has a maximal percentage of a single non-trivial* character, excluding these bracketing characters ()[]{}. Bracketing characters are allowed, but may not be selected as the highest-percentage character. Answer is scored as by running the program, with the program's source as its own input. In cases where letters have the same percentile score, any of the characters can be returned, or all of them.

*Non-trivial is defined in this case to be a character that contributes to the functionality of the program. If the character can be removed without influencing how the program runs, it is a trivial character.


Score is determined as follows:

$$(\frac{n_{char}}{n_{total}}) * 100\% $$

With nchar being the number of occurrences of that character in the input, and ntotal being the total number of non-trivial characters in the input. With this scoring criteria, all scores should be within the range (0,100]

Highest scoring solution per language wins.


Solutions should take in any valid string as input. Scoring is done using the program's source code as input(with all non-trivial charcters removed).


A single character with the highest percentage occurrence. Each solution should be capable of outputting standard ASCII, as well as the language's codepage (if applicable).


Creative solutions are encouraged. Boring solutions with long padded strings substituted in for numbers are discouraged. Standard loopholes are disallowed.









a or b or ab

| |
  • \$\begingroup\$ Since I don't see it mentioned, you may want to add we should aim for an as high as possible percentage as score. \$\endgroup\$ – Kevin Cruijssen Feb 12 at 8:25
  • \$\begingroup\$ And if I understand it correctly the input is the only possible input for the program? So it won't have to work for other inputs as well (outputting the 'most important' character of that input). \$\endgroup\$ – Kevin Cruijssen Feb 12 at 8:36
  • 1
    \$\begingroup\$ So something like '?? in 05AB1E (push "?" and output it, ignoring the input) would score 66.7%? \$\endgroup\$ – Kevin Cruijssen Feb 12 at 9:01
  • 1
    \$\begingroup\$ You are correct on aiming for the highest score. My intention was that the code should work on any inputs, however scoring is only done on the program source itself. \$\endgroup\$ – JPeroutek Feb 12 at 11:14
  • \$\begingroup\$ Ah ok, that indeed seems better. You may want to clarify that a bit, since at the Input section it now only mentions "The program's source code", hence my confusion. \$\endgroup\$ – Kevin Cruijssen Feb 12 at 11:44
  • \$\begingroup\$ You’re right, that bit is a tad vague. I will update when I get to work. \$\endgroup\$ – JPeroutek Feb 12 at 11:46
  • 1
    \$\begingroup\$ @KevinCruijssen I've edited the challenge to reflect these changes. Does this better reflect the challenge? \$\endgroup\$ – JPeroutek Feb 12 at 13:39
  • 1
    \$\begingroup\$ Yep, that's indeed a lot clearer! :) One more question: can the input potentially contain any unicode character, or is it limited to just printable ASCII and/or the language's used codepage? \$\endgroup\$ – Kevin Cruijssen Feb 12 at 13:41
  • \$\begingroup\$ Hmm, well if the character isn't on the languages codepage then it likely wouldnt be used in a solution right? I'd think that any character that the program can successfully output would be valid. \$\endgroup\$ – JPeroutek Feb 12 at 13:43
  • 1
    \$\begingroup\$ "I'd think that any character that the program can successfully output would be valid." This is different than having to support the entire codepage or extended ASCII, though. I.e. an answer in Unary/Lenguage using a single character and printing that single used character would score 100%, since the only possible input is any amount of that chosen character. And an answer in Whitespace would only have to support spaces, tabs, and newlines as potential input in that case. If that's your intention than it's fine by me, but it's different than allowing the entire codepage as input. :) \$\endgroup\$ – Kevin Cruijssen Feb 12 at 14:06
  • 1
    \$\begingroup\$ Ahh I see the distinction you are making. I'd say that the program should at least be able to printout standard ASCII, as well as the languages codepage. Does that sound reasonable? \$\endgroup\$ – JPeroutek Feb 12 at 14:10
  • \$\begingroup\$ Yep, that indeed sounds as a good solution. \$\endgroup\$ – Kevin Cruijssen Feb 12 at 14:27

Shift the digits

Here, x (supplied as input) and n (the result of your computation) are both positive integers. n * x = n shifted. Find n.

Here's an example of shifting:

123456789 -> 912345678
abcdefghi -> iabcdefgh (letters = any 0~9 digit)
123       -> 312


  • Preceding zeros count after shifting. If the number is 10 and is multiplied by 0.1 (0.1 isn't a valid input), the result is 1, which isn't equal to 01 (10 after shifting).
  • Your code has to run on Try It Online without timing out.
  • If your number only has one digit, the shifted result is your number:
1 -> 1
4 -> 4
9 -> 9

Test cases

Just to show that it's possible ...

9 -> 10112359550561797752808988764044943820224719
(In this test case, x = 9 and n = 10112359550561797752808988764044943820224719.
n shifted = n * x =              91011235955056179775280898876404494382022471)

Don't believe it? Try it online.

| |
  • \$\begingroup\$ Is this the point of the challenge: "you hardcode any number you want in your code, I give you a number as input, you multiply your number by mine and right shift it once"? \$\endgroup\$ – Lyxal Feb 16 at 7:29
  • \$\begingroup\$ @Lyxal The challenge should be self-explanatory. Can you understand it now? \$\endgroup\$ – user92069 Feb 16 at 10:01
  • \$\begingroup\$ Aha! So it's "x * n = x shifted, find n". I get it now! \$\endgroup\$ – Lyxal Feb 16 at 10:26
  • \$\begingroup\$ I feel there is something I'm missing. Are you going to give as input only numbers that have a multiple that corresponds to said shifting? \$\endgroup\$ – RGS Feb 16 at 18:06
  • \$\begingroup\$ I've been doing some thinking and I believe that asking to find the smallest possible integer is impossible for numbers which aren't all the same digit. Some test cases would be helpful. \$\endgroup\$ – Lyxal Feb 16 at 20:33
  • \$\begingroup\$ I've seen a really large integer (in a book) that shifts itself right once after being multiplied by 9. If that's really neccecary I'd try to type it here. \$\endgroup\$ – user92069 Feb 17 at 2:46
  • \$\begingroup\$ @Lyxal It's possible, see my test case. \$\endgroup\$ – user92069 Feb 17 at 3:40
  • \$\begingroup\$ @RGS I'm going to give any number that has a multiple; after division of that multiple by that number, the result will be the reverse of the shifting of the number. (I've changed my challenge since Lyxal "got" the formula.) \$\endgroup\$ – user92069 Feb 17 at 3:43

Posted here

| |

Approximate Alternating Triangles

| |
  • \$\begingroup\$ I think your added explanation is good, though I admit I still don't see how the resulting image is a triangle. It may just be me, but maybe it would be easier to see if provided a drawing? \$\endgroup\$ – FryAmTheEggman Mar 2 at 0:34
  • \$\begingroup\$ Ah, I see, but why \` (sorry comment markdown is messing that up, just the one backslash...) on the left and not |? You could also try naming it "approximate alternating triangles" or something. \$\endgroup\$ – FryAmTheEggman Mar 2 at 0:41
  • \$\begingroup\$ look less like a triangle Why do you want to make it look _less than a triangle? Why not | to make it look more like a triangle? \$\endgroup\$ – Luis Mendo Mar 4 at 11:45

Japanese Encoding Conversion

| |
  • \$\begingroup\$ I think switching between hex and decimal in the definitions is more likely to cause confusion than sticking to just one of them. I think you also don't indicate that the tuples you define are bytes that are concatenated to the final result. I'm not sure if I'm misunderstanding, but doesn't the clipping mean converting from shift JIS is ambiguous? Separately, you can use \left and \right to make your brackets the right height. \$\endgroup\$ – FryAmTheEggman Mar 1 at 18:40
  • \$\begingroup\$ @FryAmTheEggman For the Shift_JIS case, the range used is [0x81-0x9F,0xE0-0xEF] for the first byte and [0x40-0x7E, 0x80-0xFC] for the second byte, which is of size precisely 8,836. Since 区 won't exceed 128, and the starting points of 点 in both cases are separated by 95, the first case won't overlap with the second. \$\endgroup\$ – Shieru Asakoto Mar 2 at 3:24
  • \$\begingroup\$ @FryAmTheEggman I wrote kuten in decimal and bytes in hexadecimal because they were so defined; edited to only show in decimal, but keep accepting both decimal and hexadecimal input/output form. \$\endgroup\$ – Shieru Asakoto Mar 2 at 3:36
  • \$\begingroup\$ Ah yes, I see where I made an error now. I think the rewrite you did makes it easier to read. I don't see anything else, though of course I don't speak for everyone. Good luck! \$\endgroup\$ – FryAmTheEggman Mar 2 at 20:06
  • \$\begingroup\$ Typo: monas should be moras. \$\endgroup\$ – Grimmy Mar 6 at 14:24

| |
  • 1
    \$\begingroup\$ What happens if all integers are equally probable? Is that answer disqualified? Or does it score infinity? I also take it that there is a factor of randomness here, so perhaps you could mention that. \$\endgroup\$ – Lyxal Feb 14 at 6:21
  • 1
    \$\begingroup\$ Of course, I may have missed the mark completely. Are we required to create our own scale of randomness (i.e. our own deviation from uniform randomness if that makes sense)? \$\endgroup\$ – Lyxal Feb 14 at 6:22
  • 1
    \$\begingroup\$ If all integers are equally probably, wouldn't that give a score of effectively 0? (probability of 1/Integer.Max for the "most frequently occuring", which could be any of the integers)? \$\endgroup\$ – simonalexander2005 Feb 14 at 12:08
  • 3
    \$\begingroup\$ @Lyxal It is mathematically impossible for all integers to have equal probability. \$\endgroup\$ – Ad Hoc Garf Hunter Feb 14 at 14:07
  • 3
    \$\begingroup\$ This seems easy to score arbitrarily close to zero. For example, keep generating a random number from 1 to N until you get a 1, and count how many tries it takes before you succeed. To include negative outputs, pick a random sign. Make N large and the score tends to 0. \$\endgroup\$ – xnor Feb 14 at 14:45
  • \$\begingroup\$ @xnor There is a byte limit which stops "arbitrarily close" formulations. Did you miss this or am I missing what you are suggesting? \$\endgroup\$ – Ad Hoc Garf Hunter Feb 14 at 15:28
  • 4
    \$\begingroup\$ You're right, the byte limit stops you from actually getting arbitrarily close to 0. But, I expect there to be plenty of room in 100 bytes to stuff in some ginormous number bust-beaver style, at least in fairly compact languages. So, I think this challenge will mostly come down to "what's the biggest number you can express in 100-X bytes" where X is however many bytes the random part takes. \$\endgroup\$ – xnor Feb 14 at 15:33
  • \$\begingroup\$ My thought is that there are a number of possible things that you would be able to use as the random part each with different drawbacks and strengths. In my mind the challenge is sort of coming up with the random part that best fits the language. There is definitely going to be a big number component to this that is important, but since that has mostly been explored in other challenges I would expect borrowing there. \$\endgroup\$ – Ad Hoc Garf Hunter Feb 14 at 15:36
  • 1
    \$\begingroup\$ What do you think then about the challenge being just to generate a random integer so that each one has nonzero probability? I think that as is, the big number generation is so important to the score that it makes this a chameleon challenge. \$\endgroup\$ – xnor Feb 14 at 15:42
  • \$\begingroup\$ Alternatively, the "big number" N could be an input, and you stipulate that as N grows, the maximum chance of any integer to be chosen must approach zero. \$\endgroup\$ – xnor Feb 14 at 15:43
  • \$\begingroup\$ @xnor I think that I am pretty happy with the challenge as is. I prefer the current challenge over the suggested challenges since this one I feel has an incentive to loosen the distribution whereas I do not feel the others do. The big number generation is important, but I consider that as a more general technique. \$\endgroup\$ – Ad Hoc Garf Hunter Feb 14 at 15:48
  • \$\begingroup\$ Maybe I'm missing something about loosening the distribution. I'm envisioning solutions in a golfing language to be about 7 bytes of "take a number N and make a flat random distribution based on it" and 93 bytes of "generate a huge N". For regular languages with a random() function, maybe split it 25 bytes / 75 bytes. Maybe I'm missing something, but I can't really see a viable strategy that isn't effectively the N-input challenge I suggested but with big number generation code copy-pasted in for N. Do you think there is? \$\endgroup\$ – xnor Feb 14 at 15:59
  • \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$ – xnor Feb 14 at 16:07
  • 1
    \$\begingroup\$ I would allow for some entropy input to give pure languages a chance. \$\endgroup\$ – Jonathan Frech Feb 25 at 1:16
  • \$\begingroup\$ @JonathanFrech I would like to but it is a little difficult for entropy to make it work. If you have a concrete idea for how I might fairly introduce entropy, I am open to ideas. \$\endgroup\$ – Ad Hoc Garf Hunter Feb 25 at 1:35

Making Minimial Memory Masterpieces

In this challenge you will be asked to write a small computer program to paint an approximation of the painting Fine Wind, Clear Morning.

Your submission

In this challenge we are going to start with a blank canvas. We are going to add an "ant" in the top left corner. You will be telling the ant how to paint the picture by writing its brain.

An ant is a simple creature, at a given time it knows two things.

  • Some memories that it has

  • The color of the pixel it is currently standing on

And at every step the ant consults these two things it knows and then

  1. Draws one pixel of any color where it is standing

  2. Moves one pixel in a cardinal direction

  3. Replaces its all of its memory

The ant can thus be thought of as a function which takes a color and a value and spits out a color, a value and a cardinal direction.

For example here is the brain of an ant that draws a zigzag pattern in red

\$ f(c,m) = \left\{\begin{matrix}(\mathrm{Red}, & \mathrm{South}, & 1) & \mathrm{if} & m = 0\\ (\mathrm{Red}, & \mathrm{East}, & 0) & \mathrm{if} & m = 1\end{matrix}\right. \$

However our canvas is not infinite, so this ant would run into a border eventually. We will stop the ant if it tries to move off, by canceling its move and leaving it on the square it is on. You are free to use this behavior to your advantage.

The one issue here is that currently the ant will never stop, it will just keep painting forever. Which is why ants come with a builtin kill switch. When an ant's memories are equal to an exact value the ant explodes or something, ending the drawing.

Your submission will thus consist of 3 things

  • The starting memory for your ant

  • A description of the ant's function (more on this later)

  • The ending memory for your ant


The goal of this challenge is to have the ant that requires the least memory to operate. We will count this by the number of different states your ant's memory can have.

Thus to score your answer you should run it on the canvas provided. Once the ant has finished your score will be the total number of distinct memories used by your ant through the process. We will include the initial memory even if it does not appear again, but you should not count the ending memory (the one that kills the ant).

The lowest score will be the winner.

The painting

The painting will be a low resolution version of the one from the wikipedium. It will use 3 bit color resolution.

I will decide on the exact specific sizes and make the image in a bit.

A valid answer must produce this image exactly when run on the canvas.

Verification Tool

I will make a tool for running and verifying programs, using a standardized format. It will be runnable in browser.

| |
  • 1
    \$\begingroup\$ I assume based on the scoring the ant is invalid if it fails to paint exactly the required picture? \$\endgroup\$ – FryAmTheEggman Mar 9 at 20:37
  • \$\begingroup\$ @FryAmTheEggman Yes thank you. That also reminded me of another thing I forgot to say in the challenge. \$\endgroup\$ – Ad Hoc Garf Hunter Mar 9 at 20:47
45 46
48 49

You must log in to answer this question.

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