569
\$\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\$
0

4560 Answers 4560

1
43 44
45
46 47
152
2
\$\begingroup\$

Change The Quotations as if in Microsoft Word

META: Posted

\$\endgroup\$
6
  • \$\begingroup\$ What to do with consecutive quotation marks? Or this won't ever be an input? \$\endgroup\$
    – pajonk
    Aug 7, 2022 at 15:17
  • \$\begingroup\$ I've added a rule for that. \$\endgroup\$ Aug 8, 2022 at 5:58
  • \$\begingroup\$ What will be the output for ''' and ''''? I other words, what is the precedence of the rules? \$\endgroup\$
    – pajonk
    Aug 8, 2022 at 6:02
  • \$\begingroup\$ I've edited the rule I just added to accommodate these strings. Check it out. \$\endgroup\$ Aug 8, 2022 at 6:08
  • \$\begingroup\$ How come makes a brief appearance in rule 5 and nowhere else? \$\endgroup\$ Aug 8, 2022 at 12:40
  • \$\begingroup\$ Oops, didn't delete that. \$\endgroup\$ Aug 12, 2022 at 7:39
2
\$\begingroup\$

Carry-less sum given a base b

posted

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

Are these numbers from the repeated application of this function?

Given a list of at least 3 positive integers \$L\$ and a function \$F\$ which takes a positive integer and returns a positive integer, determine if \$L\$ can be sorted such that each element of the list is the result of applying \$F\$ to the previous element (besides the first of course).

Rules

  • You may, of course, assume that \$F\$ always halts.
  • You may also assume that \$F\$ will have no side-effects and is deterministic.
  • You may take the \$F\$ as a black box function in any reasonable format.
  • Instead of taking \$F\$ as an input, you may take a second list \$M\$, which is the result of applying \$F\$ to each element of \$L\$.
  • This is , shortest solution in bytes wins.

Very simple worked out example

Inputting \$F(x)=x+1\$ and \$L=[5,4,3,2,1]\$ should output truthy, because \$L\$ can be rearranged into \$[1,2,3,4,5]\$, for which each element is the result of applying \$F\$ to the previous element: \$F(1)=2\$, \$F(2)=3\$, \$F(3)=4\$, and \$F(4)=5\$.

More examples:

Truthy

F(x) = 2x,           L = [4,2,1,8]
F(x) = ceil(10/x),   L = [2,2,2,5,5,5]
F(X) = 3x+1,         L = [5,16,49,148]
F(x) = length(x),    L = [1,2,10,9876543210,1]
F(x) = 13            L = [13,13,13,13,14]

Falsy

F(x) = 2x,           L = [2,4,6,8]
F(x) = ceil(10/x),   L = [5,2,5,2,5,2,5,5]
F(X) = 3x+1,         L = [5,16,8,4,2,1,4]
F(x) = length(x),    L = [3,1,10,2]
F(x) = 13            L = [13,13,13,14,15]

META

Is this ready to post or is it missing something / bad somewhere

\$\endgroup\$
7
  • 1
    \$\begingroup\$ You might want to clarify that black-box functions are allowed .See: 1 2 3 4 \$\endgroup\$
    – naffetS
    Aug 23, 2022 at 23:16
  • \$\begingroup\$ Almost certainly this has very little to do with functional programming (other than the fact that the program should take a function as input). On the other hand, there is a proposed guideline for decision problem outputs. \$\endgroup\$
    – Bubbler
    Aug 24, 2022 at 5:42
  • 1
    \$\begingroup\$ You can refer to these for black box function input methods. Currently the top two are accepted (predefined named functions and function arguments are both OK). \$\endgroup\$
    – Bubbler
    Aug 24, 2022 at 5:47
  • 1
    \$\begingroup\$ Is there a reason the function is part of the input, instead of the input being something like L[i], F(L[i])? \$\endgroup\$ Aug 24, 2022 at 11:32
  • \$\begingroup\$ @CommandMaster Interesting, I suppose that has about the same effect. I will probably edit this to allow both input formats, though I'll have to think about it \$\endgroup\$ Aug 24, 2022 at 12:31
  • \$\begingroup\$ Doesn't that trivialize the task though? It's just checking whether L[1:] == M[:-1] if I understand correctly. \$\endgroup\$
    – naffetS
    Aug 26, 2022 at 1:41
  • \$\begingroup\$ @Steffan you cant assume the order of the elements \$\endgroup\$ Aug 26, 2022 at 1:48
