572
\$\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

4648 Answers 4648

1
21 22
23
24 25
155
3
\$\begingroup\$

Light it up

\$\endgroup\$
4
  • \$\begingroup\$ Maybe you can fill empty cells by some characters like . in your examples and testcases. Or it could be confusing: L.#. is falsy but L.# is truthy, but it is hard to see the difference. \$\endgroup\$
    – tsh
    Nov 2, 2021 at 1:53
  • \$\begingroup\$ @tsh Ok, thanks! \$\endgroup\$
    – emanresu A
    Nov 2, 2021 at 2:02
  • \$\begingroup\$ "some squares are walls, some are empty, and some are lights". Since there are testcases where only empty cell is there, will there be any testcases like ####? \$\endgroup\$
    – tsh
    Nov 2, 2021 at 5:23
  • \$\begingroup\$ @tsh Yes, see the fourth truthy one. I'll be more explicit that some may not occur at all. \$\endgroup\$
    – emanresu A
    Nov 2, 2021 at 6:13
3
\$\begingroup\$

Print □□Square□□ Numbers

Your task is to write a program or function that accepts an integer as input/argument and prints/returns all square numbers from 0 up to but not including n².

But the numbers should not just be perfect squares in the mathematical sense. They should be square in every sense. That is, the digits should

  • • occupy a square space, 5 lines by 5 columns (including separating space)
  • • form right angles at their joints
  • • be formed entirely from □ and space characters

Actually, the digits must be shaped exactly like these:

   □ □□□□ □□□□ □  □ □□□□ □□□□ □□□□ □□□□ □□□□ □□□□ 
   □    □    □ □  □ □    □       □ □  □ □  □ □  □ 
   □ □□□□ □□□□ □□□□ □□□□ □□□□    □ □□□□ □□□□ □  □ 
   □ □       □    □    □ □  □    □ □  □    □ □  □ 
   □ □□□□ □□□□    □ □□□□ □□□□    □ □□□□ □□□□ □□□□ 

Note the single column of space between each digit. Spaces at the end of each line are optional. (The three empty columns of spaces on the left side of the digit 1 are not optional.)

Each square number shall be printed on exactly 5 lines using these digits, and between each of these numbers shall be a single line containing no non-whitespace characters. You may optionally include extra blank lines at the beginning or end of the output.

Standard loopholes etc. Shortest solution in bytes is the coolest of beans.

Example Output (given the input 5):

□□□□
□  □
□  □
□  □
□□□□

   □
   □
   □
   □
   □

□  □
□  □
□□□□
   □
   □

□□□□
□  □
□□□□
   □
□□□□

   □ □□□□
   □ □
   □ □□□□
   □ □  □
   □ □□□□

(Note for sandbox: I know this is a good challenge because I had fun solving it myself. But I am worried there is another challenge I haven't seen that is too similar. Please let me know. I'll abandon it if so.)

\$\endgroup\$
3
  • \$\begingroup\$ Can't find any dupes on this search so it is probably clear. \$\endgroup\$
    – Razetime
    Jan 7, 2022 at 4:45
  • 1
    \$\begingroup\$ Closely related \$\endgroup\$
    – pxeger
    Jan 7, 2022 at 7:58
  • \$\begingroup\$ @pxeger yeah that's probably similar enough not to post this \$\endgroup\$
    – quintopia
    Jan 7, 2022 at 17:37
3
\$\begingroup\$

Expand a Rubik's Cube Commutator

Tags:

Posted: Expand a Rubik's Cube Commutator

