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 requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

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


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".


4670 Answers 4670

119 120
122 123

I see your BIDMAS and raise you a BADMIS


Given a set of numbers with operators between them: "5 + 4 * 9 / 3 - 8", return all the possible results of the expression for every permutation of the order of basic operations: [/, *, +, -].


  • Standard loopholes forbidden
  • I/O
    • Input must be ordered with infix operations, but however that is easiest (string or array)
    • Output must be all of the possible results of the expression, no specified format or order, no repeats
  • All of the inputs are valid (e.g. do not need to deal with "7 / 3 + *"
  • Operators are all left-associative so "20 / 4 / 2" = "(20 / 4) / 2"
  • This is Code Golf so fewest number of bytes wins

Test Cases (With explanation)

  • "2 + 3 * 4" = [14, 20]
    • 2 + (3 * 4) ⟶ 2 + (12) ⟶ 14
    • (2 + 3) * 4 ⟶ (5) * 4 ⟶ 20
  • "18 / 3 * 2 - 1" = [11, 6, 2, 6]
    • ((18 / 3) * 2) - 1 ⟶ ((6) * 2) - 1 ⟶ (12) - 1 ⟶ 11
    • ((18 / 3) * (2 - 1) ⟶ (6) * (1) ⟶ 6
    • (18 / (3 * 2)) - 1 ⟶ (18 / (6)) - 1 ⟶ (3) - 1 ⟶ 2
    • 18 / (3 * (2 - 1)) ⟶ 18 / (3 * (1)) ⟶ 6

Test Cases (Without explanation)

  • "45 / 8 + 19 / 45 * 3" = [5.765740740740741, 0.01234567901234568, 0.11111111111111113]
  • "2 + 6 * 7 * 2 + 6 / 4" = [154,113.5,88]
  • 1
    \$\begingroup\$ I'd recommend removing the bonus part, since people aren't going to do more than they have to, especially if it's code-golf (which I'm assuming this is, though you haven't specified it) \$\endgroup\$
    – Jo King Mod
    Sep 5, 2019 at 0:03
  • \$\begingroup\$ An I/O question: would providing 45 / 8 as 45.0 / 8.0 to the program be allowed? I suggest allowing it. This frees users working in languages which parse integers as integer types by default to work on the problem you ask, instead of an ancillary problem. \$\endgroup\$ Sep 8, 2019 at 6:22
  • \$\begingroup\$ @GammaFunction Yes that would be fine \$\endgroup\$
    – Freddie R
    Sep 8, 2019 at 22:02

The Rattlin' Bog

There's a relatively famous Irish Folk song called The Rattlin' Bog, a type of cumulative song.

Basically, this is a song that alternates between a chorus and an ever-expanding verse

The chorus is as follows:

Ho, ro, the rattlin' bog
The bog down in the valley-o
Ho, ro, the rattlin' bog
The bog down in the valley-o

Each verse starts with
And on that [x] there was a [y]
A rare [y], a rattlin' [y]

and ends with
In the bog down in the valley-o

Where x is the word from the previous round, and y is the word for the current round. In between these two is the cumulative part. It starts with:
The [z] in the bog

Each new round adds
The [y] in the [x] and
To its predecessor.


Given a list of strings, character arrays, or whatever reasonable equivalent collection of string or your language equivalent thereof, Your job is to print the lyrics to the song, alternating between the chorus and each verse, starting and ending with the chorus. The chorus and verse must be separated by a pair of newlines.

For the sake of brevity, you may write the chorus once, preceded by "[Chorus]" then write "[Chorus]" in place. I'm also omitting any sort of final verse with unique text.


Input: [House, Roof, Nest] 
Ho, ro, the rattlin' bog 
The bog down in the valley-o 
Ho, ro, the rattlin' bog 
The bog down in the valley-o  

And on that bog there was a House
A rare House, a rattlin' House
The House in the bog
In the bog down in the valley-o


And on that House there was a Roof
A rare Roof, a rattlin' Roof
The Roof in the House and the House in the bog
In the bog down in the valley-o


And on that Roof there was a Nest
A rare Nest, a rattlin' Nest
The Nest in the Roof and the Roof in the House and the House in the bog
In the bog down in the valley-o

  • \$\begingroup\$ I'm terrible at formatting, so if anyone wants to tell me the best formatting for this or edit and reformat it, that's fine. Of course, feedback is also appreciated to make this more readable or easier to understand. Also if/when I put it up on main golf, i'll add the standard disclaimers about abusing loopholes and least bytes wins, etc. \$\endgroup\$ Sep 5, 2019 at 16:27
  • 4
    \$\begingroup\$ I'm not sure that adding input is enough to make a difference between this and something like There was an Old Lady or There's a hole in the bottom of the sea... \$\endgroup\$ Sep 5, 2019 at 17:53

Sliding window minimum

The task is, given a number array of length n and a positive integer k, to compute the smallest values in all its overlapping consecutive subarrays of length k in the order they occur.

The complexity of your program should be no more than linear with respect to n with a constant added.


A positive integer array of length n and a positive integer k (k <= n)


A positive integer array with n - k + 1 elements, where the element at position i equals the least number in the subarray starting at i and ending at i + k - 1 inclusive.


[1, 3, 5, 7], 2 -> [1, 3, 5]
[1, 3, 5, 3, 5, 1], 3 -> [1, 3, 3, 1] 


Sandbox stuff

  • Is it acceptable to combine code-golf with restricted-complexity?
  • Is the complexity restriction clear enough?
  • Is it a good idea to allow calculating the maximum instead of the mininum?
  • Is the grammar correct enough?
  • Has this been posted before?
  • Do any languages have built-ins for this?
  • \$\begingroup\$ Close to a dupe. This one adds the minimum operation; you don't need to modify the programs in that question too much in order to post submissions for this challenge. \$\endgroup\$
    – user85052
    Sep 7, 2019 at 14:08
  • \$\begingroup\$ @A_ I'm perfectly certain it's not, that one doesn't have [restricted-complexity]. \$\endgroup\$ Sep 7, 2019 at 14:12
  • \$\begingroup\$ This functionality is needed in statistical analysis so I think many statistics / data analysis oriented languages or libraries would have a built-in for it. For example, this is the built-in in the R language. \$\endgroup\$
    – Joel
    Sep 7, 2019 at 15:24
  • \$\begingroup\$ Meanwhile, the complexity of the function depends also on k. So "linear with respect to n with a constant added" might not be accurate enough without mentioning k. It would be better to say sth. like "linear with respect to n for each fixed value of k". \$\endgroup\$
    – Joel
    Sep 7, 2019 at 15:28
  • \$\begingroup\$ @Joel Are you sure? I think I can compute it with a deque in O(n + k), and since k <= n that is linear with respect to n. \$\endgroup\$ Sep 7, 2019 at 15:31
  • \$\begingroup\$ A basic deque-based approach needs O(k) time to calculate or updating the minimum for each window in the worst case so the overall worse-case complexity would be O(n + k(n - k)) which is the same as O(n + kn). If you use a priority queue the complexity can be driven down to O(n+nlogk) or maybe O(n) only for some very advanced implementations. How do you implement that in O(n + k)? \$\endgroup\$
    – Joel
    Sep 7, 2019 at 15:53
  • \$\begingroup\$ @Joel reference O(n) implementation by me \$\endgroup\$ Sep 7, 2019 at 16:07
  • \$\begingroup\$ @someone OK. That algorithm is O(n). So you may emphasize in the description to say "The complexity of your program should be O(n), i.e. linear with respect to n for every possible k <= n", in case anyone wonders about whether an O(n + nlogk) implementation is accepted. \$\endgroup\$
    – Joel
    Sep 7, 2019 at 16:39
  • \$\begingroup\$ @Joel I'd argue O(n log k) is not really linear with respect to n (since that equals O(n log n)) \$\endgroup\$ Sep 8, 2019 at 6:04
  • \$\begingroup\$ @someone O(nlogk) is not linear with respect to n but it is also different from O(nlogn) because it really depends on the input k. If k has another constraint itself (e.g. an upper bound that is better than O(n)), O(nlogk) could be better than O(nlogn). That is why I suggested you clearly mention about the range of k in the complexity description to avoid any possible confusion, as I showed in my comment. \$\endgroup\$
    – Joel
    Sep 8, 2019 at 6:26

Random point on a sphere

Posted here

  • \$\begingroup\$ Must we use a specific distribution (e.g. uniform or normal) or is the "bias" acceptable? \$\endgroup\$ Aug 23, 2019 at 10:11
  • \$\begingroup\$ @EriktheOutgolfer My intention was to require a strictly uniform distribution. I do realize that it is unreasonable to verify this for each and every submission, so I have not made up my mind about that yet. Any suggestions? \$\endgroup\$
    – Jitse
    Aug 23, 2019 at 10:18
  • \$\begingroup\$ I'm in favor of just using the community default for randomness, that is, if every possible output (up to precision limits) has a non-zero probability of being returned, the submission is valid. \$\endgroup\$ Aug 23, 2019 at 10:24
  • \$\begingroup\$ @EriktheOutgolfer That sounds like a decent compromise. I'll update the challenge. \$\endgroup\$
    – Jitse
    Aug 23, 2019 at 10:43
  • \$\begingroup\$ Hm... another thing I noticed is that you have 6 tags, you can't have more than 5. \$\endgroup\$ Aug 23, 2019 at 11:13
  • \$\begingroup\$ @EriktheOutgolfer I was unaware of that. I'm removing number-theory, since it is the least fitting. \$\endgroup\$
    – Jitse
    Aug 23, 2019 at 11:20
  • \$\begingroup\$ Also, thanks for your feedback! \$\endgroup\$
    – Jitse
    Aug 23, 2019 at 11:20
  • 6
    \$\begingroup\$ Pick three uniform random numbers and normalise? I think it would be a more interesting question with the requirement that if the random number generation were substituted with true RNG from the reals then the distribution would be uniform. That opens up a variety of approaches. \$\endgroup\$ Aug 24, 2019 at 6:29
  • \$\begingroup\$ @PeterTaylor That was my original intention and I agree that it would definitely be more interesting. However, I thought it might be tricky to verify the uniformity of the distribution for each submission. Your reference could help with that, though. \$\endgroup\$
    – Jitse
    Aug 24, 2019 at 9:52
  • \$\begingroup\$ I seem to remember a similar challrnge about uniformly generating random numbers that add up to the input, but I can't find it. Not that this is a duplicate, just related \$\endgroup\$
    – Jo King Mod
    Aug 25, 2019 at 12:17
  • \$\begingroup\$ The challenge as it stands is impossible. Since there are more real numbers than finite binary strings you cannot represent real numbers in the output of a program. It is going to be impossible to create a program that has a chance of outputting all the real numbers on the surface of a sphere. You likely need to restrict the output domain in some way. \$\endgroup\$
    – Wheat Wizard Mod
    Aug 25, 2019 at 14:27
  • 1
    \$\begingroup\$ @JoKing perhaps this? \$\endgroup\$
    – Giuseppe
    Aug 27, 2019 at 14:14
  • 1
    \$\begingroup\$ @PeterTaylor Since your comment has received quite some upvotes, I have reverted the challenge back to requiring a uniform distribution. I included some examples of how to achieve this. Do you think it is clear enough like this? \$\endgroup\$
    – Jitse
    Aug 28, 2019 at 8:21
  • 1
    \$\begingroup\$ I think it's preferable to talk about being "theoretically uniform": to achieve actual uniformity "up to the precision limits of your language" would probably require using intermediate values of greater precision. Finding the right wording for questions which use floating point numbers is hard! \$\endgroup\$ Aug 28, 2019 at 8:30
  • 1
    \$\begingroup\$ In your second and third remarks, it would be good to point out that the random numbers in these invalid schemes are uniform. As shown in the fourth remark, both schemes are valid with specific non-uniform distributions. \$\endgroup\$
    – Nitrodon
    Aug 29, 2019 at 21:28

Consequence Golf

As specified by this xkcd, Consequence Golf is a game involving golfing and bombs. The most obvious consequence of bombs: damage to the course.

A Consequence Golf course consists of the union of several circular regions. The tee is located at (0, 0). On each turn, you hit the ball bomb in a direction at some power. The bomb will travel in that direction for a distance equal to the power of the shot, unless it hits the edge of the course, in which case it will explode immediately. When a bomb explodes, it adds to the course a new circle centered on the point of contact with a radius equal to the remaining power. The next shot starts at the last location of the bomb.


  • A list of circles, consisting of x/y coordinates and a radius for each circle, taken in any convenient format. If you must define a custom data type to store this information (e.g. struct c{float x,y,r};), you do not need to count that added boilerplate, nonproductive storage code in your byte count. Any code that does something besides specify storage must be counted.
  • A list of strokes, consisting of an angle in radians or degrees, and a power, again in any convenient format.


  • The location of the bomb after the final stroke.

Additional Rules

  • The course will always contain at least one circle
  • The course will always contain the tee at (0, 0)
  • If there are zero strokes, you must return (0, 0)
  • The power of a stroke will never be zero
  • "Any convenient format" means a list of lists, list of C structs, a list for each input (x, y, radius, power, angle), or similar. You may not take information that is not as it is specified. For example, you may not take the circles as a series of equations.
  • This is consequence code golf, so shortest code in bytes wins.

Test cases


Questions for META:

  • Is the description of how to play Consequence Golf clear enough?
  • Is the description of the input clear enough? This is my main concern.
  • Is allowing boilerplate storage code outside of the byte count an issue?
  • I am considering allowing fixed point approximations with at least 4 bits of precision for languages without floating point (and languages with, if it somehow makes things shorter). Would this cause any unintended issues?
  • \$\begingroup\$ The overview talks about the bomb hitting walls, but the input section doesn't include anything about the walls. \$\endgroup\$ Sep 9, 2019 at 8:27

Posted to PPCG

  • \$\begingroup\$ When I first posted this to PPCG, @PeterTaylor pointed out that although outputs to a file are allowed for King of the Hill challenges, it is preferable to use STDIN/STDOUT. But the fundamental problem is that programs need a standard venue, hidden from each other but not from the Arbiter, in order to Exchange. \$\endgroup\$
    – Purple P
    Sep 9, 2019 at 16:02
  • \$\begingroup\$ If you fail to challenge an assassination, how do you format losing two cards? \$\endgroup\$
    – Hiatsu
    Sep 9, 2019 at 16:07
  • \$\begingroup\$ @Hiatsu Assuming you mean "incorrectly challenge" or "get caught falsely blocking with a Contessa", you don't need to. You write the card you lost from the failed challenge, then the Arbiter detects that the move was an Assassination and you are eliminated. But your wording could be interpreted another way: I noticed in your answer to the original challenge that you always challenged or blocked Assassinations. You don't have to do that. You can surrender one of your cards right away. \$\endgroup\$
    – Purple P
    Sep 9, 2019 at 16:12
  • \$\begingroup\$ As long as each program has its own STDIN/STDOUT (using player=subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE); player.stdin.write("I\n"); response=player.stdout.read(1); or similar), you can copy across communication from the other player but restrict exchanges to the relevant player. \$\endgroup\$
    – Hiatsu
    Sep 9, 2019 at 16:16
  • \$\begingroup\$ Also, if you are willing to translate the Arbiter into Java, you can use this to arrange games. \$\endgroup\$
    – Hiatsu
    Sep 9, 2019 at 16:18
  • \$\begingroup\$ @Hiatsu Done! ...Well, kind of. I gave up and posted the original question. See my explanation in the comments here. \$\endgroup\$
    – Purple P
    Sep 10, 2019 at 0:09

Encode MC6000 instructions

In MC6000, these are registers list:

acc  general
dat  general
p0   simple pin
p1   simple pin
x0   XBus pin
x1   XBus pin
x2   XBus pin
x3   XBus pin
null pseudo

where general means reading from it returns the last value written to it, XBus pin means reading from or writing to it have side effect(so teq x0 x1 doesn't equal to teq x1 x0) that nothing else can take its place, simple pin means reading from it also writes zero to it(so mov 0 p0 equals to mov p0 null), writing anything to it(including the writing while reading) have side effect, and writing anything larger than 100 behaves same as writing 100, as well as writing anything smaller than 0 same as writing 0(so mov -4 p0 equals to mov 0 p0). Writing anything into null has no effect and reading from null returns 0(so mov 9 null equals to nop).

The instruction set is:

nop            Do nothing
mov R/I R      operand2:=operand1
jmp L          Jump to the specified line(can't be replaced)
slp R/I        Sleep for the number of time units specified by the operand.
slx XP         Sleep until XP avaliable(can't be replaced)
add R/I        acc:=f(acc+operand)
sub R/I        acc:=f(acc-operand)
mul R/I        acc:=f(acc*operand)
not            acc:=100(if acc was 0) or 0(otherwise)
dgt R/I        acc:=(acc/10^operand)mod 10(if operand in 0,1,2) or 0(otherwise)
dst R/I R/I    acc:=[abs(acc-[(acc/10^operand1)mod 10]*10^operand1)+abs(operand2 mod 10)*10^operand1]
               *sgn(operand2*2+1) (if operand1 in 0,1,2) or acc(otherwise)
teq R/I R/I    sym:='+'(if operand1 equals to operand2) or '-'(otherwise)
tgt R/I R/I    sym:='+'(if operand1 is larger than operand2) or '-'(otherwise)
tlt R/I R/I    sym:='+'(if operand1 is smaller than operand2) or '-'(otherwise)
tcp R/I R/I    sym:='+'(if operand1 is larger than operand2),
               '-'(if operand1 is smaller than operand2) or '*'(otherwise)
gen SP R/I R/I Output 100 and 0 to the simple pin for the latter two operands, inclusive

Here R/I means a register or an integer between -999 and 999, inclusive; R means a register, L means an integer between 0 and 13, XP means an XBus pin, and SP means a simple pin. f(x) is defined as min(999,max(-999,x)). Sleeping for zero or negative time units sleep for time as long as a nop(so nop=slp 0=slp -3).

Before an instruction, symbol +, - and @ can exist, meaning that the instruction is executed only if sym is +, - and @, inclusive. (@ doesn't work like this in fact but that doesn't affect this problem) Whether the instruction is executed matters even if it's a no operand(so + nop doesn't equal to - nop, but + nop equals to + tgt 1 0).After an instruction, comment start with # can exist, which can be ignored. Spaces work as separator, and can be added or removed as long as words are separated in the same way(continious spaces, spaces at both side).

Now, write a program A that, reads an instruction and output an integer; and write a program B that reads the output of program A and output an equal or same instruction fed into program A.

Your score will be the sum of length of program A, length of program B, and difference between the maximum and minimum of output of A. Lowest score in every language win.

Using MetaGolfScript is allowed. Only write MetaGolfScript in language area and show the exact version you use in code area to make it leaderboard friendly.

  • 1
    \$\begingroup\$ Why do you allow MetaGolfScript? Does it add anything to the challenge apart from a boring winner answer? \$\endgroup\$
    – wastl
    Sep 9, 2019 at 13:47
  • \$\begingroup\$ @wastl Pure (difference between the maximum and minimum of output of A) worth optimize \$\endgroup\$
    – l4m2
    Sep 10, 2019 at 4:39

Tiling string

(inspired by the tiling pattern effect tipic of the texturing of landscapes. This question I would like to ask is not exactly the same thing but close to it, or at least it was the idea)

Given a string S check if it has some repeating tile pattern and prove it providing at least one repeating pattern.

A substring tile pattern is a pattern of any form which repeats inside the string where one or more(alpha case insensitive) chars forms a fixed structure that can contain also others generic chars(all printable ascii table set)

the output will be false,0,f or any meaningful negative expression if no tiling occours. true,1,... plus at least one repeating tile pattern instead.

for example :

 they were obsessed by the sessions
             s#ss          s#ss
 outputs : true s#ss

look at that truck
      t$t  t$t
outputs: 1,t$t

- case insensitive. 
- only letters matters as tile pattern.   
- if two letters are separated by space or every non letter char they still form a pattern.  
- overlaps doesnt make tiling effect.
- a pattern must contain half or more structure chars and must be len>1 to be considered, and must be repeated at least two times.


"Hello world!"=> false or 0 or f or no

aaa=>false. "aaaa"=> true(aa)
"aabbabab"=>true:ab,ba or 1 ab ba. or yes[ba,ab] or...any reasonable format

This is code-golf so shortest answer wins

  • \$\begingroup\$ Can you give an example of a tile with non-structure characters? \$\endgroup\$
    – Hiatsu
    Sep 14, 2019 at 21:51
  • \$\begingroup\$ Hi!ho!bushy! => h#! Here h and ! Form a pattern of 2 fixed symbols and one ?symbol between. But it's not valid as ! is not an alpha character. The same applies to spaces or , or . for example.. \$\endgroup\$
    Sep 15, 2019 at 8:06

Observability and controllability


Note: if you like, you can skip this part, and simply implement the suggested algorithm.

When looking at dynamic systems, there exist the notions of observability and controllability. They are the answers to the questions

  • Observability: can we know all the internal states of a system by looking only at the given outputs?
  • Controllability: can we influence all the internal states of a system by changing only the inputs?

For the sake of this question, we will only look at LTI (linear time-invariant) systems, either in continuous or discrete time. During the rest of the question, I will only present the case of a state-space representation of the system and suggest using the observability- or controllability Gramian, but you may use any other algorithm to decide the controllability and observability of the given LTI system.


You are given an LTI system, $$ \mathbf{\dot{x}}(t) = A\mathbf{x}(t) + B\mathbf{u}(t)\\\mathbf{y}(t)=C\mathbf{x}(t)$$ where \$A\$, \$B\$ and \$C\$ are matrices containing only integers. The dimensions of these matrices are \$\dim{A}=n \times n\$, \$\dim{B} = n \times p \$ and \$\dim{C} = q \times n\$ with \$n\$, \$p\$ and \$q\$ positive integers.

A suggested input method would be to simply input these matrices, but you may also take input as function objects, string representations of differential equations, or transfer functions.


You must output two thruthy/falsy values, one indicating whether the system is controllable, and one indicating whether the system is observable. Order does not matter but must always be the same. Alternatively, you may have four distinct outputs (e.g., the integers 0, 1, 2, 3) each corresponding to a possible combination of controllability/observability.

Suggested algorithm

To decide on observability and controllability, you can calculate the so-called observability Gramian (a square matrix), $$\begin{bmatrix}C & CA & CA^2 & ... & CA^{(n-1)}\end{bmatrix}^T$$ and controllability Gramian $$\begin{bmatrix}B & AB & A^2B & ... & A^{(n-1)}B\end{bmatrix}$$ The system is observable iff the observability Gramian is invertible. The system is controllable iff the controllability Gramian is invertible. There are many ways to check if a matrix is invertible; an obvious way would be to check if the determinant equals zero.


Coming soon, because I want to include worked examples.

  • \$\begingroup\$ I'm not sure requiring tests for both is particularly meaningful, since an LTI system \$ (A, \cdot ,C) \$ is observable iff the LTI system \$ ( A^{T}, C^{T}, \cdot ) \$ is controllable. Otherwise I think this is fine (though for some reason I thought it had already been asked, but I didn't find a dupe). \$\endgroup\$ Sep 15, 2019 at 18:54
  • \$\begingroup\$ @FryAmEggman True but I think almost-repetition can make golfing challenges interesting because there's so many ways to do that. \$\endgroup\$
    – Sanchises
    Sep 15, 2019 at 20:10
  • \$\begingroup\$ @FryAmTheEggman Thanks for the edits, by the way. \$\endgroup\$
    – Sanchises
    Sep 15, 2019 at 20:11


  • \$\begingroup\$ So: If input ends with ? and has , return text from last , until before ? Else, if input ends with ? return No Else, return Yes. Right? \$\endgroup\$
    – Adám
    Sep 15, 2019 at 9:20
  • \$\begingroup\$ That's correct. \$\endgroup\$
    – user85052
    Sep 15, 2019 at 10:55
  • \$\begingroup\$ Then maybe just say so instead of over-complicating it? \$\endgroup\$
    – Adám
    Sep 15, 2019 at 11:36

Smallest put pixel function

Task: write in any language which can generate images e.g. JavaScript, the smallest "put pixel" function. You can initialise screen inside that function or in separate code. The put-pixel function should consume 6 arguments: x,y,r,g,b,a where x,y pixel coordinates and r,g,b,a are color values (a is for alpha - transparency - you need blend new color with old color). Provide also example which use that function a draw something.

  • 2
    \$\begingroup\$ I think the way this is worded will likely make it too broad or unclear. I think it would work better if you essentially required that this function be implemented to solve a more normal golf task that you could have test cases for. For example, "given vectors x,y,r,g,b,a produce an image where each pixel xi,yi has colour (ri,gi,bi,ai) and the rest are black". That would usually make submissions do as you say, but avoid ambiguities like "function" and "arguments" which may not exist precisely in languages people want to use. \$\endgroup\$ Sep 19, 2019 at 19:45

Shuffling Sequence

Consider an operation \$f_n\$ that takes a length-\$2n\$ list and performs a perfect shuffle on it, reversing the second half. For example, \$f_4 [abcdABCD] = [aDbCcBdA]\$.

Under composition, \$f_n\$ generates a cyclic group. That is, there exists some minimal positive integer \$m\$ such that \$(f_n)^m\$ (which means \$f_n\$ composed \$m\$ times with itself) is an identical map, leaving its argument alone. Here's an example for ya:

$$f_2 [abAB] = [aBbA]$$ $$f_2 [aBbA] = [aABb]$$ $$f_2 [aABb] = [abAB]$$

$$f_2(f_2(f_2 [abAB])) = (f_2)^3 [abAB] = [abAB]$$

Since \$(f_2)^3\$ is the identity, we say that \$f_2\$ has order 3.

Your task is to determine the order of \$f_n\$. You've got a few choices for how to do this:

  • Take as input \$n\$ and provide as output the order of \$f_n\$
  • Take as input \$n\$ and provide as output the order of each \$f_k\$ for \$k < n\$ or for \$k \le n\$ (your choice)
  • Output these orders indefinitely, beginning with that of \$f_0\$ or \$f_1\$ (your choice)

For reference, the first 77 terms (beginning from \$n = 1\$; you may optionally return \$1\$ for \$n = 0\$) are provided below. This is OEIS A294673.


Standard IO and loophole rules apply. This is , so the shortest program (in bytes) in each language wins! Happy golfing!

  • \$\begingroup\$ You may want to add a brief explanation that the exponentiation you use is on the group (i.e. repeated application of \$ f_{n} \$) and not the one most people are used to. I'd guess the average reader of this site doesn't know what a group is, but I may be being overcautious since it wouldn't really make much sense otherwise. Maybe run it by some people who don't know what groups are, if you can. \$\endgroup\$ Sep 19, 2019 at 18:48
  • \$\begingroup\$ @FryAmTheEggman How's that? \$\endgroup\$ Sep 19, 2019 at 18:55
  • \$\begingroup\$ I don't understand what you are asking, but maybe I rambled too much to be clear? Anyway, my point was that I think the challenge is good but it might come off as inaccessible to users with less maths background. I suggested asking other people (maybe someone you know or people in chat) about if the wording is confusing to them. \$\endgroup\$ Sep 19, 2019 at 19:15
  • \$\begingroup\$ @FryAmTheEggman My mistake. What I meant was "Updated. What do you think now?" Dang ambiguity. \$\endgroup\$ Sep 19, 2019 at 19:46
  • \$\begingroup\$ Haha, I didn't see the edit because I didn't scroll up, my bad. That definitely looks better, though I'm not exactly the target of my own comment. \$\endgroup\$ Sep 19, 2019 at 19:49

Golf Golf!

This is my first challenge, so please be gentle! The challenge is to write a program that will output the correct score for a layout in the card game "Golf."

The card game Golf has many variations. The house rules I use follow the standard rules for Six-Card Golf given by Pagat, with one slight difference.

Each player has a 2x3 layout of cards. By the end of each round all cards are turned face up and scored as follows:

  • Each ace counts 1 point.
  • Each two counts minus two points.
  • Each numeral card from 3 to 10 scores face value.
  • Each Jack or Queen scores 10 points.
  • Each King scores zero points.
  • A pair of equal cards in the same column scores zero points for the column (even if the equal cards are twos).
  • Three equal cards in the same row scores zero points for the row (even if the equal cards are twos).


The input can be a string or array of any kind.


An integer representing the score of the Golf hand.


These use the notation A23456789TJQK.







This is code golf, so the shortest answer in bytes wins!

  • \$\begingroup\$ I'd recommend allowing submissions to take the layout as a list of numbers with a reasonably convention. The point of this challenge appears to be in analysing the layout and applying the rules, not in performing string parsing. Otherwise this looks good to me. \$\endgroup\$ Sep 22, 2019 at 20:07

Reorder a matrix, twice

You are given a square \$n \times n\$ matrix \$A\$, and a list (or vector) \$u\$ of length \$n\$ containing the numbers \$1\$ through \$n\$ (or \$0\$ through \$n-1\$). Your task is to reorder the columns and rows of the matrix \$A\$ according to the order specified in \$u\$.

That is, you will construct a matrix \$B\$ where the \$(i,j)\$-th element is the \$(u(i),u(j))\$-th element of \$A\$. You should also output the inverse of this action; that is, the (i,j)-th element of \$A\$ will end up at position \$(u(i),u(j))\$ in a new matrix \$C\$.

For example, given $$A = \begin{bmatrix} 11 &12& 13 \\ 21& 22& 23 \\ 31& 32& 33 \end{bmatrix},\quad u=\begin{bmatrix}3 & 1 & 2\end{bmatrix}$$

the output should be $$B = \begin{bmatrix}33 & 31 & 32 \\ 13 & 11 & 12 \\ 23 & 21 & 22 \end{bmatrix},\quad C= \begin{bmatrix}22 & 23 & 21 \\32 & 33 & 31 \\ 12 & 13 & 11 \end{bmatrix}$$

You may take input and output through any of the default I/O methods. You do not have to specify which matrix is \$B\$ or \$C\$, as long as you output both. You may assume \$A\$ only contains positive integers. You must support matrices up to at least size \$64 \times 64\$.


===== Input =====
A =
 35     1     6    26    19    24
  3    32     7    21    23    25
 31     9     2    22    27    20
  8    28    33    17    10    15
 30     5    34    12    14    16
  4    36    29    13    18    11
  3 5 6 1 4 2

==== Output =====
B = 
  2    27    20    31    22     9
 34    14    16    30    12     5
 29    18    11     4    13    36
  6    19    24    35    26     1
 33    10    15     8    17    28
  7    23    25     3    21    32
C = 
 17    15     8    10    28    33
 13    11     4    18    36    29
 26    24    35    19     1     6
 12    16    30    14     5    34
 21    25     3    23    32     7
 22    20    31    27     9     2

No, you don't need deep learning: AlphaGo edition

To counter the industry fad of tackling the most trivial problems with deep learning, I propose that a proof of concept be created to demonstrate that simple database queries are in fact often sufficient. To wit, I propose to demonstrate that a database query can in fact be used to do what AlphaGo does and even do it better.

The proof of concept will consist of two parts:

  • A Script to create a script to create a (...) query that, given the state of a game of Go, will retrieve a move that will result in eventual victory.
  • A Script to create a script to create a (...) script to initialize the database.

This is a challenge so the least total bytes wins. Some rules for the challenge:

  1. You may use whatever database lets you golf best
  2. There is no limit for how many recursions of running the script generated by the script are required
    1. This includes directly submitting the query and (if the universe's hard drive capacity somehow permits) the init data
  3. The final init script may also be an executable-ish that connects to the database backend to populate it
  4. You may either pass the game state as an argument to the query or store the state in the database (storing the state in the DB doesn't count toward your score)
  5. Handicap games don't need to be accounted for.

The rules of Go are, paraphrased:

  • The game is played by placing black and white stones on a 19x19 grid
  • The aim of the game is to score points by surrounding open space with your stones (The edges of the board count as surrounding)
  • Black plays first
  • A stone is part of a group if it is orthogonally connected to a member of the group
  • The empty spaces orthogonally adjacent to a group are called liberties
  • A group without liberties is considered captured and is removed from the board and added to the capturing player's score
  • A group that can not escape capture is considered dead, and remains on the board but will count as captured for scoring purposes
  • Suiciding your own group by filling its last liberty is not allowed
  • Ko rule: If a single stone is captured so that capturing the capturing stone will return the board to the immediately previous state, such second capture is illegal on the turn after the first capture.
  • The game ends when both players pass, indicating that they can't improve their score by playing another stone.

  • 1
    \$\begingroup\$ As it stands there doesn't seem to be any requirements on making actually good moves. I'm not convinced you can fix that well without making this into a king-of-the-hill which will be a lot more work for you. Further, I suspect databases that make any actually good moves will need to be so large that you may struggle to see meaningful results. \$\endgroup\$ Sep 21, 2019 at 19:07
  • \$\begingroup\$ So it looks like you want us to write a solver for go that's optimal but likely extremely slow? I suspect this will come down to implementing the rules of Go then writing a simple recursive evaluation function, and that the Go rules will take most of the work. I'm confused where the database and scripts come in. \$\endgroup\$
    – xnor
    Sep 22, 2019 at 5:30
  • \$\begingroup\$ @xnor I thought this up when I read a rather ranty blog post (which I can't seem to find anymore) about how one doesn't need deep learning, with the sole supporting argument being that data retrieval can be done with database queries. \$\endgroup\$
    – HAEM
    Sep 22, 2019 at 8:55
  • \$\begingroup\$ @FryAmTheEggman This is a bit of a joke challenge (see above comment for details) \$\endgroup\$
    – HAEM
    Sep 22, 2019 at 8:55
  • \$\begingroup\$ Come to think of it, I could probably leave out generating the query and leave it at just the database initialization. \$\endgroup\$
    – HAEM
    Sep 22, 2019 at 8:59

Where am I?

Given an input folder structure (i.e. a tree data structure with named nodes), and a pointer to a directory (a specific node) within that tree structure, the program should output the full path to the directory the pointer is pointing at (in linux format, so /var/log for example), without ever inspecting the name of the current node or its ancestors; only its descendants.

The rules of the challenge are the equivalent of:

"you can cd and ls but not pwd" if this was being run on a live linux files system

but I feel I should expand on that a bit regarding how it works for a tree:

  • The method starts with the pointer, and it can ls to see what is contained within this directory (i.e. view the immediate child nodes in the tree structure, but not its own name)
  • the method can also cd dirname into any directory (i.e. move the pointer to any immediate child in the tree from the current node), and cd .. to go to a previous directory (i.e. move the pointer to the immediate previous child in the tree)
    • cd .. leaves you in the same directory (node), if there is no parent
    • cd invalidDirNameleaves you in the same directory (node), if there is no immediate child with that name
  • Any directory can contain any number of other directories, or none.
  • You are forbidden to do the equivalent of cd /


A tree-structure representing a file system and a pointer to a node in that tree

Assumptions 1. There are no duplicate folder names in the same parent folder (so ls can't return folder, folder; for example) - but there may be other folders with the same name elsewhere in the tree structure; in which case it doesn't matter which your program outputs (as it has no way of knowing which is correct) 2. ...Therefore, it may not be possible to determine which folder you started in - in which case a best-guess is fine (see examples 3, 4) 3. Symlinks and cyclical trees are not a part of this challenge - it will always be a simple parent-child tree structure - so you are always guaranteed to find the root by doing cd .. enough times.


The path that the pointer was pointing at, as a string or char array (or equivalent for your language).


scoring is used, so shortest bytes wins.

Example 1

input map: /var/ftp/in, /var/ftp/out/child, /var/etc/test/child/etc, /var/etc/test/c2/etc2, /var/etc/test/c3

input pointer points at: c2

sample working:

  1. ls -> "etc2"
  2. cd .., ls -> "child","c2", "c3" - three options, need to find which is correct
  3. cd child, ls -> "etc2" - this doesn't match 1, so go back
  4. cd .., cd c2, ls -> "etc2" - this is correct, so I know my path ends with "/c2"
  5. cd .., cd .., ls -> "test" - only one folder, so I know my path ends with "/test/c2"
  6. cd .., ls -> "ftp", "etc" - two options, need to find which is correct
  7. cd ftp, ls -> "in", "out" - incorrect, so go back
  8. cd .. -> there was only two options, so "etc" must be correct. my path ends with "/etc/test/c2"
  9. cd .., ls -> "var" - only one folder, so path ends with "/var/etc/test/c2"
  10. cd .., ls -> "var" - same option, so assume we're at root.
  11. Output "/var/etc/test/c2"

Example 2

input map: /app/data/dir/in

input pointer points at: /app/data

Output: "/app/data"

Example 3

input map: /var, /app, /test

input pointer points at: /app

Output: "/var", "/app" or "/test" are all valid outputs.

Note that there is no way for the program to differentiate between the three folders; and so any of the three are a valid answer for the purposes of this application.

Example 4

input map: /var/etc/test, /app/etc/two

input pointer points at: /app/etc

Output: "/app/etc"


  1. Does the spec make sense?
  • \$\begingroup\$ Nice idea for a challenge, but: I would remove the free cd and ls helpers for it only creates problems, you can (partially) solve the issue of using system built-ins by just allowing the directory-structure as input and not a directory-node (there will still be one or two solutions like eval mkdir -p $1;eval $2;pwd) but they are not really interesting and need to create the directories which is a penalty). I would also remove the explanations of examples 2-4, one suffices and more makes the post hard to read. \$\endgroup\$ Dec 13, 2018 at 22:24
  • \$\begingroup\$ Thanks for your comments! I think I'll remove the cd/ls stuff and the file system input, like you suggest. What would you recommend for the examples 2-4 then - just show the input and output? Or just show the working but not the text explanations? Should I include the result of "ls" each time also in that case? \$\endgroup\$ Dec 14, 2018 at 9:49
  • \$\begingroup\$ Just input and output should suffice imo. Maybe you want to exchange 1 and 2 such that there is the more thorough explanation of 2 and 1 just i/o. \$\endgroup\$ Dec 14, 2018 at 10:26
  • \$\begingroup\$ done :) Thanks for your input. How does it look now? \$\endgroup\$ Dec 14, 2018 at 13:16

Title: The Liquorice All-sort

I have just invented a new sorting algorithm, which I would like you to implement in the smallest number of bytes... The Liquorice All-sort

Given that the individual sweets are (or were) named: chips, rocks, Buttons[sic], nuggets, plugs, twists, spogs (https://en.wikipedia.org/wiki/Liquorice_allsorts), we can say that:

A bag (multiset) of Liquorice allsorts is comprised of 0..n of each item chip, rock, Button, nugget, plug, twist, spog, plus a bonus of 1..2 Bertie.

Given an input of an arbitrary array characters (A-z, 0-9, space), and a bag of Liquorice allsorts, sort as follows:

For each input character, from last to first:
    Is the bag empty?
           Yes: Exit the sort
    Else, Is the input equal to a letter (case-sensitive) that is contained in the name of one or more of the sweets in the bag?
       Yes: The number of items it matches is the number of positions it moves up the list (can't move past the top of the list).
            Take a bite out of each of the used sweets, by removing the letter we used. 
            Have we used all the letters in any item?
               Yes: Remove that item from the bag
    Else: move to the bottom of the list.


two inputs - the numbers to sort, and the list of sweet names. Both are guaranteed to be non-empty bags (sets that can contain duplicates; or an equivalent in your language), and the bags of sweets contains a minimum of one Bertie.


The sorted numbers


  1. {Bertie},{B} -> {B}
  2. {Bertie},{X,B} -> {B,X}
  3. {chip, rock, Button, nugget, plug, twist, spog, Bertie}, {A,B,C,k,e,r,w} -> {B,C,k,e,r,w,A} -> {B,C,k,e,r,w,A} -> {B,k,e,r,w,A,C} -> {k,B,e,r,w,A,C} -> {e,k,B,r,w,A,C} -> {e,r,k,B,w,A,C} -> {e,r,k,w,B,A,C}
  4. {Bertie, rock}, {r,o,c,k,r,o,c,e} -> {r,o,c,k,r,o,c,e} -> {o,r,c,k,r,o,c,e} -> {o,c,r,k,r,o,c,e} -> {o,c,k,r,r,o,c,e} -> (remove rock from the bag) -> {o,c,k,r,o,c,e,r} -> {o,c,k,r,c,e,r,o} -> {o,c,k,r,e,r,o,c} -> {o,c,k,e,r,r,o,c}

Sandbox Questions

I really like the idea of doing something with this (I like the wordplay of bag, etc.); but I don't know if the algorithm is just too arbitrary. Any thoughts or alternatives would be appreciated!

  • \$\begingroup\$ Absolutely not. (although you're encouraged to post your sandbox challenges when they're ready) \$\endgroup\$
    Apr 10, 2018 at 14:56
  • 1
    \$\begingroup\$ You only have 3 challenges in the Sandbox at the moment; some people have north of 30 - You don't have to worry. \$\endgroup\$ Apr 10, 2018 at 15:43

Title - Fix the note

Given a musical note letter (A to G), followed by any number of accidentals (either 0..n # or 0..n b, not a combination of both); output a representation of the same note with the least possible number of accidentals.

A # means "shift the note one semitone up", and a b means "shift the note one semitone down".

All valid output notes are as follows (in order, then loops):

A A#/Bb B C C#/Db D D#/Eb E F F#/Gb G G#/Ab

So a sharp would move to the right along that list (and loop); and a flat would move you to the left.


  • A -> A
  • B# -> C
  • Fb -> E
  • A##### -> D
  • Dbbb -> B
  • Gbbbbbbbbbbbb -> G
  • Bb -> Bb
  • F# -> F#
  • E## -> F#
  • E# -> F

You can assume that the length of the input won't overflow your language.

Where the input has sharps, the output can also only contain 0..1 sharps; and vice-versa for flats.

This is , so shortest bytes wins. Standard rules apply

  • \$\begingroup\$ These accidentals aren't even correct. There's no such thing as E sharp sharp. \$\endgroup\$
    – S.S. Anne
    Sep 25, 2019 at 20:42
  • \$\begingroup\$ Also, should E sharp be simplified to F? Is this bass, treble, or tenor? \$\endgroup\$
    – S.S. Anne
    Sep 25, 2019 at 20:43
  • 1
    \$\begingroup\$ @JL2210 sure there is - any note can be represented as accidentals of another note, in theory. I know that in practise you wouldn't do so. \$\endgroup\$ Sep 26, 2019 at 8:26
  • \$\begingroup\$ E# should be simplified to F, yes, because the aim is to reduce the number of accidentals where possible \$\endgroup\$ Sep 26, 2019 at 8:27
  • 1
    \$\begingroup\$ I'm not sure what you mean by "is this bass, treble or tenor?" - The instrument shouldn't matter for the purposes of this - this is purely theoretical (they're notes, not chords, if that helps) \$\endgroup\$ Sep 26, 2019 at 8:28

Title: Score my Tarok hand

Inspired by this challenge

In Slovenia (and elsewhere in central Europe), the card game Tarok is very popular. See here for a complete list of rules, but essentially it is a trick taking game, played in teams that change per round.

This challenge is a challenge, concerning the scoring of a hand, at the end of a round.

In a normal round, the game is played in partnerships. Any one player could decide the "contract" for the round, and that player (plus anyone on their team) either wins or loses the round, giving them a positive or negative score. They are known as the "Declaring team". The "Opposing team" cannot score in that round.

The input for this challenge will therefore be the Declaring team's cards, plus the contract type they bid for.

The cards

In a game of Tarok, there are 54 cards; as follows (shown as highest to lowest in each suit - names in brackets after a card are local names given to certain cards):

  • Spades, Clubs: King, Queen, Knight, Jack, 10, 9, 8, 7
  • Diamonds, Hearts: King, Queen, Knight, Jack 1, 2, 3, 4
  • Taroks: Joker (škis), XXI (mond), XX, XIX, ... III, II, I (pagat)

The point value of the cards are as follows:

  • kings, škis, XXI and I - 5 points each
  • queens - 4 points each
  • knights - 3 points each
  • jacks - 2 points each
  • all other cards - 1 points each

Scoring a hand

This is what I believe makes this challenge interesting.

  • For each set of three cards in your hand, add up their values and subtract 2.
  • If you end up with one or two cards left over after making the sets of three, add up their values and subtract 1.
    • So, a pair or a set of three one-point cards are both worth 1 point; but a single one-point card is worth nothing.

The total value of the pack comes to 70 card points.

In most contracts (see below), the declarer's side wins if at the end of the play they have at least 36 of the available 70 points; otherwise they lose. Because of this, the members of each team pool their cards for scoring; and so if you know the score of one team, you can calculate the score of the other.

Once the hand value has been calculated, the difference from 35 is taken (i.e. handValue - 35), and this difference is rounded to the nearest 5 points.

Contracts and Bonuses

Once the hand score is known for the declaring team, the final score is calculated based on the "contract" that was chosen at the start of the round (where "difference" is the rounded hand difference from 35, calculated above. Note this may be negative, if the opposing team got more points):

Contract Name          | Scoring (+ if contract won, - if lost)
Three                  | difference +/- 10
Two                    | difference +/- 20
One                    | difference +/- 30
Solo Three             | difference +/- 40
Solo Two               | difference +/- 50
Solo One               | difference +/- 60
Beggar*                | 70 (fixed)
Solo without           | 80 (fixed)
Open Beggar*           | 90 (fixed)
Colour Valat Without** | 125 (fixed), no bonuses
Valat Without**        | 500 (fixed), no bonuses

With the exception of those marked, all contracts are "won" if the difference is 36 or higher; otherwise it was "lost".

* - to win the points, you must win no tricks (and therefore no cards)

** - to win the points, you must win ALL the tricks (and therefore all the cards). In this case, no other scoring bonuses are applied.

Bonus points are awarded to the declaring team, or subtracted from the declaring team if the opposing team complete the criteria. Bonuses are only awarded on contracts where the difference is taken into account. (i.e. from "Three" to "Solo One" only, in the above table)

Bonus Criteria                                | Bonus Points
Take škis, XXI and I ("the Trule") in tricks  | 10
Take all 4 kings in tricks                    | 10
Take all the tricks ("Valat")                 | 500, no other scoring is applied

(note that in Tarok, there are some actions that take place during play which give additional bonuses, such as announcing at the start of the game your intention to get a certain bonus; but as those would require more inputs to calculate, I will leave these out of this challenge.)

Some Examples

All 54 cards, any contract -> +500 points

No Cards, called Beggar -> + 70 points

king, king, king, king, škis, XXI, I, queen, queen, queen, queen, knight, knight, knight, knight, jack, jack, 1H, 2H; called "One" -> 30 points for contract + 20 points difference (hand score is 56 which is 21 different from 35, so round to 20) + 10 points kings bonus + 10 points Trule Bonus = 70 points

No cards, called "Solo One" -> -500 (opposing team got Valat bonus)

KS,8S,7S, called "Two" ->failed contract, so -30 (difference), -20 (contract), -10 (opponents got Trule bonus) = -60 points

KH, KD, škis, I, queen, queen, queen, queen, knight, knight, knight, knight, jack, jack, 1H, 2H, 7C,1D,2D,4D; called "Solo Without" = +80 points

KH, KD, škis, I, queen, queen, queen, queen, knight, knight, knight, knight, jack, jack, 1H, X, III,II,2D,KS; called "Three" = +15 difference (49-35, rounded) + 10 contract = +25


Spreadsheet Columns

In most spreadsheet programs, columns go A, B, C, ... X, Y, Z. After this comes AA, AB, AC ... AX, AY, AZ, BA and so on.

Your task is to convert one of these strings in to a column number. You must support inputs up to the maximum length of your language, to a minimum of 3.

Test Cases:

A   => 1
B   => 2
Z   => 26
AA  => 27
AC  => 29
AZ  => 52
BA  => 53
FC  => 159
ID  => 238
AAA => 703

Standard loopholes are forbidden.


  1. Are my test cases correct? They were done of the top of my head, so they may not be accurate.
  2. Is this a duplicate? My searching suggests otherwise, but it may not be comprehensive.
  3. Are there any other tags I could add?
  • \$\begingroup\$ As far as I can tell, your test cases are correct. I would specify how long the input can be (e.g. max of two characters) and provide some slightly larger test cases. Also, maybe the arithmetic/math tag? \$\endgroup\$ Sep 29, 2019 at 13:40
  • \$\begingroup\$ @cairdcoinheringaahing Edited. \$\endgroup\$
    – gadzooks02
    Sep 29, 2019 at 13:56
  • \$\begingroup\$ I feel as though this may be a dupe of one of the various base-conversion questions. Do you expect there is a better way to solve this than converting the letters to numbers and then interpreting them as a base 26 number? (Even if that is the best approach it won't necessarily mean it is a duplicate, I haven't checked through them yet, but I wanted to make sure you had considered it) \$\endgroup\$ Sep 29, 2019 at 17:39
  • \$\begingroup\$ @FryAmTheEggman I had considered it. In fact, I was going to make some test cases that way, but I realised that a) I would have to convert by subtracting 10 and b) that conversion would most likely be too costly. I mean, how would you actually do that? Interpret as base 36, subtract ten, convert to string, interpret as base 26, convert to base 10? Doesn't seem feasible. \$\endgroup\$
    – gadzooks02
    Sep 29, 2019 at 18:03
  • \$\begingroup\$ I didn't mean using builtins for base conversion, though they may be problematic too, but just literally doing base conversion. \$\endgroup\$ Sep 29, 2019 at 18:27
  • \$\begingroup\$ @FryAmTheEggman Congratulations, you have the first answer! While good, I'm certain 63 bytes can be improved, and would be about standard for a Python answer. \$\endgroup\$
    – gadzooks02
    Sep 29, 2019 at 18:38
  • \$\begingroup\$ Sorry, I think I haven't explained myself well. I was trying to show that base conversion questions might be a duplicate target for this one since this challenge can be solved directly with a base conversion after a very minor transformation. I haven't actually found a question that seems like a good enough target yet, but I wanted you to be aware of it (and perhaps look yourself :) ). \$\endgroup\$ Sep 29, 2019 at 19:18
  • \$\begingroup\$ I think I found a duplicate, though it has some annoying extra bits of copying over the row number. \$\endgroup\$
    – xnor
    Sep 29, 2019 at 23:05
  • 2
    \$\begingroup\$ Duplicate \$\endgroup\$
    – Jo King Mod
    Sep 30, 2019 at 1:57

DayByte Savings

Input: Any positive integer 1..n; or a year in the future (e.g. 2025)

Output: The date-times (UTC) that Britain will change to/from daylight savings times (i.e. 1am on the last Sunday in March and 2am on the last Sunday in October) between now (according to the machine running the code) and the current date in the year specified in the input. We can assume this rule won't change in the future.

Any valid list of date-time formats is fine for the output (e.g. "28th October 2018 2am" or "28-OCT-18T02:00:00" or "1540692000" [epoch time])

inspired by https://stackoverflow.com/questions/50839863/future-list-of-daylight-savings-changeover-date-times-uk

You could store all the data in your program (it counts towards your byte count), or just call a builtin that calculates it - your choice.

You can assume that 2099 (however far ahead that is) is the largest input.

, usual rules and exclusions apply. You won't have to deal with invalid inputs.

Example (assuming today is 23rd September 2019):

2020 or 1 -> 27th Oct 2019 2am; 29th Mar 2020 1am

2099 or 80 -> 27 October 2019 02:00:00
      29 March 2020 01:00:00
      25 October 2020 02:00:00
      28 March 2021 01:00:00
      31 October 2021 02:00:00
      27 March 2022 01:00:00
      30 October 2022 02:00:00
      26 March 2023 01:00:00
      29 October 2023 02:00:00
      31 March 2024 01:00:00
      27 October 2024 02:00:00
      30 March 2025 01:00:00
      26 October 2025 02:00:00
      29 March 2026 01:00:00
      25 October 2026 02:00:00
      28 March 2027 01:00:00
      31 October 2027 02:00:00
      26 March 2028 01:00:00
      29 October 2028 02:00:00
      25 March 2029 01:00:00
      28 October 2029 02:00:00
      31 March 2030 01:00:00
      27 October 2030 02:00:00
      30 March 2031 01:00:00
      26 October 2031 02:00:00
      28 March 2032 01:00:00
      31 October 2032 02:00:00
      27 March 2033 01:00:00
      30 October 2033 02:00:00
      26 March 2034 01:00:00
      29 October 2034 02:00:00
      25 March 2035 01:00:00
      28 October 2035 02:00:00
      30 March 2036 01:00:00
      26 October 2036 02:00:00
      29 March 2037 01:00:00
      25 October 2037 02:00:00
      28 March 2038 01:00:00
      31 October 2038 02:00:00
      27 March 2039 01:00:00
      30 October 2039 02:00:00
      25 March 2040 01:00:00
      28 October 2040 02:00:00
      31 March 2041 01:00:00
      27 October 2041 02:00:00
      30 March 2042 01:00:00
      26 October 2042 02:00:00
      29 March 2043 01:00:00
      25 October 2043 02:00:00
      27 March 2044 01:00:00
      30 October 2044 02:00:00
      26 March 2045 01:00:00
      29 October 2045 02:00:00
      25 March 2046 01:00:00
      28 October 2046 02:00:00
      31 March 2047 01:00:00
      27 October 2047 02:00:00
      29 March 2048 01:00:00
      25 October 2048 02:00:00
      28 March 2049 01:00:00
      31 October 2049 02:00:00
      27 March 2050 01:00:00
      30 October 2050 02:00:00
      26 March 2051 01:00:00
      29 October 2051 02:00:00
      31 March 2052 01:00:00
      27 October 2052 02:00:00
      30 March 2053 01:00:00
      26 October 2053 02:00:00
      29 March 2054 01:00:00
      25 October 2054 02:00:00
      28 March 2055 01:00:00
      31 October 2055 02:00:00
      26 March 2056 01:00:00
      29 October 2056 02:00:00
      25 March 2057 01:00:00
      28 October 2057 02:00:00
      31 March 2058 01:00:00
      27 October 2058 02:00:00
      30 March 2059 01:00:00
      26 October 2059 02:00:00
      28 March 2060 01:00:00
      31 October 2060 02:00:00
      27 March 2061 01:00:00
      30 October 2061 02:00:00
      26 March 2062 01:00:00
      29 October 2062 02:00:00
      25 March 2063 01:00:00
      28 October 2063 02:00:00
      30 March 2064 01:00:00
      26 October 2064 02:00:00
      29 March 2065 01:00:00
      25 October 2065 02:00:00
      28 March 2066 01:00:00
      31 October 2066 02:00:00
      27 March 2067 01:00:00
      30 October 2067 02:00:00
      25 March 2068 01:00:00
      28 October 2068 02:00:00
      31 March 2069 01:00:00
      27 October 2069 02:00:00
      30 March 2070 01:00:00
      26 October 2070 02:00:00
      29 March 2071 01:00:00
      25 October 2071 02:00:00
      27 March 2072 01:00:00
      30 October 2072 02:00:00
      26 March 2073 01:00:00
      29 October 2073 02:00:00
      25 March 2074 01:00:00
      28 October 2074 02:00:00
      31 March 2075 01:00:00
      27 October 2075 02:00:00
      29 March 2076 01:00:00
      25 October 2076 02:00:00
      28 March 2077 01:00:00
      31 October 2077 02:00:00
      27 March 2078 01:00:00
      30 October 2078 02:00:00
      26 March 2079 01:00:00
      29 October 2079 02:00:00
      31 March 2080 01:00:00
      27 October 2080 02:00:00
      30 March 2081 01:00:00
      26 October 2081 02:00:00
      29 March 2082 01:00:00
      25 October 2082 02:00:00
      28 March 2083 01:00:00
      31 October 2083 02:00:00
      26 March 2084 01:00:00
      29 October 2084 02:00:00
      25 March 2085 01:00:00
      28 October 2085 02:00:00
      31 March 2086 01:00:00
      27 October 2086 02:00:00
      30 March 2087 01:00:00
      26 October 2087 02:00:00
      28 March 2088 01:00:00
      31 October 2088 02:00:00
      27 March 2089 01:00:00
      30 October 2089 02:00:00
      26 March 2090 01:00:00
      29 October 2090 02:00:00
      25 March 2091 01:00:00
      28 October 2091 02:00:00
      30 March 2092 01:00:00
      26 October 2092 02:00:00
      29 March 2093 01:00:00
      25 October 2093 02:00:00
      28 March 2094 01:00:00
      31 October 2094 02:00:00
      27 March 2095 01:00:00
      30 October 2095 02:00:00
      25 March 2096 01:00:00
      28 October 2096 02:00:00
      31 March 2097 01:00:00
      27 October 2097 02:00:00
      30 March 2098 01:00:00
      26 October 2098 02:00:00
      29 March 2099 01:00:00
  • \$\begingroup\$ p.s. how do people add formatted tags to answers? \$\endgroup\$ Jun 13, 2018 at 15:17
  • 1
    \$\begingroup\$ [tag:<name>], e.g. [tag:code-golf] (in comments, it looks like code-golf) \$\endgroup\$
    – wastl
    Jun 13, 2018 at 17:56
  • \$\begingroup\$ You can click at the "edited..." link and click "source" to view markdown source. \$\endgroup\$
    Jun 14, 2018 at 11:29
  • \$\begingroup\$ Should the output be accurate to the date the challenge is posted, the date a solution is posted or the date that solution is run? Or, to put it another way, if I post a solution now it should, obviously, include 27/10/19 in the output but, if that solution is run after that date, should it still be included? \$\endgroup\$
    – Shaggy
    Sep 27, 2019 at 22:25
  • \$\begingroup\$ My thinking is, the date the challenge is run (i.e. whatever date is set on the machine the code is run on) \$\endgroup\$ Sep 30, 2019 at 8:01
  • \$\begingroup\$ Would this challenge be better if it was just "print the next time after "today" on your local system"? or "print the next time after the input date"? \$\endgroup\$ Oct 4, 2019 at 14:50

Golf a new OEIS sequence.

This is a challenge. The goal of this challenge is to create an integer sequence that is not in the OEIS using the fewest possible number of bytes.

Your program can either output an infinite list, or it can be a function from the natural numbers to the integers, which when evaluated on 1, 2, 3, 4,... gives a sequence that is not in the OEIS.


Without any restrictions, this is a very easy challenge, we can simply write a program that prints out the constant sequence consisting of 33, for example.

In order to avoid accepting "easy" sequences like this, your proposed sequence cannot be a finite linear combination or entrywise product of existing sequences or any rows or columns of existing tables in the OEIS.1

Also, I want to avoid submissions that take an otherwise disallowed sequence and prepend some list (e.g. 3,1,1,1,1,1,1,1,1,1,1). Thus the above rule must stand even after ignoring the first N terms of the sequence.2


Post your source code, the first few terms of the sequence, and an explanation of what your source code is doing.

It's okay if your submission is not very mathematically interesting, but I'm hoping that one or two will be.

(Lastly, if your sequence is disqualified by someone writing is as linear combinations of existing sequences, feel free to modify/fix it, but please don't delete it.)

1 This rule disallows all polynomials in n, for example, since these can be written as finite linear combinations of columns in A009999 read as a square array.

2 This rule also disallows all finite-length sequences.


Note: I don't know if this challenge is totally silly, or if it has obvious loopholes, or if closing loopholes results in a challenge that is too difficult or arbitrary.

  • Tags: ,
  • Is this a duplicate?
  • Any other restrictions? Any loosening of current restrictions?
  • 3
    \$\begingroup\$ I like the idea, but checking if an answer is valid seems really hard. For example, take n mod 13. It's not in OEIS (single-digit moduli are). But, there may well be 13 period-13 sequences in OEIS that are linearly independent, which would disqualify it. Maybe this could be a cops-and-robber style challenge where robbers try to invalidate answers, but the robber's task doesn't seem than fun. \$\endgroup\$
    – xnor
    Oct 5, 2019 at 18:31
  • 2
    \$\begingroup\$ What's to stop people from using the output of a seeded PRNG? It would be trivial to find a sequence from a seeded PRNG that doesn't exist on OEIS. The restriction of no linear combinations or entrywise products makes it more difficult to validate, but it is almost certainly still possible. \$\endgroup\$
    – user45941
    Oct 5, 2019 at 18:38
  • 1
    \$\begingroup\$ @Mego, exactly the sort of feedback I was hoping for. I don't know how to elegantly work around that sort of answer—especially since a PRNG from a library wouldn't be in the spirit of the question, but a PRNG written by the user would be a great answer. I think I'll avoid submitting this question. \$\endgroup\$ Oct 5, 2019 at 18:59
  • 1
    \$\begingroup\$ In addition to what has been said, ideas like linear combinations etc. start to break down when the sequences end. All (or at least most) OEIS sequences only have a finite number of terms present, some only even have a finite number of terms that can be calculated with modern computing power. So how do we deal with the finiteness of the sequences? \$\endgroup\$
    – Wheat Wizard Mod
    Oct 7, 2019 at 4:12
  • 1
    \$\begingroup\$ I don't know whether the issues raised in earlier comments can be fixed, but if they can then there's another which can and should be: OEIS isn't static. If someone comes up with an interesting answer, it may well be submitted to OEIS. There are various ways to solve this problem: the easiest to verify would be to say that OEIS sequences beyond Axxxxxx can be ignored, where the sequence chosen is e.g. the highest numbered one with no assigned but unpublished gaps below it. \$\endgroup\$ Oct 7, 2019 at 10:54

Draw a CE mark

Your input is the scaling factor n. You must output an image of width 82n and height 48n (if you are generating a vector image, it should have that as its default size). The image will be either transparent or white, with the following regions in black:

  • The segment of a ring centred at 24n,24n of outer radius 20n and inner radius 14n that is left of the vertical line at 26n.
  • A copy of that segment displaced 34n to the right. The original rings would therefore exactly overlap if they were not segments.
  • A rectangle with upper left corner at 44n,21n and lower right corner at 56n,27n.

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



  • 1
    \$\begingroup\$ It's better to specify exactly what constitutes a valid output, rather than just saying "you can make up your own." That way we know what golfing tricks are permitted and what aren't. \$\endgroup\$ Jun 11, 2019 at 4:49
  • \$\begingroup\$ @EsolangingFruit Okay. Since it is code-golf, not popularity contest, that would be better. I'll fix that. \$\endgroup\$
    – LegenDUST
    Jun 11, 2019 at 8:06
  • 2
    \$\begingroup\$ Bonuses/penalties in code-golf is not okay \$\endgroup\$
    – MilkyWay90
    Jun 11, 2019 at 14:59
  • \$\begingroup\$ @MilkyWay90 Thank you for your advise. \$\endgroup\$
    – LegenDUST
    Jun 12, 2019 at 10:18
  • \$\begingroup\$ Can this be more self-contained? It seems that the majority of the question is hidden behind links to other sites. \$\endgroup\$ Jun 12, 2019 at 10:52
  • \$\begingroup\$ @PeterTaylor I wanted to, but if I contain Korean character ascii arts in article, it gets so long. So I separated it. I though too long question is not good. If long question is okay, then I'll change it. \$\endgroup\$
    – LegenDUST
    Jun 12, 2019 at 11:09
  • \$\begingroup\$ @LegenDUST You could put all input-output in the same code-block, then a scrollbar is added automatically and the challenge is still self-contained. Then again, in the link you provided I only see ASCII arts for single or combinations of 2 Korean characters, whereas the examples have 3 Korean characters combined, so if all triplet-Korean characters are added as ASCII art it's quite a big list to scroll through.. \$\endgroup\$ Jun 12, 2019 at 12:17
  • \$\begingroup\$ @KevinCruijssen Thanks for tip! \$\endgroup\$
    – LegenDUST
    Jun 12, 2019 at 12:19
  • \$\begingroup\$ Seconding the recommendation against bonuses, I would make proper indentation required. \$\endgroup\$
    – lirtosiast
    Jun 16, 2019 at 8:03
  • \$\begingroup\$ @lirtosiast I'll think about it. Thanks. \$\endgroup\$
    – LegenDUST
    Jun 17, 2019 at 8:03

Typhoon: Where am I from?


A typhoon is basically a hurricane in the northwestern Pacific region. Unlike hurricanes, typhoons are named by 14 regions, each providing 10 names, adding up to 140 names. The 140 names are used in a cyclic pattern; after the last name is used, the first one will be used again. The names may sometimes be retired, mainly because of the devastation the typhoon with those names have made.

Here are the 140 names.

enter image description here


Region             Column 1   Column 2   Column 3   Column 4   Column 5   Column 6   Column 7   Column 8   Column 9   Column 10
Cambodia           Damrey     Ampil      Kong-rey   Krosa      Nakri      Maysak     Krovanh    Chanthu    Trases     Nesat
China              Haikui     Wukong     Yutu       Bailu      Fengshen   Haishen    Dujuan     Dianmu     Mulan      Haitang
DPR Korea          Kirogi     Jongdari   Toraji     Podul      Kalmaegi   Noul       Surigae    Mindulle   Meari      Nalgae
Hong Kong, China   Yun-yeung  Shanshan   Man-yi     Lingling   Fung-wong  Dolphin    Choi-wan   Lionrock   Ma-on      Banyan
Japan              Koinu      Yagi       Usagi      Kajiki     Kammuri    Kujira     Koguma     Kompasu    Tokage     Yamaneko
Lao PDR            Bolaven    Leepi      Pabuk      Faxai      Phanfone   Chan-hom   Champi     Namtheun   Hinnamnor  Pakhar
Macao, China       Sanba      Bebinca    Wutip      Peipah     Vongfong   Linfa      In-fa      Malou      Muifa      Sanvu
Malaysia           Jelawat    Rumbia     Sepat      Tapah      Nuri       Nangka     Cempaka    Nyatoh     Merbok     Mawar
Micronesia         Ewiniar    Soulik     Mun        Mitag      Sinlaku    Saudel     Nepartak   Rai        Nanmadol   Guchol
Philippines        Maliksi    Cimaron    Danas      Hagibis    Hagupit    Molave     Lupit      Malakas    Talas      Talim
RO Korea           Gaemi      Jebi       Nari       Neoguri    Jangmi     Goni       Mirinae    Megi       Noru       Doksuri
Thailand           Prapiroon  Mangkhut   Wipha      Bualoi     Mekkhala   Atsani     Nida       Chaba      Kulap      Khanun
U.S.A.             Maria      Barijat    Francisco  Matmo      Higos      Etau       Omais      Aere       Roke       Lan
Viet Nam           Son-Tinh   Trami      Lekima     Halong     Bavi       Vamco      Conson     Songda     Sonca      Saola


{"Cambodia":["Damrey","Ampil","Kong-rey","Krosa","Nakri","Maysak","Krovanh","Chanthu","Trases","Nesat"],"China":["Haikui","Wukong","Yutu","Bailu","Fengshen","Haishen","Dujuan","Dianmu","Mulan","Haitang"],"DPR Korea":["Kirogi","Jongdari","Toraji","Podul","Kalmaegi","Noul","Surigae","Mindulle","Meari","Nalgae"],"Hong Kong, China":["Yun-yeung","Shanshan","Man-yi","Lingling","Fung-wong","Dolphin","Choi-wan","Lionrock","Ma-on","Banyan"],"Japan":["Koinu","Yagi","Usagi","Kajiki","Kammuri","Kujira","Koguma","Kompasu","Tokage","Yamaneko"],"Lao PDR":["Bolaven","Leepi","Pabuk","Faxai","Phanfone","Chan-hom","Champi","Namtheun","Hinnamnor","Pakhar"],"Macao, China":["Sanba","Bebinca","Wutip","Peipah","Vongfong","Linfa","In-fa","Malou","Muifa","Sanvu"],"Malaysia":["Jelawat","Rumbia","Sepat","Tapah","Nuri","Nangka","Cempaka","Nyatoh","Merbok","Mawar"],"Micronesia":["Ewiniar","Soulik","Mun","Mitag","Sinlaku","Saudel","Nepartak","Rai","Nanmadol","Guchol"],"Philippines":["Maliksi","Cimaron","Danas","Hagibis","Hagupit","Molave","Lupit","Malakas","Talas","Talim"],"RO Korea":["Gaemi","Jebi","Nari","Neoguri","Jangmi","Goni","Mirinae","Megi","Noru","Doksuri"],"Thailand":["Prapiroon","Mangkhut","Wipha","Bualoi","Mekkhala","Atsani","Nida","Chaba","Kulap","Khanun"],"U.S.A.":["Maria","Barijat","Francisco","Matmo","Higos","Etau","Omais","Aere","Roke","Lan"],"Viet Nam":["Son-Tinh","Trami","Lekima","Halong","Bavi","Vamco","Conson","Songda","Sonca","Saola"]}

This chart is based from that on the Japan Meteorological Agency website, retrieved on 10 October 2019. Conventionally the list is divided into 5 columns, but in order to list all the names by region, I have organized them into 10 columns, so that each row fits all names from the same region. Moreover, two of the names, Mangkhut and Rumbia are retired and are still pending for replacement. Here I will keep these 2 names for integrity.


Write a program or function, that receives a name in the list above as input, and returns or outputs which region it is named after.

The input and output formats are flexible. For input, you may omit the hyphens and/or receive all uppercase or lowercase input. For output, you may also instead return an element from a set of 14 distinct values of your choice, each representing a region.

Your program does not need to deal with invalid inputs.

Sample I/O

Input: Chan-hom (exact wording)
Output: Lao PDR (exact wording)

Input: Kongrey (Kon-grey; without hyphen)
Output: KH (Cambodia; ISO 3166 code, uppercase)

Input: atsani (Atsani; all lowercase)
Output: th (Thailand; ISO 3166 code, lowercase)

Input: LAN (Lan; all uppercase)
Output: 12 (U.S.A; 0-indexed)

Input: choiwan (Choi-wan; without hyphen & all lowercase)
Output: 4 (Hong Kong, China; 1-indexed)

Input: INFA (In-fa; without hyphen & all uppercase)
Output: Macau (Macao, China; common name) 

Again, you may have different output formats, but the input and output formats you use must be stated.

Winning Criteria

The shortest submission in each language wins. No loophole is allowed.

  • 1
    \$\begingroup\$ Please add a table in a machine readable format. \$\endgroup\$
    – Adám
    Oct 10, 2019 at 9:51
  • \$\begingroup\$ @Adám Added just below the image. \$\endgroup\$ Oct 10, 2019 at 9:56
  • \$\begingroup\$ How about CSV or JSON? \$\endgroup\$
    – Adám
    Oct 10, 2019 at 9:56
  • 1
    \$\begingroup\$ @Adám I think I will add a json version. \$\endgroup\$ Oct 10, 2019 at 9:58
  • \$\begingroup\$ @Adám Added the corresponding JSON for the table. \$\endgroup\$ Oct 10, 2019 at 10:32
  • \$\begingroup\$ Unfortunately, this challenge becomes more about compressing the table than anything else :-( \$\endgroup\$
    – Adám
    Oct 10, 2019 at 10:52
  • \$\begingroup\$ @Adám I know that's just some reverse lookup, but well my intent is to see how this can be golfed smartly actually hmm.. \$\endgroup\$ Oct 11, 2019 at 1:18
  • 1
    \$\begingroup\$ Without compression, the best I came up with was to take input without dashes, but with capitals, then remove "rona" and look it up in a string of first-three-letters-except-"rona". You could give the table as an input… \$\endgroup\$
    – Adám
    Oct 11, 2019 at 1:20

How often does the word sixty-eight (68) appear in numbers from 1 to N. The upper limit for N to which the program needs to be able to perform is 100 000 000.

The program will take N as input and return every number in which the word sixty-eight appears from 1 to N, and a sum of all appearances of sixty-eight at the end.

I'm looking for the spoken form, so the word sixty-eight appears in

68 000 000 - sixty-eight million - once

68 680 000 - sixty-eight million six-hundred thousand - once

68 068 068 - sixty-eight million sixty-eight thousand and sixty-eight - three times

and so on. The shortest implementation that gives a correct result wins.

  • 1
    \$\begingroup\$ Thank you so much for using the sandbox. \$\endgroup\$
    – Adám
    Oct 10, 2019 at 13:48
  • \$\begingroup\$ Alright, no tie-breaker then \$\endgroup\$
    – Magisch
    Oct 10, 2019 at 14:10
  • \$\begingroup\$ What, exactly, is a "sum of all appearances of sixty-eight at the end"? Also, there is a typo in your second test case I think (should be six-hundred eighty thousand, right?). \$\endgroup\$ Oct 10, 2019 at 18:34
  • 1
    \$\begingroup\$ 68 680 000 should be sixty-eight million six-hundred eighty thousand, right? \$\endgroup\$
    – u-ndefined
    Oct 13, 2019 at 7:14

Doing something with Haifu

Haifu is an esoteric programming language by David Morgan-Mar, which, in addition to having a very weird control scheme also has the requirement that each program should be in the form of Haiku.

Maybe it would be possible to do a -like challenge with it. The robber's task is to write a Haifu program doing something non-trivial, using a shorthand code, where each command/variable is replaced by a unique single- or two-character identifier, and ignoring the haiku structure demand (The language is weird enough that even "Hello World" isn't a trivial task). The cop's task is to take a robber's code and turn it into a valid Haiku. However, this would either be a , or maybe even outsourced to a different SE site.

Meta questions:

Is this a feasible concept and does it fit into the spirit of CodeGolf.SE?

The Haifu specification is not quite complete. If I'd be doing this, I'd need first some sharp eyes to help me spot all the holes and fill them. Then, the shortened syntax for the coding part would need to be designed. If enough people say it might be feasible, I'll probably open a chat room to discuss this.

Lastly, of course, what to do with the turning code into Haiku part of the challenge?

  • \$\begingroup\$ Is there an implementation of Haifu already? Regardless, based on the allowance of comments in the poems it does not appear difficult to produce any particular program in Haifu (though golfing is a different matter). Making this a popularity contest sounds like a rather bad idea - what objective voting criterion would you be considering? Of course, if you make one yourself you could probably post it to puzzling. \$\endgroup\$ Oct 17, 2019 at 19:47

Intersect the integer ranges

Integer ranges take one of four forms:

  1. A start, a step and an end. Both ends are included in the range. The difference between the end and start is guaranteed to be a multiple of the step. The step is guaranteed to be positive, even if the start is equal to the end (it may not be greater).
  2. A start and a step. This is a half-infinite range.
  3. A step and an end. This is also a half-infinite range.
  4. An empty range. You can decide how you want to represent this, but you must accept as input any empty range you can output.

Given two integer ranges, please output their intersection.

  1. If the two ranges are disjoint, return an empty range.
  2. If the two ranges are identical, simply output one of them.
  3. If one range completely subsumes the other, output the latter.
  4. Determine the values common to both ranges, and output a range that represents these values.


[1, 1, 6] ∩ [3, 1, 9] = [3, 1, 6]
[1, 2, 9] ∩ [2, 1, 8] = [2, 2, 8]
[1, 2, ~] ∩ [2, 3, ~] = [5, 6, ~]
[~, 2, 9] ∩ [1, 3, ~] = [1, 6, 7]
[1, 2, 3] ∩ [2, 2, 2] = []

If would be nice if you could indicate any preconditions that your answer doesn't require (e.g. if it works for a step of zero when the start and end are the same).

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

  • \$\begingroup\$ [] v [] makes it look like you want the union () instead of intersection () \$\endgroup\$
    – Kroppeb
    Oct 17, 2019 at 15:53
  • \$\begingroup\$ @Kroppeb Whoops, I was so lazy that not only didn't I look up the right character but I used the wrong ASCII character too... sorry about that. \$\endgroup\$
    – Neil
    Oct 17, 2019 at 17:47

Can I run this?

I'm a big fan of challenges, and an idea recently struck me. Suppose you're on a *nix system and you want to know how many executable programs you have installed that you can run. Given a file with mode mode, you can run it if it is a normal file (mode & S_IFMT == S_IFREG) and any of the following are true:

  • Its owner is equal to your effective user id and 0100 & p != 0 (user executable bit is set)
  • Its group is a group you are a member of and 0010 & p != 0 (group executable bit is set)
  • 0001 & p != 0 (world executable bit is set)


TODO: See below.

For Sandbox

Writing a good challenge is hard. I have some ideas, but I've brainstormed some easy solutions and I want to know which challenge and restrictions would be most well-received.

There are three possible challenges I am considering:

  • single file: Given a path as input, output truthy/falsy whether the path is a path to a file the user can run.

  • count in directory: output the number of files the user can run at any depth underneath the current working directory (or a provided directory, should you prefer that)

  • count in PATH: output the number of files the user can run immediately under any directory in the environment variable PATH. The value of PATH may also be given as input to the program/function.

Potential restrictions (I marked as spoilers since these can provide solutions if I don't ban them):

  • Banning the use of access()/os.access()/etc.

  • Banning the use of the which executable typically found on *nix machines (which is exactly the solution to the first challenge)

  • Banning the use of any external executables

I am currently inclined to choose the second challenge, allow all solutions, but award a bounty to the shortest program which follows the above restrictions.


Universal duct tape programming

The task is to write a program that [TODO: insert simpleish task here] that works in as many languages as possible, while only using code that was already written before by someone else at http://stackoverflow.com. To minimize time, you are trying to use as few snippets as possible. Therefore, they must be as long as possible.

Code from http://stackoverflow.com is defined as substrings of code blocks in questions, answers and comments created before this challenge [TODO: or perhaps this sandbox post?]. You must link to the source of the code in your answer. You can concatenate multiple snippets, optionally inserting newlines.

Your code must work in at least two different languages.

Your score is equal to the minimum of the number of languages your code works in and the length of the shortest snippet you use. Highest score wins.

Sandbox stuff

  • Is this a good idea?
  • How simple should the simpleish task be?
  • Can the scoring system be abused?
  • Does the "multiple languages" part need clarification?
  • Does the "stackoverflow snippets" part need clarification?
  • 1
    \$\begingroup\$ Is this supposed to be a polyglot or just multiple versions of the same problem? Why require 2 snippets? I think a better scoring system would be language_count/number_of_snippets. The best way to abuse the scoring system right now is to copy from overly verbose languages like Java. \$\endgroup\$
    – Beefster
    Sep 13, 2019 at 20:25
  • \$\begingroup\$ @Beefster This is supposed to be a polyglot. Will try to fix all 3 points in a few hours. \$\endgroup\$ Sep 14, 2019 at 0:03
  • \$\begingroup\$ Can we use snippets from code review as well? \$\endgroup\$
    – lyxal
    Sep 15, 2019 at 4:21
  • \$\begingroup\$ -1 duct-taping and polyglotting are mostly incompatible goals. This will tend to result in a lot of C/C++ solutions and not much else. \$\endgroup\$
    – Beefster
    Sep 16, 2019 at 0:52
119 120
122 123

You must log in to answer this question.

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