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

4668 Answers 4668

1
81 82
83
84 85
156
1
\$\begingroup\$

Find all matches for the digit pattern

In an older challenge, you were tasked with finding numbers which, in base-ten, matched this specific digit pattern:

(n)(x)(n+1)(x)(n+2)(x)(n+3) etc...

Meaning any number between 4 and 18 digits long such that the digits could be considered as a string of increasing single digits interlaced with (at most) a constant single digit number.

For example, 19293949 would fit the pattern, with n being 1 and x being 9.

In this challenge, instead of deciding whether a given number fits one fixed pattern, you will be given a pattern as input, and are tasked with outputting the sequence of numbers which match the pattern.

Patterns

This section is a definition of what the patterns are and what they represent. A format similar to the one used in the original post will be used for these examples. More clarification on I/O rules will come afterward.

A pattern consists of one or more clearly delimited tokens, each matching a single base-ten digit.

(token)(token)(token)

Tokens can either be constants, accumulators, or a loop.

Constants are each marked with a single token, and there can be up to ten different constants, as each distinct constant represents a distinct digit from each other constant. Here it is represented as a single character from a to j in parenthesis ()

(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)

This pattern, for example, could match the number 1234567890, but not the number 1111111111.

Important note: Numbers cannot have leading 0s, so the pattern would not match 0123456789.

(a)(a)(a)

This pattern would match 111, 222, etc. all the way up to 999. It would not match 000, as it contains leading 0s, and it would not match 123, as all of the digits marked with the same constant must be the same.

Accumulators are marked with a single fixed symbol. The first instance of an accumulator represents any digit from 0 to 9, and each successive instance represents a digit that is one more than the previous instance. Here it is represented as (n+)

(n+)(n+)(n+)(n+)(n+)

For example, this pattern matches 12345, 23456, 34567, 45678, and 56789. Combining constants and accumulators is allowed, giving us access to patterns similar to that of the original challenge:

(a)(n+)(a)(n+)(b)(n+)(b)

Constants can't match the same digits as other constants, but they are allowed to match the same digits as accumulators. This pattern matches, for example, 9192838, but it also matches 1112333.

This isn't enough to support the pattern given in the original problem, so finally we introduce the loop token. This token can only appear at the end of the pattern, or not at all. Here it is represented as ...

(a)(b)(c)(n+)(n+)...

A pattern with the loop token matches all numbers that the pattern would if it did not have the loop, as well as all numbers matched by the pattern repeated twice, as well as three times, as well as four times etc. This pattern matches 78901, but it also matches 7890178923, as well as 789017892378945, etc. all the way up to 7890178923789457896778989.

(a)(a)(a)...

Beware: A pattern with no accumulators but having constants and a loop matches infinitely many numbers. This one matches 111, 111111, 111111111, etc.

Rules

Input can be given in any reasonable format, so long as each token type is clearly distinct, clearly delimited, and consistent. This includes lists of characters, lists of strings, lists of numbers, a single string, curried arguments, etc.

The loop token in particular can be taken anywhere in the input convenient, including separate from all of the other tokens. e.g. you could take it as a separate boolean input, or a command line argument, or at the beginning of the string instead, etc.

Standard rules apply, so you can either output all matches, or take another number n as input and return the nth matching number, etc. Whatever the rules in the tag allow is fine with me.

You may assume any/all of the following:

  • All patterns given have at least a single valid match.
  • When given a pattern with finitely many matches, you will not be given an input asking you to exceed that amount of matches (so you wont be asked to generate the 11th number that matches (a)).
  • Constant variable names first appear in some specific order. So you could, for example, accept (a)(b)(c)(a)(c) but ignore (x)(y)(z) and (c)(b)(a). So long as at least one equivalent form is allowed, it's fine. I doubt this helps anyone, just covering my bases.
  • Not strictly an assumption, but you are allowed to ignore 0 as an output number or assume no input will ask for it, as it technically breaks the "no leading zeros" rule. Edge cases wouldn't add much to the challenge :P

Finally, this is , so shortest code in bytes wins.

Examples

Examples will be given as a pattern, followed by a natural n, followed by the nth matching number (including 0), 0 indexed, all delimited with |.

Still work in progress, the ?s are temporary,

(a)          |   1 | 1
(a)          |   9 | 9
(a)(b)(c)    |   0 | 102
(a)(b)(c)    |   1 | 103
(a)(b)(c)    |   7 | 109
(a)(b)(c)    |   8 | 120
(a)(b)(c)    |   9 | 123
(a)(b)(c)    |   ? | 987
(a)(b)(c)... |   ? | 987
(a)(b)(c)... | ?+1 | 102102
(n+)         |   1 | 1
(n+)         |   9 | 9
(n+)...      |   1 | 1
(n+)...      |   9 | 9
(n+)...      |  10 | 12
(n+)...      |  11 | 23
(n+)...      |  17 | 89
(n+)...      |  18 | 123
(n+)...      |  19 | 234
(n+)...      |  24 | 789
(n+)...      |  25 | 1234
(n+)...      |  26 | 2345

Meta

Should I allow leading zeroes in interest of reducing edge cases?

\$\endgroup\$
7
  • \$\begingroup\$ Can you take the loop as a separate boolean, instead of as a token at the end of the pattern? \$\endgroup\$ Jul 18, 2022 at 3:56
  • \$\begingroup\$ @CommandMaster sure thing, i'll clarify \$\endgroup\$ Jul 18, 2022 at 4:28
  • \$\begingroup\$ For examples format you can use just pattern | beginning of sequence or pattern | n | nth number in sequence (with several ns for each pattern). The second one may be better for sequences which are tricky for big ns. \$\endgroup\$
    – pajonk
    Jul 18, 2022 at 8:02
  • 1
    \$\begingroup\$ @thejonymyster ofc you can use other delimiters like \t and justify to make it more human-readable. \$\endgroup\$
    – pajonk
    Jul 19, 2022 at 7:27
  • \$\begingroup\$ @pajonk right thats a good idea, i was planning on justifying as well but i was rushed away from my computer ~_~; i feel bad about boosting this post to the top over and over so ill get it next edit when i add a bunch of test cases lol \$\endgroup\$ Jul 19, 2022 at 12:36
  • 1
    \$\begingroup\$ Do the matches have to be in order? If so, do they have to be in numerical order, or can they be in lexographic order (like 10 being after 1)? \$\endgroup\$
    – naffetS
    Jul 22, 2022 at 1:55
  • \$\begingroup\$ @Steffan oh actually good point, i guess the order doesnt matter so much. that makes writing examples much more difficult though >_< will have to rephrase the rules next edit, ty \$\endgroup\$ Jul 22, 2022 at 2:52
1
\$\begingroup\$

Move n, out n

Your task is to write a code, where if you move n adjacent characters, the program has to output n.
The code has to work for all integer n's \$0 \le n < \text{code-size}\$
The winning-criteria is

Rules

  • Code length has to be greater than 1
  • You can choose which substring to move for each n
  • Code size is not measured by bytes (ofc), but by the number of characters

