571
\$\begingroup\$

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

Posting

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.

Discussion

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.

Other

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

\$\endgroup\$
2
  • \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$
    – None1
    Commented May 15 at 14:05
  • \$\begingroup\$ @None1 If you don't get feedback for a while you can ask in the nineteenth byte \$\endgroup\$
    – mousetail
    Commented May 29 at 13:27

4705 Answers 4705

1
44 45
46
47 48
157
2
\$\begingroup\$

Conversions Galore!

\$\endgroup\$
2
\$\begingroup\$

Generate the Sequence of Equivalence Relations (OEIS A231428)

Introduction

An equivalence relation \$R\$ on a set \$S\$ is

  • reflexive: \$ \forall a\in S: aRa\$
  • symmetric: \$ \forall a,b \in S: aRb \leftrightarrow bRa \$
  • transitive: \$ \forall a,b,c \in S: aRb \wedge bRc \rightarrow aRc \$

These relations can be represented as boolean matrices where:

  • reflexive: the diagonal is all ones
  • symmetric: the entries are symmetric over the diagonal (\$a_{ij}=a_{ji}\$)
  • transitive: the matrix, when pairs of rows and the corresponding pairs of columns are suitably swapped, consists of entirely-1 and entirely-zero blocks, with the on-diagonal blocks entirely-1.

Here are a few such matrices:

1 0        1 1 0 0 0        1 0 1 0       can swap rows     1 1 0 0
0 1        1 1 0 0 0        0 1 0 1  -->  2&3, columns  --> 1 1 0 0
           0 0 1 1 1        1 0 1 0       2&3 to obtain:    0 0 1 1
           0 0 1 1 1        0 1 0 1                         0 0 1 1
           0 0 1 1 1

Making use of the reflexive and symmetric properties, we can encode such a matrix by concatenating the rows of its upper-right triangle, and converting from binary to decimal. (The example matrices encode as 0b0=0, 0b10 0000 0111=519, 0b01 0010=18, and 0b10 0001=33.)

Challenge

Write a program or function that outputs all equivalence relations in order (as encoded above). Default sequence rules apply, so you can output an unbounded list, you can take an input \$n\$ and return the \$n^{th}\$ term, or you can take an input \$n\$ and return the first \$n\$ terms. Default Loopholes forbidden. This is , so shortest program wins.

For reference, the first 25 terms of this sequence are

0, 1, 2, 4, 7, 8, 12, 16, 18, 25, 32, 33, 42, 52, 63, 64, 68, 80, 96, 116, 128, 130, 136, 160, 170

Here are example matrices which generate the first few terms of the sequence:

A: 1 0 0     
   0 1 0    0b000 -> 0    
   0 0 1     
          
B: 1 0 0 0
   0 1 0 0    0b00 0000 0001 -> 1    (also: 1 1 among others)
   0 0 1 1                                  1 1 
   0 0 1 1

C: 1 0 0 0 0
   0 1 0 0 0
   0 0 1 0 1    0b00 0000 0010 -> 2
   0 0 0 1 0
   0 0 1 0 1

D: 1 0 0 0 0
   0 1 0 0 0
   0 0 1 1 0    0b00 0000 0100 -> 4
   0 0 1 1 0
   0 0 0 0 1

E: 1 1 1
   1 1 1    0b111 -> 7
   1 1 1

F: 1 0 0 1
   0 1 0 0    0b00 1000 -> 8
   0 0 1 0
   1 0 0 1

G: 1 0 0 0 0
   0 1 0 0 1
   0 0 1 1 0    0b00 0000 1100 -> 12
   0 0 1 1 0
   0 1 0 0 1

Sandbox notes

related: Is This an Equivalence Relation?, Determine if a relation is transitive

My first try, so please don't be shy about suggesting improvements, making edits, heckling... I can take it =)

\$\endgroup\$
3
  • \$\begingroup\$ While I think it's mostly clear, I think it would be helpful if you included the matrices for the first 2 or 3 values in the sequence. Additionally, the default [sequence] rules also allow answers to take \$n\$ as input and output the first \n\$ terms. I'd clarify that isn't allowed, if you intend to override the default. Other than that, looks like a well-written and interesting challenge! \$\endgroup\$ Commented Oct 23, 2022 at 16:45
  • \$\begingroup\$ @cairdcoinheringaahing thanks for the thoughts. On including the first few examples: would you suggest making that code-block one fairly-wide line of examples, or include a few lines of matrices. (I don't know what's easiest to scroll around for people.) On the second point, I didn't intend to override the default--I'll just remove mention of \$n\$ from the challenge section. \$\endgroup\$
    – nitsua60
    Commented Oct 23, 2022 at 19:12
  • 1
    \$\begingroup\$ I think either a code block, or a few lines of mathjax, would both work fine, it's probably just a matter of preference \$\endgroup\$ Commented Oct 23, 2022 at 19:59
2
\$\begingroup\$

Fastest approximate square root of a floating point number


In this challenge, you'll approximate the square root of a floating point number, using some basic arithmetic, bitwise, and control flow operators. Your score will take into account the number of operations your code performs, in addition to its accuracy.

Background:

(Expanation of how IEEE-754 double precision floats work)

Opcodes:

(A list of operations, including basic arithmetic, bitwise, and conditionals/jumps)