\$\endgroup\$
5
  • \$\begingroup\$ What do you mean by "expand" the commutator? Also, 3x3x3*, a 3x3 would be a rubik's square :) \$\endgroup\$ Jan 11, 2022 at 15:12
  • \$\begingroup\$ @thejonymyster The common names for Rubik's cubes are by the size of a face since they're usually cubes, so we just call them "3x3" for a 3x3x3 cube, etc. Only in cuboids like the 3x3x4 cuboid actually have the 3rd dimension "Expanding" the commutator == Listing out all the moves performed in the commutator \$\endgroup\$
    – bigyihsuan
    Jan 11, 2022 at 19:59
  • \$\begingroup\$ ahh, that makes sense, for both parts. +1 \$\endgroup\$ Jan 11, 2022 at 20:03
  • 1
    \$\begingroup\$ "Each part of the commutator can be a separate value" - I see this is to make IO more flexible than flat string to flat string, which is good, but I would go further and allow the moves themselves be separate values in each part, and allow a list of moves as the output in order to focus on the challenge itself. This would allow, for example, [["F'", "U2", "R"], ["D", "B2"]] -> ["F'", "U2", "R", "D", "B2", "R'", "U2", "F", "B2", "D'"]. \$\endgroup\$ Jan 11, 2022 at 23:07
  • \$\begingroup\$ I couldn't resist and just gave it a go in Jelly and got a 15 byte solution (assuming IO is further relaxed as I suggested, which I believe you will do given your current relaxation). This is a good challenge IMO. \$\endgroup\$ Jan 11, 2022 at 23:20
3
\$\begingroup\$

Will the tower balance?

You are given as input a tower made of bars of unit height, and your task is to decide if the tower is stable. Here is an ascii art drawing of a tower:

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

For extra clarity here is the same tower but with the different bars in different characters:

 A
BBBB
C DDDD
EEEEE

The bars are rigid, but they are not connected to each other. Even though the bars are not connected, they stay still under the influence of gravity. Here however is a tower that is not stable:

      B
CCCCCCCC
   D
  EEE
FFFFFFFF

In this tower, under the influence of gravity, the top bar will fall to the right.

The following tower is metastable:

AA
B

The center of mass of the A-bar lies on top of the edge of the B-bar. In this kind of situation the tower is considered unstable, since even a small perturbation will cause it to fall eventually.

Input/output format

The input format is an ascii drawing of the tower like so:

 ###
  #
### #

In this picture there are 4 bars. It is guranteed that all bars are on top of another bar or on top of the ground and that every row has at least one bar. You can use a different printable ascii character instead of #. You can also take a 2d array instead of a string and use two distinct values for # and . In that case please use simple values, that don't encode extra information (standard loopholes prohibited).

Output two distinct values for STABLE and UNSTABLE.

Test cases

#

STABLE

###
 #
 ##
  #

UNSTABLE

  ###
 ###
###

UNSTABLE (metastable)

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

STABLE

###
 #
#####
 #

STABLE

 #
#####
 #

UNSTABLE

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

STABLE

\$\endgroup\$
2
  • 1
    \$\begingroup\$ The rules do not actually specify what makes a tower stable. The stable test cases use balancing methods not stated anywhere, and the rules themselves just seem to be more examples. As a non physicist, "use gravity" isn't enough information IMO. This is a cool idea though and +1 once that's fixed \$\endgroup\$ Jan 17, 2022 at 13:49
  • \$\begingroup\$ Just highlighting the bars on their own would be interesting IMO \$\endgroup\$
    – emanresu A
    Jan 17, 2022 at 18:36
3
\$\begingroup\$

Recursive palindromes

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

Shrink ASCII art

\$\endgroup\$
1
  • \$\begingroup\$ convert like ---, 3 to [---, 3]? \$\endgroup\$
    – Fmbalbuena
    Dec 26, 2021 at 0:48
3
\$\begingroup\$

Is this continuous terrain? Part II

\$\endgroup\$
1
  • 1
    \$\begingroup\$ i like it emanresu A! \$\endgroup\$
    – DialFrost
    Jan 19, 2022 at 8:50
3
\$\begingroup\$

Only one from each set