Example Program

abcd

abcd -> 0
bcad -> 1 (Move a)
acdb -> 2 (Move cd)
bcda -> 3 (Move bcd)

\$\endgroup\$
3
  • \$\begingroup\$ Do we get to choose which substring gets moved and whither, for each n? Or do we have to make it work for every possible move?? \$\endgroup\$
    – pxeger
    Jul 24, 2022 at 15:49
  • \$\begingroup\$ @pxeger right I'll make it clear \$\endgroup\$
    – math scat
    Jul 24, 2022 at 15:55
  • 1
    \$\begingroup\$ Could you detail what each program should output, supposing your code is abcd? \$\endgroup\$ Jul 24, 2022 at 16:09
1
\$\begingroup\$

Find The Average String

\$\endgroup\$
20
  • \$\begingroup\$ Tag: edit-distance \$\endgroup\$
    – naffetS
    Jul 28, 2022 at 23:49
  • \$\begingroup\$ string, ring can also be sring. The only other possibility for Hello and Ho is Heo. \$\endgroup\$
    – naffetS
    Jul 28, 2022 at 23:57
  • \$\begingroup\$ If there are multiple possibilities, can we output all of them? If so, can it contain duplicates? (I'm running a script for Seggan, Steffan to look for more possibilities - it's really slow.) \$\endgroup\$
    – naffetS
    Jul 29, 2022 at 0:02
  • \$\begingroup\$ Ok, it took like 10 mins to run, but here's the full list: ['Seffan', 'Sefgan', 'Segfan', 'Stefgan', 'Stegfan', 'Steggan'] \$\endgroup\$
    – naffetS
    Jul 29, 2022 at 0:11
  • \$\begingroup\$ @Steffan thanks \$\endgroup\$
    – Seggan
    Jul 29, 2022 at 1:05
  • \$\begingroup\$ you can remove "I hand-made these, so some might be wrong" sicne I checked them with Vyxal lol \$\endgroup\$
    – naffetS
    Jul 29, 2022 at 2:27
  • \$\begingroup\$ Why cannot I simply output the first input and do nothing? For example, for input Seggan, Steffan, Seggan have edit distance 0 to Seggan and 3 to Steffan which average is 1.5. \$\endgroup\$
    – tsh
    Jul 29, 2022 at 2:33
  • \$\begingroup\$ @tsh The rules state: "You may not output any of the inputs" \$\endgroup\$
    – naffetS
    Jul 29, 2022 at 3:26
  • \$\begingroup\$ @Steffan So, for input abc, abcd, should I output abce so it have average 1 instead of abc which have average 0.5? \$\endgroup\$
    – tsh
    Jul 29, 2022 at 5:03
  • \$\begingroup\$ How do we define Levenshtein distance with multi-case input? Is the distance between Ab and ab 0 or 1? I suggest sticking to upper- or lower-case. Suggested test case with no common letters. \$\endgroup\$
    – pajonk
    Jul 29, 2022 at 5:31
  • \$\begingroup\$ Will the outputs only contain characters in the inputs? This would simplify things a lot, and the current test cases imply that. \$\endgroup\$
    – naffetS
    Jul 29, 2022 at 15:52
  • \$\begingroup\$ @tsh Probably, the intended output would be abd with average 1, but waitnig for clarification. \$\endgroup\$
    – naffetS
    Jul 29, 2022 at 15:53
  • \$\begingroup\$ @pajonk there will be no inputs without common letters. Sure, I'll stick to lowercase \$\endgroup\$
    – Seggan
    Jul 29, 2022 at 15:57
  • 1
    \$\begingroup\$ I would suggest changing output a word with "lowest average distance" to two inputs to output a word with "lowest maximum distance" to two inputs and allow output one of input as-is. It may solve the confuse output for abc abcd, and keeping all current testcases valid. This will be different if two input have distance at least 4, for example abcdef, af -> [abcf abdf abef acdf acef adef] but not abf acf adf aef abcdf abcef abdef acdef. \$\endgroup\$
    – tsh
    Jul 30, 2022 at 6:42
  • 1
    \$\begingroup\$ From current specification, average of aaa and aaaa is... aa, aaaaa? it could be confuse to me. \$\endgroup\$
    – tsh
    Jul 30, 2022 at 8:48
1
\$\begingroup\$