(Paradigm, probably either based on a finite number of registers or a stack, is yet to be decided)

Task:

Given a 64-bit floating point number, approximate its square root in the fewest number of operations possible. Your score is a sum of the scores for (around 100k) individual test cases, each of which is scored as the following, where \$n_{ops}\$ is the number of operations the program took to complete, \$x\$ is the input, and \$f(x)\$ is the program's output:

$$\frac{{n_{ops}}^2}{\max(\frac{f(x)}{\sqrt{x}},\frac{\sqrt{x}}{f(x)})}$$

(Note that the actual \$\sqrt{x}\$ will be used for scoring, rather than the closest floating point value, meaning that even a maximally accurate submission would still be slightly penalized for inaccuracy)

\$\endgroup\$
7
  • \$\begingroup\$ The question of the fastest floating-point calculation of the square root has been coming up again and again for decades, but is hardly relevant anymore on modern architectures and standard libraries. I have a little doubt whether such a question still makes a lot of sense, since there are already excellent answers, e.g., stackoverflow.com/questions/71336291/… . Everyone who wants to win such a challenge has hardly any other option than to copy the already known methods. \$\endgroup\$ Commented Nov 14, 2022 at 16:56
  • \$\begingroup\$ @HugoPfoertner I disagree. This question will likely encourage answers which use just a few instructions total. Not having to be very accurate, at all, will allow for some really neat bitwise stuff. \$\endgroup\$ Commented Nov 14, 2022 at 17:13
  • \$\begingroup\$ In order for me to be able to imagine anything concrete under the problem statement, you would have to be a bit more specific as to what you want to allow under "basic arithmetic". Without division, for example, it gets tricky. Likewise, you would have to say if you have an instruction to get the exponent of the floating point number. Without such information it is difficult to decide whether this will be a worthwhile task. \$\endgroup\$ Commented Nov 14, 2022 at 17:49
  • \$\begingroup\$ @HugoPfoertner I'm thinking something like this: chat.stackexchange.com/transcript/message/62332621#62332621 \$\endgroup\$ Commented Nov 14, 2022 at 19:28
  • \$\begingroup\$ FYI you can use \left and \right to make the brackets the right size. \$\endgroup\$ Commented Nov 14, 2022 at 21:35
  • \$\begingroup\$ @RadvylfPrograms It is a bit strange when reference is first made to IEEE-754 double precision floats, but then in the task no use is made of the division of the number into mantissa and exponent described there. If you deny direct access to the exponent, then most of the "neat bitwise stuff" mentioned is probably needed to get the exponent information anyway. \$\endgroup\$ Commented Nov 16, 2022 at 21:02
  • \$\begingroup\$ @HugoPfoertner All of the bitwise operations would act on the 64-bit integer representation of the float, not the float itself (just like in assembly/machine code). So to shift the mantissa for example, you could mask that, shift it, and xor the old sign and exponent back in. I considered adding operations which acted specifically on either the mantissa or exponent, but that seemed like it would make it too easy. \$\endgroup\$ Commented Nov 17, 2022 at 3:43
2
\$\begingroup\$

Counting Stripey Bracelets

\$\endgroup\$
2
  • \$\begingroup\$ I suggest adding an example (or examples) which will correspond to the bracelets on the image, which is used to explain the idea of stripes (e.g (6,3,4) and/or (6,3,6)). \$\endgroup\$
    – pajonk
    Commented Nov 2, 2022 at 13:56
  • 1
    \$\begingroup\$ Good call @pajonk, I've aligned a couple of the examples and highlighted which are where in the image. \$\endgroup\$ Commented Nov 2, 2022 at 18:08
2
\$\begingroup\$

Maximum average ord

\$\endgroup\$
2
  • \$\begingroup\$ It may be rounded to any number of decimal places. Can that number be zero (integer)? Can we floor or ceil instead of round? \$\endgroup\$
    – naffetS
    Commented Nov 4, 2022 at 18:58
  • \$\begingroup\$ @Sʨɠɠan - I'll say it must be 1 or more (I've edited that into the post). And, it must be rounded properly (e.g. 1.23 cannot be "rounded" to 1.3). \$\endgroup\$
    – The Thonnu
    Commented Nov 4, 2022 at 19:36
2
\$\begingroup\$

Simple Boolean Algebra Calculator

\$\endgroup\$
2
  • \$\begingroup\$ This is an interesting idea, but the current structure of the post makes it hard to tell what the program is supposed to do. Perhaps you could break down and explain one of the examples in full? \$\endgroup\$
    – Ginger
    Commented Nov 11, 2022 at 14:55
  • \$\begingroup\$ @Ginger Thanks for commenting! I added some explanations above. \$\endgroup\$ Commented Nov 11, 2022 at 15:04
2
\$\begingroup\$

Transform a lattice polygon to minimum diameter by shearing