\$\endgroup\$
3
  • \$\begingroup\$ "There are no gaps in the numbers " does it means that the input flattened must contain all the numbers [1..n] where n is the maximum number in it? \$\endgroup\$
    – AZTECCO
    Jan 23, 2022 at 10:31
  • \$\begingroup\$ @AZTECCO Yes, exactly \$\endgroup\$
    – AnttiP
    Jan 23, 2022 at 10:32
  • \$\begingroup\$ Ok, i think you should explain it, careful.. there are some test cases non valid. I think you may also specify that inner lists are sorted (if it's so I guess) \$\endgroup\$
    – AZTECCO
    Jan 23, 2022 at 10:40
3
\$\begingroup\$

Shanghai ascii game sticks

Posted

\$\endgroup\$
4
  • \$\begingroup\$ Looks great, ready to post \$\endgroup\$
    – ophact
    Jan 21, 2022 at 10:38
  • \$\begingroup\$ @ThisFieldIsRequired thanks, I still got something to tweak.. I'm gonna take some time \$\endgroup\$
    – AZTECCO
    Jan 21, 2022 at 12:32
  • \$\begingroup\$ How are the last two testcases possible? \$\endgroup\$
    – emanresu A
    Jan 22, 2022 at 19:29
  • 2
    \$\begingroup\$ @emanresu A the last test case is an edge case were 4 sticks are all bounded and one sits by itself and satisfy the one and only one stick removable condition, you are not required to remove all sticks but just the first \$\endgroup\$
    – AZTECCO
    Jan 22, 2022 at 20:11
3
\$\begingroup\$

Highlight a Wordle guess

\$\endgroup\$
7
  • \$\begingroup\$ confused to be honest . maybeeee abit too hard? \$\endgroup\$
    – DialFrost
    Jan 17, 2022 at 9:57
  • \$\begingroup\$ @DialFrost Can you be more specific? What part are you confused about? \$\endgroup\$
    – pxeger
    Jan 17, 2022 at 9:58
  • \$\begingroup\$ er mostly about the highlighting value \$\endgroup\$
    – DialFrost
    Jan 17, 2022 at 10:00
  • \$\begingroup\$ @DialFrost do you mean: 1) you don't understand when to highlight the letters in which colour; or 2) you don't understand how the output values used for highlighting can be chosen? Or something else? \$\endgroup\$
    – pxeger
    Jan 17, 2022 at 10:01
  • \$\begingroup\$ both i dont understand \$\endgroup\$
    – DialFrost
    Jan 17, 2022 at 10:01
  • \$\begingroup\$ @DialFrost without some more details on what you're missing, I can't help you to understand or clarify the description. What bits you do you understand? \$\endgroup\$
    – pxeger
    Jan 17, 2022 at 10:05
  • \$\begingroup\$ pretty much none i just meant i dont understand the hilighting value and how it works the most \$\endgroup\$
    – DialFrost
    Jan 17, 2022 at 10:06
3
\$\begingroup\$

Reversed Multiple Pair

\$\endgroup\$
5
  • \$\begingroup\$ maybe give an example and a step by step of evaluating if it is reversed multiple? \$\endgroup\$ Jan 13, 2022 at 20:19
  • \$\begingroup\$ @thejonymyster Done \$\endgroup\$ Jan 13, 2022 at 20:29
  • 3
    \$\begingroup\$ really simple, but it is clearly specified. seems like a decent easy challenge. To make it slightly more difficult you can make this a challenge of finding all reversed multiple pairs under a given limit. \$\endgroup\$
    – Razetime
    Jan 14, 2022 at 3:35
  • \$\begingroup\$ @Razetime codegolf.meta.stackexchange.com/a/9384/105116? \$\endgroup\$ Jan 14, 2022 at 15:31
  • \$\begingroup\$ it's your choice whether that change makes it more interesting or whether it is an unnecessary burden. \$\endgroup\$
    – Razetime
    Jan 14, 2022 at 15:55
3
\$\begingroup\$

Cubax Folding Game

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

Happy new year string builder

Posted here.

