577
\$\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\$ Commented May 29 at 13:27

4833 Answers 4833

1
45 46
47
48 49
162
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\$ 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\$ 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\$ 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\$ 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\$ 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\$ 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\$ 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\$ Commented Feb 9, 2023 at 5:16
  • \$\begingroup\$ Also your solution just needs to theoretically work, ignoring numerical limits like always \$\endgroup\$ 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\$ 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\$ 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
2
\$\begingroup\$

All languages have their strengths, right? (Cops' thread)

This is the cops' thread of a challenge. The robbers' thread can be found [here] (sandbox note: will add the link when posting)

The main idea of this challenge is whether there are languages which are always better than some other ones for .

As a cop, you will choose two languages, and claim that one of them (let's call it A) will always be better for code golf than the other (let's call it B). You post starts as uncracked.

Robbers have two avenues to crack your post:

  • If they think your claim is wrong, they can crack it by giving a code golf task and a solution to it in B.
  • If they think your claim is right, they can crack it by proving it.

If your post was cracked by a counterexample, you can counter the crack by giving a solution in A which is shorter than the given solution in B. This invalidates their crack, and makes your post uncracked once again. Robbers can now attempt to crack it again.

If your post was cracked by a proof you can't counter it (assuming the proof is correct).

Scoring

Each cop gains 1 point for every uncracked post, and loses 1 point for every cracked post. The goal is to get as many points as possible.

Rules

  • Both languages must be freely available.
  • Your claim must not be implied by transitivity from existing uncracked posts.
  • The robbers' tasks must disallow all standard loopholes, and allow all standard I/O methods.
  • The robbers' tasks must only have textual I/O.

All languages have their strengths, right? (Robbers' thread)

This is the robbers' thread of a challenge. The cops' thread can be found [here] (sandbox note: will add the link when posting)

The main idea of this challenge is whether there are languages which are always better than some other ones for .

As a robber, you have two ways to crack a claim:

  • If you think the claim is wrong, you can crack it by giving a code golf task and a solution to it in the language the claim states is worse.
    • This crack can be countered by the cop finding a shorter solution in the language they claim is better.
  • If you think the claim is right, you can crack it by proving it.
    • This crack can't be countered as long as the proof is correct.

Scoring

Each robber gains 1 point for every uncountered robbers post, and loses 1 point for every countered robbers post. The goal is to get as many points as possible.

Rules

Sandbox Questions

Does this format, where a cop claims something, a robber tries to refute/prove it, and the cop tries to defend it, seem interesting? Is it on-topic? What tags are appropriate? I haven't seen it before.

How should I disallow some types of builtins? I want to avoid the challenge turning to "find a builtin the other language doesn't have". In particular, if eval is allowed then the challenge of "Evaluate this language" will almost always be a universal robbers solution. However, I'm not sure how those builtins can be classified.

How should I prevent "output this specific error string" as a universal robbers solution?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I feel this might be too easy when considering languages that are very verbose but also have a very limited set of builtin like shakesphere. I'd suggest cops would need to have a challenge in mind that would crack it, to ensure it's actually possible, then reveal it after some time \$\endgroup\$ Commented Mar 6, 2023 at 11:44
  • 1
    \$\begingroup\$ @mousetail I thought about that, but for a hard challenge the solution for the problem in the two languages will be close in length, so it's quite possible the cop will miss some optimization which turns their proposed counterexample false. Additionally, this changes the challenge from finding pairs of languages with one strictly better to finding pairs of languages with very similar code-golf performances, which while an interesting challenge isn't what I want. I'd prefer to prevent trivial submissions in some other way, for example by allowing a proof of the cop's claim as a crack. \$\endgroup\$ Commented Mar 6, 2023 at 11:59
2
\$\begingroup\$

Generate a Random Integer

Your task is to create a program or function that outputs an integer from \$-\infty\$ to \$+\infty\$ non-deterministically (the output will not always be the same result). Each integer should have a nonzero chance of being outputted.

Rules

  • Please explain what your code does to confirm that it can produce any integer.
  • For the purpose of this challenge, you may ignore your language's number limits for storing an arbitrarily large/small number.
  • Output should be in decimal form.
  • This is , so the shortest answer in bytes wins.
\$\endgroup\$
3
  • \$\begingroup\$ How does "you may ignore number limits" interact with a builtin to produce a random value in the range [INT_MIN, INT_MAX]? \$\endgroup\$
    – Bbrk24
    Commented Mar 10, 2023 at 23:32
  • \$\begingroup\$ @Bbrk24 What I mean is that you would be able to store an arbitrarily large number into a variable or other data structure. \$\endgroup\$
    – Yousername
    Commented Mar 10, 2023 at 23:43
  • 2
    \$\begingroup\$ related, but with stricter probability requirements \$\endgroup\$
    – lyxal
    Commented Mar 10, 2023 at 23:50
2
\$\begingroup\$

Idea:

Given a polyomino shape figure out the minimum number of cuts required to fill it with a herring-bone pattern of 2×1 tiles.

Gylda is a contractor who installs decks. She receives the deck plan from an architect who always chooses it to be shaped as a polyomino, that is a single connected piece cut from a square grid. The deck surface is manufactured in 2×1 rectangular tiles. Gylda installs the tiles in a herringbone pattern because it looks nice, and is stable. However not all shapes can be made perfectly with a herringbone pattern, sometimes Gylda is forced to cut a tile in half. Sometimes Gylda is forced to cut a lot of tiles in half. However how many cuts are needed, depends on exactly where the pattern is placed relative to the boundaries of the deck.

Now Gylda wants to minimize the number of cuts she has to make so she wants a computer program which will take a deck shape and will tell her the minimum number of cuts required. This is the number of cuts, not the number of half pieces used in the final construction. Each cut produces two 1×1 pieces which can both be used.

There is one catch. If a herringbone pattern would produce a layout where two half pieces are adjacent by an edge, Gylda will instead place a single 2×1 tile, even though it breaks the herringbone pattern. For example in the following layout:

 ====||
 ||====
 ||||==

There are two half pieces in the bottom right so instead we would lay out a single whole piece:

====||
||====
||====

This means the 3×3 square polyomino only requires 1 cut, not 2.

Gylda wants the program to take this special rule into account.

Task

Take a polyomino as input in any reasonable format. Output the minimum number of cuts Gylda needs to install that deck.

This is so the goal is to minimize the size of your source code as measured in bytes.

\$\endgroup\$
2
  • \$\begingroup\$ It would be helpful if you could define a herringbone pattern, and highlight the tiles in the example. \$\endgroup\$ Commented Mar 18, 2023 at 7:53
  • \$\begingroup\$ @CommandMaster Yeah, this challenge is unfinished right now, so it's missing a deal of the specification. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Mar 18, 2023 at 15:42
2
\$\begingroup\$

Isolate the binary signals

There are n binary signals, with intervals of 1 through n. For example, for n=3 the lists could be [1], [0, 1], [1, 0, 1]. Each list represents a repeating pattern. So [0,1] is really [0, 1, 0, 1, 0, 1, ...]

The signals all start at the same time, but they are sent over the same channel. So you only know the sum of all the signals at a given time.

Given a list of length at least LCM(1..n) representing the sum of the values at each item of each signal.

If there are multiple possible options, you may output any of them.

Test Cases

List n Expected Result
[1, 3, 1, 2, 2, 2] 3 [1], [0,1], [1,0,1]
[2, 3, 3, 3, 1, 4, 3, 2, 2, 4, 2, 3] 4 [[1], [0, 1], [1, 0, 1], [0, 1, 1, 0]]
\$\endgroup\$
1
  • \$\begingroup\$ Is n part of the input? Or can you output any valid n as long as LCM(1..n) isn't greater than the input length? \$\endgroup\$ Commented Mar 23, 2023 at 8:32
2
\$\begingroup\$

Draw the GKMS aperiodic tile

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

Play Rock Paper Scissors 25

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

Make a Custom Bayer Matrix

\$\endgroup\$
6
  • \$\begingroup\$ I think this part "successive numbers are as distant from each other as possible" needs more precise definition, as it's the main part of the challenge, as I get it. Also, as the input will be only 2,4,8 or 16, there is possibility that some approaches will just hardcode the outputs (no judgment, maybe it's intended). \$\endgroup\$
    – pajonk
    Commented Feb 8, 2023 at 17:16
  • \$\begingroup\$ @pajonk I will try to make that part more clear. Yes, there is the option of hardcoding the output, but I would expect that in most programming languages that would not be the shortest possible answer. \$\endgroup\$
    – Yousername
    Commented Feb 8, 2023 at 22:45
  • \$\begingroup\$ Is [0 3;2 1] valid? \$\endgroup\$
    – l4m2
    Commented Feb 10, 2023 at 9:14
  • \$\begingroup\$ @l4m2 As long as your output format stays consitent with orher inputs, yes. \$\endgroup\$
    – Yousername
    Commented Feb 10, 2023 at 14:07
  • \$\begingroup\$ It's not format, it's order when tie distance \$\endgroup\$
    – l4m2
    Commented Feb 10, 2023 at 20:48
  • \$\begingroup\$ @l4m2 Yes, that is allowed (the third rule). \$\endgroup\$
    – Yousername
    Commented Feb 10, 2023 at 21:10
2
\$\begingroup\$

Selection and Prediction

Your challenge: to select the strings A and B and predict others' selections in an -style .

All entries should be Python 3.10ish META: version? also possibly JS if I have time ._..

Part 1: Selection

You are tasked with selecting the strings A and B as randomly as possible. You are given the previous selections you have made and the guesses your 'opponent' has made. Each input is a string of A and B. For example, 'ABBAB' and 'ABABA' may be arguments passed to your program.

Your program should output either of A or B deterministically, meaning the same input should result in the same output. This means no calling random.choice() or similar, or using the date and time as seeds for a random number generator. META: maybe I should choose the first letter for them, since this constraint results in them always starting with the same letter You may also output a tuple (letter_str, state) and the state will be passed in as a keyword argument next round.

An example entry (this will compete):

Selector: AAAAAA, 3 bytes

Not much to say. This program loves the letter A

def aaaaaa(selections, guesses):
    return "A"

Part 2: Prediction

Your task is to predict the most likely move that your opponent will make. Same input, output and constraints as above.

Another example entry: (this will compete too)

Predictor: Anti-repeater, 3 bytes

Assumes you tend to repeat your previous selection.

def anti_repeater(selections, guesses):
    # It's fine to modify the lists
    return selections.pop()

Part 3: Scoring

Each Selector submission will go against each Predictor submission for a total of 110 rounds. They will select and predict for the first round, then select and predict again, and again, until all rounds have finished.

For each round correctly predicted (excluding the first 10 rounds, since they may be hard to predict) the Predictor submission wins 1 point. For each round incorrectly predicted (also excluding the first 10 rounds) the Selector submission wins 1 point.

The winners are the submissions with the most total points from all Selector and Predictor submissions. Since there are two winners no answer will be accepted.

If you type hint you get 0 extra points. my respect!

(Part 4: meta)

EDIT: added scoring

What do you call a where every cop goes against every robber and vice versa?

EDIT: Change 'key' to 'string' and fix up typo

EDIT: Some other stuff added

\$\endgroup\$
7
  • \$\begingroup\$ How will submissions be scored? \$\endgroup\$ Commented Dec 18, 2022 at 12:06
  • \$\begingroup\$ It's a KOTH - they go against each other \$\endgroup\$
    – W D
    Commented Dec 18, 2022 at 19:56
  • \$\begingroup\$ Who wins the KOTH though? \$\endgroup\$ Commented Dec 18, 2022 at 20:26
  • \$\begingroup\$ forgot that >_< Added now \$\endgroup\$
    – W D
    Commented Dec 19, 2022 at 20:33
  • \$\begingroup\$ Isn't it supposed to be random.choice()? \$\endgroup\$ Commented Dec 20, 2022 at 12:57
  • \$\begingroup\$ Thanks @UndoneStudios don't know how I missed that \$\endgroup\$
    – W D
    Commented Dec 20, 2022 at 23:00
  • \$\begingroup\$ Maybe you can allow seeded random.choice() as it still deterministic . \$\endgroup\$
    – tsh
    Commented Jan 4, 2023 at 3:30
2
\$\begingroup\$

Posted

\$\endgroup\$
2
  • \$\begingroup\$ It's not exactly clear to me which doors are opened by which guards. I see the example of "i, 2, i..." but that doesn't form a clear pattern to me and I'm not sure why i is listed twice. \$\endgroup\$
    – Bbrk24
    Commented Apr 1, 2023 at 15:16
  • \$\begingroup\$ @Bbrk24 Yes, make it more clear! \$\endgroup\$
    – lesobrod
    Commented Apr 1, 2023 at 16:53
2
\$\begingroup\$

Enumeration of free polyominoes

Posted here

\$\endgroup\$
4
  • 2
    \$\begingroup\$ What makes a polyomino "free"? \$\endgroup\$
    – Bbrk24
    Commented Mar 17, 2023 at 18:47
  • 3
    \$\begingroup\$ What is a "rigid transformation"? Is it an isometry, an orientation preserving isometry, a translation, something else ...? \$\endgroup\$
    – Wheat Wizard Mod
    Commented Mar 17, 2023 at 23:16
  • 1
    \$\begingroup\$ @Wheat Wizard hope it's more clear now \$\endgroup\$
    – math scat
    Commented Mar 18, 2023 at 7:55
  • \$\begingroup\$ I suggest listing drawings/ascii art of the polyominoes for the first few n. \$\endgroup\$
    – pajonk
    Commented Mar 19, 2023 at 9:23
2
\$\begingroup\$

Shortest Path Around Obstacle

\$\endgroup\$
1
45 46
47
48 49
162

You must log in to answer this question.

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