\$\endgroup\$
8
  • \$\begingroup\$ The math formulas look... strange. Why not MathJax? \$\endgroup\$ Commented Nov 14, 2022 at 8:55
  • \$\begingroup\$ I hope it's better now. I have little practice in writing LaTeX, but I'll give it a try. \$\endgroup\$ Commented Nov 14, 2022 at 9:54
  • \$\begingroup\$ That'll do. Besides, you might want to align the testcases so that it'll be easier to comprehend the inputs and outputs \$\endgroup\$ Commented Nov 14, 2022 at 9:56
  • \$\begingroup\$ The alignment is done. Now the input has to handle spaces between the numbers correctly. \$\endgroup\$ Commented Nov 14, 2022 at 10:27
  • 1
    \$\begingroup\$ We generally discourage cumbersome I/O formats and prefer to let answerers choose what's best for them (within reason). \$\endgroup\$
    – pajonk
    Commented Nov 14, 2022 at 19:16
  • \$\begingroup\$ @pajonk I don't think the proposed output format is cumbersome. I would just like to be able to directly interpret the results of the programs. If someone is unable to separate the coordinates with commas, for example, then the program is of little use to me. \$\endgroup\$ Commented Nov 14, 2022 at 22:53
  • \$\begingroup\$ You may ask to provide code to convert from golfiest representation to your output, but score only the main task. I suspect that in some languages the boilerplate code to handle specific I/O may be as long as the code to solve the task. This makes the challenge less interesting in my opinion. Also, I suggest rephrasing the winnning criteria, as now ("the shortest code able to solve all test cases wins") it is closer to test-battery than code-golf - in code-golf we usually require the code to theoretically handle any case of the specified problem. \$\endgroup\$
    – pajonk
    Commented Nov 15, 2022 at 7:24
  • \$\begingroup\$ @pajonk Thanks for the suggestions! I have now tried to change the task description accordingly. I suppose that it goes without saying that all the specified tests must be passed. \$\endgroup\$ Commented Nov 16, 2022 at 20:40
2
\$\begingroup\$

How much STAB do I get?

With the new Terastal mechanic in Pokémon Scarlet and Violet, moves can now get a variety of Same Type Attack Bonuses.

This bonus, known as STAB for short, varies depending on the type of the move and the Pokémon's type(s) (Pokémon can have multiple types) and Tera type, but also on whether the Pokémon has the Adaptability ability.

The rules are as follows:

  • If the Pokémon hasn't been Terastallised:
    • If the move is not one of the Pokémon's types then the STAB is 1× (i.e. no bonus)
    • Otherwise if the Pokémon has the Adaptability ability then the STAB is 2×
    • Otherwise the STAB is 1.5×
  • If the Pokémon has been Terastallised into a different type:
    • If the move is neither the Tera type or its regular types then the STAB is 1×
    • Otherwise if the move is the Tera type and the Pokémon has the Adaptability ability then the STAB is 2×
    • Otherwise the STAB is 1.5×
  • If the Pokémon has been Terastallised into one of its regular types:
    • If the move is not one of the Pokémon's types then the STAB is 1×
    • Otherwise if the move is not the Tera type then the STAB is 1.5×
    • Otherwise if the Pokémon has the Adaptability ability then the STAB is 2.25×
    • Otherwise the STAB is 2×

As a table:

Is Terastallised Move has Tera type Move has regular type Adaptability STAB
No No No No
No No No Yes
No No Yes No 1.5×
No No Yes Yes
No Yes No No
No Yes No Yes
No Yes Yes No 1.5×
No Yes Yes Yes
Yes No No No
Yes No No Yes
Yes No Yes No 1.5×
Yes No Yes Yes 1.5×
Yes Yes No No 1.5×
Yes Yes No Yes
Yes Yes Yes No
Yes Yes Yes Yes 2.25×

Your task is to write a program or function that, given a move's type, a Pokémon's Tera type and set of base type(s) as some kind of comparable value (e.g. type names as strings), and its Terastallisation and Adaptability states as a byte-sized flag, outputs the move's resulting STAB. Instead of a seprate Terastallisation flag you can also use a sentinel value for the Tera type to indicate that the Pokémon hasn't been Terastallised. You can optionally take an additional argument which is the set of types that are boosted by Adaptability.

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

\$\endgroup\$
2
\$\begingroup\$

Santa's Shortest Path Problem

1st-time trying to come up with a challenge. Please provide feedback if this is a nice challenge/if it's doable and/or if anything is unclear.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Thanks for using the Sandbox! What do you mean by "readable format"? I suggest skipping the "readable" as it may be too vague. I also suggest relaxing the output to allow any kind of coordinates, not just letter+number. Finally, I suggest finishing the route at the last village as returning to A1 is unnecessary IMHO (but that just my preference). \$\endgroup\$
    – pajonk
    Commented Dec 7, 2022 at 10:16
  • \$\begingroup\$ @pajonk, thanks for the prompt response. I hope the edit makes for a more approachable challenge. \$\endgroup\$
    – JvdV
    Commented Dec 7, 2022 at 14:34
2
\$\begingroup\$

But can it run Fibonacci?

Cops will write a programming language interpreter (or transpiler or compiler) in 2048 bytes or less. It must be capable of a Fibonacci program which works until limited by integer sizes or some similar restriction (no finite look-up tables or similar, and a reasonable number of fibonacci numbers must be supposed, with 17711 being a reasonable minimum).

Robbers will try to find this fibonacci program.

\$\endgroup\$
2
\$\begingroup\$

Approximate my Atomic Weight

\$\endgroup\$
2
2
\$\begingroup\$

Number program police

This question is related to Counting and so on

Content

With some clever engineering, we now have program that can count like us.

But this is not enough. We are making a math society and society isn't as simple as counting.