\$\endgroup\$
2
  • \$\begingroup\$ The regex should probably be /^(have a )?happy new year( to you)?!*$/i (removed unnecessary grouping, added string start and end match, and the i tag means the search is case insensitive by default.) \$\endgroup\$
    – hakr14
    Feb 7, 2022 at 23:12
  • \$\begingroup\$ @hakr14 thanks, editing the answer. \$\endgroup\$
    – ophact
    Feb 8, 2022 at 6:07
3
\$\begingroup\$

The Con Man

The bots start with a balance of 100 points each. Each round is a 1v1 between two bots. One bot is the Proposer and the other is the Receiver.

P provides R with two numbers: think of it as a loan and repayment with interest. For example, P could propose (50, 60) which means that P wants to swap 50 points for 60 points with R. P also decides whether or to scam R. If R accepts, P can scam R by not upholding their end of the deal and instead taking the 50 points outright.

The twist is, R can see the outcomes of past transactions of P to determine whether or not to trust P and accept the offer.

The format of the tournament is that of a round robin where every bot will play P and R the same number of times against all opponents, in an unspecified order.

Whichever bot ends up with the most points wins.

The language of this challenge is JS.

Format (in TypeScript):

type Bot = {
  R(
    offer: [number, number], // loan, repay
    opponentBalance: number,
    pastTransactions: [number, number, number][] // loan, repay, outcome (0 -> accept, 1 -> reject, 2 -> scam)
  ): boolean,
  P(
    opponentBalance: number,
    pastTransactions: [number, number, number][]
  ): [number, number, boolean] // [loan, repay, scam]
}

Meta

  • Does this make for diverse enough strategies to be worthwhile?
  • Should more or less information about the opponent be supplied to the players?
\$\endgroup\$
2
  • \$\begingroup\$ And if the bot runs out of money, does it die or can it take a loan? It can't give out loans obviously right? \$\endgroup\$
    – ophact
    Feb 15, 2022 at 8:41
  • \$\begingroup\$ @ophact I think it should die since no reasonable strategy would accept a deal with a bot with no money. \$\endgroup\$ Feb 16, 2022 at 2:16
3
\$\begingroup\$

Largest rectangle in a skyline

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

Golfing Coins (suggested rewrite)

The challenge is to write a program that begins with a board like this:

O O X
O O X
O O X

The O's are coins. X's are empty.

Rules

Every round you will uniformly randomly choose a coin and a cardinal direction. You will move that coin 1 spot in that direction, if there is an empty space there. Or in other words, moves must satisfy the following rules:

  • The coins can only move up, down, left or right 1 spot.
  • Coins cannot move outside the board
  • Coins cannot overlap

This process should be repeated until every coin has moved into each spot on the board. You should output the state of the board after every move.

This is so shortest code in each language wins.

\$\endgroup\$
1
  • \$\begingroup\$ Still don't quite understand what is uniformly randomly choose here mean. For example, the board is OXO/XOX/OOO. If we first choose one coin, and then choose its direction, it will have 1/5 chance to chose the O in the middle. But if we list all possible moves and choose one from them, the middle one should have a 1/3 chance. \$\endgroup\$
    – tsh
    Feb 21, 2022 at 6:20
3
\$\begingroup\$

Draw an ASCII Volume

Posted here

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

Posted here

\$\endgroup\$
3
  • 2
    \$\begingroup\$ What is the order each rules applied? For example, for rules "11=12", "12=21", "22=3". If input is "1112", should it be "1112 -> 1212 -> 2121" or "1112 -> 1221 -> 131" or "1122 -> 1222 -> 123"? \$\endgroup\$
    – tsh
    Feb 22, 2022 at 7:58
  • \$\begingroup\$ All of them. See the original specification for Shue in the linked challenge, or the interpreter. \$\endgroup\$
    – Seggan
    Feb 22, 2022 at 15:11
  • \$\begingroup\$ As challenges should be self-contained, I suggest you add the mathematical definition from my post (and maybe an informal explanation of how the rules are applied non-deterministically) \$\endgroup\$
    – AnttiP
    Feb 22, 2022 at 16:46
