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

4830 Answers 4830

1
38 39
40
41 42
161
2
\$\begingroup\$

Middle-Square RNG: What Number Came Before? (WIP)

A well-known, but statistically poor, way of generating random numbers is to square the number and take the middle digits (when expressed in base 10)

Your task is to take a 4-digit number as input and output any 4-digit number that produces the input number (there may be more than one, which is one of the statistical flaws of this method) when applying middle-square. If the square has an odd number of digits, take an extra digit off the left side.

If there is no such number (some numbers with this method have no predecessor- yet another statistical flaw), indicate that clearly in a way that cannot be mistaken as a valid answer. Some possible ways of indicating this:

  • Output nothing
  • Output null/None/nil/false
  • Output an empty list
  • Output a negative number
  • Output an error message that is clearly not a 4-digit number
  • Throw an exception
  • Crash
  • Exit with a nonzero status

\$\endgroup\$
2
  • \$\begingroup\$ Is there a theoretical guarantee that any number if attainable? (i.e. is there always a solution?) \$\endgroup\$ Commented Nov 23, 2020 at 8:21
  • \$\begingroup\$ @RobinRyder no. Some numbers have no predecessor. \$\endgroup\$
    – Beefster
    Commented Nov 30, 2020 at 21:11
2
\$\begingroup\$

Operational countdown

  • Posted.
\$\endgroup\$
2
  • \$\begingroup\$ How to handle floating point imprecision in this given that your doing floating point division and roots then checking to see if those are integers? I cooked up a solution in Perl that is off by 1 on several of your examples because as it gets near 1, the subtraction ends in .999999...... \$\endgroup\$
    – Xcali
    Commented Dec 3, 2020 at 4:15
  • \$\begingroup\$ @Xcali it's a trivial part of the challenge, this kind of problem is common to many languages, anyway I think that Perl, like most of languages, can handle integer numbers properly. \$\endgroup\$
    – AZTECCO
    Commented Dec 3, 2020 at 5:11
2
\$\begingroup\$

A Snake, A Camel And A Kebab.

As many of you will know, almost every programming language has a standard casing system; unfortunately, we have not been able to agree on a singular system to use and now must frequently switch between camelCase, snake_case and kebab-case.

Now I know what you're thinking... wouldn't it be nice if we had a program that could convert from one casing to another?
Well - soon we're going to have plenty!!! (This is where you come in)

Challenge

You're job is to write a program/function that will take an input string, and a casing system. It will then print/return the converted string.

Inputs:

You're program will receive two inputs, an alphabetic string that is to be converted and a string that will always be one of kebab camel or snake.

Outputs:

You're program should output a string that conforms to the new casing if it is possible. If the input string was invalid, and had mixed casing, you're program should print/do nothing.

Test Cases:

Valid Examples:
"aJavaVariable", "snake" = "a_java_variable"
"a_python_variable", "kebab" = "a-python-variable"
"golf", "camel" = "golf"
"", "snake" = ""
"doHTMLRequest", "kebab" = "do-h-t-m-l-request"

Invalid Examples (no output):
"an_InvalidName", "kebab"
"invalid-inPut_bad", "camel"

Additional Info:

  • As most programming languages prefer lowercase variable names, you should convert all letters to lowercase unless it is needed to be upper case for camel casing.

Meta

  • Is this a duplicate? I couldn't find any quite like it.
  • Are the rules clear?
  • Would it lead to more creative answers if I remove the possibility of being given invalid input, and assume all input will be valid?
\$\endgroup\$
4
  • 3
    \$\begingroup\$ I think you should remove the invalid input handling, as it might only increase the code length.. \$\endgroup\$
    – vrintle
    Commented Dec 14, 2020 at 3:41
  • \$\begingroup\$ Very very similar to this,, except there's an extra casing requirement. \$\endgroup\$
    – Razetime
    Commented Dec 14, 2020 at 3:45
  • 1
    \$\begingroup\$ @Razetime Good find. I think that although the premise of the question is very similar, the difference in triggering which case to convert to, will lead to very different code logic. \$\endgroup\$
    – Scott
    Commented Dec 14, 2020 at 20:23
  • \$\begingroup\$ Suggested expansion: PascalCase \$\endgroup\$
    – Beefster
    Commented Dec 14, 2020 at 23:47
2
\$\begingroup\$

How Many Atoms?

Post

\$\endgroup\$
3
  • 1
    \$\begingroup\$ So we don't need to handle (Ne(St(Ed_2)_3)_4)_5 formulas? \$\endgroup\$
    – Bubbler
    Commented Dec 17, 2020 at 7:26
  • \$\begingroup\$ @Bubbler adding that in as a test case \$\endgroup\$
    – bigyihsuan
    Commented Dec 17, 2020 at 16:01
  • \$\begingroup\$ Looks like your test cases have some typos. H_20 should have an answer of 20, or the 0 should be an O. Also, the third to last has an _ after a number (C_21_H...), which doesn't seem right. In general, though, if the goal here is just to count the atoms, and not to check the validity of a formula, I find that the BNF and the list of elements is unnecessary and confusing to the task at hand. It seems like the challenge is going to be about validating a formula and then it becomes something completely different. \$\endgroup\$
    – Xcali
    Commented Dec 18, 2020 at 18:44
2
\$\begingroup\$

Based Palindromes

\$\endgroup\$
6
  • \$\begingroup\$ “All integer base 10 numbers below 1000” would include negative numbers. Based on your test cases, you should clarify that you mean non-negative or positive numbers. Also, wouldn’t 0 be a palindrome in any base? Why is it excluded from the base 2 test case? \$\endgroup\$ Commented Dec 24, 2020 at 23:22
  • \$\begingroup\$ @water_ghosts alright, i've edited the problem to show that it's only from 0-1000 inclusive, as well as added 0 to the output for base 2. \$\endgroup\$
    – Gio D
    Commented Dec 25, 2020 at 0:04
  • \$\begingroup\$ This title is a downgrade from "Based Palindromes" \$\endgroup\$
    – Razetime
    Commented Dec 25, 2020 at 3:15
  • 1
    \$\begingroup\$ @Razetime haha, i didn't know whether "based palindromes" made it clear what the challenge was and so i changed it. I've changed it back, though. \$\endgroup\$
    – Gio D
    Commented Dec 25, 2020 at 3:31
  • \$\begingroup\$ Related. This is a simpler challenge than most of the other challenges that ask for palindromes in multiple bases, so I think it's fine. \$\endgroup\$
    – Razetime
    Commented Dec 25, 2020 at 3:47
  • \$\begingroup\$ Now that this has been posted, I've edited it down to save space \$\endgroup\$ Commented Dec 27, 2020 at 22:12