There is always some blatant number police who calls you out if you makes a single bit of mistake. Without those police it will never be a complete society.

Task

Make a program that identifies whether a shape is a number shape.

shape

A shape is a Boolean matrix, here represented using spaces and #s:

 ########
 #   ####
 ########

(the above shape is also an example of valid Number shape which represents 0)

Number shape

Basic Number shape:

  #  ###  ###  # #  ###  ###  ###  ###  ###  ###
  #    #    #  # #  #    #      #  # #  # #  # #
  #  ###  ###  ###  ###  ###    #  ###  ###  # #
  #  #      #    #    #  # #    #  # #    #  # #
  #  ###  ###    #  ###  ###    #  ###    #  ###

A basic Number shape can be enlarged, twisted, be longer or shorter, while still being valid, as long as it Resembles the shape:

Is a Number shape of 9:
#####  ######  ###
##  #  #    #  # #
##  #  ######  ###
#####       #  ###
    #       #    #
    #       #    #
            #

Is not a Number shape of 9:

###   #####   ###  ####
# #   # #     # #  # ##
# #   ###     ###  ###
  #     #      #     #
        #      #     #

Acceptable reshape:

Original shape:

   ###               ####
   # #      widen    #  #
   ###     ------->  ####
     #                  #
     #                  #

           extend   ###       shorten   ###
           -------> # #   or            # #
                    ###                 ###
                      #                   #
                      #
                      #



          lengthen  ###
           -------> # #
                    # #
                    ###
                      #
                      #

     enlarge line   ###      ####      ####      ###           ###
           -------> ###  or  # ##  or  ## #  or  # #  but not  # # (this is
                    # #      ####      ####      ###           ###  not 9
                    ###        ##         #      ###           ###  but a 0)
                      #        ##         #        #           ###  
                      #        


You can do 1 or more of those actions on the same digit for any amount of units, for example:

#####
#  ##
#  ##
#####
   ##
   ##
   ##
   ##

Is Widened, extended, enlarged, and lengthened.

The Basic Number shape (or smaller varient of it) should be obtained if you repeatedly remove one out of two consecutive identical rows or columns.

For digits that contain a hole in it (6, 8, 9, 0), the hole should exist for it to be valid (length, wide does not matter).

For U-shaped holes (2, 3, 4, 5, 6), those should have at least one empty byte that resembles a hole:

###  is done by shortening, and then enlarge line.
 ##  
###  Valid.
 ##
###

For numbers that have more than one digit, digits should have at least one spacing between them, and they should not be connected in any way:

#  ###
#    #
#  ###
#  #
   ###
is identified as 12

A Number shape can also start with 0:

### #
# # #
### #

I/O

Basically follows the standard I/O rules:

The input can be request in any convenience format

For example, list the split with newline can be the input.

The output follows the standard output rule

Testcase

Is Number shape: (- is to separate each testcase out)

###
# #
###
------------------
#####
#####
## ##
#####
#####
------------------
### 
# # #
### 
------------------
 ####
 #  #
 ####
 #  #
 ####
------------------
# # # # #

Is not Number shape:

 ##
  #
###
# 
###
------------------
#####
#####
## ##
#####
  ###
------------------
######
# #  #
# ####
# ##
######
------------------
#######
#   # #
### ###
# #   #
###   #
------------------
####
# ##
####
## #
####
------------------
###
  #
 ##
  #
###

Rules

  • No standard loopholes
  • is code golf so shortest police is the best police.

Meta

  • Is the title good?
  • Any tag that suits this question but not included?
  • Is it clear?
  • Extra suggestion would help me out a lot!
\$\endgroup\$
1
2
\$\begingroup\$

Calculate my income tax

\$\endgroup\$
2
  • \$\begingroup\$ If I earn £100,003, does my personal allowance go down by £1 or £1.50? \$\endgroup\$
    – pxeger
    Commented Dec 20, 2022 at 11:49
  • \$\begingroup\$ @pxeger Actually I'll change that. It's up to you which one you want. \$\endgroup\$
    – The Thonnu
    Commented Dec 20, 2022 at 12:01
2
\$\begingroup\$

Find the Prime Signature

\$\endgroup\$
4
  • \$\begingroup\$ I find it a tad confusing that you group inputs with identical signatures together, using ", " but also use "," as thousands separator. \$\endgroup\$
    – Adám
    Commented Dec 27, 2022 at 22:29
  • \$\begingroup\$ @Adám I've updated it to be consistent (removing thousands separator) with the Wikipedia list. I considered thousands separator with "; " as the list separator, but that looked worse (imo) \$\endgroup\$ Commented Dec 27, 2022 at 22:40
  • \$\begingroup\$ Do I understand correctly that outputting a set is not allowed as it has no defined order of elements? \$\endgroup\$
    – pajonk
    Commented Dec 28, 2022 at 9:09
  • \$\begingroup\$ @pajonk Correct. Not only is a set generally implemented without preserving insertion order, a set in computer science can only contain unique items; for example 6 has a prime signature of {1, 1} (in number theory set notation), but a set would only be able to store one of the 1s \$\endgroup\$ Commented Dec 28, 2022 at 9:12
2
\$\begingroup\$

Find the first run of numbers summing to n

Given as input a number n and a sequence of digits 0-9 (which may be taken as a string or a list), find the first contiguous subsequence of digits in the sequence that sums to n and output the start and end indexes. You may use zero- or one-based indexing. If no such subsequence exists, your program may output any constant value.