3
\$\begingroup\$

Draw a Signal strength indicator

Posted here

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

Convert to UTF-∞

\$\endgroup\$
1
  • \$\begingroup\$ I believe if Unicode code points are used up. They are most probability caused by CJK characters. Until then, there are already >50% used code points represent CJK characters. And characters used by Chinese dialect other than Cantonese (HK source) are still missing in Unicode. \$\endgroup\$
    – tsh
    Feb 22, 2022 at 8:23
3
\$\begingroup\$

Ragged slice

Your task is to slice a ragged list. Your input is a ragged list and two lists of integers, corresponding to the beginning index and end index of the slice, where the beginning index is inclusive and the end index is exclusive.

Explanation

Let's start from the very basics. How does regular slicing work? Let's say we have the list [a,b,c,d,e,f] and we want the slice [1,4]. How does this work? Here is an illustration:

[a,b,c,d,e,f]
^ ^ ^ ^ ^ ^ ^
0 1 2 3 4 5 6
  v v v v
  [b,c,d]

This means that [a,b,c,d,e,f][1,4]==[b,c,d]. Ragged slicing is a bit tricky, so please make sure that the previous diagram is mostly clear. Ok, now ragged lists.

Let's first just draw the indices like previously for the list [a,[b,c],[d,[e]],f]:

[a, [b,c] , [d, [e] ] ,f]
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
0 1 1 1 1 2 2 2 2 2 2 3 4
    0 1 2   0 1 1 1 2
                0 1

Now, let's see what a slice of [1 1, 2 1 0] would look like:

[a, [b,c] , [d, [e] ] ,f]
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
0 1 1 1 1 2 2 2 2 2 2 3 4
    0 1 2   0 1 1 1 2
                0 1
      v v v v v v       
      ,c] , [d, [
       c] , [d
     [[c] , [d]]

The last steps are probably the most confusing. But basically we want to do two things, in the following order:

  1. Trim the left side until an element, or an opening bracket is encountered. Do the same on the right side, except with a closing bracket.
  2. Balance the remaining brackets and keep the depth of every array element the same as in the input, by wrapping the output in brackets.

Now, let's look at what happens when we have empty arrays. In fact, let's replace every letter in our previous example with an empty array:

[[] , [[] ,[] ] , [[] , [[] ] ] ,[] ]
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
0 0 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 4
  0   0 0 1 1 2   0 0 1 1 1 1 2   0
        0   0       0   0 0 1
                          0
          v v v v v v v v
          ,[] ] , [[] , [
           [] ] , [[]
         [[[] ] , [[]]]

Notice that for the empty array, the starting bracket doesn't have an index. This is because for an empty array, an index of 0 is already "one past the end" in an empty array, so there is no smaller index for the beginning.

If we would have used index 2 1 0 0 as the ending index, then this would have happened:

[[] , [[] ,[] ] , [[] , [[] ] ] ,[] ]
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
0 0 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 4
  0   0 0 1 1 2   0 0 1 1 1 1 2   0
        0   0       0   0 0 1
                          0
          v v v v v v v v v
          ,[] ] , [[] , [[]
           [] ] , [[] , [[]
         [[[] ] , [[] , [[]]]]

Lastly, let's see what happens if the slice is empty. We'll use [1 1 0, 2]:

[[] , [[] ,[] ] , [[] , [[] ] ] ,[] ]
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
0 0 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 4
  0   0 0 1 1 2   0 0 1 1 1 1 2   0
        0   0       0   0 0 1
                          0
            v v v
            ] ] ,

Here after step 1, the input just disappeared. We'll just return the empty list [].

Rules

Your input will contain only lists (no numbers, letters, etc.), and the starting and ending index. Indices can in bounds or one past the last in some array. Indices are non-empty lists of non-negative integers. The starting index is not greater than then ending index.

You can choose the order of the indices and also if they are 0 or 1 based (but they must be inclusive-exclusive).

This is so shortest code wins.

Meta

This is a bit tricky to explain. If there were parts that were unclear, or poorly written, etc. then please comment. If you think there is a better explanation, please also let me know.

\$\endgroup\$
4
  • \$\begingroup\$ I don't get why sometimes the opening bracket is indexed, and sometimes not. Could you explain? \$\endgroup\$
    – pajonk
    Feb 27, 2022 at 16:41
  • \$\begingroup\$ @pajonk I've added a paragraph explaining that. Basically it only happens for empty lists (that the starting bracket doesn't have an index). \$\endgroup\$
    – AnttiP
    Feb 27, 2022 at 16:57
  • \$\begingroup\$ Ok, that was a little confusing. Suggestion: replace empty lists with elements (like numbers) and disallow empty lists - wouldn't this be +/- equivalent and easier to explain? \$\endgroup\$
    – pajonk
    Feb 27, 2022 at 17:06
  • \$\begingroup\$ I would suggest simply index any elements and the ending of an array. So for example, Array [1, 2, 3] is indexed as [ 0=>1 1=>, 2 2=>, 3 3=> ]. And a slicing simply exclude the ending element. \$\endgroup\$
    – tsh
    Mar 1, 2022 at 7:56
3
\$\begingroup\$

Hello Shue! (Cops)

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

Circular chained compound

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

Draw the Ukrainian Flag

Draw the Ukrainian Flag

\$\endgroup\$
3
  • 1
    \$\begingroup\$ "horizontally down the middle" -> "horizontally across the middle" \$\endgroup\$
    – att
    Mar 18, 2022 at 21:54
  • \$\begingroup\$ @att oops, fixed \$\endgroup\$
    – Ginger
    Mar 18, 2022 at 21:57
  • \$\begingroup\$ Ginger u stole my challange idea :D (i thought it was too easy so i didnt post it) \$\endgroup\$
    – DialFrost
    Mar 19, 2022 at 0:23
3
\$\begingroup\$

Resolve a Super Auto Pets Round

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

Remove unmatched brackets

\$\endgroup\$
8
  • \$\begingroup\$ "containing of brackets"->"containing brackets"? Also, what characters to expect apart from brackets? You may also want to specify that we want to match the closest brackets together (inferred from example). And I think you lost first 543 in your example. \$\endgroup\$
    – pajonk
    Mar 17, 2022 at 19:51
  • \$\begingroup\$ @pajonk Fixed those. \$\endgroup\$
    – emanresu A
    Mar 17, 2022 at 20:19
  • \$\begingroup\$ What's with the 1 in the third testcase? \$\endgroup\$
    – ophact
    Mar 18, 2022 at 6:30
  • \$\begingroup\$ @ophact A typo. \$\endgroup\$
    – emanresu A
    Mar 18, 2022 at 7:44
  • \$\begingroup\$ "the input will only contain those and lowercase letters" - but the example string contains digits too! Could you remove them? \$\endgroup\$
    – pxeger
    Mar 23, 2022 at 6:39
  • \$\begingroup\$ @pxeger Oops... \$\endgroup\$
    – emanresu A
    Mar 23, 2022 at 8:28
  • 2
    \$\begingroup\$ I think it would be good to add a definition of "matched." It may not be immediately obvious to everyone who reads the challenge why [abc]def] should result in [abc]def and not [abcdef], since you could view either close bracket as being matched with the open bracket. \$\endgroup\$
    – DLosc
    Mar 23, 2022 at 14:06
  • \$\begingroup\$ @DLosc Done. (filler) \$\endgroup\$
    – emanresu A
    Mar 24, 2022 at 3:26
3
\$\begingroup\$

Interpret +-=

\$\endgroup\$
9
  • \$\begingroup\$ I would say this is a fairly simple challenge, but it could still produce some interesting answers. However, it definitely needs some more clarification on input specifications. Should code read from a file? Prompt for input once and interpret that program? Prompt for an input, interpret that, and then repeat? \$\endgroup\$
    – des54321
    Mar 23, 2022 at 21:36
  • \$\begingroup\$ @des54321 prompt, interpret, repeat, as i think that has more golfing potential \$\endgroup\$ Mar 23, 2022 at 22:07
  • 1
    \$\begingroup\$ However I do realize that it won't exactly work on TIO... so idrk \$\endgroup\$ Mar 23, 2022 at 22:10
  • \$\begingroup\$ A few things I think you should specify : Is this code-golf or something else ? Can we assume input is always valid? Usually we do the task just once, it can be a full program or a function tacking arguments. \$\endgroup\$
    – AZTECCO
    Mar 24, 2022 at 12:17
  • \$\begingroup\$ @AZTECCO 1. this... is code-golf... are you ok? 2. Yes you can. \$\endgroup\$ Mar 24, 2022 at 21:13
  • \$\begingroup\$ Instead of explaining my suggestions in a comment I edited adding comments, feel free to reject anything you don't like. Hope it helps a bit.. Nice challenge btw! \$\endgroup\$
    – AZTECCO
    Mar 24, 2022 at 21:41
  • \$\begingroup\$ I would perhaps add a test case that results in negative output(s) (e.g. +=----= resulting in 1 -3) and perhaps one with multiple adjacent == (e.g. --== resulting in -2 -2). Apart from that I'd say it's good enough to be posted. And it may be simple, but it's good to have some simple challenges every now and then. :) In fact, I'd say it becomes harder and harder to come up with easy challenges suitable for beginners that aren't duplicates yet, so +1 from me. (I've already prepared a solution for when it goes to main.) \$\endgroup\$ Mar 28, 2022 at 15:31
  • \$\begingroup\$ @KevinCruijssen how about some of these? \$\endgroup\$ Mar 28, 2022 at 19:42
  • \$\begingroup\$ @BowlingPizzaBall Looks good. 👍 \$\endgroup\$ Mar 28, 2022 at 20:35