2
\$\begingroup\$

Partial sums of the kempner series

Posted

\$\endgroup\$
2
  • \$\begingroup\$ Can we output rational numbers (or numerator/denominator pairs) instead of floats? \$\endgroup\$
    – Dingus
    Commented Dec 31, 2020 at 13:41
  • \$\begingroup\$ @Dingus , yes according to the Default I/O methods. Do you think I should specify this in the challenge? \$\endgroup\$ Commented Dec 31, 2020 at 14:14
2
\$\begingroup\$

Eye test - How many squares are in this picture?

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

Run the lottery

Rules

Your job is to write a program to accept lottery tickets, adding all the money to a pool, and divvy out the winnings based on how many numbers each ticket has guessed correctly. The amount of money people spent on their tickets is used to determine how much each person should take home.

  1. You will receive a list of lottery tickets, which will be how much the person has paid, along with 5 numbers between 1 and 25. The numbers do not have to be unique, and order matters. [1, 2, 3, 4, 5] and [3, 2, 1, 4, 5] are considered different, and [1, 1, 1, 1, 1] is a valid ticket.
  2. You will also receive 5 numbers between 1 and 25, which are the winning numbers. This follows the same restrictions as a participant's ticket.
  3. Each participant will be given a "score" based on how many numbers they guessed correctly. They must guess the number, and guess it in the correct spot as well. [x, x, 1, x, x] is not a winning number for [1, 2, 3, 4, 5]. [1, 1, 1, 2, 3] counts as 2 correct guesses for [1, 2, 1, 1, 1].
  4. The score is \$4^n\$ where \$n\$ is the number of winning numbers. Yes, a participant with 0 correct numbers has a score of 1, and is eligible to take home some money.
  5. Each participant's final weight is their score times the amount they spent on the ticket. A person with a score of 4 (1 correct guess) and paid $4 for a ticket has the same weight as a person with a score of 16 (2 correct guesses) and paid $1 for their ticket.
  6. Finally, the prize pool is then divvied up. 10% goes to you, the lottery company. The remaining 90% gets divvied up proportionally by each participant's final weight, rounded to the cent.

The input and output of the program can be in any format. The only stipulation is that monetary values must be decimals. For instance, $15.68 cannot be represented as 1568.

Example game

The winning numbers are as follows

  • [2, 18, 1, 15, 7]

Four people bought tickets with the following prices and numbers

  • $6, [9, 5, 6, 15, 22], one match, score of 4, weight of 24
  • $2, [2, 25, 17, 7, 7], two matches, score of 16, weight of 32. Notice how only the second 7 counts, order matters
  • $67, [11, 16, 9, 20, 16], no matches, score of 1, weight of 67
  • $1, [12, 19, 6, 25, 2], no matches because the 2 is in the wrong spot, score of 1, weight of 1

The total pool is $76, $68.4 after we take our cut, which is then sent out based on the weights. The sum of all weights is 124.

  • First ticket gets 24/124, $13.24
  • Second ticket gets 32/124, $17.65
  • Third ticket gets 67/124, $36.96
  • Fourth ticket gets 1/124, a whole 55 cents
\$\endgroup\$
3
  • \$\begingroup\$ I think you should explain that the winning numbers are not necessarily distinct in rule 2, instead of leaving it until the examples. Likewise, you should state the 'order matters' rule earlier. \$\endgroup\$
    – Dingus
    Commented Jan 12, 2021 at 11:57
  • 1
    \$\begingroup\$ @Dingus I added those clarifications to rules 1-3. Thoughts? \$\endgroup\$
    – Daffy
    Commented Jan 15, 2021 at 23:46
  • \$\begingroup\$ Looks good to me. \$\endgroup\$
    – Dingus
    Commented Jan 16, 2021 at 5:02
2
\$\begingroup\$

Is each bracket matched?

Given a string consisting only of the characters ()[]{}, determine if each type of bracket is matched--that is, every ( corresponds to one later ), every [ corresponds to one later ], and every { corresponds to one later } (and vice-versa).

Pairs are allowed to overlap: ([)] is just as valid as ([]).

Output one consistent value for one classification and anything else for the other, or following your language's truthiness semantics (inverted if you want).

Test cases:

Matched:

()
[]
{}
()[]{}
()()([])
{[][}]
{{{}}}
([{}]){([]})
[(()())(((())))(]()(()))

Not matched:

(
]
{{}
[)
(()())((((()))))(()()(())(())))
{}{}{)
[())[])]
)(

Meta

  • Does this admit a variety of interesting solutions?
  • Would it be better to add <> as a bracket type? Have fewer bracket types? Arbitrarily many?
  • I'm writing this up entirely because I'm surprised it hasn't been asked yet, so although I have looked, this might still be a duplicate.
  • Although I don't think it's necessarily unclear, I feel like the specification could be worded better.
\$\endgroup\$
2
2
\$\begingroup\$

Count strictly overlapping substrings

Posted

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Is it correct that 1 is never a valid result? \$\endgroup\$
    – Adám
    Commented Jan 28, 2021 at 17:04
  • \$\begingroup\$ @Adám yes; do you think I should add that? \$\endgroup\$
    – pxeger
    Commented Jan 28, 2021 at 17:04
  • \$\begingroup\$ Probably a good idea. \$\endgroup\$
    – Adám
    Commented Jan 28, 2021 at 17:05
  • \$\begingroup\$ You need test cases with longer bs that can overlap themselves in multiple ways. \$\endgroup\$
    – Adám
    Commented Jan 28, 2021 at 17:27
2
\$\begingroup\$

Pad a jagged array to be square

Posted

\$\endgroup\$
11
  • \$\begingroup\$ Add a test case for pad value -1 or something like that. \$\endgroup\$
    – user202729
    Commented Feb 12, 2021 at 14:55
  • \$\begingroup\$ Can any dimension of the input array be 0? [please review other sandbox posts] \$\endgroup\$
    – user202729
    Commented Feb 12, 2021 at 14:56
  • \$\begingroup\$ Also add a test case with an array consisting of only fill values. \$\endgroup\$
    – user202729
    Commented Feb 12, 2021 at 14:58
  • \$\begingroup\$ @user202729 what do you mean by "[please review other sandbox posts]"? I don't see the need for a test case with pad value -1, because the type of the elements in the array is answer-defined. I'll clarify the other two though \$\endgroup\$
    – pxeger
    Commented Feb 12, 2021 at 16:22
  • \$\begingroup\$ I suggest that you specify more clearly what input formats are allowed, that is, what counts as an "array". For example, is it acceptable to take lines of text with space as separator within each line? Or use two types of brackets, such as {[1, 5, 3], [4, 5], [1, 2, 2, 5]}? \$\endgroup\$
    – Luis Mendo
    Commented Feb 12, 2021 at 18:31
  • \$\begingroup\$ @LuisMendo input should be taken in your language's natural representation of nested arrays. If it doesn't have a builtin array representation, then take it in some kind of text representation like I mentioned in the rules section \$\endgroup\$
    – pxeger
    Commented Feb 12, 2021 at 18:49
  • \$\begingroup\$ The problem with saying "natural representation" is that a language may have more than one way of representing nested tuples. That said, I think what you have in the question is alright - perhaps to clarify what Luis is talking about you could add: "input can be any unambiguous representation of a jagged array"? I think what Luis may be getting at is that there could be a problem with e.g. a Python array contains meta-information (the length) while a C array wouldn't, but usually I think that is left out. \$\endgroup\$ Commented Feb 12, 2021 at 19:26
  • \$\begingroup\$ To explain my point better: MATLAB (or MATL) can use curly braces for arbitrary arrays, and square brackets for rectangular arrays. So either {{1, 5, 3}, {4, 5}, {1, 2, 2, 5}} or {[1, 5, 3], [4, 5], [1, 2, 2, 5]} could be used as input. The latter is probably better to reduce code length. Can we just choose the most convenient one? What is the limit where choosing a convenient format counts as "pre-processing" the input and is not allowed? All this is language-dependent, but some general specification would be needed \$\endgroup\$
    – Luis Mendo
    Commented Feb 12, 2021 at 19:33
  • \$\begingroup\$ @pxeger Something that I tend to add to my sandbox review comments recently, hoping to reduce the problem of the sandbox posts not being reviewed enough. \$\endgroup\$
    – user202729
    Commented Feb 13, 2021 at 2:37
  • 1
    \$\begingroup\$ @LuisMendo You can probably choose any convenient one (I think that's the common consensus?) \$\endgroup\$
    – user202729
    Commented Feb 13, 2021 at 2:38
  • \$\begingroup\$ The "-1" thing is just to make people notice that the value to be padded is an input rather than hard coded by the code. \$\endgroup\$
    – user202729
    Commented Feb 13, 2021 at 2:46
2
\$\begingroup\$

Snail word

Very similar to other challenges

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

Reconstruct an integer from its prime exponents

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

Draw four colorful quarter circles

The challenge is to reproduce this image in your favorite language:

enter image description here

  • Your image must be at least 400 by 400 pixels.
  • The fill colors don't need to be the same as in the image but they must be different from each other.
  • You must include the outlines but they can be any visible thickness you choose.
  • The quarters should be at the same orientation as in the image.
  • Your image must have four quarter circles aligned as in the image which each touch the edge of the circle at a point.
  • Your code must take input which specifies the location, in pixels, of the point where the quarter-circles meet; you can take this input in any reasonable format, but the units must be pixels (no relative units, such as a fraction of the width/height of the image). You can assume these inputs are always within the bounds of the outer circle. You can also assume that the inputs are such that all four quarter circles can be drawn within the circle.

Here is some LaTeX code as an example:

\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{calc,through}

\usetikzlibrary{intersections}


\begin{document}
\begin{tikzpicture}[inner sep=0pt, outer sep=0pt]

  \coordinate (point) at (-0.1,0.4);

  \draw [name path=mycirc] (0,0) circle [radius=1];
  \path [name path=di-1] (point) -- ++(-2,2);
  \path [name path=di-2] (point) -- ++(-2,-2);
  \path [name path=di-3] (point) -- ++(2,-2);
  \path [name path=di-4] (point) -- ++(2,2);
  
  \foreach \col [count=\i] in {yellow,red,blue,brown}{
  
      \fill [red, name intersections={of=mycirc and di-\i}] (intersection-1) circle [radius=0.05] node (inter-\i) {};
      
      \fill[\col,draw=black,rotate around={(\i+3)*90:(point)}] (point)
        let \p1 = ($(point) - (inter-\i)$) in 
        arc [start angle=0, end angle=90, radius={0.707*veclen(\x1,\y1)}]
        -- +(270:{0.707*veclen(\x1,\y1)}) -- cycle ; 
  }
  
  \fill[red] (point) circle [radius=0.05];
   
\end{tikzpicture}
\end{document} 

[I would love help on how to improve this challenge.]

\$\endgroup\$
7
  • 4
    \$\begingroup\$ Describing the exact ratios of the shapes would be helpful in drawing them \$\endgroup\$
    – user
    Commented Mar 5, 2021 at 15:34
  • 2
    \$\begingroup\$ Those are quarter-circles, not semicircles \$\endgroup\$
    – pxeger
    Commented Mar 5, 2021 at 15:46
  • \$\begingroup\$ Might be more interesting if the center of the shape (where the petals meet) was an input \$\endgroup\$ Commented Mar 5, 2021 at 15:54
  • \$\begingroup\$ @pxeger ahem.. thanks :) \$\endgroup\$
    – user7467
    Commented Mar 5, 2021 at 15:57
  • \$\begingroup\$ @ZaelinGoodman Could you say exactly how that could be specified? \$\endgroup\$
    – user7467
    Commented Mar 5, 2021 at 15:59
  • 2
    \$\begingroup\$ @Anush Since the image is 300 x 300 pixels, you could say something like you must take input which specifies the location, in pixels, of the point where the quarter-circles meet; you can take this input in any reasonable format, but the units must be pixels (no relative units, such as a fraction of the width/height of the image). You can assume these inputs are always within the bounds of the outer circle. \$\endgroup\$ Commented Mar 5, 2021 at 16:03
  • 1
    \$\begingroup\$ "Your image must be at least 400 by 400 pixels" what about vector graphics? If some one choice to output the image with vector graphics format. How to define its width and height? \$\endgroup\$
    – tsh
    Commented Mar 9, 2021 at 5:51
2
\$\begingroup\$

Gray code... Gray code?

Your Task

Your task is to print (in an easily readable and consistent format) the binary representations of the numbers 0-255 in some order such that only one bit is altered between two consecutive numbers.

Your Restrictions

Each successive byte of the source code after the first can only change one bit from the previous byte.

Other Information

Example valid code (in utf-8): q1!#c. Here, q (01110001) and 1 (00110001) are different in only one bit, and so on

Example invalid codes (in utf-8): Q1!, "!"

Example valid outputs (seperated by an empty line):

10101010 10101011 11101011 ... 01010101

[10, 11, 1011, 1111, 1110, ...]

10
0
1
11
111
...

Example invalid outputs (seperated by an empty line):

0000000100000011000000100000000000000100...

0
01
10
11
100
...

0 1 ... 100000000 110000000 ... 11111111

00 01 11 10 0100 0101 ...

0 1 3 2 5 6 ...

Notes:

  • A character can be stored as two bytes, but the bytes must differ by only one bit
  • If your interpreter ignores a character (like Whitespace ignores almost all characters) it cannot be used
\$\endgroup\$
10
  • \$\begingroup\$ Is printing 1 3 2 6 7 5 4 and onwards ok? \$\endgroup\$
    – PkmnQ
    Commented Feb 28, 2021 at 4:36
  • 1
    \$\begingroup\$ What does "some form of gray code" mean exactly? / Clarify that the restriction part applies to the source code of the program. \$\endgroup\$
    – user202729
    Commented Feb 28, 2021 at 6:49
  • 1
    \$\begingroup\$ I'll change it to binary gray code to avoid confusion. \$\endgroup\$
    – Hyperbole
    Commented Feb 28, 2021 at 15:55
  • \$\begingroup\$ You should describe what the gray code is to avoid ambiguities. \$\endgroup\$ Commented Feb 28, 2021 at 21:49
  • \$\begingroup\$ Do you think this challenge is too hard? \$\endgroup\$
    – Hyperbole
    Commented Mar 2, 2021 at 15:01
  • \$\begingroup\$ Is it okay if the output is printed in decimal instead of binary? \$\endgroup\$
    – user202729
    Commented Mar 3, 2021 at 13:20
  • \$\begingroup\$ Perhaps add "addition of leading zeroes doesn't count as a change" and some examples to illustrate/example valid output (just for challenge accessibility, this is implied from the definition (and the Wikipedia page)) \$\endgroup\$
    – user202729
    Commented Mar 3, 2021 at 13:21
  • 1
    \$\begingroup\$ Would be hard for practical languages, but for everything-are-valid languages it should not be a problem. Good challenge idea. \$\endgroup\$
    – user202729
    Commented Mar 3, 2021 at 13:22
  • \$\begingroup\$ Does the last statement means "Your program should not work by removing any single bytes", or "Any subsequence of your program should not work."? \$\endgroup\$
    – tsh
    Commented Mar 16, 2021 at 11:43
  • \$\begingroup\$ @tsh neither. It means that you can't use a character if it is completely skipped over by the interpreter. For example, in the python code "if len('abc') < 4: print('Hello, World')" the "c" can still be used because it is not skipped over by the interpreter. \$\endgroup\$
    – Hyperbole
    Commented Mar 18, 2021 at 17:29
2
\$\begingroup\$

Subarrays With At Least N Distinct Integers

\$\endgroup\$
5
  • \$\begingroup\$ I don't get it. From 1,2,2,3 you can make 3 subsequences of 2 integers: 12; 22; 23. And the middle one is not made of different integers. So how it comes that "the number of contiguous subsequences that contain at least N distinct integers" is 5 in this case? \$\endgroup\$
    – anotherOne
    Commented Mar 7, 2021 at 11:55
  • 2
    \$\begingroup\$ @Sheik 1,2, 1,2,2, 2,2,3, 2,3, 1,2,2,3 are the subsequences that contain at least 2 distinct integers. In my opinion, there should be a column in the table of test-cases that contains these sub-sequences for clarity. \$\endgroup\$
    – Hyperbole
    Commented Mar 7, 2021 at 17:40
  • \$\begingroup\$ @Hyperbole thank you very much. It wasn't that hard to get but, I don't know, English is not my language. Anyway if not on the test cases, they should be at least in an example before the tests. \$\endgroup\$
    – anotherOne
    Commented Mar 7, 2021 at 18:24
  • 1
    \$\begingroup\$ @Hyperbole I appreciate the feedback. I updated the post with the example. \$\endgroup\$
    – user101295
    Commented Mar 7, 2021 at 18:57
  • 1
    \$\begingroup\$ @SheikYerbouti I have updated the post with the example. \$\endgroup\$
    – user101295
    Commented Mar 7, 2021 at 18:57
2
\$\begingroup\$

Tri tri tribonacci

Tribonacci from Wikipedia:

The tribonacci numbers are like the Fibonacci numbers, but instead of starting with two predetermined terms, the sequence starts with three predetermined terms and each term afterwards is the sum of the preceding three terms.

The challenge

Given three arrays of three integers, for each array:

  1. Find the generator G (the first non-negative integer) of the sequence to which the three numbers belong
  2. Then find the G-th element of the sequence (zero-indexed*)

The three integers found are indeed part of a tribonacci sequence, output the G-th element of that sequence.

*The sequences are zero-indexed because G may be 0 and in that case you have to find the 0th element of the sequence.

Example

Given the input

[[5, 11, 20], [1, 2, 3], [23, 39, 67]]

5 11 20 are part of the sequnce 2 4 5 11 20, which starts with 2, so we take the 2nd element of the sequence: 5

1 2 3 are part of 0 1 0 1 2 3, so we take 0

23 39 67 are part of the sequence 7 11 5 23 39 67 129 235 so we take 235

Now 5 0 235 are part of the sequence 230 5 0 235 so the output is the 230th element of that sequence:

174892031986606286607812889236621806383715371411020300455075910

Input / output

You can take the input as you prefer: an array of three arrays, three arrays, an object, a string, etc.

You are not required to handle integers larger than those implemented by your chosen language, I will post plenty of test cases with smaller output after I make a program for the challenge.

This is , everyone wins.

Meta

Please say something.

\$\endgroup\$
7
  • 2
    \$\begingroup\$ Are you sure you meant to put This is [tag:code-golf], everyone wins.? That's not code golf :p \$\endgroup\$
    – rydwolf
    Commented Mar 8, 2021 at 23:55
  • \$\begingroup\$ Looks fine to me, except for the "zero-indexed" part. 0-indexing and 1-indexing are usually equally allowed. (Also, people might complain about "why not just make it two challenges, one for finding the generator and one for n-th tribonacci") \$\endgroup\$
    – Bubbler
    Commented Mar 9, 2021 at 0:00
  • \$\begingroup\$ @RedwolfPrograms we keep the truth in the sandbox, I will put "the shortest wins" in the challenge \$\endgroup\$
    – anotherOne
    Commented Mar 9, 2021 at 0:00
  • \$\begingroup\$ @Bubbler the zero-indexing is because the sequence may start with 0, and in that case you have to find the 0th element of the sequence. About splitting the challenge, I didn't check but it's possible that one or both of the parts already exist. \$\endgroup\$
    – anotherOne
    Commented Mar 9, 2021 at 0:03
  • 1
    \$\begingroup\$ @SheikYerbouti That makes sense. Then it would be better to include the justification of why it should be 0-indexed in the post. \$\endgroup\$
    – Bubbler
    Commented Mar 9, 2021 at 0:07
  • \$\begingroup\$ @Bubbler I added a note to justify the restriction, thank you for the feedback! \$\endgroup\$
    – anotherOne
    Commented Mar 9, 2021 at 0:15
  • \$\begingroup\$ Maybe "This is code golf, so shortest code wins, but who's counting?" instead of "everyone wins"? \$\endgroup\$
    – Beefster
    Commented Mar 15, 2021 at 15:47
2
\$\begingroup\$

Integer partitions into fixed parts with coprime constraint, and exclusion set

Background

Let \$a\$ \$\in \mathbb{N}\$, \$b\$ \$\in \mathbb{N}\$, \$c\$ \$\in \mathbb{N}\$ and \$S\$ be some subset of \$\{i:1\leq i\leq a\}\$.

Consider \$X(a ,b, c, S)\$: The number of integer partitions of \$a\$ into \$b\$ many parts, where each of the parts are co-prime to \$c\$ and no part is contained within \$S\$.

Formally, for \$b=2\$

$$X(a ,2, c, S) = |\{(x, y): x + y = a,\ gcd(c, x) = gcd(c, y) = 1, x \notin S, y \notin S,\ x \leq\ y\}|$$

Challenge

Codegolf, standard rules apply. Write code to calculate the function \$X(a ,b, c, S)\$ above.

Inputs:

  • \$a\$, an integer. Your function does not need to be correct for \$a \le 2\$.

  • \$b\$, an integer. Your function does not need to be correct for \$b \le 1\$.

  • \$c\$, an integer.

  • \$S\$, can be any set of integers between \$1\$ and \$a\$ (inclusive). The elements of \$S\$ are unique.

Test-cases

Below test cases are written in the following format: \$a, b, c, S =\$ Answer

3, 2, 2, {} = 0
4, 2, 2, {} = 1
4, 2, 3, {2} = 0
7, 3, 5, {} = 3
7, 3, 2, {5} = 1
11, 3, 1, {} = 10
11, 3, 2, {} = 4
11, 3, 3, {5, 7} = 1

BONUS

Brownie points for anyone who can do either of the following:

  1. Disprove the following recursive relationship.
  2. Extend the following recursive relationship (for higher values of \$b\$), and/or write code utilising it.

Recursive formula for \$b = 3\$ (Might be incorrect):

$$X(a ,3, c, S) = \sum_{i=1}^{i=\lfloor\frac{a}{2}\rfloor} {X(a - i, 2, c, T_i)} $$

With

$$T_0 = S$$

and,

$$T_i = T_{i-1}\cup\{i - 1, a + 1 - i\},\ for\ i \geq 1$$

Questions for sandbox

Is this challenge good to go?

\$\endgroup\$
7
  • \$\begingroup\$ you can add tags here via [tag:<tagname>]. \$\endgroup\$
    – Razetime
    Commented Feb 27, 2021 at 8:37
  • \$\begingroup\$ @Razetime , sorry total noob here. In the comment section? or do I edit the post and add the [tag:<tagname>] at the end? \$\endgroup\$ Commented Feb 27, 2021 at 9:30
  • 1
    \$\begingroup\$ in the post. Add it near the title, like in the other posts. \$\endgroup\$
    – Razetime
    Commented Feb 27, 2021 at 9:55
  • \$\begingroup\$ About test cases. It looks like that this challenge doesn't have too many test cases, don't need a lot. \$\endgroup\$
    – user202729
    Commented Feb 27, 2021 at 12:15
  • \$\begingroup\$ I think the info about integer types makes the question harder to read (they all have default rules), so I removed it. \$\endgroup\$
    – user202729
    Commented Feb 27, 2021 at 12:15
  • \$\begingroup\$ The tag doesn't matter too much, as long as there's a code golf tag. // Usually people don't like time limits, but if you insist there's either "solutions must have time complexity that does not exceed (something)" or "you must be able to run the program to completion with the following test cases" or "the program must finish on my machine in X seconds" (requires you running the programs) [please review other sandbox posts] \$\endgroup\$
    – user202729
    Commented Feb 27, 2021 at 12:17
  • \$\begingroup\$ @user202729 Thanks for the edits. Yes I suppose I'm not interested in any time constraints. Rather just interested to see the solutions people can come up with. Yes I will need to make some test cases, will add them when I get a chance. \$\endgroup\$ Commented Feb 27, 2021 at 13:01
2
\$\begingroup\$

Decompress an integer, Jelly style

\$\endgroup\$
1
  • 3
    \$\begingroup\$ Algorithm description looks good. Requiring to handle inputs up to \$2^{64}-1\$ sounds unfair to the languages that do not support that large integers though. I'd prefer something in the line of the 5th bullet under the Rules on this challenge. \$\endgroup\$
    – Bubbler
    Commented Mar 25, 2021 at 0:09
2
\$\begingroup\$

(Σ*)² ⟲ Σ* (aka Round-Trip a String Pair)

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

Unique languages

As we found out before, each of the 680 languages on Try it online! has a "TIO uniqueness", defined as the length of the shortest substring that appeared in the language's name and no others'.

This time, we're going to make it more general. Given a list of strings S and a target T, output the length of the shortest substring of T that is not in any other element of S. You may choose whether T is part of S or not. The elements of S will always be unique. All elements of S, and T, will only contain lowercase letters (abcdefghijklmnopqrstuvwxyz). You may also take input as uppercase if you wish.

Your score will be calculated as code length × TIO uniqueness, where code length is measured in bytes and TIO uniqueness is the TIO uniqueness as specified here. If a language has an undefined TIO uniqueness, it cannot compete in this challenge.

The answer with the lowest score wins.

Meta

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

Check B-powersmoothness - posted

\$\endgroup\$
2
  • \$\begingroup\$ Can you link to the wiki article please. \$\endgroup\$
    – Alex bries
    Commented Mar 29, 2021 at 8:57
  • 1
    \$\begingroup\$ @Alexbries I added a link \$\endgroup\$ Commented Mar 29, 2021 at 9:06
2
\$\begingroup\$

Quoted rational numbers

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

Battery charging tracker

If there are any better titles please post them in the comments


If any more tags might be appropriate, please post them in the comments


The task here is to create a program which can output a battery's percentage at all times. It will be given input in the form of an array of "indications". These dictate when to plug and unplug the charger.

If this sounds confusing, let us take this sample input:

[[12, 23, 34], [15, 28, 67]]

Note: you can take input in the form of a list of strings or a single string if you would like.

The first array indicates the number of seconds to wait before unplugging the charger, and the second one indicates the number of seconds to wait before plugging in the charger. There will never be two coinciding values in one of the arrays or between the arrays. So [[11, 22, 33], [15, 22, 34]] is not valid input and neither is [[1, 2, 3, 3, 6], [15]]. Both arrays are guaranteed to have at least one value in them. Also, all values are positive non-zero integers.

The "battery" we are trying to simulate starts with 0%. When your program runs, the charger is automatically "plugged in", and each second the charge should tick up by 1% if the charger is plugged in, and decrease by 1% if it is not.

Each second, the program should output the amount of charge the battery has. It should not charge beyond 100% and should not go down below 0%; if the battery hits 100% then it will stay there until the charger is unplugged and if it hits 0% it will stay there until the charger is plugged in.

In addition, your program should store a "second counter" containing information on how long the program has been running for. When this counter hits any of the integers in either of the input arrays, the charger will be either unplugged or plugged in depending on which array it was in. It is guaranteed that between two "unplug" events there will be at least one "plug" event and vice versa, and it is also guaranteed that the first event is "unplug".

Whenever the charger is unplugged or plugged, a "U" or "P" should be shown, respectively.

In the case of our sample input, the charger is "unplugged" when the counter reaches twelve, 23 or 34 seconds and is "plugged" when the counter reaches fifteen, 28 or 67 seconds.

What, then, is the output of our example?

1
2
3
4
5
6
7
8
9
10
11
12
U
11
10
9
P
10
11
12
13
14
15
16
17
U
16
15
14
13
12
P
13
14
15
16
17
18
U
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

To be clear, the first zero should not be outputted, the charger is acted on after the corresponding second, meaning that we wait 12 seconds before unplugging the charger; the 12th second does not happen after the charger is unplugged. The program runs for the highest value in the input array, in this case 67.

The question is so the shortest answer in bytes wins. Standard loopholes are not allowed here.

\$\endgroup\$
2
  • \$\begingroup\$ You should clarify that the program does not need to wait 1 second between each output (assuming that is the case). Also, title suggestion: Battery charging tracker or something along those lines? \$\endgroup\$
    – pxeger
    Commented Apr 5, 2021 at 17:17
  • \$\begingroup\$ @pxeger thanks for the suggestion, the program should wait 1s between each output except for the U or P indicators \$\endgroup\$
    – user100690
    Commented Apr 5, 2021 at 17:33
2
\$\begingroup\$

Draw the flag of Bangladesh

,

The flag of Bangladesh is very simple. It looks like below:

enter image description here

The flag will be in bottle green (#006a4e) and rectangular in size in the proportion of length to width of 10:6, with a red circle in near middle. The red circle will have a radius of one-fifth of the length of the flag. This image will help you to understand the proportions properly:

enter image description here

In this Graphical output challenge, you need to draw the flag of Bangladesh like first image. Standard loopholes apply, Shortest code wins.

Resolution cannot be 0px, or echo style answers not supported.

Minimum resolution is 286*176

\$\endgroup\$
8
  • 1
    \$\begingroup\$ I think you need to state a minimum resolution. \$\endgroup\$
    – Adám
    Commented Apr 12, 2021 at 8:28
  • \$\begingroup\$ @Adám what do you mean by minimum resolution? \$\endgroup\$
    – Wasif
    Commented Apr 12, 2021 at 8:29
  • 1
    \$\begingroup\$ If my output is 0px tall, then the width has to be 10×0px÷6=0px wide, and the red circle's diameter has to be 4×0px÷6=0px. Easy; here you go: \$\endgroup\$
    – Adám
    Commented Apr 12, 2021 at 8:31
  • \$\begingroup\$ You should also specify what the colours are and/or if an exact colour match is acceptable. \$\endgroup\$
    – Adám
    Commented Apr 12, 2021 at 8:32
  • \$\begingroup\$ Is ASCII art acceptable? \$\endgroup\$
    – Adám
    Commented Apr 12, 2021 at 8:33
  • \$\begingroup\$ @Adám ascii art is not acceptable, also in place of bottle green (#006a4e) dark green is acceptable, if you have more flaws come to chat \$\endgroup\$
    – Wasif
    Commented Apr 12, 2021 at 8:35
  • \$\begingroup\$ You had specified the color of green background. So what is the color for the circle? \$\endgroup\$
    – tsh
    Commented Apr 13, 2021 at 3:52
  • \$\begingroup\$ @tsh I suppose it is #f42a41 \$\endgroup\$
    – Adám
    Commented Apr 13, 2021 at 7:46
2
\$\begingroup\$

Saboteurs in our Halls

This is a challenge, where one member on each team attempts to sabotage their team in secret.

Similar to Red vs. Blue - Pixel Team Battlebots, bots will be divided into teams, based on the user ID number of the user who posted them. Your user ID can be found by navigating to your profile (click your icon in the top bar) and looking at the URL:

https://codegolf.stackexchange.com/users/[user-id]/[display-name]

For example, my user ID is 66833: https://codegolf.stackexchange.com/users/66833/caird-coinheringaahing

If your ID is an even number, then you are on the Red team.
If your ID is an odd number, then you are on the Blue team.
There is no way to change teams.

As you cannot change your user ID, and to prevent one team flooding the field with bots, each user may only submit one bot


How the KotH will work

At the start of the game, each bot will be placed in a random cell in a \$1000\times1000\$ cell grid. No bot will be placed on the same cell as another bot, or within 5 cells of another bot. Additionally, \$999\$ random cells will be filled with 1 food. These cells may be any cell on the board that doesn't contain a bot.

The aim of the game is to collect food. Each bot will navigate their way around the grid, attempting to gather food. The team with the most food at the end of the game wins.

However, one bot will actually be a saboteur. This bot will appear to be a member of one team, but will instead act in a manner that helps the other team. When writing your bot, you should consider the existing bots on the opposing team and try to write in a sabotage tactic that will help them without being overly obvious.

Let's say that for this specific match, the saboteur is Blue. Their actions should aim to help the Red team win, while not giving themselves away to the Blue team. If either team suspects that bot to be the saboteur, they can then act in a preventative manner towards that bot. If Blue wins, the saboteur has failed, and so will get no points when the rest of Blue does. If Red wins, then the saboteur has succeeded, and thus gets 2 points. No matter which team the saboteur is on, each member of the winning team always gets 1 point.

Which bot is the saboteur is randomly chosen at the start of the game and remains constant until the game ends. There is only ever one saboteur per game.


The game is broken up into turns. Each team acts on alternating turns, so Red moves, then Blue, then Red etc. or the other way around. Each turn, each bot will be passed a list of game data, detailed below, and will return an integer between \$1\$ and \$9\$ inclusive, indicating which direction it would like to move in:

enter image description here

The bot is at \$5\$ before moving.

The bots for each team are called in a random order each turn, but none of them move until they all have returned values.

After all bots in a team have returned their movement choice, all moves happen at the same time. If two bots on the same team attempt to move into the same cell, neither bot moves. If a bot tries to move out of bounds, nothing happens. If a bot moves into a cell with food, it adds that piece of food to the amount it has already gathered. Initially, all bots have gathered \$0\$ food.

If a bot moves into a cell containing an enemy bot, the two bots fight. The winner is determined by which bot has gathered the most food. The winner then "steals" the losers food, adding it to their total gathered food. The loser is then removed from the board and re-placed at a random location not within 5 cells of another bot, and with an initial \$0\$ food again. If both bots have the same amount of food, then both bots are removed and re-placed, and any food they had is randomly placed in empty cells around the board.

After \$10000\$ turns, the game ends. Each team has their total gathered food counted, and the team with the most food wins. The actual competition will have \$100\$ games played. If a team wins a game, each team member receives 1 point. However, if the saboteur's team (the one it's on, not the team it's helping) wins, the saboteur does not get this point. If the saboteur's team loses, the saboteur gains 2 points.

The team with the most total points of all its bots at the end of \$100\$ games wins.

How to answer

You should include in your answer 2 functions: move and sabotage. move is the function that will be called each turn when you aren't the saboteur and sabotage will be called each turn that you are the saboteur.

Both functions will receive the same arguments:

  • x and y. The x and y coordinates of your bot, each an integer between \$0\$ (top-left corner) and \$999\$ (bottom-right corner).
  • food. The current amount of food you are carrying. Initially 0, and changed by the controller for you when necessary.
  • t_near. A list of bots on your team within a square, side length 33 cells, centered on you. Each bot is represented by a list containing their x and y coordinates, the amount of food they're currently carrying, and the CGCC ID of their poster.
  • e_near. A list of bots n the opposing team within a square, side length 33 cells, centered on you. Each bot is represented by a list containing their x and y coordinates, the amount of food they're currently carrying, and the CGCC ID of their poster.
  • f_near. A list of coordinates of all food within a square, side length 33 cells, centered on you. Each food is represented by a pair [x, y] representing it's coordinates
  • team_chat. A list of all chat messages sent between your team.

Messages

In order to allow inter-game cooperation, each team will have a "chat" ability. Each bot will be passed team_chat, an array containing the chat history of that team - i.e. a series of strings saying more-or-less whatever you want. The most recent message will be at the end of the array. Each bot may, on each turn, append up to 3 messages to the chat. Each message must be no longer than 100 characters, and will be prefixed with the ID of the bot who sent it (with a space after the ID).

For example, if a bot with a user ID of 1234 sent Hello, World! to the chat, the message would be 1234 Hello, World!.

Example Submission

This is Joey. Joey isn't too smart, and hasn't got the hang of proper sabotage. If not the saboteur, Joey just hunkers down and waits for the game to end. Otherwise, he moves around the board aimlessly in random directions:

import random

def move(x, y, food, t_near, e_near, f_near, team_chat):
	return 5

def sabotage(x, y, food, t_near, e_near, f_near, team_chat):
	return random.randint(1, 9)

Rules

Any attempted gaming of the rules will lead to a disqualification of your bot. If you break any rules, your bot will be disqualified until it is fixed (if possible).

  • You may only edit your answer within 12 hours of posting to prevent answers that continually optimise against new bots. You may not delete and repost your answer in order to try to circumvent this restriction
  • Your code must not take longer than half a second (give or take a few milliseconds) to return its move
  • You may not attempt to modify the controller or other bots' code; attempt to communicate outside of using the team chats; make web queries; or do anything malicious.

I'll keep an eye out for other unsportsmanlike behaviour, such as stealing code verbatim from other answers or using sock puppets to mess with the other team.

You are welcome to collaborate and scheme with your team, but keep the contest friendly and ethical. We don't need or want this to devolve into anarchy.

You will have 2 weeks from the posting of the challenge to submit bots. After which time, I'll run 100 games with 10000 turns each and determine the winner


Meta

  • Is this clear enough?
  • Is this a duplicate?
  • I'm not sure whether to write this in Python or Javascript. On the one hand, I'm better at Python, but Javascript is more popular/used. Thoughts?
  • Tags are , , . Suggestions?
  • Any further feedback?
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Very nice challenge :) Just one thing: have you considered letting bots know about the food quantity of nearby bots (in t_near and e_near)? I think it could give the saboteur a little more room to do his job (like kamikaze against enemies if they have more food than he does). Otherwise, it seems to me that there aren't many ways for the saboteur to help the enemy team, but maybe I just haven't given it enough thought. \$\endgroup\$
    – Delfad0r
    Commented Apr 11, 2021 at 16:14
  • \$\begingroup\$ Also, do you plan to do anything to prevent unbalanced teams (i.e. teams of different sizes)? It seems to me that having one less teammate is almost as bad as having a saboteur in your team, although this is probably because (as I said above) I still haven't found many effective strategies for the saboteur. \$\endgroup\$
    – Delfad0r
    Commented Apr 11, 2021 at 16:18
  • \$\begingroup\$ @Delfad0r Yeah, that sounds like a good idea, editing in the food suggestion for t_near and e_near. I'm not sure about dealing with unbalanced teams (it seems as though it wasn't a problem with Red vs Blue, which gives some kinda hope) \$\endgroup\$ Commented Apr 11, 2021 at 16:25
2
\$\begingroup\$

The Meeker numbers sequence

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I've edited the draft a bit, mainly "The Challenge" section to be more in line with the standard [sequence] rules (which is what I think you were going for). I've also cleared up some of the wording. Feel free to revert/rollback if you dislike my changes \$\endgroup\$ Commented Apr 11, 2021 at 13:57
2
\$\begingroup\$

R.E.P.A.I.R. T.H.E. K.E.Y.B.O.A.R.D.

\$\endgroup\$
7
  • \$\begingroup\$ This is a very good challenge, apart from one thing - help mode is FAR too overpowered. I could take +, * and h (in Python), and write the password as chr(1+1+1.....) +chr(1+1+1.....) and write all of the characters that way, using multiplication to ease the process. Though, without it, I think this becomes a very interesting challenge, especially for languages like Befunge-98/<><, which would be unable to do as such. An idea would be to ban +/*, or add a penalty for using it, though I'm just throwing ideas around at this point, so take my upvote. \$\endgroup\$ Commented Apr 11, 2021 at 9:37
  • \$\begingroup\$ @StackMeter i reduced help mode to take one key only \$\endgroup\$
    – Wasif
    Commented Apr 11, 2021 at 9:59
  • \$\begingroup\$ Thanks - that should cover any loopholes. \$\endgroup\$ Commented Apr 11, 2021 at 10:27
  • \$\begingroup\$ Are functions/programs allowed to share auxiliary definitions? For instance, if two of my programs need a function for (say) computing the factorial, do I count the bytes of this function once or twice? \$\endgroup\$
    – Delfad0r
    Commented Apr 11, 2021 at 10:52
  • \$\begingroup\$ @Delfad0r you have to write seperate programs for different keys, and so unlike your example you have two use the function twice instead of once, and it will doubled in the byte count. But don't worry its not code golf! \$\endgroup\$
    – Wasif
    Commented Apr 11, 2021 at 11:15
  • \$\begingroup\$ DISALLOW WHITESPACE!!!!!!!!! I cannot stress this enough. \$\endgroup\$
    – emanresu A
    Commented Apr 12, 2021 at 9:34
  • \$\begingroup\$ @Ausername then I'd disallow deadfish~ too \$\endgroup\$
    – Wasif
    Commented Apr 12, 2021 at 9:42
2
\$\begingroup\$

Make it prime with the smallest suffix


Posted

\$\endgroup\$
3
  • \$\begingroup\$ "Your solution must work for the largest integer your language supports" If my language support integers in 0~n. Is this means my program should support all inputs in range 0~n? Or is this means my program should support all inputs when connect it with its output, the result of connection still in 0~n? \$\endgroup\$
    – tsh
    Commented Apr 14, 2021 at 3:07
  • \$\begingroup\$ Java has support to signed 64 bit integers as long type. But Java also have java.math.BigInteger support. By saying "largest integer your language supports", does it means I must working on BigInteger instead of long or int types? \$\endgroup\$
    – tsh
    Commented Apr 14, 2021 at 3:11
  • \$\begingroup\$ @tsh my intent here was that Java users would have to do that, yes. Considering that java isn't that popular of a golfing language to begin with, I'm not really concerned about the insane verbosity that brings. I am, however, considering bringing the cap to \$2^{53}-1\$ since that's the largest odd integer that can be represented with double-precision floats. \$\endgroup\$
    – Beefster
    Commented Apr 14, 2021 at 16:05
2
\$\begingroup\$

Posted

\$\endgroup\$
4
  • 1
    \$\begingroup\$ There's many challenges which have this as a subproblem, but no exact dupe I could find. \$\endgroup\$
    – Razetime
    Commented Apr 12, 2021 at 5:34
  • 2
    \$\begingroup\$ Presumably, code-golf? And add decision-problem array-manipulation \$\endgroup\$
    – pxeger
    Commented Apr 12, 2021 at 6:45
  • 1
    \$\begingroup\$ Heh, lots of solutions to this exact problem were presented at the recent APL conference. \$\endgroup\$
    – Adám
    Commented Apr 12, 2021 at 8:29
  • 3
    \$\begingroup\$ Given how trivial this is, I'd suggest just limiting it to digits 1 to 9, as the overall approach isn't going to change much in list-based languages, but it'll allow string based languages (e.g. Retina) to compete better/easier. Also, as far as I can tell, this is, somehow, not a dupe \$\endgroup\$ Commented Apr 12, 2021 at 13:09
1
38 39
40
41 42
161

You must log in to answer this question.

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