Examples

These examples use zero-based indexing.

Input: 10 123456789
Output: 0 3
Input: 32 444444444
Output: 0 7
Input: 33 444444444
Output: No solutions
\$\endgroup\$
3
  • \$\begingroup\$ Shouldn't the first test case be 0 4? \$\endgroup\$
    – mousetail
    Commented Jan 9, 2023 at 14:48
  • \$\begingroup\$ @mousetail That would be the subsequence 12345, which sums to 15. \$\endgroup\$
    – Ginger
    Commented Jan 9, 2023 at 14:53
  • \$\begingroup\$ My bad I assumed exclusive range \$\endgroup\$
    – mousetail
    Commented Jan 9, 2023 at 14:53
2
\$\begingroup\$

Estimate the world population, at 5 different levels of accuracy

Your goal is, given a year between 1952 and 2020 to output the world population in that year. However, you must write 5 different expressions. Each program must contain the previous as a substring.

Your first program is 5 bytes, the second 10, then 20, 40 finally a program or function with a maximums size of 80 bytes. Each expression must contain the previous expression as a substring.

For the purpose of this challenge, snippets that take input from global variables are allowed, for all programs except the last. which must be either a complete program or a function.

Scoring

For each year, your score is the product of the proportional square error. In other words:

$$\frac{(X_0 - V)^2 \cdot (X_1 - V)^2 \cdot (X_2 - V)^2 \cdot(X_3 - V)^2 \cdot (X_4 - V)^2}{V^{10}}$$

Where Xn is the estimate your nth program outputs and V is the true population at that year. Your total score is sum of the score of each year.

Lower score is better.

Example

Python, Score \$7.503\cdot10^{59}\$

Note the numbers here are absolute nonsense, I hope most submissions will have a score that can be written in the title without needing scientific notation

5 byte solution:

413e7

10 byte solution

413e7+x**2

20 byte solution

413e7+x**2.46*4.321

40 byte solution

0*413e7+x**2.46*4.321+x**3.718232*8.3e9

80 byte solution

lambda x:0.010*413e7+x**2.46*4.321+x**3.718232*8.3e9+__import__("math").sin(x/2)

Data

Year Population
2020 7,794,798,739
2019 7,713,468,100
2018 7,631,091,040
2017 7,547,858,925
2016 7,464,022,049
2015 7,379,797,139
2014 7,295,290,765
2013 7,210,581,976
2012 7,125,828,059
2011 7,041,194,301
2010 6,956,823,603
2009 6,872,767,093
2008 6,789,088,686
2007 6,705,946,610
2006 6,623,517,833
2005 6,541,907,027
2004 6,461,159,389
2003 6,381,185,114
2002 6,301,773,188
2001 6,222,626,606
2000 6,143,493,823
1999 6,064,239,055
1998 5,984,793,942
1997 5,905,045,788
1996 5,824,891,951
1995 5,744,212,979
1994 5,663,150,427
1993 5,581,597,546
1992 5,498,919,809
1991 5,414,289,444
1990 5,327,231,061
1989 5,237,441,558
1988 5,145,426,008
1987 5,052,522,147
1986 4,960,567,912
1985 4,870,921,740
1984 4,784,011,621
1983 4,699,569,304
1982 4,617,386,542
1981 4,536,996,762
1980 4,458,003,514
1979 4,380,506,100
1978 4,304,533,501
1977 4,229,506,060
1976 4,154,666,864
1975 4,079,480,606
1974 4,003,794,172
1973 3,927,780,238
1972 3,851,650,245
1971 3,775,759,617
1970 3,700,437,046
1969 3,625,680,627
1968 3,551,599,127
1967 3,478,769,962
1966 3,407,922,630
1965 3,339,583,597
1964 3,273,978,338
1963 3,211,001,009
1962 3,150,420,795
1961 3,091,843,507
1960 3,034,949,748
1959 2,979,576,185
1958 2,925,686,705
1957 2,873,306,090
1956 2,822,443,282
1955 2,773,019,936
1954 2,724,846,741
1953 2,677,608,960
1952 2,630,861,562

In JSON format:

{2020: 7794798739, 2019: 7713468100, 2018: 7631091040, 2017: 7547858925, 2016: 7464022049, 2015: 7379797139, 2014: 7295290765, 2013: 7210581976, 2012: 7125828059, 2011: 7041194301, 2010: 6956823603, 2009: 6872767093, 2008: 6789088686, 2007: 6705946610, 2006: 6623517833, 2005: 6541907027, 2004: 6461159389, 2003: 6381185114, 2002: 6301773188, 2001: 6222626606, 2000: 6143493823, 1999: 6064239055, 1998: 5984793942, 1997: 5905045788, 1996: 5824891951, 1995: 5744212979, 1994: 5663150427, 1993: 5581597546, 1992: 5498919809, 1991: 5414289444, 1990: 5327231061, 1989: 5237441558, 1988: 5145426008, 1987: 5052522147, 1986: 4960567912, 1985: 4870921740, 1984: 4784011621, 1983: 4699569304, 1982: 4617386542, 1981: 4536996762, 1980: 4458003514, 1979: 4380506100, 1978: 4304533501, 1977: 4229506060, 1976: 4154666864, 1975: 4079480606, 1974: 4003794172, 1973: 3927780238, 1972: 3851650245, 1971: 3775759617, 1970: 3700437046, 1969: 3625680627, 1968: 3551599127, 1967: 3478769962, 1966: 3407922630, 1965: 3339583597, 1964: 3273978338, 1963: 3211001009, 1962: 3150420795, 1961: 3091843507, 1960: 3034949748, 1959: 2979576185, 1958: 2925686705, 1957: 2873306090, 1956: 2822443282, 1955: 2773019936, 1954: 2724846741, 1953: 2677608960, 1952: 2630861562}
\$\endgroup\$
4
  • \$\begingroup\$ Just some nitpicking: you say 1951 in the question but only supply data back to 1952. Also I believe your 5 byte solution was meant to be 413e9. Also it can be nice to provide a scoring script/link in some common language, not necessary of course. \$\endgroup\$ Commented Jan 12, 2023 at 17:23
  • \$\begingroup\$ 413e7 is correct, that comes out to 4,130,000,000. Note the lack of a decimal point in 413 \$\endgroup\$
    – mousetail
    Commented Jan 12, 2023 at 17:35
  • 1
    \$\begingroup\$ Oh, I meant because that's what it is in the next four. Something needs to change for it to adhere to the substring rule. \$\endgroup\$ Commented Jan 12, 2023 at 17:57
  • \$\begingroup\$ Oops, thanks for pointing that out \$\endgroup\$
    – mousetail
    Commented Jan 12, 2023 at 18:04
2
\$\begingroup\$

Cheat at Chess

Inspired by a meme my brother showed me that I cannot find anymore, that looked something like this with the caption "White to play, mate in one:"

The image shows the white rook going over several pieces to end up putting the black king in checkmate (Rxh8). Of course this is not a legal move, but it shows a misunderstanding of chess that I thought could make a fun code challenge.

Task

Given a chess board as input, output the move that puts the king in check, using algebraic notation.

The move must follow the movement rules for a chess piece, but can ignore any pieces standing in its way.

Input format: string matrix or multiline string, each element either empty (empty string, empty matrix element, whatever makes sense) or with a letter - K: King, Q: Queen, R: Rook, B: Bishop, N: Knight, or P: Pawn, uppercase for white and lowercase for black.

The input will always be a board that has a valid solution for this. If there are multiple possible solutions, choose any of them.

Test cases:

r n b - k - - r
p p - p p p - p
- q p - - n p b
- - - - - - - -
- P - - - - - -    -> Rxh8
- - P P - - - -
P Q - - P P P P
R N B - K B N R

More test cases whenever I have time to make them.

This is , so shortest code in bytes wins.

Sandboxing

  • Should the task be "find the move that causes checkmate" instead of just check? I feel like this might make golfing too difficult though.
  • I haven't had time to work on an implementation for solving this yet, so not sure how hard this will be.
  • Any suggested test cases?
\$\endgroup\$
8
  • 1
    \$\begingroup\$ In the example you gave, the king is in check, it's not checkmate because the knight and bishop can block \$\endgroup\$
    – c--
    Commented Jan 16, 2023 at 21:03
  • \$\begingroup\$ @c-- Sorry, I suck at chess haha. That's why I need to cheat >.< I'll edit the example. The challenge does say to put the king in check, not checkmate though. \$\endgroup\$ Commented Jan 16, 2023 at 22:09
  • \$\begingroup\$ can ignore any pieces standing in its way. What about the last position(dst)? \$\endgroup\$
    – l4m2
    Commented Jan 17, 2023 at 3:10
  • \$\begingroup\$ Won't F1-B5 is another way to check? \$\endgroup\$
    – tsh
    Commented Jan 17, 2023 at 5:31
  • \$\begingroup\$ I don't have time to finish this right now, I'll most likely come back to it in a few days. \$\endgroup\$ Commented Jan 18, 2023 at 2:13
  • \$\begingroup\$ Can I cheat to capture king? \$\endgroup\$
    – l4m2
    Commented Jan 18, 2023 at 10:56
  • 3
    \$\begingroup\$ Note that this cheat method isn't actually cheating - it's what chess anarchists like myself call the Siberian swipe. Note that it can only be performed if the h file pawn hasn't been moved and if the h file rook hasn't been moved as well. \$\endgroup\$
    – lyxal
    Commented Jan 23, 2023 at 1:18
  • \$\begingroup\$ @lyxal that was the meme I was thinking of haha. I’ll mention it in the challenge, but I already wrote the challenge so I don’t think I’m going to change it \$\endgroup\$ Commented Jan 23, 2023 at 15:37
2
\$\begingroup\$

Print the notes of an increasing octave-repeating scale.

\$\endgroup\$
1
  • \$\begingroup\$ Maybe talk some about half steps? \$\endgroup\$ Commented Jan 18, 2023 at 8:22
2
\$\begingroup\$

Enable 2char-JsFuck

Write some javascript code that allow using only 2 characters to execute all javascript code.

As I can tell, these are possible chosen set:

f`   [a-zA-Z$_]`
f;   [a-zA-Z$_][;,\n]
f.   [a-zA-Z$_]\.
[]   \[\]

Obviously, the first one is lot easier than the other few. Therefore, different set are not scored together.

Shortest code in each (environment,chosen set) wins.