3
\$\begingroup\$

Give me the electronic configuration.

As simple as the title.

Input will be a number denoting the atomic number.

The output will be the electronic configuration of the element of the given atomic number.

There are 2 rules for electronic configuration:

  • The maximum number of electrons each shell can hold is given by \$2n^2\$ where n is the shell number starting from 1.
  • The number each shell is allowed to hold from the last shell is given by \$2n^2\$ where n is the number starting from 2, in reverse.

You must fill each shell to it's limited capacity from left to right, with the remaining electrons on the last shell.

Test cases

12 -> [2,8,2]
13 -> [2,8,3]
20 -> [2,8,8,2]
86 -> [2,8,18,32,18,8]
29 -> [2,8,18,1]
\$\endgroup\$
9
  • \$\begingroup\$ You may specify this a little more, as according to current spec any of [2,2,8], [2,8,1,1],[1,1,1,1,1,1,1,1,1,1,1,1] is a valid answer for 12. \$\endgroup\$
    – pajonk
    Apr 10, 2022 at 20:03
  • 1
    \$\begingroup\$ @pajonk i added this line You must fill each shell to it's limited capacity. \$\endgroup\$
    – zoomlogo
    Apr 11, 2022 at 3:23
  • \$\begingroup\$ 29 should return [2,8,18,1], not [2,8,18,2] \$\endgroup\$
    – naffetS
    Apr 11, 2022 at 4:12
  • 1
    \$\begingroup\$ BTW, it's more accurate to call it the electronic shell structure, not the electronic configuration \$\endgroup\$
    – naffetS
    Apr 11, 2022 at 4:13
  • 1
    \$\begingroup\$ @Steffan that's how we learnt it \$\endgroup\$
    – zoomlogo
    Apr 11, 2022 at 5:09
  • \$\begingroup\$ @PyGamer0 You must fill each shell to it's limited capacity from left to right, with the remaining electrons on the last shell, maybe? Remember, you're dealing with programmers here ;-) \$\endgroup\$
    – pajonk
    Apr 11, 2022 at 11:14
  • \$\begingroup\$ @pajonk ok, edited. \$\endgroup\$
    – zoomlogo
    Apr 11, 2022 at 11:29
  • \$\begingroup\$ If you look up the electronic configuration of atomic number 12, for example, you'll see things like 1s^2 2s^2 2p^6 3s^2 at the top. If you look up electron shells of atomic number 12, it will tell you 2,8,2. \$\endgroup\$
    – naffetS
    Apr 11, 2022 at 16:07
  • 1
    \$\begingroup\$ I just noticed this is a duplicate of codegolf.stackexchange.com/questions/37657/… \$\endgroup\$
    – naffetS
    Apr 19, 2022 at 18:36