2
\$\begingroup\$

Implement level-index addition

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

This is less of a challenge proposal, and more of a idea for how to mesh the two title tags.

A series of targeted fights

Consider a heads-up, 1v1 "game" between two king-of-the-hill style bots. However, unlike a general king-of-the-hill, where every bot plays against every other bot, we instead build bots that target specific bots to win against. An example of an existing bot would be Low Blow from Cooperative Counting, which aimed to identify it's opponent, then play counter to that bot. However, in this challenge, the bot wouldn't have to identify its opponent: it would only play one bot, the bot it was designed to beat.

The aspect comes from this targeting:

  • User A posts Bot A, targeting a provided example bot.
  • User B then posts Bot B, targeting Bot A.
  • User C then posts Bot C, targeting a second example bot.
  • User D then posts Bot D, also targeting Bot A.

And so on, creating a "tree" of answers, each targeting a previous answer. Note that new answers don't have to target the latest, but can instead target any previous answer.

However, to prevent bots that "target", but don't actual perform well against their target, we'd need to require that it beats its target in \$X\%\$ of \$Y\$ battles, or else it is disqualified. Obviously, this prevents bots from being edited to improve themselves once targeted.

This begs the question: what is our scoring criteria? Clearly, depth from the root bots (provided in the challenge) must be a central part, as it's harder to create a bot the further down the chain you go. However, this doesn't differentiate between Bot B and Bot D in our example, despite the fact that Bot D beats Bot A \$82\%\$ of the time, vs Bot B's meager win rate of \$61\%\$. Clearly, we should take winning rate into account. One potential score:

$$\text{Score} = \text{Win rate} \times \text{Depth}$$

where \$\text{Win rate}\$ is between \$0\$ (never wins) and \$1\$ (always wins).


Thoughts?

\$\endgroup\$
2
  • \$\begingroup\$ I don't know if this is a legitimate concern, but I'd be worried about rock-paper-scissors-like loops where A is always defeated by B, B is always defeated by C, and C is always defeated by A. In that case, it would always be advantageous to post a counter to the most recent post of A/B/C, which means that the score could go to infinity while resulting in very uninteresting bots. You could limit this by saying "no repeat answers", and people probably wouldn't do this in practice because it's boring, but it points to a possible failure mode. \$\endgroup\$ Sep 10, 2022 at 17:53
  • \$\begingroup\$ @97.100.97.109 I don't think that's something to worry about. Ideally, the game would be designed such that, if Bot B beats Bot A the majority of the time, then, if Bot C defeats Bot B, it also must defeat Bot A. For example, in RPS, the "loop" style only occurs by defining the specific win/loss relationship. A 1v1 game with a points based scoring wouldn't encounter such a loop \$\endgroup\$ Sep 10, 2022 at 18:25
2
\$\begingroup\$

write the "index by number" sequence

Imagine writing out positive integer numbers, and indexing each character in a 1-indexed array (indices read vertically on the top two rows, numbers read horizontally on the third):

000000000111111111122222222223333333333444444444
123456789012345678901234567890123456789012345678
one two three four five six seven eight nine ten

Now, imagine if we skipped some numbers so we write the index at the point we start the next number:

000000000111111111122222222223333333333444444444
123456789012345678901234567890123456789012345678
one five ten fourteen twenty three thirty six fo

now, imagine that the first number doesn't have to be "one":

000000000111111111122222222223333333333444444444
123456789012345678901234567890123456789012345678
      seven thirteen twenty two thirty three for

Input

A single number from 1..999, in any format you like ("1", '1', 1, "one" etc.)

This forms the starting number for the sequence

Output

A sequence of numbers, written long-hand in UK English ("one hundred and one" - no other differences), from (input)..(999) inclusive.

Code golf, usual rules.