Sandbox Notes

  • Any other sets? (not counting g+ or other variable name)
  • Why I remember I've sandboxed this idea?
\$\endgroup\$
2
  • \$\begingroup\$ Is the code we write a function or a full program? Can we choose to insert the two-char JSFuck at an arbitrary point of our code, or does it have to be at the end? \$\endgroup\$ Commented Jan 23, 2023 at 15:43
  • \$\begingroup\$ @Jacob Full program(actually snippet). Must be at the end otherwise it turns into binary converting \$\endgroup\$
    – l4m2
    Commented Jan 23, 2023 at 16:18
2
\$\begingroup\$

Output a random value from the last 16 values outputted

Output the numbers 1-16 (or any other set of 16 distinct items). Then, repeatedly, output a random value chosen uniformly from the last 16 items outputted.

After the same item is printed 16 times in a row or more, halt.

\$\endgroup\$
2
\$\begingroup\$

Roll a painted cube

\$\endgroup\$
2
  • \$\begingroup\$ May we map the directions to values 1-4 (or 0-3)? May we map the colors to values 1-6 (or 0-5)? \$\endgroup\$
    – pajonk
    Commented Dec 12, 2022 at 5:24
  • \$\begingroup\$ Yes, that would be fine also \$\endgroup\$
    – mousetail
    Commented Dec 12, 2022 at 6:20
2
\$\begingroup\$

Avoid the hole

xkcd

Given a continuous black-box function as a input, output a different continuous, differentiable function that never enters the box \$ 1.5 \leq x \leq 2 \wedge 1 \leq y \leq 1.5 \$. Your output must exactly match the input function when \$ x \leq 0 \vee 3 \leq x \$.

The output must be continuous. You may assume the input function is continous, and defined over all \$ \mathbb{R} \$. The function you output must also be defined over all \$ \mathbb{R} \$. Both functions must also be differentiable, meaning their derivative is defined everywhere.

You may optionally take the derivative of the input function as a second input.

You may assume your languages float type has infinite precision and all operations on it are exact.

\$\endgroup\$
9
  • \$\begingroup\$ An issue you are going to run into is that it's basically impossible (mathematically impossible not just really hard) to anything non-trivial with arbitrary real numbers. For example it is very easily undecidable whether the input even passes through the box. This is because an arbitrary real number takes up an infinite amount of memory, so any program that deals with them has to be able to treat them like streams of digits. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Feb 8, 2023 at 20:47
  • \$\begingroup\$ Yes, so for the width of the box the output of the original function would need to be entirely ignored, as like you say you don't know about any weired outlier that could happen in that area. In the space around the edges of the box, where this doesn't really matter, you would need to create some kind of interpolation function. \$\endgroup\$
    – mousetail
    Commented Feb 8, 2023 at 20:49
  • \$\begingroup\$ There is actually a really simple solution of just creating 2 cubic beziers around the edges of each box \$\endgroup\$
    – mousetail
    Commented Feb 8, 2023 at 20:50
  • \$\begingroup\$ I'm not sure if that "simple" solution is actually possible, for two reasons 1) Doing even basic math with arbitrary reals tends to be undecidable (addition is undecidable for example) 2) determining the derivative of a black box function is like super impossible, even with some pretty hefty assumptions. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Feb 8, 2023 at 20:54
  • 1
    \$\begingroup\$ I agree. This might be do-able if you limit it from a black-box function to a Polynomial with known values instead, although that may make it trivial \$\endgroup\$
    – ATaco
    Commented Feb 8, 2023 at 21:00
  • \$\begingroup\$ @WheatWizard that's why you can take the derivative as a second input \$\endgroup\$
    – mousetail
    Commented Feb 9, 2023 at 5:16
  • \$\begingroup\$ Also your solution just needs to theoretically work, ignoring numerical limits like always \$\endgroup\$
    – mousetail
    Commented Feb 9, 2023 at 5:20
  • 1
    \$\begingroup\$ Hole on your picture displaces with your word \$\endgroup\$
    – l4m2
    Commented Feb 10, 2023 at 8:28
  • \$\begingroup\$ @l4m2 sorry what do you mean? \$\endgroup\$
    – mousetail
    Commented Feb 10, 2023 at 8:29
2
\$\begingroup\$

Time to shortest transposition

\$\endgroup\$
7
  • \$\begingroup\$ Is the answer 13:14? \$\endgroup\$
    – Seggan
    Commented Feb 9, 2023 at 16:18
  • 1
    \$\begingroup\$ Why 14:21 not 413? \$\endgroup\$
    – l4m2
    Commented Feb 9, 2023 at 17:36
  • \$\begingroup\$ Once you fix that, suggested test case: 23:41 -> Nil \$\endgroup\$
    – The Thonnu
    Commented Feb 9, 2023 at 18:51
  • 1
    \$\begingroup\$ 413 is not a valid 24-hour string. Note that when you shift around the numbers, you must pick the time string that comes after the input and is a valid 24-hour string \$\endgroup\$ Commented Feb 10, 2023 at 2:31
  • \$\begingroup\$ In this case, the transpositions are 12:41, 11:24, 11:42, and 14:12. Since all of these come before 14:21 , they cannot be picked. \$\endgroup\$ Commented Feb 10, 2023 at 2:32
  • \$\begingroup\$ So the time must be in the same day? \$\endgroup\$
    – mousetail
    Commented Feb 10, 2023 at 8:21
  • \$\begingroup\$ Technically, yes. \$\endgroup\$ Commented Feb 10, 2023 at 8:31