3
\$\begingroup\$

Convert angle to clock time

\$\endgroup\$
5
  • \$\begingroup\$ I strongly discourage strict output format restriction. Also, you may want to specify that only integer angles will be inputted (if that's the case). \$\endgroup\$
    – pajonk
    Apr 14, 2022 at 12:18
  • \$\begingroup\$ @pajonk Is it okay now? \$\endgroup\$
    – Yousername
    Apr 14, 2022 at 12:30
  • \$\begingroup\$ As long as identifiable as clock times by humans is also a list of hours and minutes and other reasonable formats - I'm fine with that :-) \$\endgroup\$
    – pajonk
    Apr 14, 2022 at 12:38
  • \$\begingroup\$ Outputting 0:00 instead of 12:00 is invalid, right? \$\endgroup\$
    – naffetS
    Apr 17, 2022 at 23:34
  • \$\begingroup\$ @Steffan Yes. The 12-hour time convention should be used. \$\endgroup\$
    – Yousername
    Apr 18, 2022 at 0:01
3
\$\begingroup\$

How normal is this group?

Let \$(G, *)\$ be some group. That is, for all \$x, y, z \in G\$, the following axioms hold:

  • \$x * y \in G\$
  • \$x * (y * z) = (x * y) * z\$
  • There exists some \$e \in G\$ such that \$x * e = e * x = x\$
  • There exists some \$x^{-1} \in G\$ such that \$x * x^{-1} = x^{-1} * x = e\$

For some group \$(G, *)\$, we define a subgroup of this as a group \$(H, *)\$ for some subset \$H \subseteq G\$. The trivial subgroups of a group \$(G, *)\$ are when \$H = \{e\}\$ (the identity element of \$G\$) and when \$H = G\$.

For the sake of convenience, we will denote \$x * y\$ as \$xy\$. Let \$N\$ be a subgroup of \$G\$. We say that \$N\$ is normal if, for all \$g \in G\$ and \$x \in N\$, \$gxg^{-1} \in N\$. For any group, the trivial subgroups are normal, and so any group has at least 2 normal subgroups.

For example, let \$G = \{0,1,2,3\}\$ and \$x * y = x + y \bmod 4\$. The subgroups of \$G\$ are \$\{0\}\$, \$\{0, 2\}\$ and \$\{0,1,2,3\}\$, all of which are normal. Therefore, \$(G, *)\$ has 3 normal subgroups.


Given a finite group, output a positive integer \$n \ge 2\$ counting the number of normal subgroups of the input. You may take a group as input in any reasonable manner, including but not limited to:

  • The set \$G\$ (as a set, list, etc.) along with a black-box function \$* : G \times G \to G\$
  • A square matrix representing the Cayley table of the group. You may choose whether to take \$G\$ as a separate input
  • A collection of triples \$(a, b, c)\$ where \$a, b, c \in G\$ and \$c = a * b\$ (the order of such a triple is irrelevant, but must be consistent for all triples)
  • etc.

This is a challenge, so the shortest code in bytes in each language wins.


Test cases

G
∗ : G×G → G
output

{0,1,2,3}
a*b = a+b mod 4
3
\$\endgroup\$
0
1
21 22
23
24 25
155

You must log in to answer this question.

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