Implement String Projection

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Do I understand correctly that it's simply: keep characters from first input that are in the second input? \$\endgroup\$
    – pajonk
    Aug 4, 2022 at 6:09
  • \$\begingroup\$ That's essentially what it outputs. \$\endgroup\$
    – bigyihsuan
    Aug 4, 2022 at 15:01
  • 2
    \$\begingroup\$ Why not state it in the challenge then? If you like, you may keep the formal definition, but I think it's just confusing. Also, what do you mean by if you have unicode support? Do we have to handle unicode or not? I suggest removing this test-case. \$\endgroup\$
    – pajonk
    Aug 4, 2022 at 17:37
  • 1
    \$\begingroup\$ I like the challenge, but I think that adding an informal description of the procedure (like pajonk's) is necessary. \$\endgroup\$ Aug 4, 2022 at 18:53
  • 1
    \$\begingroup\$ I suggest removing the formal definition of projection and the pseudocode. I don't think they help readers at all here. \$\endgroup\$
    – xnor
    Aug 5, 2022 at 10:11
1
\$\begingroup\$
\$\endgroup\$
0
1
\$\begingroup\$

Same number list shape?

Given two lists of positive integers, decide whether the two lists can be made equal by only repeated application of any/either of these two functions:

  • Multiply all numbers of one list by a positive integer constant
  • Add a positive integer constant to all numbers in one list

This is , so shortest code wins.

Extra spec:

  • You can assume lists will be at least three integers long.
  • Both lists input will be the same length.
  • Both lists will be given in strictly ascending order.
  • Standard I/O and rules apply.

Worked out example:

list a: 2 4 8
list b: 1 4 10

multiply elements of list a by 3

list a: 6 12 24
list b: 1 4  10

multiply elements of list b by 2

list a: 6 12 24
list b: 2 8  20

add 4 to elements of list b

list a: 6 12 24
list b: 6 12 24

done, return truthy

Shorter examples

1 1 1 1
3 3 3 3
true

5 10 11 14 16
2 12 14 20 24
true

10 100 1000 10000 100000
1  10  100  1000  10000
true

31   301  3001 30001 300001
1113 1131 1311 3111  21111
true

1 11 111 1111 11111
1 10 100 1000 10000
true

1 2 3 5 8  13
2 3 5 8 13 21
false

1 2 4 8 16
1 3 5 9 17
false

2 3 4 5
7 7 7 7
false

Meta

  • Is it a dupe of are they colinear? Methinks maybe but this only has strictly ascending inputs, slope guaranteed to be on (0,inf) exclusive, and arbitrarily many "points".

  • Better title? This was initially going to emphasize the fact that the allowed transforms don't alter the ratios of differences between numbers, but idk if it's relevant with this new phrasing

  • Ascending order? Is this assumption necessary/would the challenge be better without it maybe?

  • Any better falsy examples? I can't think of any other significant ones, probably will have to wait til post when people are all like "suggested test case:"

\$\endgroup\$
1
  • 3
    \$\begingroup\$ Another way to think about this is "do these 2D points lie on a straight line with positive slope?", where the lists contain the respective x- and y-coordinates. \$\endgroup\$
    – xnor
    Aug 3, 2022 at 9:58
1
\$\begingroup\$

When to give up and start again

Consider the following setup. An evil wizard has ten opaque boxes in front of him. Hidden from you, he chooses a random number of coins \$x \in \{1 \dots 10\}\$ and spreads them uniformly at random in the boxes. That is, there should be equal probability of assignment of coins to boxes from all possible assignments of \$x\$ coins to 10 boxes. If you can prove that in fact there are \$x=10\$ coins hidden in the boxes the wizard will grant you a wish.

In this game, you can look inside one box at a time chosen by you. When you do that, you can see how many coins there are in that box.

However the wizard, being evil, will never let you look in box 10. This might still be ok as you might find 10 coins in the other boxes and in fact the only way to be granted the wish is to have found all 10 coins in the first 9 boxes.

Unfortunately, the wizard does not let you play the game for free. It costs you one dollar to look in box 1, two dollars to look in box two, four in box three, doubling each time up to 256 dollars for box 9. Remember, you can never look in box 10.

The wizard has one last twist for you. At any point, you can choose to give up on this set of boxes and get him to start the whole process again (with a new random \$x\$). Of course, if you have looked in all the 9 boxes and you still have not found 10 coins you have no choice but to give up and start again. But you might want to give up earlier too. Sadly you never get any money back so your costs just carry on building.

Your goal is to devise a strategy that will get you the wish at the minimum expected cost. You should report your mean cost.

Testing

Once you have chosen your strategy, you should run it until you get the wish 10,000 times and report the mean cost. If two answers have the same strategy, the one posted first wins. If two strategies have similar mean costs you may need to test it 100,000 or even more times to tell the difference.

\$\endgroup\$
8
  • \$\begingroup\$ "You want to find out if there are 10 points that have been chosen". I'm confused about the meaning of this sentance \$\endgroup\$
    – mousetail
    Aug 9, 2022 at 7:55
  • \$\begingroup\$ @mousetail I meant if x=10. I'll rephrase. Thanks \$\endgroup\$
    – user108721
    Aug 9, 2022 at 8:29
  • 1
    \$\begingroup\$ What does "spreads them uniformly at random in the boxes" mean? "Spreads them uniformly" sounds like each box gets the same number of coins, but that obviously can't be true. From the rest of the challenge, it seems like he puts the coins in the boxes at random, such that each box contains 0 or more coins and each coin is in one of the boxes. (Also, I'm not sure how the boxes can be sealed if the wizard is putting coins in them--does he magically teleport the coins? Why can't the boxes just be normal unsealed boxes?) \$\endgroup\$
    – DLosc
    Aug 9, 2022 at 16:38
  • \$\begingroup\$ @DLosc Thank you. I changed sealed to opaque. I also changed the randomness wording. Is it better now? \$\endgroup\$
    – user108721
    Aug 9, 2022 at 16:56
  • \$\begingroup\$ Just to clarify, is this a KotH? Could you put tags at the top if you find any that are applicable? \$\endgroup\$
    – user
    Aug 11, 2022 at 21:11
  • \$\begingroup\$ @user Added the tag. From reading the guidance it seems code-challenge is right. \$\endgroup\$
    – user108721
    Aug 11, 2022 at 21:14
  • \$\begingroup\$ "so your costs just carry on building" Does that mean that when you open the first box of the second set, the cost is one greater than your position in the first set? Or does it reset to 1, but add on the the total from the first set? \$\endgroup\$
    – Xcali
    Aug 18, 2022 at 22:42
  • \$\begingroup\$ What's the winning criteria? Shortest code? Lowest average cost? If the latter, a consistent number of runs needs to be determined. \$\endgroup\$
    – Xcali
    Aug 18, 2022 at 22:43
1
\$\begingroup\$

Solve the Greek Computer Puzzle Toy

Posted live: Solve the Greek Computer Puzzle Toy

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

Find "Millionaire" score

I was looking through the uploads of GAMES Magazine to archive.org, and in the first publication I found a challenge called "Millionaire: a word-and-number prize competition".

In this game, each word is assigned a score in the following way:

  1. Turn each letter in the word into a number: A becomes 1, B becomes 2, C becomes 3, and so on.
  2. Multiply the numbers.

For example, the score for BED is \$2*5*4 = 40\$.

(In the competition, the goal was to find the word whose score is closest to a million, but that's not relevant here.)

The challenge

Given a word (i.e. a sequence of uppercase letters) as an input, output its score.

Test cases

Input Output
A 1
Z 26
BED 40
CHAIR 3888
BOTTOM 2340000

Questions

This challenge is probably not new -- please let me know what it's duplicating. I could make the challenge something like "given a list of words, find the word whose score is closes to a million", but I think that's particularly uninteresting.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Closely related, likely related enough to count as a duplicate. This one multiplies the letters, that one adds them. Although if it was me, I would close the other one as it requires you to error if there's special characters, and you have to handle both lowercase and uppercase. \$\endgroup\$
    – naffetS
    Aug 22, 2022 at 17:25
1
\$\begingroup\$

Make a Brainfuck Interpreter

\$\endgroup\$
3
  • 1
    \$\begingroup\$ @thejonymyster woops. fixed \$\endgroup\$
    – Seggan
    Aug 30, 2022 at 22:57
  • \$\begingroup\$ It might be nicer to allow solvers to assume that the input doesn't contain anything besides <>,.+-[]? \$\endgroup\$ Aug 30, 2022 at 23:29
  • \$\begingroup\$ @Adam true. I'll update it \$\endgroup\$
    – Seggan
    Aug 30, 2022 at 23:56
1
\$\begingroup\$

Optimally pop all the bubbles

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

Render a triangle in vulkan

The vulkan API is famous for requiring graphic engines to be very verbose (usually at least 1000 lines of code for a basic result). I am curious to see how far we can escape this trend.

Task

Using vulkan and no other rendering API, have a triangle rendered to screen with a color pattern as seen in this image: vulkan triangle For rendering to screen, some extensions are needed. You should use the minimal number of extensions and layers necessary.

Points are counted as the number of bytes of the program file plus number of bytes of shader files if needed.

You can take whatever shortcuts you want as long as it runs on your machine. You should provide a screenshot of the result as a minimal kind of proof.

Hints

  • As a reference implementation you can check the vulkan tutorial. The code of 15_hello_triangle.cpp is 34536 bytes, and it uses two shaders of 389 and 158 for a total of 35 083 bytes. The c++ code is contained in a single file but this is far to be an optimal solution.
  • You can assert the running machine will be yours and skip all the property checks for devices, queues etc.
  • Well known window creation libraries such as GLFW or SDL are authorized.
  • You can use existing Language bindings to provide a solution in you favorite language.
\$\endgroup\$
1
  • \$\begingroup\$ Welcome to Code Golf, and thanks for using the Sandbox! \$\endgroup\$
    – naffetS
    Sep 5, 2022 at 19:04
1
\$\begingroup\$

Posted

\$\endgroup\$
0
1
\$\begingroup\$

Guess the Caesar cipher shift

A Caesar cipher is a cipher which takes a message and an integer \$n\$ between 0 and 25 (inclusive). Each letter in the message is then "shifted over" in the alphabet by \$n\$ letters, wrapping around the beginning of the alphabet. For example, when \$n=1\$, A becomes B, B becomes C, and so on, up to Z which becomes A. (Uppercase/lowercase is kept the same and punctuation is ignored.)

The challenge

Given a string which represents a message encoded using a Caesar cipher with some shift \$n \in [0,25]\$, output a guess for \$n\$. (You can decide whether punctuation is included or stripped ahead of time.) For example, if you take the word Happy code golfing! and encode it using a Caesar cipher with a shift of 3, you get Kdssb frgh jroilqj!. So if your program takes in Kdssb frgh jroilqj!, it should output 3. Your solution should be deterministic -- e.g. no random number generators.

Scoring

To find the score of your function, it should be tested on every paragraph in Pride and Prejudice1 and every possible shift value (from 0 to 25). Here's a link to a text file with each paragraph on a single line, and here's an alternate version where the quote marks have been replaced with ASCII alternatives. There are 2074 paragraphs, so there are \$26*2074 = 53924\$ test inputs. Your score is equal to

$$s(b,p)=(1+\sqrt{b}) (1+\sqrt{p})-1$$ $$b = \text{number of bytes}$$ $$p = \text{proportion incorrect} = 1-\frac{\text{number of test inputs correct}}{53924}$$

so, for example, a 100 byte program that got 13481 tests correct (i.e. \$\frac34\$ of them incorrect) would have a score of \$(1+\sqrt{100})(1+\sqrt{\frac34})-1 = 15.5\$.

Your goal is to minimize your score.

Here's a link to some Python code, which can be run online, containing a test harness, along with a baseline program to which you can compare your answer. In this case, I've opted to remove all punctuation before parsing each line. For reference, this function is 89 characters and gets 40144/53924 tests correct, so its score is 14.70850917.

Test cases

Input Output
Hs hr z sqtsg tmhudqrzkkx zbjmnvkdcfdc, sgzs z rhmfkd lzm hm onrrdrrhnm ne z fnnc enqstmd, ltrs ad hm vzms ne z vhed. 25
“Rk! brx duh d juhdw ghdo wrr dsw, brx nqrz, wr olnh shrsoh lq jhqhudo. Brx qhyhu vhh d idxow lq dqbergb. Doo wkh zruog duh jrrg dqg djuhhdeoh lq brxu hbhv. L qhyhu khdug brx vshdn loo ri d kxpdq ehlqj lq pb olih.” 3
“That is a question which Mr. Darcy only can answer.” 0
Vczqrsvky cffbvu ritycp, reu klievu rnrp. Yvi ivjzjkretv yru efk zealivu yvi nzky kyv xvekcvdre, reu yv nrj kyzebzex fw yvi nzky jfdv tfdgcrtvetp, nyve kylj rttfjkvu sp Dzjj Szexcvp, 17

1Chosen because it's the most popular book on Gutenberg at the time of writing.

Questions

The scoring function seems like it could be gamed by writing a really short, really inaccurate function, so I'm thinking of adding a function which penalizes incorrect answers even harsher.

\$\endgroup\$
9
  • 1
    \$\begingroup\$ Every paragraph in a whole book? Man, that will be a pain to do lol \$\endgroup\$
    – naffetS
    Aug 24, 2022 at 2:32
  • 1
    \$\begingroup\$ Suggested tags: test-battery, cipher, string. Related: codegolf.stackexchange.com/questions/241532/… \$\endgroup\$
    – pajonk
    Aug 24, 2022 at 11:02
  • 1
    \$\begingroup\$ Suggestion: make accuracy explicit (as correct guesses / total tests). Also maybe add a line that the goal is to minimise the score. \$\endgroup\$
    – pajonk
    Aug 24, 2022 at 11:07
  • \$\begingroup\$ @pajonk Is this too similar to the related question? \$\endgroup\$ Aug 24, 2022 at 16:38
  • 1
    \$\begingroup\$ @Adam, no, I don't think so. Although the concept of reversing Caesar is common to both of them, the test-battery will surely make resulting approaches very different. I provided the link only for reference. \$\endgroup\$
    – pajonk
    Aug 24, 2022 at 18:22
  • 1
    \$\begingroup\$ you might want to ban random generators since luck can affect score \$\endgroup\$
    – okie
    Sep 3, 2022 at 4:01
  • 1
    \$\begingroup\$ The scoring functions seems to mean that any code that gets everything correct gets a score of 0 no matter how long it is. An empty program also scores 0 in a language where this is a valid program producing 0, say by exit code. \$\endgroup\$
    – xnor
    Sep 11, 2022 at 10:44
  • \$\begingroup\$ @xnor I've updated the function to resolve this, though it's not particularly elegant. \$\endgroup\$ Sep 11, 2022 at 19:43
  • \$\begingroup\$ a 0 byte answer with 0 correct will have score 1, same as a 1 byte answer that get 100% correct, which means 0 byte basically wins \$\endgroup\$
    – okie
    Sep 17, 2022 at 2:26
1
\$\begingroup\$

Calculate Pi unto a Point using the Nilakantha series

\$\endgroup\$
2
  • \$\begingroup\$ What should be the desired precision - are floating-point errors ok? Suggested tag: sequence (+adopting output rules from there). Suggestion: merge odd and even cases to one using \$(-1)^n\$ for \$n>1\$. Please make the test-cases copy-friendly (see codegolf.meta.stackexchange.com/a/8101/55372). \$\endgroup\$
    – pajonk
    Sep 13, 2022 at 11:41
  • \$\begingroup\$ There you go. I've added all of that. \$\endgroup\$ Sep 13, 2022 at 12:48
1
\$\begingroup\$

Title

God Save the Queen (or King)!

Input

A calendar year from 927 to the present year. For example 2022.

Output

You can use any three distinguishable outputs. As an example,

“K” (short for King)

or

“Q” (short for Queen)

depending on which was right in England in that year. If there was both a King and Queen in that year you can output either.

If there was no King or Queen for the whole of that year, your code must output something that is not one of those two messages.

Dates

Kings: 937-1553, 1603-1649, 1660-1702, 1714-1837, 1901-1952, 2022

Queens: 1553-1603, 1689-1694, 1702-1714, 1837-1901, 1952-2022

\$\endgroup\$
7
  • \$\begingroup\$ An interesting idea: instead of forcing it to be on January 1, allow years with multiple monarchs to choose one arbitrarily? Could add some depth to the compression strategies. \$\endgroup\$ Sep 17, 2022 at 5:23
  • \$\begingroup\$ @UnrelatedString Good idea \$\endgroup\$
    – user108721
    Sep 17, 2022 at 5:28
  • 1
    \$\begingroup\$ Two downvotes?? Please explain \$\endgroup\$
    – user108721
    Sep 17, 2022 at 5:30
  • \$\begingroup\$ The fixed output strings are a common thing to avoid. I think they'd be better off as any two outputs of the golfer's choice, with everything else corresponding to neither king nor queen. \$\endgroup\$
    – xnor
    Sep 17, 2022 at 7:57
  • \$\begingroup\$ @xnor that's a shame as the messages are what make the challenge more fun. \$\endgroup\$
    – user108721
    Sep 17, 2022 at 9:20
  • \$\begingroup\$ I really don't see how "K" or "Q" (which is what the output requires now) makes the challenge more fun. \$\endgroup\$
    – user
    Sep 17, 2022 at 16:37
  • \$\begingroup\$ @user it was previously "God Save the King" but I changed it on xnor's advice. \$\endgroup\$
    – user108721
    Sep 17, 2022 at 16:40
1
\$\begingroup\$

Is there a area that can see the entire perimeter of a polygon

Oh no, your despotic regime has too many political prisoners and not enough guards! Time for drastic measures: Only build prisons that require only a single guard. But there are many prison design and little time. How to check?

The challenge

Given a polygon, as a list of points, determine if there is a area (where the guard can stand) that can see the entire perimeter of the polygon.

Any convex shape trivially qualifies:

pentagon

Some concave shapes qualify too:

concave shape

But not all:

concave shape where there is no place for a guard

Algorithm hint

The area where a guard can stand is the intersection of the areas on the inside of the tangent of every edge.

Test Cases

Image Points Outcome
TBD
\$\endgroup\$
1
\$\begingroup\$

Calculating Pi using the Gregory-Leibniz series unto a point

\$\endgroup\$
2
  • \$\begingroup\$ Why can't we treat \$\pi_n\$ as a sequence? Also, some test-cases would be nice. \$\endgroup\$
    – pajonk
    Sep 17, 2022 at 19:27
  • \$\begingroup\$ I think this might be too similar to your earlier challenge on Nilakantha series. For instance, loopy walt's answer is already summing up the Gregory-Leibniz series then correcting it by \$\pm 1/n \$ at the end. \$\endgroup\$
    – xnor
    Sep 17, 2022 at 20:35
1
\$\begingroup\$

Construct Digit From Digits

In the game All Ten, each day you are given four single-digit positive integers, and have to use all four of those numbers once each to construct the values 1 through 10 using the following operations:

  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Concatenation, i.e. joining two numbers together; for example, \$1 \text{ concat } 23 = 123\$. (You can only apply this operation if both of the numbers are integers and the number on the right is non-negative.)

So, for example, given numbers \$[4,4,8,9]\$, to make \$4\$ you could do \$((4 \text{ concat } 4) - 8 ) / 9\$. which equals \$(44 - 8)/9 = 36 / 9 = 4\$.

You're allowed to compose these operations however you want, in whatever order, including concatenation (e.g. you can do \$16 - ((2-1) \text{ concat } 3) = 16 + (-1 \text{ concat } 3) = 16 - 13 = 3\$.)

The challenge:

Your function is given two inputs: \$I\$, which is a list of four single digit positive integers (i.e. in the range \$1,2,\ldots,9\$) which are not necessarily unique, and \$n\$, which is also a single digit positive integer.

Your function should return a way of using all four numbers in \$I\$ to construct \$n\$ using the rules above.

Output Format

You can provide the output in any meaningful way, including:

  • A string (or list of numbers/characters) representing the expression which evaluates to \$n\$, using any symbols besides \$1,2,\ldots,9\$ to represent the operations / parentheses necessary
    • e.g. "((4c4)-8)/9"
    • You're also allowed to represent concatenation with the empty string (i.e. no operator at all) -- e.g. "((44)-8)/9"
    • You can leave out parentheses if you specify the order of operations -- e.g. you say that concatenation has highest priority, then return "(44-8)/9"
  • A tree or nested list with where each leaf represents a number in \$I\$ and the parents represent the various operations

You may assume there is at least one solution; if there's more than one solution, you may output any of them.

Test cases

[To do -- I need to enumerate all of the possible ways to construct a given value for this to be useful.]

Questions

This is a really bad title, but it's hard to describe succintly. There's also a lot of text here, but I don't know how to shorten it.

\$\endgroup\$
8
  • \$\begingroup\$ May the output be in Reverse Polish notation, removing the need for parenthesis completely? Or does that bend the 'provide output in any meaningful way' too much? \$\endgroup\$ Sep 27, 2022 at 12:07
  • \$\begingroup\$ Also, is the division regular division or integer division? If the first, is something like ((1/5)concat 5)*8 = 2 valid (where 1 /5 -> 0.2 concat 5 -> 0.25 *8 -> 2)? And how to deal with floating point inaccuracies in that case? \$\endgroup\$ Sep 27, 2022 at 12:13
  • \$\begingroup\$ Closely related - partial duplicate Difference is that that challenge asks to use the digits 0 through 9, instead of an input-list of 4 digits. And this challenge allows concatenation, whereas the other answer allowed exponentiation. But my 05AB1E answer would be nearly the same. \$\endgroup\$ Sep 27, 2022 at 12:26
  • \$\begingroup\$ @KevinCruijssen (1) I think that Polish notation should be allowed. (2) It's supposed to be regular divison, though the expression you gave isn't valid because you aren't allowed to concatenate non-integers. I don't understand the second part -- the solver needs to handle floating point inaccuracies so they give the correct answer. (3) I don't know how close two challenges need to be before they are counted as distinct -- do you think this is still worth posting? It seems like the answer is no... \$\endgroup\$ Sep 27, 2022 at 15:00
  • \$\begingroup\$ @97.100.97.109 In the original game, concatenation is only allowed on the original integers; i.e. you cannot do (2 - 1) concat 3. Is that not the case here? \$\endgroup\$
    – pigrammer
    Sep 27, 2022 at 16:36
  • \$\begingroup\$ @pigrammer You can if you do, e.g. (2-1)=, which saves a 1 to your "workspace", which means you can then do 1 concat 3. \$\endgroup\$ Sep 27, 2022 at 17:35
  • \$\begingroup\$ @97.100.97.109 No, it gives an error "Combo buttons cannot be used in two-digit numbers" \$\endgroup\$
    – pigrammer
    Sep 27, 2022 at 17:36
  • \$\begingroup\$ @prigrammer Whoops, I was wrong. I think I'll still allow it since it makes the application marginally simpler. \$\endgroup\$ Sep 27, 2022 at 18:47
1
\$\begingroup\$

Create a nibble shorthand

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Is it strict graphical-output or we may return a collection of symbols (read: ascii-art) to represent a nibble? Also, is scaling allowed (I mean, like mirrored r is smaller version of the image for the reverse of r)? \$\endgroup\$
    – pajonk
    Sep 25, 2022 at 18:47
  • \$\begingroup\$ @pajonk It's graphical output. Scaling is not allowed. \$\endgroup\$
    – Wheat Wizard Mod
    Sep 25, 2022 at 18:53
1
\$\begingroup\$

Longest alternating subsequence

\$\endgroup\$
2
  • \$\begingroup\$ If our language uses an SBCS, can we use UTF-8 if it helps with the score? \$\endgroup\$
    – naffetS
    Sep 29, 2022 at 0:22
  • \$\begingroup\$ @Steffan You can choose the encoding in your favor if your language supports multiple encodings. \$\endgroup\$
    – Bubbler
    Sep 29, 2022 at 0:32
1
\$\begingroup\$

Partition square into squares

Given integers \$n\$, \$m\$ and \$k\$, randomly output a list of \$k\$ numbers between \$1\$ and \$m\$ (inclusive) such that the sum of the squares of the numbers in the list is equal to \$n\$ squared. In other words, find a way to randomly split \$n^{2}\$ into \$k\$ squares between \$1\$ and \$m^{2}\$.

If there is no solution (which may happen if \$k = 2\$), you may exit from your program or return an error.

The program should take less than 40 seconds for inputs with \$k, n, m\$ less than 10000.

Scoring

This is , so the smallest score in bytes wins.

Input

Three numbers \$n\$, \$m\$, and \$k\$.

Output

A random list of \$k\$ numbers between \$1\$ and \$m\$, such that the sum of the squares of them is equal to \$n^{2}\$. All possible lists that satisfy the conditions should be equally likely.

Test cases

Input (n, m, k)      Possible output
114, 100, 6          [13, 1, 25, 76, 44, 67]
114, 100, 6          [64, 58, 20, 32, 64, 4]
57, 40, 7            [2, 32, 18, 26, 26, 17, 16]
7, 10000, 2          [error]
7, 7, 3              [2,3,6], [2,6,3], [3,2,6], [3,6,2], [6,2,3], [6,3,2]
\$\endgroup\$
2
  • \$\begingroup\$ The time limit isn't bad, but it sure will make low efficiency languages unable to answer. Also, output all the possible result is better than randomly choose one, random is sometime unavailable and is hard to define, while adding no challenge to the original question. Nice question overall \$\endgroup\$
    – okie
    Oct 7, 2022 at 4:56
  • \$\begingroup\$ Hello, and welcome to the Code Golf SE! \$\endgroup\$ Oct 7, 2022 at 18:53
1
\$\begingroup\$

Prime number checksum

Posted here

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

Alphabet checksum

\$\endgroup\$
7
  • \$\begingroup\$ This question may be tricky with our current default I/O rules, i.e. allowing I/O as char codes. Such I/O trivialises the problem (as it's just sum the input and take mod 26). OTOH, disallowing this explicitly may be disadvantageous to some languages that cannot process strings natively. \$\endgroup\$
    – pajonk
    Oct 20, 2022 at 18:19
  • \$\begingroup\$ @pajonk - I'm going to say that the input must be a string. Otherwise, the challenge is way too easy. \$\endgroup\$
    – The Thonnu
    Oct 20, 2022 at 18:34
  • \$\begingroup\$ Can we switch to uppercase if we want? \$\endgroup\$
    – Adám
    Oct 22, 2022 at 23:03
  • \$\begingroup\$ @Adám - I'll say no for that one. It needs to be lowercase. If you want, you can just convert it to uppercase at the start of your program. \$\endgroup\$
    – The Thonnu
    Oct 23, 2022 at 6:11
  • \$\begingroup\$ Also, I forgot to link it but I've already posted the challenge on the main site. \$\endgroup\$
    – The Thonnu
    Oct 23, 2022 at 6:13
  • \$\begingroup\$ Can we use 1-based alphanumeric mapping? With a = 1, b = 2, c = 3 ... z = 26 instead of a = 0, b = 1, c = 2 ... z = 25? Obviously, this changes the outputs... \$\endgroup\$
    – acvill
    Oct 24, 2022 at 20:13
  • \$\begingroup\$ @acvill - no. It must be 0-based. Also, the challenge has already been posted on the main site. \$\endgroup\$
    – The Thonnu
    Oct 25, 2022 at 7:10
1
\$\begingroup\$

Render an Ideographic Description Sequence

There are 12 characters in Unicode that can be used to describe any CJK character, which are often made up of reoccurring parts ("radicals") composed in different ways.

For example, U+86D9 蛙 can be described as U+2FF0 U+866B U+572D ⿰虫圭.

Your task is to take such an Ideographic Description Sequence as input and produce an image of the resulting character as an output. You can assume the input conforms to the following grammar, which is taken from the Unicode standard, which explains this topic very well:

IDS := Ideographic | Radical | CJK_Stroke | Private Use | U+FF1F
    | IDS_BinaryOperator IDS IDS
    | IDS_TrinaryOperator IDS IDS IDS
CJK_Stroke := U+31C0 | U+31C1 | ... | U+31E3
IDS_BinaryOperator := U+2FF0 | U+2FF1 | U+2FF4 | ... | U+2FFA | U+2FFB
IDS_TrinaryOperator := U+2FF2 | U+2FF3

This is a kind of prefix notation (polish notation).

Ideographic and Radical are defined in PropList.txt:

2E80..2E99    ; Radical # So  [26] CJK RADICAL REPEAT..CJK RADICAL RAP
2E9B..2EF3    ; Radical # So  [89] CJK RADICAL CHOKE..CJK RADICAL C-SIMPLIFIED TURTLE
2F00..2FD5    ; Radical # So [214] KANGXI RADICAL ONE..KANGXI RADICAL FLUTE

3006          ; Ideographic # Lo       IDEOGRAPHIC CLOSING MARK
3007          ; Ideographic # Nl       IDEOGRAPHIC NUMBER ZERO
3021..3029    ; Ideographic # Nl   [9] HANGZHOU NUMERAL ONE..HANGZHOU NUMERAL NINE
3038..303A    ; Ideographic # Nl   [3] HANGZHOU NUMERAL TEN..HANGZHOU NUMERAL THIRTY
3400..4DBF    ; Ideographic # Lo [6592] CJK UNIFIED IDEOGRAPH-3400..CJK UNIFIED IDEOGRAPH-4DBF
4E00..9FFF    ; Ideographic # Lo [20992] CJK UNIFIED IDEOGRAPH-4E00..CJK UNIFIED IDEOGRAPH-9FFF
F900..FA6D    ; Ideographic # Lo [366] CJK COMPATIBILITY IDEOGRAPH-F900..CJK COMPATIBILITY IDEOGRAPH-FA6D
FA70..FAD9    ; Ideographic # Lo [106] CJK COMPATIBILITY IDEOGRAPH-FA70..CJK COMPATIBILITY IDEOGRAPH-FAD9
16FE4         ; Ideographic # Mn       KHITAN SMALL SCRIPT FILLER
17000..187F7  ; Ideographic # Lo [6136] TANGUT IDEOGRAPH-17000..TANGUT IDEOGRAPH-187F7
18800..18CD5  ; Ideographic # Lo [1238] TANGUT COMPONENT-001..KHITAN SMALL SCRIPT CHARACTER-18CD5
18D00..18D08  ; Ideographic # Lo   [9] TANGUT IDEOGRAPH-18D00..TANGUT IDEOGRAPH-18D08
1B170..1B2FB  ; Ideographic # Lo [396] NUSHU CHARACTER-1B170..NUSHU CHARACTER-1B2FB
20000..2A6DF  ; Ideographic # Lo [42720] CJK UNIFIED IDEOGRAPH-20000..CJK UNIFIED IDEOGRAPH-2A6DF
2A700..2B739  ; Ideographic # Lo [4154] CJK UNIFIED IDEOGRAPH-2A700..CJK UNIFIED IDEOGRAPH-2B739
2B740..2B81D  ; Ideographic # Lo [222] CJK UNIFIED IDEOGRAPH-2B740..CJK UNIFIED IDEOGRAPH-2B81D
2B820..2CEA1  ; Ideographic # Lo [5762] CJK UNIFIED IDEOGRAPH-2B820..CJK UNIFIED IDEOGRAPH-2CEA1
2CEB0..2EBE0  ; Ideographic # Lo [7473] CJK UNIFIED IDEOGRAPH-2CEB0..CJK UNIFIED IDEOGRAPH-2EBE0
2F800..2FA1D  ; Ideographic # Lo [542] CJK COMPATIBILITY IDEOGRAPH-2F800..CJK COMPATIBILITY IDEOGRAPH-2FA1D
30000..3134A  ; Ideographic # Lo [4939] CJK UNIFIED IDEOGRAPH-30000..CJK UNIFIED IDEOGRAPH-3134A
31350..323AF  ; Ideographic # Lo [4192] CJK UNIFIED IDEOGRAPH-31350..CJK UNIFIED IDEOGRAPH-323AF

Rules

Keep in mind that output has to be an image, not a unicode character, as per the default loophole, but I recommend a text rendering engine to render each radical.

You can assume the input won't contain private use characters.

Use the following definitions of the Ideographic Description Characters. The percentages are not defined in unicode, but made up for this challenge. Each component should be squashed to the required shape, so that each intermediate result is a square. The output should also be a square image. See also: https://en.wikipedia.org/wiki/Chinese_character_description_languages#Ideographic_Description_Sequences

Code point Character Meaning
U+2FF0 divide horizontally in halves
U+2FF1 divide vertically in halves
U+2FF2 divide horizontally in thirds
U+2FF3 divide vertically in thirds
U+2FF4 enclose; the lengths should be 20%, 60%, 20%
U+2FF5 surround from top; the inner has 60% the width and 80% of the height
U+2FF6 surround from below; the inner has 60% the width and 80% of the height
U+2FF7 surround from left; the inner has 80% the width and 60% of the height
U+2FF8 surround from top-left; the inner has 80% the width and height
U+2FF9 surround from top-right; the inner has 80% the width and height
U+2FFA surround from top-right; the inner has 80% the width and height
U+2FFB overlay with transparency

Examples

Input Output
⿰虫圭
⿲彳圭亍
⿵几皇
⿻工从
⿴囗⿰⿱鹵凼⿰丨㇌ 2
⿱井蛙 1
⿱井⿰虫圭 1
⿱井⿰虫⿱土土 1
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Is it too long? \$\endgroup\$
    – corvus_192
    Oct 25, 2022 at 20:00
  • 1
    \$\begingroup\$ Downvoter, could you please explain why? \$\endgroup\$
    – corvus_192
    Oct 26, 2022 at 11:46
  • \$\begingroup\$ why not restrict output to graphical ones only for simplicity? \$\endgroup\$ Oct 27, 2022 at 11:55
  • 1
    \$\begingroup\$ @鳴神裁四点一号 I'm not sure I understand what you mean. This is graphical-output, so the output must be an image or image file. \$\endgroup\$
    – corvus_192
    Oct 27, 2022 at 12:37
1
\$\begingroup\$

Increment, decrement, undo, peek

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Nice challenge! I was thinking maybe add the tags: function and number \$\endgroup\$
    – The Thonnu
    Oct 25, 2022 at 16:21
  • \$\begingroup\$ I think this is a very interesting challenge, but the definitions for the four functions are very difficult to understand as they're currently written. I haven't figured out a really good way to phrase them, but at the very least I think replacing "has the value" with something like "contains the value". When I read "Increment has the value of the function that created it plus 1" it took me a long time to figure out that it didn't mean incr == 1. \$\endgroup\$ Oct 25, 2022 at 16:47
  • \$\begingroup\$ What should eval(undo)() return in your example? Maybe this is undefined and we don't need to handle such cases? Do we need to keep track of all operations for undo or there's a limit? \$\endgroup\$
    – pajonk
    Oct 27, 2022 at 7:13
  • \$\begingroup\$ @pajonk Good questions, thanks. I suppose that behavior should just be undefined. Re: Limit I think the only limit should be the limitations of your system/language. \$\endgroup\$
    – Jordan
    Oct 27, 2022 at 12:00
1
\$\begingroup\$

Length of Binary as Base 10 [OEIS A242347]

\$\endgroup\$
6
  • 3
    \$\begingroup\$ Can we use default sequence rules and output infinitely, or output the first \$n\$ terms? \$\endgroup\$
    – naffetS
    Oct 26, 2022 at 4:13
  • \$\begingroup\$ I'll edit it to output the first n terms \$\endgroup\$
    – pacman256
    Oct 26, 2022 at 13:00
  • \$\begingroup\$ I second @Sʨɠɠan's suggestion to allow standard sequence rules. Also, your wording now is misleading - A242347 isn't the number of digits in the first n terms of A008559 (it's the number of digits of the nth term). I suggest changing the tile to reflect the challenge by adding "Length of" and updating the OEIS number accordingly. Another thing, good practice is to give meaningful labels to hyperlinks - I suggest changing "here" to "A008559" and "this sequence" to "sequence A242347". \$\endgroup\$
    – pajonk
    Oct 27, 2022 at 7:06
  • \$\begingroup\$ @pajonk will do \$\endgroup\$
    – pacman256
    Oct 27, 2022 at 12:59
  • \$\begingroup\$ Your test cases don't match the specs currently (only one number instead of first n terms). Also, the \$a(1)=2\$ in the Input section is confusing. \$\endgroup\$
    – pajonk
    Oct 27, 2022 at 15:37
  • \$\begingroup\$ fixed those issues \$\endgroup\$
    – pacman256
    Oct 27, 2022 at 16:14
1
\$\begingroup\$

Power sequence differences

\$\endgroup\$
6
  • \$\begingroup\$ Any reason for the first 5 terms portion in the challenge description? I see in the rules you allow the default [sequence] rules, so it can be the \$n^{th}\$, first \$n\$, or infinite sequence, instead of specifically the first \$5\$, right? \$\endgroup\$ Oct 27, 2022 at 12:29
  • 1
    \$\begingroup\$ @KevinCruijssen I will edit the challenge to allow anything that includes the 5th term. This includes the first 5 terms, just the 5th term, or the infinite sequence. \$\endgroup\$
    – The Thonnu
    Oct 27, 2022 at 12:32
  • \$\begingroup\$ These finite differences have a closed form, which I'm not sure is your intention? No matter what you choose you should define the domains of \$ x \$ and \$ d \$. \$\endgroup\$ Oct 27, 2022 at 18:52
  • \$\begingroup\$ @FryAmTheEggman I don't get what you mean by that. Could you explain further? \$\endgroup\$
    – The Thonnu
    Oct 28, 2022 at 9:03
  • \$\begingroup\$ For the first part of my comment, I wanted to let you know that the 5th term of the \$d\$th difference sequence of \$n^{x}\$ was \$ \sum_{i=0}^{d} \binom{d}{i} (4+d-i)^{x} (-1)^{x} \$. I think a lot of answers would probably use that rather than manually computing difference sequences, which I wasn't sure was what you wanted. There isn't anything wrong with it, unless you don't like it. The other part is that you don't specify that \$ x \$ and \$ d \$ are positive integers and \$ d < x \$. You can choose other domains, but those are true of your test cases. \$\endgroup\$ Oct 28, 2022 at 14:56
  • \$\begingroup\$ @FryAmTheEggman - for the first bit, I don't really mind if people use a formula for it. For the second bit, yes that is the domain I wanted. I'll edit that in now. \$\endgroup\$
    – The Thonnu
    Oct 28, 2022 at 15:36
1
\$\begingroup\$

Longest Total Distance Cyclic Quine Chain

Write a program of upto 100 bytes that outputs another program that outputs another program etc. until after a finite number of iterations outputting the original program again.

Each program in the cycle must have a length less than or equal to 100 bytes.

Your score is the sum of the Levenshtein distance between each program and it's output. I hope this leads to answers that do something more creative than change a single digit each time.

Maximum possible score is: $$256^{101}$$

\$\endgroup\$
14
  • \$\begingroup\$ finite? As in, how many iterations exactly? \$\endgroup\$ Nov 1, 2022 at 7:47
  • \$\begingroup\$ Like after 10, 20, or 100? \$\endgroup\$ Nov 1, 2022 at 7:47
  • \$\begingroup\$ The goal is to get the highest finite number of iterations \$\endgroup\$
    – mousetail
    Nov 1, 2022 at 7:48
  • \$\begingroup\$ I imagine scores will be around 10^100 \$\endgroup\$
    – mousetail
    Nov 1, 2022 at 7:49
  • \$\begingroup\$ I see. And why upto 100 bytes? I imagine some really verbose language like Taxi wouldn't be able to answer this. \$\endgroup\$ Nov 1, 2022 at 7:50
  • 2
    \$\begingroup\$ Related: Cyclic levenquine \$\endgroup\$
    – Bubbler
    Nov 1, 2022 at 7:52
  • \$\begingroup\$ I need to set a limit or you could easily get arbitrarily high scores. Shorter languages can easily get scores that are so high as to be uncomputable even for short lengths. I hope with this length languages like python can participate but golfing languages can still genuinely compete against each-other, since their difference in score is hopefully representable. \$\endgroup\$
    – mousetail
    Nov 1, 2022 at 7:52
  • \$\begingroup\$ And I don't really understand ` that outputs another program `. Are we supposed to output the source code of another program, that when executed output's the source code of yet another one? \$\endgroup\$ Nov 1, 2022 at 7:54
  • \$\begingroup\$ @Bubbler It's different since you are trying to get the highest distance possible instead of a distance of exactly 1 \$\endgroup\$
    – mousetail
    Nov 1, 2022 at 7:54
  • \$\begingroup\$ @py3_and_c_programmer yes, it's a quine like \$\endgroup\$
    – mousetail
    Nov 1, 2022 at 7:55
  • 1
    \$\begingroup\$ @py3_and_c_programmer Not being answerable in some languages is totally OK. @ mousetail: Yes, I'm aware of the differences. \$\endgroup\$
    – Bubbler
    Nov 1, 2022 at 7:55
  • \$\begingroup\$ Would some test cases in a particular... No, never mind. \$\endgroup\$ Nov 1, 2022 at 7:58
  • 1
    \$\begingroup\$ 1) I think you should clarify that it is NOT "longest chain, ties broken by highest distance sum". I guess my initial misconception is due to the title. Maybe "Most distant cyclic quine chain"? 2) The theoretical maximum score is (sum of lengths of all possible programs of 100 bytes or shorter) * 2, which is a bit lower than 256^101. \$\endgroup\$
    – Bubbler
    Nov 1, 2022 at 8:00
  • \$\begingroup\$ Suggested tag: busy-beaver \$\endgroup\$
    – alephalpha
    Nov 1, 2022 at 11:13
1
\$\begingroup\$

Perfect Nontransitive Sets

\$\endgroup\$
7
  • \$\begingroup\$ "in comparing two tuples the one that has more elements greater than the other is greater" - how do we compare each element to the other tuple? Maybe you mean that we should compare elements to the respective element in the other tuple (i.e. zip with <) and then the lesser tuple is the one with more truthy results? Or maybe you mean we compare an element to each of the three in the other tuple? Maybe a worked example would help. \$\endgroup\$ Nov 3, 2022 at 16:50
  • \$\begingroup\$ @JonathanAllan Shoot, I was afraid the wording there was confusing. Yes, it's essentially zip with <, hopefully the the edits clear up my intent. \$\endgroup\$ Nov 3, 2022 at 18:01
  • \$\begingroup\$ It seems that {(n-i, 0, i) for i in range(n)} will satisfy the property (since no pair of elements contain one that is less than the other). \$\endgroup\$ Nov 3, 2022 at 18:15
  • \$\begingroup\$ ...e.g. {(1, 0, 4), (2, 0, 3), (3, 0, 2), (4, 0, 1), (5, 0, 0)} \$\endgroup\$ Nov 3, 2022 at 18:22
  • \$\begingroup\$ @JonathanAllan This would not be a valid set since none of them are comparable. It appears things are still confusing. Do you think it would be better if I simply disallow tuples that have any element-wise equalities? \$\endgroup\$ Nov 3, 2022 at 18:30
  • \$\begingroup\$ So "all pairs must be comparable" means one must be "less than" the other? If you spell that out it's probably fine, but it would probably be worth adding an invalid example output to ensure the point gets accross. \$\endgroup\$ Nov 3, 2022 at 18:43
  • 1
    \$\begingroup\$ Went ahead and did both, if anybody still finds this confusing let me know \$\endgroup\$ Nov 3, 2022 at 18:57
1
81 82
83
84 85
156

You must log in to answer this question.

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