2
\$\begingroup\$

Generate an emoticon

\$\endgroup\$
2
\$\begingroup\$

Ptolemy's table of chords

\$\endgroup\$
1
2
\$\begingroup\$

Print all pandigital numbers

\$\endgroup\$
2
\$\begingroup\$

Split some points

\$\endgroup\$
2
\$\begingroup\$

Primes with Distinct Prime Digits

\$\endgroup\$
7
  • \$\begingroup\$ This challenge seems a bit boring, also please use the default sequence rules \$\endgroup\$ Commented Feb 12, 2023 at 0:55
  • \$\begingroup\$ @Jacob I thought I did follow the default sequence rules. Also, could you clarify what exactly makes the challenge boring? \$\endgroup\$
    – Bob th
    Commented Feb 13, 2023 at 2:34
  • \$\begingroup\$ The default sequence rules state that the submission may either output the nth term, the first n terms, or the entire sequence. I changed my mind about the challenge being boring, there are likely a few interesting ways to solve this \$\endgroup\$ Commented Feb 13, 2023 at 2:46
  • 1
    \$\begingroup\$ @Jacob Oh, I see, I misread the sequence page; it says the answers may use "one of the following", not "any of the following", so I got confused. Thanks for pointing that out \$\endgroup\$
    – Bob th
    Commented Feb 13, 2023 at 2:50
  • \$\begingroup\$ Is infinite loop allowed if choosing to output whole sequence, like other sequence? \$\endgroup\$
    – l4m2
    Commented Feb 14, 2023 at 4:57
  • \$\begingroup\$ @l4m2 it's not an infinite sequence, though. Could you elaborate on what would be printed in an infinite loop? \$\endgroup\$
    – Bob th
    Commented Feb 14, 2023 at 19:25
  • \$\begingroup\$ Print nothing lol \$\endgroup\$
    – l4m2
    Commented Feb 15, 2023 at 0:25
2
\$\begingroup\$

Generate a permutation from the high-water marks

\$\endgroup\$
2
\$\begingroup\$

Convert imperative code to functional

The imperative language

We'll consider 2 very simple languages, first a imperative one. The imperative language is a list of statements. Statements can be one of these 4 expressions:

[literal] // a literal
[variable] // a variable
([expression] # [expression]) // Some arbitrary operator
([expression] $ [expression]) // Some different arbitrary operator

Or one of these 3 statements:

[variable] = [expression] // assignment
while [expression] { [statement]* } // looping
if [expression] { [statement] } // condition

The last line is guaranteed to be a expression and it's value is the output of the entire program.

Note: Syntax isn't important here. You can take input as any arbitrary tree like structure. There is also no fixed format for variables, you can use any arbitrary infinite series to represent variables, and the same for literals. As long as all 6 values are distinct, you are good to go.

For example, take this code:

a=(5 # 2)
a=(a $ 7)
8 # a

This program would output 8. You could represent this like this:

[
    {op:'=', left:0, right:{op:'#',left:5,right:2},
    {op:'=', left:0, right:{op:'$',left:{op:'var',var:0},right:7},
    {op:'#',left:8,right:{op:'var',var:0}}
]

Or even more concisely [[4,0,[2,[0,5],[0,2]]],[4,0,[3,[1,0],[0,7]]],[2,[0,8],[1,0]]]. Where the first number represents the index of the expression type and the rest the arguments.

The operators are guarenteed to be saf

The functional language

The functional language has the following builtins:

[literal]         // a literal
[variable]        // a variable
(# [expr] [expr]) // one arbitrary operation, you don't need to worry about what it does
($ [expr] [expr]) // another arbitrary operation
(? [expr] [expr] [expr]) // if expression is truthy, return the first expression, otherwise the second
(lambda [variable]* [expr]) // define a function
([expr] [expr]*) // call a function with the given arguments

Again, you can use any built in tree-like structure to represent this, and use any data type with a potentially infinite number of items to represent variables and literals.

Your task

Your task is to convert some code in the imperative language to the functional equivalent. For example:

a=12
b=15
if b # a {
   b = b $ 12
}
c=(a # 12) $ (a # 18)
while a $ (a # b) {
    a = a # (c $ b)
}
a

Could be converted to:

(
   (lambda a:
       (lambda b:
           (lambda b:
                (lambda c:
                    (lambda y:
                        (
                            y,
                            lambda q: (
                                  lambda a: (
                                       lambda a: a,
                                       (? ($ a ($ a b)) (q (# a ($ c b)))) a)
                                  )
                            ), a)
                        )
                    ),
                    lambda a: (a a)
                ),
                ($ (# a 12) (# b 18))
           ),
           ((? (# b a) ($ b 12) b)
       ),
       15
   )),
   12
)

This is code golf, shortest code wins. Size of the output is irrelevant, specifically you can just repeat the y combinator every loop.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ Could you explain in the challenge how to convert imperative to functional? In addition, a worked out simple example would be helpful. \$\endgroup\$
    – pajonk
    Commented Mar 10, 2023 at 7:43
1
44 45
46
47 48
157

You must log in to answer this question.

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