\$\endgroup\$
9
  • \$\begingroup\$ 101 is "one hundred one" right? \$\endgroup\$ Sep 4, 2022 at 1:36
  • \$\begingroup\$ @thejonymyster one hundred and one \$\endgroup\$ Sep 5, 2022 at 6:33
  • \$\begingroup\$ Maybe you need include how to read number in UK English in your post. \$\endgroup\$
    – tsh
    Sep 9, 2022 at 9:40
  • \$\begingroup\$ @tsh updated to try and clarify \$\endgroup\$ Sep 9, 2022 at 10:15
  • 1
    \$\begingroup\$ 40 is "forty" in all standard English variants. \$\endgroup\$
    – pxeger
    Sep 9, 2022 at 12:14
  • \$\begingroup\$ @pxeger TIL. Corrected in spec. Thanks \$\endgroup\$ Sep 9, 2022 at 13:24
  • \$\begingroup\$ So we go up to the last number that starts before or exactly at 9999 even if it goes beyond 9999 once it's 'written'? 9999 is pretty high, btw. I think the challenge would be just as interesting but much easier to debug/verify with 999 (still high) or even 99 as the upper bound. \$\endgroup\$
    – Arnauld
    Sep 19, 2022 at 20:35
  • \$\begingroup\$ @Arnauld I don't want to end up creating an edge case that needs to be coded separately, so I'm happy to take guidance on how that would work - if the input is 9999 the output would be either nine thousand nine hundred and ninety nine or n (i.e. writing index #9999 then nothing above that) - which is better? Or best left optional? \$\endgroup\$ Sep 20, 2022 at 7:46
  • \$\begingroup\$ @Arnauld aside from that, I'll lower the bounds to 999 \$\endgroup\$ Sep 20, 2022 at 7:46
2
\$\begingroup\$

Generate a different sudoku


Task

Given a valid sudoku board, generate another sudoku board that isn't equivalent to the one inputted.

What do we consider as equivalent sudoku boards?

  • they are the same,
  • the digits are relabeled (eg. 2<->7 or 2->5->8->2),
  • three-column or thee-row bands are permuted,
  • the rows or columns within a band are permuted,
  • one is a reflection of the other (horizontally, vertically or along any of the diagonals),
  • one is a rotation of the other,
  • or any combination of the above.

According to Ed Russell and Frazer Jarvis there are 5 472 730 538 essentially different sudoku classes.

What is a valid sudoku?

(borrowed from here)

  • Each row contains the digits from 1 to 9 exactly once.
  • Each column contains the digits from 1 to 9 exactly once.
  • Each of the nine 3x3 subgrids contains the digits from 1 to 9 exactly once.

Rules

You may take input and output in any reasonable format, like a 9x9 matrix, list of rows/columns, a string of 81 digits etc.

Taking digits 0-8 instead of 1-9 is allowed, but please be consistent.

Test cases

Input:
7 2 5 8 9 3 4 6 1
8 4 1 6 5 7 3 9 2
3 9 6 1 4 2 7 5 8
4 7 3 5 1 6 8 2 9
1 6 8 4 2 9 5 3 7
9 5 2 3 7 8 1 4 6
2 3 4 7 6 1 9 8 5
6 8 7 9 3 5 2 1 4
5 1 9 2 8 4 6 7 3
Example output:
1 2 3 4 5 6 7 8 9 
4 5 6 7 8 9 1 2 3 
7 8 9 1 2 3 4 5 6 
2 3 1 5 6 4 8 9 7 
5 6 4 8 9 7 2 3 1
8 9 7 2 3 1 5 6 4 
3 1 2 6 4 5 9 7 8
6 4 5 9 7 8 3 1 2 
9 7 8 3 1 2 6 4 5

Input:

Example output:

Meta

  • Any mistakes in the test-cases?
  • Is it sufficiently diffent to existing challenges?
  • Is it better as or a challenge to check whether two given grids are equivalent?
\$\endgroup\$
6
  • \$\begingroup\$ I think the decision-problem version would be better, since that doesn't actually involve validating a sudoku board, which i believe is already a challenge. IMO anyway. \$\endgroup\$ Sep 21, 2022 at 19:51
  • \$\begingroup\$ Are there any other possible sudoku equivalencies? Or is it safe to say that's it / that's all we care about ? \$\endgroup\$ Sep 21, 2022 at 19:52
  • \$\begingroup\$ You might want to use the word "permuted" instead of "swapped" (I'm pretty sure that's what you mean) \$\endgroup\$
    – Pandu
    Sep 22, 2022 at 3:35
  • \$\begingroup\$ Since you were asking if you should do a related decision-problem question instead: In case you want it, here's another related question. I don't know it's that great is as is for CGCC -- feels so specific it's maybe too overspecified, but just in case it's useful: "Generate a specified equivalent sudoku given inputs originalSudoku, symbolPermutation, rowPermutations, columnPermutations, bandPermutation, stackPermutation, shouldReflect." Happy to elaborate on this if needed. \$\endgroup\$
    – Pandu
    Sep 22, 2022 at 3:56
  • 1
    \$\begingroup\$ @thejonymyster in the open-ended-function challenge I was hoping for a smart solution using some transformation not listed. These transformations are actually what pops up in literature (wikipedia link) - your previous comment prompted me to research this closer. But if it isn't a case, you're right that decision-problem may be better. \$\endgroup\$
    – pajonk
    Sep 22, 2022 at 4:33
  • \$\begingroup\$ @Pandu thanks for help in the wording. Regarding the challenge idea, I think you're right that it may be overspecified. \$\endgroup\$
    – pajonk
    Sep 22, 2022 at 4:35
2
\$\begingroup\$

Print every Fool's Mate

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

N-element Rock Paper Scissors

Given an odd integer \$n>2\$, decide the winner for \$n\$-element Rock Paper Scissors.

What is \$n\$-element Rock Paper Scissors?

Rock Paper Scissors is a game in which two players choose between the elements Rock, Paper, and Scissors, and simultaneously reveal their selections. If one player chooses Rock, they will win against a player who chose Scissors, lose against a player who choses Paper, and tie a player who also chose Rock. It is a zero sum game, so a player losing means their opponent has won, and vice versa. Every element beats one element, loses to another, and ties with itself.

A common extension to this game is to add two aditional elements (most famously "Lizard" and "Spock"). In this extension, there are now 5 elements, so each element beats two elements, loses to two elements, but still ties only itself. We can generalize this cleanly to any odd number of elements \$n\$, in which each element will beat \$(n-1)/2\$ elements, lose to \$(n-1)/2\$ elements, and tie with itself.

Challenge specification

Program 1

This program should take an odd integer \$n>2\$ as input in any reasonable format decided by the solver, and output the Program 2 as defined below in terms of \$n\$. Alternatively, this program may instead take the Program 2's inputs along with \$n\$, and provide the Program 2's expected output instead.

This program is the one you will be scored on. This is , so shortest code in bytes wins.

Program 2

This program should take two elements \$A\$ and \$B\$ as input in any reasonable format decided by the solver, and consistently output either one of the following:

  • Whether \$A\$ beats \$B\$, loses to \$B\$, or ties with \$B\$.
  • The winner between \$A\$ and \$B\$, or in the case of a tie, some other distinct output.

Only \$n\$ possible inputs need to be handled by this program. Each possible element must consistently beat \$(n-1)/2\$ elements, lose to \$(n-1)/2\$ elements, and tie with itself. If some element \$a\$ beats an element \$b\$, element \$b\$ loses to element \$a\$. Which elements are allowed and which elements beat which etc. are to be decided by the solver. This must be consistent for each execution of Program 2 for the same \$n\$

Examples:

Your I/O may differ.

Format:
n (input to Program 1)
a b c d e (list of inputs accepted by Program 2, space delimited for all examples)
x y (inputs to Program 2, space delimited for all examples)
value (whether x wins, loses, or ties y)

3
r p s
r p
lose

3
r p s
r r
tie

3
r p s
r s
win

5
0 1 2 3 4
0 1
win

5
0 1 2 3 4
0 2
win

5
0 1 2 3 4
0 3
lose

5
0 1 2 3 4
0 4
lose

5
abcde bcdea cdeab deabc eabcd
bcdea cdeab
lose

5
abcde bcdea cdeab deabc eabcd
bcdea deabc
lose

5
abcde bcdea cdeab deabc eabcd
bcdea eabcd
win

5
abcde bcdea cdeab deabc eabcd
bcdea abcde
win

5
abcde bcdea cdeab deabc eabcd
bcdea bcdea
tie

13
a b c d e f g h i j k l m
g e
lose

13
a b c d e f g h i j k l m
g m
win

13
a b c d e f g h i j k l m
d h
win

13
a b c d e f g h i j k l m
h d
lose

Meta

Everything clear? Any other examples needed? Maybe a worked out example?

\$\endgroup\$
1
  • \$\begingroup\$ info: i am currently working on a worked-out example including a visual aide, and also like in the process of getting a new job, so thats what is taking me so long on this lol \$\endgroup\$ Oct 17, 2022 at 13:16
2
\$\begingroup\$

Repeat Values In Array

\$\endgroup\$
1
  • \$\begingroup\$ this is actually a builtin in jelly (x) \$\endgroup\$
    – naffetS
    Sep 25, 2022 at 1:05
2
\$\begingroup\$

Abbreviate the inputted phrases

Given an ASCII string, replace all occurrences of " is ", " are ", " am ", and " have " with "'s ", "'re ", and "'ve " respectively. This must be done case insensitively.

Examples

Input Output
I am I'm
She is She's
The dog is The dog's
I have a dog I've a dog
I have been hurt I've been hurt
Wadsfajsdfl have asdasd Wadsfajsdfl've asdasd
So, is 6 am fare So,'s 6'm fare
foo amxyz foo amxyz
have I have I
HAVE I HAVE I
I HAVE I've
I AM I'm
I haven't I'ven't
ambc xisz ambc xisz
\$\endgroup\$
7
  • 1
    \$\begingroup\$ What is the expected result for "So, is 6 am fare"? \$\endgroup\$
    – Adám
    Oct 1, 2022 at 23:57
  • \$\begingroup\$ I'll add it as a test case, one moment. \$\endgroup\$
    – Qaziquza
    Oct 2, 2022 at 1:06
  • 1
    \$\begingroup\$ Related (this one is much simpler) \$\endgroup\$
    – naffetS
    Oct 2, 2022 at 1:10
  • 1
    \$\begingroup\$ What's the winning criterion? What character set is expected in the input? What to do if the word to replace is at the beginning of string? How do we handle upper case? Please specify those the rules. Suggested test cases: "foo amxyz", "have I", "I HAVE", "I haven't", "ambc xisz". \$\endgroup\$
    – pajonk
    Oct 2, 2022 at 4:08
  • \$\begingroup\$ Done! <filler text> \$\endgroup\$
    – Qaziquza
    Oct 2, 2022 at 6:59
  • \$\begingroup\$ Personally, I think this challenge would be better if it wasn't a simple replacement challenge, and wouldn't replace things in the middle of words and after punctuation. For example: "So, is 6 am fare" -> "So, is 6'm fare", "foo amxyz" -> "foo amxyz" \$\endgroup\$
    – pigrammer
    Oct 2, 2022 at 18:34
  • \$\begingroup\$ Hmmm, that would make sense. I'll change the rules, then. \$\endgroup\$
    – Qaziquza
    Oct 3, 2022 at 1:55
2
\$\begingroup\$

Make a Court Transcriber

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

Partial Fractions

\$\endgroup\$
5
  • 2
    \$\begingroup\$ I think that most of this challenge would involve the somewhat tedious task of parsing the input rather than actually making the partial fractions. Also, isn't the first testcase you gave using a factorised input ((x+3)^2)? \$\endgroup\$ Oct 8, 2022 at 19:18
  • 1
    \$\begingroup\$ Suggested input format: two list of integers that represent the coefficients of the numerator and the denominator. Suggested output format: A list of pairs of lists of integers. For example: ([1, 4], [1, 6, 9]) -> [([1], [1, 3]), ([1], [1, 6, 9])]. \$\endgroup\$
    – alephalpha
    Oct 11, 2022 at 2:27
  • \$\begingroup\$ @DialFrost x^2+3 would be [1,0,3]. \$\endgroup\$
    – alephalpha
    Oct 11, 2022 at 2:31
  • \$\begingroup\$ @alephalpha fixed! Tysm, is there anything else that needs fixing? \$\endgroup\$
    – DialFrost
    Oct 11, 2022 at 2:45
  • \$\begingroup\$ @DialFrost Suggested tag: polynomials. \$\endgroup\$
    – alephalpha
    Oct 11, 2022 at 2:49
2
\$\begingroup\$

Infinite Integer Derivative

We can consider the derivative of a integer sequence to simply be the difference between each element and the next:

1  5  8  13  2
 4  3  5  -11

Note this will produce a sequence one shorter than the original. We can repeat this process to find the second derivative:

-1 2 -16

And continue this process till there is one element left.

Conjecture A sequence of length n can be exactly represented by first element of each integer derivative. We call this the infinite integer derivative.

Example:

              [8   4  12   6  3]
8              [-4  8   -6  -3]
8 -4             [12 -14  3]
8 -4 12           [-26  11]
8 -4 12 -26          [37]
8 -4 12 -26 37

Example python code:

f = lambda x:x and [x[0]]+f([x[i]-x[i-1] for i in range(1,len(x))])

Note there may be more efficient ways to compute values than this formula.

Test cases

{
    [1,2,3,4,5]:    [1,1,0,0,0],
    [1,2,1,2,1]:    [1,1,-2,4,8],
    [1,2,4,8,16]:   [1,1,1,1,1],
    [5,1,-1,0,6,3]: [5,-4,2,1,1,-17],
    []:             [],
    [12]:           [12],
    [5,5,5,5,5,4]:  [5,0,0,0,-1],
    [5,4]:          [5,-1]
}
\$\endgroup\$
5
  • 1
    \$\begingroup\$ Related but closed. \$\endgroup\$
    – alephalpha
    Oct 10, 2022 at 9:57
  • \$\begingroup\$ While the pyramid shape is the same this is about a different combination of sides and the formula appears to be completely different. \$\endgroup\$
    – mousetail
    Oct 10, 2022 at 10:41
  • 1
    \$\begingroup\$ I believe your example has an arithmetic error, it should be ``` [8, 4, 12, 6, 3] [-4, 8, -6, -3] [12, -14, 3] [-26, 17] [43] ``` \$\endgroup\$ Oct 11, 2022 at 17:50
  • \$\begingroup\$ Perhaps you shouldn't have [] as a valid input, since I don't think it adds anything in particular to the challenge and it might prevent some interesting approaches. \$\endgroup\$ Oct 20, 2022 at 17:01
  • 1
    \$\begingroup\$ Very closely related: binomial transform, which is the same as this but with the sign flipped at odd indices (see wikipedia). \$\endgroup\$
    – Bubbler
    Oct 24, 2022 at 5:45
2
\$\begingroup\$

Prime factor power sorting

Background

We will introduce a new way of writing numbers where the digits represent powers of primes starting with the largest prime factor of the number, and ending with the power of 2 in the prime factorization. As an example, 2 = 21, so it would be written as 1. Slightly more complicated, 3 = 31 * 20, so it is written as 1 0. Here's a few more:

6:     1 1
7: 1 0 0 0
8:       3
9:     2 0
10:  1 0 1

So the place value of the n'th "digit" is the n'th prime number, and the digit itself represents the power of that prime in the factorization of the number. 1 is encoded simply as or 0 (the choice does not affect comparison).

The Challenge

We can compare numbers in this form by first examining how many digits it has, and then breaking ties by comparing the digits themselves like normal. For instance, any power of 2 has only one digit, and so 2n < 3 for all n because 3's prime power representation has two digits. However, when numbers have the same length (meaning their highest prime factors are equal) we compare the lists of digits element-wise. Therefore 12 < 9 because 12th = 1 2 and 9 = 2 0.

Your challenge is to write a function or program which takes as input a collection of distinct integers greater than or equal to 1, and outputs the same collection sorted this way in ascending order. This is code golf, so the score is the length of your solution in bytes.

Examples:

I have written an example solution (Try it online!) which generates the following examples with the input and output separated by a colon:

1 2 3 4 5: 1 2 4 3 5
2 4 8 16 32 64 3: 2 4 8 16 32 64 3
1 3 5 7 9 11 13 15: 1 3 9 5 15 7 11 13
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55: 48 54 40 45 50 42 49 44 55 52 51 46 41 43 47 53
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019: 1000 1008 1001 1014 1012 1015 1007 1003 1005 1010 1017 1016 1002 1004 1011 1006 1018 1009 1013 1019
 
\$\endgroup\$
2
\$\begingroup\$

Triangular honeycomb numbers

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

Box blur the string

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Don't forget to specify the scoring system, I'm assuming code golf, in which case you just need to stick a "This is code-golf, so shortest code in bytes wins." \$\endgroup\$ Oct 19, 2022 at 12:43
  • 1
    \$\begingroup\$ tag suggestions: ascii-art, array or maybe matrix i think \$\endgroup\$ Oct 19, 2022 at 12:43
2
\$\begingroup\$

Conversions Galore!

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

Generate the Sequence of Equivalence Relations (OEIS A231428)

Introduction

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

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

These relations can be represented as boolean matrices where:

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

Here are a few such matrices:

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

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

Challenge

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

For reference, the first 25 terms of this sequence are

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

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

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

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

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

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

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

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

Sandbox notes

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

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

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

Fastest approximate square root of a floating point number


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

Background:

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

Opcodes:

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

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

Task:

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

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

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

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

Counting Stripey Bracelets

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

Maximum average ord

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

Simple Boolean Algebra Calculator

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

Transform a lattice polygon to minimum diameter by shearing

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

Where are zeros? Self-describing sequence

Background

A167519: Lexicographically earliest increasing sequence which lists the positions of the zero digits in the sequence.

3, 10, 11, 12, 11000, 11111, 11112, 11113, 11114, 11115, 11116, 11117, 11118, 11119,
11121, 11122, 11123, 11124, 11125, 11126, 11127, 11128, 11129, 11131, 11132, 11133,
11134, 11135, 11136, 11137, 11138, 11139, 11141, 11142, 11143, 11144, ...

If we list the digits, we get

3 1 0 1 1 1 2 1 1 0 0 0 1 1 1 1 1 1 1 1 1 2 1 1 1 1 3 1 1 1 1 4 ...
    ^             ^ ^ ^

The digits at index 3, 10, 11, 12, 11000, ... are zeros, and all the other digits are nonzero.

It looks a bit boring after a few terms. It becomes a bit more interesting if we consider the same sequence in smaller bases:

Base 5

(in base 10)
3, 5, 10, 11, 150, 156, 157, 158, 159, 161, ...

(in base 5)
3, 10, 20, 21, 1100, 1111, 1112, 1113, 1114, 1121, ...

Explanation:

  1. The first term cannot be 1 (the first base-5 digit is 1, not 0) or 2 (the next number would have a leading zero), so it is 3.
  2. The next term cannot be 4 (leading zero), so it must be 5 = 10(5). It satisfies the first term (3rd base-5 digit is 0).
  3. The third term must have at least 2 digits and its 2nd digit is 0. The smallest number that satisfies this is 10 = 20(5).
  4. Another 2-digit number can fit here without causing a leading zero. The smallest such number exceeding 10 is 11 = 21(5).
  5. The next number cannot be 2-digit or 3-digit, so it must have 4 digits, giving 1100(5). We don't have any more zeros for a while, giving a series of zeroless numbers starting with 1111(5).

Base 4

(in base 10)
3, 8, 9, 80, 85, 86, 87, 89, 90, 91, 93, 94, 95, 101, 102, 103, 105, 106, 107,
109, 110, 113, 1344, 16448, 21824, 32833, 34133, 38229, 38230, 38231, ...

(in base 4)
3, 20, 21, 1100, 1111, 1112, 1113, 1121, 1122, 1123, 1131, 1132, 1133, 1211, 1212,
1213, 1221, 1222, 1223, 1231, 1232, 1301, 111000, 10001000, 11111000, 20001001,
20111111, 21111111, 21111112, 21111113, ...
  1. The first term is 3 by the same logic.
  2. The next term cannot be 10(4) due to leading zero, and the next fitting number is 20(4).
  3. The rest goes on by the "long-term logic". The next interesting part comes earlier than in higher bases, so I decided to include it here.

Starting here, the "long-term logic" refers to the following:

  • If the last number has k digits, the next number will also have k digits unless such a number does not exist or it causes a leading zero in the next term.
  • Otherwise, increase the number of digits until the next term won't have a leading zero, and fill the nonzero digits with 1.

Base 3

(in base 10)
4, 6, 10, 12, 19, 22, 24, 111, 121, 122, 124, 125, 130, 131, 133, 134, 148, 149,
151, 152, 157, 158, 160, 161, 202, 283, 1089, 6921, 6925, 9837, 13482, 13486,
16402, 16403, 16405, 16408, 16411, 16412, 16414, 16415, 16429, 16430, 16432,
16433, 16435, ...

(in base 3)
11, 20, 101, 110, 201, 211, 220, 11010, 11111, 11112, 11121, 11122, 11211, 11212,
11221, 11222, 12111, 12112, 12121, 12122, 12211, 12212, 12221, 12222, 21111,
101111, 1111100, 100111100, 100111111, 111111100, 200111100, 200111111, 211111111,
211111112, 211111121, 211111201, 211111211, 211111212, 211111221, 211111222,
211112111, 211112112, 211112121, 211112122, 211112201, ...
  1. The first term cannot be 3 since it is 10(3) but 2 is not in the sequence. Therefore, the first term is 4 = 11(3).
  2. The sequence goes on with the long-term logic.

Base 2

(in base 10)
2, 4, 5, 7, 31, 63, 127, 191, 255, 511, 1021, 1023, 2047, 4095, 8191, 16383, 28671,
32767, ...

(in base 2)
10, 100, 101, 111, 11111, 111111, 1111111, 10111111, 11111111, 111111111,
1111111101, 1111111111, 11111111111, 111111111111, 1111111111111, 11111111111111,
110111111111111, 111111111111111, ...

Determining the initial terms here is particularly tricky.

  1. The first term is 2 = 10(2) because it satisfies the first zero position.
  2. The next term cannot be 3, but 4 = 100(2) works. This also fixes the next two terms 5 = 101(2) and 7 = 111(2).
  3. The next term should be at least 12, but:
    • 12 doesn't work because <1>100 (<x> marks where 0 has to be)
    • 13 doesn't work because 1<1>01
    • 14 doesn't work because 11<1>0
    • 15 doesn't work because 111<1> Therefore the number has at least 5 bits, the first 4 of which must be 1. Then the last bit cannot be 0 either (16 is not in the sequence), so it becomes 31 = 11111(2).
  4. Now the rest follows the long-term logic, except that it continues to grow exponentially. This is because, for every number k, there is only one k-bit number that does not contain 0.

Code used for handcrafting these sequences.

Challenge

Given the base n >= 2, output the sequence generated by the definition of A167519 in base n.

I/O rules apply. You may choose one of the following:

  • Given n, output the terms of the sequence indefinitely;
  • Given n and a 0- or 1-based index k, output the kth term of the sequence n;
  • Given n and a positive integer k, output the first k terms of the sequence n.

You may output the terms in base 10 or base n.

Standard rules apply. The shortest code in bytes wins.

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

How much STAB do I get?

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

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

The rules are as follows:

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

As a table:

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

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

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

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

Santa's Shortest Path Problem

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

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

But can it run Fibonacci?

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

Robbers will try to find this fibonacci program.

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

Approximate my Atomic Weight

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

Number program police

This question is related to Counting and so on

Content

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

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

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

Task

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

shape

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

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

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

Number shape

Basic Number shape:

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

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

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

Is not a Number shape of 9:

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

Acceptable reshape:

Original shape:

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

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



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

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


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

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

Is Widened, extended, enlarged, and lengthened.

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

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

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

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

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

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

A Number shape can also start with 0:

### #
# # #
### #

I/O

Basically follows the standard I/O rules:

The input can be request in any convenience format

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

The output follows the standard output rule

Testcase

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

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

Is not Number shape:

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

Rules

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

Meta

  • Is the title good?
  • Any tag that suits this question but not included?
  • Is it clear?
  • Extra suggestion would help me out a lot!
\$\endgroup\$
1
1
43 44
45
46 47
152

You must log in to answer this question.

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