536
\$\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 needs more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended!

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".

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

3505 Answers 3505

1
99 100
101
102 103
117
0
\$\begingroup\$

Which Ninjutsu am I casting?

Posted

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Bad title considering that validation is the smallest part of the challenge, but it looks pretty good otherwise \$\endgroup\$ Feb 9 at 12:58
  • 1
    \$\begingroup\$ @UnrelatedString I changed the title. \$\endgroup\$ Feb 9 at 13:08
  • \$\begingroup\$ (note that it's recommended (in the sandbox FAQ) to leave sandbox posts for at least 72 hours. \$\endgroup\$
    – DELETE_ME
    Feb 11 at 6:31
0
\$\begingroup\$

Trilobaccis' speed

The challenge is inspired by this beautiful one: Speed of Lobsters. And it's similar to this other one: Is it a lobster number?.

The word Trilobacci is a blend of Tribonacci and Lobster.

About tribonacci, quoting Wikipedia:

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

Regarding lobsters and speed, they refer to this subreddit where people have fun editing the text of images to create new phrases.

The challenge

The challenge is to "blank out" the digits of given numbers (let's say a,b,c) using the digit of other numbers (say x,y,z) which you have to find by yourself, and then tell whether you could use all the digits from x,y,z to blank out some (or even all) of the digits from a,b,c.

Being more specific: given three positive integers in ascending order, which are necessarily part of a tribonacci sequence (at least the one they can generate), find the three numbers that generated the sequence and use them to blank out the original input numbers according to the lobsters rules.
Then output a truthy value if you used all the digits from the found numbers, or a falsy value if you are left with digits that couldn't be used to blank out the input digits.

For the numbers generating the sequence, I mean the the three smallest non-negative integers being part of the sequence.

Lobsters rule!

Start taking the first digit of the first number of x,y,z and blank out its first occurrence in the digits of a,b,c. Then proceed with the next digit from x,y,z looking for its first occurrence in a,b,c, starting from where you left.

Examples

Given

[ 13, 23, 43 ]

you'll find out that they are part of a sequence generated by

[ 1, 3, 3 ]

so then you can proceed at the speed of lobsters:

[ 1, 3, 3 ]   --->   [ 13, 23, 43 ]
               ||
              _||_
              \  /
               \/
[ X, 3, 3 ]   --->   [ *3, 23, 43 ]

[ X, X, 3 ]   --->   [ **, 23, 43 ]

[ X, X, X ]   --->   [ **, 2*, 43 ]

And in this case you output a truthy value because you used all the digits from [ 1, 3, 3 ].

The numbers [ 903, 1661, 3055 ] are also generated by [ 1, 3, 3 ], but the output for them is a falsy value:

[ 1, 3, 3 ]   --->   [ 903, 1661, 3055 ]
               ||
              _||_
              \  /
               \/
[ X, 3, 3 ]   --->   [ 903, *661, 3055 ]

[ X, X, 3 ]   --->   [ 903, *661, *055 ]

[ X, X, 3 ]   --->   [ 903, *661, *055 ] can't find any 3 after the last blanked digit

Input

Three integers. (One by one, into an array, as one or more a strings, split like bananas, etc.)
You can even take them in descending order if like.

Output

Choose a truthy and a falsy value and be consistent with them.

Standard rules apply for your answer, with standard I/O conventions, while default Loopholes are forbidden.

It would be nice if you could provide an easy way to try your program and possibly an explanation of how it works.

This is , the shortest wins.

Test cases

Soon...

Meta

  • Any feedback / suggestion?
  • I thought about considering the digits of x,y,z as always, but blanking out their occurrence in a,b,c from right-to-left, so that who participated to the previous lobster challenges would have to renew this part of the answer. Do you think it would be a good thing?
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Nice challenge, maybe a bit convoluted but I like it. I'd mention somewhere that the numbers in a tribonacci sequence need to all be positive, otherwise for example [1,3,3] could come after [-1,1,3] and there would be no beginning. I believe going left-to-right or right-to-left in the last step does not make any difference, if one of them is possible the other one will be as well \$\endgroup\$
    – Leo
    Feb 10 at 5:30
  • \$\begingroup\$ @Leo I am going to highlight "For the numbers generating the sequence, I mean the the three smallest non-negative integers being part of the sequence." And I'll specify that the input is positive. Regarding the right-to-left, thing, I expressed it so badly: I meant considering the digits of x,y,z LtR as always, but blanking their occurrence in a,b,c in RtL direction. Since you are already finding the sequence in reverse, it could make sense to rename the challenge like Retrolobacci and do the LtR thing, but I don't know. \$\endgroup\$ Feb 10 at 11:25
  • 1
    \$\begingroup\$ Oh, sorry, I had missed the part about non-negative integers! To make it completely dumb-proof (read: Leo-proof) you could add a "positive" also to the input description section. Also, some people will probably want to take the input numbers backwards, I don't know if this is already a default but it may be worth explicitly allowing it in the text. I think Trilobacci sounds better than Retrolobacci, but other than that I have no opinion on LtR vs RtL :) \$\endgroup\$
    – Leo
    Feb 10 at 22:07
  • \$\begingroup\$ @Leo I added the backward input, thank you! I don't like Retrolobacci either, it could be "Trilobaccis' speed, when running backwards", maybe too long but somehow funny. \$\endgroup\$ Feb 10 at 22:23
0
\$\begingroup\$

Challenge

Print all the Tamil characters in any order you like. They should be 12 vowels, 18 consonants and the special symbol ஃ .

Your code should not print anything except for those letters but it can print one letter per line.

The consonants are: க் ங் ச் ஞ் ட் ண் த் ந் ப் ம் ய் ர் ல் வ் ழ் ள் ற் ன்

The vowels are: அ ஆ இ ஈ உ ஊ எ ஏ ஐ ஒ ஓ ஔ

Shortest code wins

\$\endgroup\$
9
  • 1
    \$\begingroup\$ @user Done. I hope it helps. \$\endgroup\$
    – Anush
    Feb 11 at 14:59
  • \$\begingroup\$ There isn't really a point in doing this: 31 bytes, copy-paste the letters. \$\endgroup\$ Feb 11 at 21:19
  • \$\begingroup\$ @fasterthanlight if you add the print statement do you think you won’t be able to do any better? Also, how would you do it in C for example? \$\endgroup\$
    – Anush
    Feb 11 at 21:25
  • \$\begingroup\$ I don't specialize in C. For example, in O5AB1E, you can just do ,"க் ங் ச் ஞ் ட் ண் த் ந் ப் ம் ய் ர் ல் வ் ழ் ள் ற் ன் அ ஆ இ ஈ உ ஊ எ ஏ ஐ ஒ ஓ ஔ ஃ in 33 bytes, excluding spaces \$\endgroup\$ Feb 11 at 21:30
  • \$\begingroup\$ @fasterthanlight and no more compact way to go over the relevant Unicode characters? \$\endgroup\$
    – Anush
    Feb 11 at 21:32
  • \$\begingroup\$ @fasterthanlight what about if I changed it to printing all the Unicode Tamil symbols? \$\endgroup\$
    – Anush
    Feb 11 at 21:35
  • \$\begingroup\$ Could you also include the Unicode codepoints of the characters? I think that would make it easier for solvers to consider strategies for generating them. \$\endgroup\$
    – xnor
    Feb 11 at 22:40
  • \$\begingroup\$ @xnor yes I will do that. Do you think 31 characters is too few for it to be interesting? \$\endgroup\$
    – Anush
    Feb 12 at 8:39
  • 1
    \$\begingroup\$ @Anush I think it depends how the code points are distributed, whether they're not too random or too ordered. \$\endgroup\$
    – xnor
    Feb 12 at 21:12
0
\$\begingroup\$

Generate a "Pi-ey" number

Generate the smallest integer of the form \$x^x\$ with \$10^{n-1}\cdotπ\$ digits, rounded down, given \$n\$. If there is no such number, take the nearest number that has as many digits of \$π\$ in its digit count. For example, if \$n=5\$, then the number of digits would be 31415. If there was no such number of form \$x^x\$, then take the nearest digit count similar to 31415, like 31414 and 31416.

If there are multiple values of \$x\$ that will work, whichever one is closer to \$3.1415926e3141...\$ will be the chosen value. For instance, if two solutions for \$n=5\$ were \$1.234e31414\$ and \$1.234e31416\$, we would select the former, as it is closer to \$3.1415926...e31415\$.

Test cases:

Glitchy picture

Rules:

  • Shortest amount of bytes of code wins
  • Please post the number of bytes as well as the runtime for \$n=5\$.
  • It is recommended that you post your score (below), but is not required.

Scoring

  • Your score will be based on your program time and length. \$\text{score} = \text{program length in bytes} + 10 \times \text{time to execute in seconds}\$
\$\endgroup\$
9
  • \$\begingroup\$ The first paragraph seems unclear to me. For the \$n\pi\$ digits, do we round that down, or to the nearest integer? The second sentence seems a little unclear as well, do you mean to find the number that's closest to having \$n\pi\$ digits? If so, if there are multiple (let's say \$1.1234e313\$ and \$1.1234e315\$), which one should be chosen? \$\endgroup\$ Feb 11 at 21:20
  • \$\begingroup\$ @RedwolfPrograms For the \$n\pi\$ digits, round down. For you second question, if \$n=5\$, you would find the closest number of form \$x^x\$ with 31415 digits. If there is no such number, with 31415 digits, then find the nearest number with a digit count closest to 31415 (i.e. 31414, 31416, etc). To answer your last question, the number that is closer to \$3.141926535...e314\$ will be selected if there are multiple. \$\endgroup\$ Feb 11 at 21:24
  • \$\begingroup\$ I'd recommend editing that into the post, when you include that information it's much more clear. Also, you might want to put the test cases in as text rather than an image to make them easier to copy-paste. Other than that, it looks clear to me, but I'd wait a day or two to make sure nothing else is unclear. (Don't worry, it's way better than my first post :p) \$\endgroup\$ Feb 11 at 21:28
  • 1
    \$\begingroup\$ Program length plus time in what? Seconds? On what machine? Combining length and speed in this way is very sensitive to how the speed is measured. Taking a step back, getting this tradeoff to be balanced and interesting for golfers is very hard, possibly impossible across a wide range of languages of varying golfiness and speed. I'd strongly recommend against this, especially for your first challenge. I think either code-golf or fastest-code would be better. \$\endgroup\$
    – xnor
    Feb 11 at 22:09
  • \$\begingroup\$ @xnor I have changed my post so that it will be easier, with point bonuses as needed \$\endgroup\$ Feb 11 at 22:20
  • 2
    \$\begingroup\$ @fasterthanlight Bonuses have fallen really out of favor with the community. Including this many large bonuses is virtually guaranteed to get your challenge downvoted. \$\endgroup\$
    – xnor
    Feb 11 at 22:22
  • \$\begingroup\$ Thanks for moving your post to the sandbox. I generally agree with xnor that trying to score in this way is ill-advised, but if you want to continue with it you should decide for which values you will test the speed. In addition, assuming I am understanding correctly, the output is the full value \$ x^{x} \$. I think it is possible that an efficient answer will spend more time printing out this number than it would take to calculate it, which seems to somewhat defeat the purpose. \$\endgroup\$ Feb 12 at 0:27
  • \$\begingroup\$ @FryAmTheEggman So how can you tell when a program is done calculating something? \$\endgroup\$ Feb 12 at 1:28
  • \$\begingroup\$ Ah, sorry I meant to suggest that just asking for \$ x \$ should solve the problem. \$\endgroup\$ Feb 12 at 3:50
0
\$\begingroup\$

Compute the analysis spectrum

This is based on a task I had in work a few years back.

A diode-array detector (DAD) is a kind of chromatography detector which fires light into a sample and detects the strength of the light that passes through it at different wavelengths. From this you can determine, among other things, the contents or the purity of the sample.

Most detectors can only detect on one wavelength. A DAD however can scan across a spectrum of wavelengths, typically from 190nm to 650nm. From that spectrum we can then pick out the wavelengths that we're interested in. Maybe for our sample we want to analyse it at wavelengths 300nm, 350nm, and 550nm. These are called 'channels'.

Each wavelength may also have a bandwidth across which the signal strength is averaged. If we have analyse on wavelength 420nm, with a bandwidth of 10nm, the range for that channel would be from 415nm to 425nm (5nm lower, 5nm higher than the base wavelength). However, this bandwidth is optional.

The DAD we'll be working with does not take a set of channels, but rather we must provide it with a minimum wavelength and a maximum wavelength to detect across. This will be our task.

The Challenge

Write a program or function that, when given a collection of channels, determines the lowest and highest wavelength to analyse across for these channels.

For this challenge, a channel consists of an integer wavelength, and an optional integer bandwidth. The wavelength can be positive or negative, but the bandwidth is always positive.

Bandwidths can be odd numbers, but in that case you would then shrink it down to an even number.

The upper limit can be the same as the lower limit, but can never be smaller.

Also, you can safely assume that at least one channel is given to your code.

Example 1

Channel 1
Wavelength = 420
Bandwidth = 10

For channel 1, the base wavelength is 420 and the bandwidth is 10.

Channel 1's lower range is the base wavelength minus half of the bandwidth. In this case, it's 420 - (10 / 2) = 415. The upper range is the base wavelength plus half of the bandwidth: 420 + (10 / 2) = 425.

Answers: Lower = 415, upper = 425

Example 2

Channel 1
Wavelength = 394
Bandwidth = 19

Channel 2
Wavelength = 500
Bandwidth = N/A

For channel 1, the base wavelength is 394 and the bandwidth is 19. Because the bandwidth is an odd number, and our DAD cannot accept floating-point numbers, we can round it down to 18.

Channel 1's lower range is the base wavelength minus half of the bandwidth. In this case, it's 394 - (18 / 2) = 385. The upper range is the base wavelength plus half of the bandwidth: 394 + (18 / 2) = 403.

Channel 2 has no bandwidth, so it's range is just at its base wavelength: 500.

Comparing the channel ranges, channel 1 has the minimum lower limit with 385. Channel 2 has the maximum upper limit, with 500.

Answers: Lower = 385, upper = 500

Test cases

Test case 1:

Wavelength 1 = 400
Bandwidth 1 = N/A

Answers: lower = 400, upper = 400

-------------------------------------

Test case 2:

Wavelength 1 = 200
Bandwidth 1 = 15

Answers: lower = 193, upper = 207

-------------------------------------

Test case 3:

Wavelength 1 = 394
Bandwidth 1 = 19

Wavelength 2 = 500
Bandwidth 2 = N/A

Answers: lower = 385, upper = 500

-------------------------------------

Test case 4:

Wavelength 1 = 394
Bandwidth 1 = 40

Wavelength 2 = 500
Bandwidth 2 = 10

Wavelength 3 = 380
Bandwidth 3 = 5

Answers: lower = 374, upper = 505

Rules

The range that you must produce must consist of an integer lower limit and an integer upper limit. This particular DAD cannot accept decimal numbers, so while your code may accept and output floating-point types, the values themselves must be whole numbers.

Computing this range is important for other settings on the DAD. Therefore, you may not take just any input and return an extremely small lower limit and/or an extremely large upper limit. Your outputs must be based on your inputs.

Standard rules apply, including the default I/O rules. Similarly, default loopholes are forbidden.

Finally, this is so shortest answer in bytes wins.

Sandbox Questions

  • Is the challenge itself too complex or too easy?
  • Is the requirement for whole-numbered outputs valid, or does it seem a little bit arbitrary?
  • Are the examples and the test cases useful?
  • Finally, would this be an interesting challenge?
\$\endgroup\$
1
  • \$\begingroup\$ Some notes: (1) is it guaranteed that the outputted "lower value" will always be strictly greater than zero? (2) It appears that most people will want to take N/A bandwidth as zero. (3) of course requiring floor/ceil is "valid", whether it's arbitrary is up to people. (4) while I can understand the challenge, it's mainly because I read the provided example explanation, so I can't be entirely sure that the rules part is clear enough. [please review other sandbox posts] \$\endgroup\$
    – DELETE_ME
    Feb 13 at 2:44
0
\$\begingroup\$

Print the nth sequence from oeis

The input is one natural number n - the sequence number

Your task is to put this numeric link https://oeis.org/A (example of a link with n = 1: https://oeis.org/A1), then you should get the html of this page and get the sequence from there

Examples:

n -> sequence
1 -> 0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4, 267, 1, 4, 1, 5, 1, 4, 1, 50, 1, 2, 3, 4, 1, 6, 1, 52, 15, 2, 1, 15, 1, 2, 1, 12, 1, 10, 1, 4, 2
2 -> 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2
3 -> 1, 1, 1, 1, 2, 2, 1, 2, 2, 2, 3, 2, 2, 4, 2, 2, 4, 2, 3, 4, 4, 2, 3, 4, 2, 6, 3, 2, 6, 4, 3, 4, 4, 4, 6, 4, 2, 6, 4, 4, 8, 4, 3, 6, 4, 4, 5, 4, 4, 6, 6, 4, 6, 6, 4, 8, 4, 2, 9, 4, 6, 8, 4, 4, 8, 8, 3, 8, 8, 4, 7, 4, 4, 10, 6, 6, 8, 4, 5, 8, 6, 4, 9, 8, 4, 10, 6, 4, 12, 8, 6, 6, 4, 8, 8, 8, 4, 8, 6, 4
4 -> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
5 -> 1, 2, 2, 3, 2, 4, 2, 4, 3, 4, 2, 6, 2, 4, 4, 5, 2, 6, 2, 6, 4, 4, 2, 8, 3, 4, 4, 6, 2, 8, 2, 6, 4, 4, 4, 9, 2, 4, 4, 8, 2, 8, 2, 6, 6, 4, 2, 10, 3, 6, 4, 6, 2, 8, 4, 8, 4, 4, 2, 12, 2, 4, 6, 7, 4, 8, 2, 6, 4, 8, 2, 12, 2, 4, 6, 6, 4, 8, 2, 10, 5, 4, 2, 12, 4, 4, 4, 8, 2, 12, 4, 6, 4, 4, 4, 12, 2, 6, 6, 9, 2, 8, 2, 8
6 -> 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18
7 -> 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
8 -> 1, 1, 2, 2, 3, 4, 5, 6, 7, 8, 11, 12, 15, 16, 19, 22, 25, 28, 31, 34, 40, 43, 49, 52, 58, 64, 70, 76, 82, 88, 98, 104, 114, 120, 130, 140, 150, 160, 170, 180, 195, 205, 220, 230, 245, 260, 275, 290, 305, 320, 341, 356, 377, 392, 413, 434, 455, 476, 497, 518, 546
9 -> 1, 1, 1, 2, 2, 3, 4, 5, 6, 8, 10, 12, 15, 18, 22, 27, 32, 38, 46, 54, 64, 76, 89, 104, 122, 142, 165, 192, 222, 256, 296, 340, 390, 448, 512, 585, 668, 760, 864, 982, 1113, 1260, 1426, 1610, 1816, 2048, 2304, 2590, 2910, 3264, 3658, 4097, 4582, 5120, 5718, 6378

,

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

Posted

\$\endgroup\$
19
  • \$\begingroup\$ The issue with the requirement is that it's non-observable. While it's true that sometimes we judge answers by understanding it (especially when answerers have to prove something about the answers), most people consider it problematic. \$\endgroup\$
    – DELETE_ME
    Feb 12 at 13:13
  • \$\begingroup\$ Language having no random function a problem, we have rules for that. \$\endgroup\$
    – DELETE_ME
    Feb 12 at 13:13
  • \$\begingroup\$ Meta post about non-observable requirement: codegolf.meta.stackexchange.com/questions/11197/… \$\endgroup\$
    – DELETE_ME
    Feb 12 at 13:19
  • \$\begingroup\$ You could make it observable by requiring that the results of intermediate steps be output. \$\endgroup\$
    – xnor
    Feb 12 at 20:31
  • \$\begingroup\$ even in this case people can still always output the sum... (although it will probably not save that much) (besides you can remove the "rules" part) \$\endgroup\$
    – DELETE_ME
    Feb 13 at 5:43
  • \$\begingroup\$ Remark: by default "random" means "all values are possible in theory". codegolf.meta.stackexchange.com/questions/17563/… [please review other sandbox posts] \$\endgroup\$
    – DELETE_ME
    Feb 13 at 5:45
  • \$\begingroup\$ Maybe I didn't understand you properly @user202729, but the elements in a do cover all values possible in theory, as long as their sum is 1. \$\endgroup\$ Feb 13 at 10:42
  • \$\begingroup\$ Yes, generally it's not a problem. \$\endgroup\$
    – DELETE_ME
    Feb 13 at 10:45
  • \$\begingroup\$ As I 've said above , people might skip the final compare solution, although I see no way to enforce it. Otherwise clear enough [please review other sandbox posts] \$\endgroup\$
    – DELETE_ME
    Feb 15 at 2:06
  • \$\begingroup\$ I think your "print" in step 3 and "return" in step 5 is to say that both these results should be output, but it should allow both to be printed or returned in a pair. I'd suggested rewording to say that these two things need to be "output", which is generic enough to cover both functions and programs. The short-circuiting in step 1 of outputting a negative number is not ideal because it's Requiring multiple types as return value. I'd suggest thinking if there's a way to avoid that. \$\endgroup\$
    – xnor
    Feb 15 at 4:36
  • \$\begingroup\$ It's not clear to me in step 2 what is required for a random array of non-negative reals summing to 1. Must it be uniform on that (n-1)-dimensional space? See this meta post. I think you should say explicitly what is expected -- the meta post that user202729 linked to isn't really definitive. \$\endgroup\$
    – xnor
    Feb 15 at 4:40
  • \$\begingroup\$ Fixed @xnor, is it okay now? \$\endgroup\$ Feb 15 at 7:00
  • \$\begingroup\$ Yes about the randomness, but see my other comment. \$\endgroup\$
    – xnor
    Feb 15 at 7:28
  • \$\begingroup\$ @xnor What about changing the negative number in step 1 into throwing an error / exception? For step 3 & 5, what about saying "output" these two results? \$\endgroup\$ Feb 15 at 7:56
  • \$\begingroup\$ @SketchySketch Throwing an error/exception might also be too language specific. Maybe just allow any behavior that's not output of the form in the later steps? Though, is this complication of checking n>=4 even worth having in the challenge? Its seems like a straightforward extra bit to add in. You could just have the input guarantee that n>=4. \$\endgroup\$
    – xnor
    Feb 16 at 6:17
0
\$\begingroup\$

post

\$\endgroup\$
5
  • 3
    \$\begingroup\$ The main issue with fastest-code is that you need to specify the specification of a machine to judge solutions on, and a set of test cases. (note that 8x8x8 is probably too small for meaningful timing) (There's also golf-cpu and atomic-code-golf, but I don't see the former used much) [please review other sandbox posts] \$\endgroup\$
    – DELETE_ME
    Feb 13 at 2:40
  • \$\begingroup\$ @user202729 Thank you for the comments. Already updated. \$\endgroup\$
    – JimmyHu
    Feb 13 at 11:03
  • \$\begingroup\$ I can't tell if N=16 is sufficient (the input data size is N^3, the time complexity is probably O(N^3 log(N)) -- or O(N^6)? I don't know), but because of the fluctuation in runtime because of various reasons, make sure that the run time of the fastest solution on the largest test case is at least a few seconds so it can be reliably measured. \$\endgroup\$
    – DELETE_ME
    Feb 13 at 11:11
  • \$\begingroup\$ @user202729 Thank you for the mentioned point about the fluctuation in runtime. I choose N = 16, 25 and 30 for measuring. If there is any other issue of this challenge, please let me know. \$\endgroup\$
    – JimmyHu
    Feb 15 at 1:44
  • 1
    \$\begingroup\$ there might be several languages with built in for this. // there might be n^3 log n solutions which will be very fast anyway, but (I think) it's okay to fix the test cases later (I assume you're solving it in n^6?) -- but in this case whether the challenge is interesting is another matter. // Otherwise looks good. [please review other sandbox posts] \$\endgroup\$
    – DELETE_ME
    Feb 15 at 3:07
0
\$\begingroup\$

Introduction

Book cipher

A Book cipher is a very unique method of a encipher. Here's how's it done:

  • You have a book / a document or a article (something full of text, the more pages of text the better).
  • You have a message to convey (a secret, of some sort)
  • You simply-put read trough the text and the secret message (may come from input, or reading it from 2 separate files) - split it into words (so, separate spaces, commas and [dots]) so, ',' , '.' and spaces is the only requirement, how is not really that hugely important and you keep the count of how many words there are in the text, now input the secret message (note, the secret's words must be in the text, so if you secret was "My Secret" then, the words "My" and "Secrets" must both exist in the text.) and output the position of the inputted secret message. (E.g if the word "My" was nearly at the first page, maybe the 20th Word in the text, the program should print out '20'. Same with the word "Secrets", if that maybe were later, (let say the 93th word in the text) then your program should print out '93'.

Note the data type of input and output:

output numbers: Integers.

Input numbers: Integers

( Excluding if the secret actually contains a number, then it does not need to be treated as a int. Can be a plus if it does but is not necessary.)

Mini Example:

document.txt - file that contains text.

Secret: "My Secret"

(in the text, this is the 20th and the 93th word) (Note, this is only a made up secret, it is not from a real file, or a real input) a more better example is below.

Program input:

You enter "My Secret"

Program output:

20

93

And, again - you enter those numbers(**Integers**):

20 93

Program outputs:

My

Secret

this is just to show how input and outputs are related to each other.

For reference (if needed) You have a Python3 implementation available at my GitHub page, to see a book cipher in action here: GitHub - Book cipher in Py3

  • Why is this challenge interesting?

I personally think this is a educational (and interesting) challenge ( one might also exercise, because of how simple it might seem to make, but really took myself - literally years to even know how to implement this correctly)

Interesting article to get some background of what Cicada3301 is (not my site) - https://www.clevcode.org/cicada-3301/

Wikipedia: Cicada3301

I created this challenge both to, see other peoples methods of solving this (you are free to use any programming language!) and also - how long it would take others (For me, really I think it took more than 4 years actually - even in Python3. It looks simple but, for me - really not)

  • A motivating fact: There are still so little info (especially on example codes) on the internet(at least by the time writing this challenge) about just, book cipher implementations

Challenge

I would highly suggest making dedicated functions for this challenge

  • (instead of writing all code in the main() function - but it's totally fine to have it all in main!)

Operation:

Here's how the program should read, process, and output the result:

First, take the text (the book/document, with the lots of text, (not the secret)) and:

Note: The text can either be entered or read from a file. You choose this.

  1. read it (From a file, or enter it as input)
  2. split it into words (by, I.e detecting '.', spaces(' '), and commas ',') (Or if you already have split the input & are ready to move on to step 3, do that :) )
  3. count the number of words.

Repeat this process with the Secret input part.

So, the input secret part should be:

  • read it (from, again a file or enter it as input)
  • split it (i.e if your input was "My Secret" - split it into words like so: "My" "Secret")

My Python3 implementation only separate spaces.

The Key sequence - this is the nth words your text contains, e.g the 93th word in above example "Secrets".

The winner will be chosen by how short the code is. (So, the shortest code = win)

Example Input and Output

example file used 'document1.txt'in this section is available at the GitHub page. as well as the Python3 file used in the example below.

The output of your program should match the output of the Python3 program.

Input:

python3 bookcipher.py

input text: a house with a Bob inside

Output:

you entered these words: ['a', 'house', 'with', 'a', 'Bob', 'inside']

2

3

5

2

0

30

Input again: (decrypting)

input key-sequence sep. With spaces: 2 3 5 2 0 30

a

house

with

a

Bob

inside

\$\endgroup\$
11
  • \$\begingroup\$ I am new, this is the first challenge, but feel free to edit/ask for clarification/ anything! Thanks, I hope the guys at the orig. Post led me to the right place; if this is not the correct place(or way!) to add proposal; please tell me how I would go around of doing that! //Have a Corona Free week! \$\endgroup\$ Feb 17 at 11:34
  • 3
    \$\begingroup\$ You're in the right place. Well done! \$\endgroup\$
    – Adám
    Feb 17 at 12:14
  • \$\begingroup\$ @Adam thanks; I am still a bit new here, but should I wait now - or what specifically should I do ? \$\endgroup\$ Feb 17 at 17:56
  • 1
    \$\begingroup\$ Welcome to Code Golf, this is a pretty good challenge! I would suggest being a bit more liberal with the input format (allowing solutions to read from STDIN or take the "book" as a function argument instead of reading from a file). I would also suggest splitting this up into two challenges - encrypting and decrypting - but that's up to you. As for what you should do now - just wait a few days so you can get feedback and modify your question, and then you can post on the main site. \$\endgroup\$
    – user
    Feb 17 at 19:42
  • 1
    \$\begingroup\$ If your proposal goes unnoticed for a really long time, you might also want to ask others to review it in the site's chat room. \$\endgroup\$
    – user
    Feb 17 at 19:50
  • \$\begingroup\$ I generally recommend leaving challenges here for minimum a week as people ave various schedules, e.g. only visiting on weekends or only on (certain) weekdays. \$\endgroup\$
    – Adám
    Feb 17 at 20:11
  • \$\begingroup\$ Just to make sure... did you address all the problems raised in the comments under the main site post? \$\endgroup\$
    – DELETE_ME
    Feb 18 at 13:02
  • \$\begingroup\$ @user202729 Oh, maybe not - fixed now though, thanks for pointing it out, and okay with the chat - got it :) \$\endgroup\$ Feb 18 at 19:24
  • 1
    \$\begingroup\$ (note that I'm not the same user as [user]. Even the chat highlight is wrong) \$\endgroup\$
    – DELETE_ME
    Feb 19 at 9:09
  • 2
    \$\begingroup\$ The text could be more concise and flow more logically. Right now I see five sections: (1) description of the cipher, (2) example (3) personal background, (4) requirements for the code, (5) more examples. I think you should aim to merge (1) and (4) where possible (there's some redundancy there), and likewise (2) and (5). (3) is not really relevant and should (I think) be deleted. \$\endgroup\$
    – Dingus
    Feb 20 at 1:15
  • 2
    \$\begingroup\$ I also suggest formatting the examples using code blocks instead of block quotes. \$\endgroup\$
    – Dingus
    Feb 20 at 1:15
0
\$\begingroup\$

Subbasis. Generate. Discrete?

Objective

Given finitely many finite sets, interpret them as a subbasis to generate a space, and decide whether the resulting topology is discrete.

Introduction to Topology

Given a set \$X\$, a topology \$\mathcal{T}\$ over \$X\$ is a subset of the power set \$\mathcal{P}(X)\$ such that:

  • \$\emptyset, X \in \mathcal{T}\$.

  • For all \$\space \mathcal{U} \subset \mathcal{T}\$, \$\bigcup\mathcal{U} \in \mathcal{T}\$.

  • For all \$Y_1, Y_2 \in \mathcal{T}\$, \$Y_1 \cap Y_2 \in \mathcal{T}\$.

Members of a topology are said to be open. So the rules above in plaintext are:

  • The empty set and \$X\$ itself are open.

  • The union of arbitrarily many open sets is open.

  • The intersection of finitely many open sets is open.

Endowed with a topology, \$X\$ is said to be a (topological) space.

If \$\mathcal{T} = \mathcal{P}(X)\$, \$\mathcal{T}\$ is said to be discrete.

Basis and Subbasis

A subset \$\mathcal{B}\$ of the power set \$\mathcal{P}(X)\$ is said to be a basis (pl. bases) of a set \$X\$ if:

  • For all \$x \in X\$, there exists \$B \in \mathcal{B}\$ such that \$x \in B\$.

  • For all \$B_1, B_2 \in \mathcal{B}\$, there exists \$C \in \mathcal{B}\$ such that \$C \subset B_1 \cap B_2\$.

We take every subset \$\mathcal{U} \subset \mathcal{B}\$ and declare \$\bigcup\mathcal{U}\$ to be open to generate a topology \$\mathcal{T}\$. Note that \$\mathcal{B} \subset \mathcal{T}\$ always holds.

If we omit the second requirement, we have a subbasis of \$X\$. A subbasis generates a topology by also declaring the intersection of finitely many members to be open.

Input and Output

Given a set of finitely many finite sets \$\mathcal{S}\$, \$X\$ shall be implicitly defined as \$\bigcup\mathcal{S}\$. Note that by this, the first requirement for bases always holds.

The input/output format is flexible. In every case, inputs that don't fit in your input format fall in don't care situation.

Examples

Truthy

  • \$\emptyset\$ (Generates \$X = \emptyset\$ and \$\mathcal{T} = \{\emptyset\}\$)

  • \$\{\emptyset\}\$ (Ditto)

  • \$\{\{0\}\}\$ (Generates \$X = \{0\}\$ and \$\mathcal{T} = \{\emptyset, \{0\}\}\$)

  • \$\{\emptyset,\{0\}\}\$ (Ditto)

  • \$\{\{1\}\}\$ (Generates \$X = \{1\}\$ and \$\mathcal{T} = \{\emptyset, \{1\}\}\$)

  • \$\{\{0\},\{1\}\}\$ (Generates \$X = \{0,1\}\$ and \$\mathcal{T} = \{\emptyset, \{0\},\{1\},\{0,1\}\}\$)

  • \$\{\{0\},\{1\},\{0,1\}\}\$ (Ditto)

  • \$\{\{0\},\{1\},\{2\}\}\$ (Generates \$X = \{0,1,2\}\$ and \$\mathcal{T} = \{\emptyset, \{0\},\{1\},\{2\},\{0,1\},\{0,2\},\{1,2\},\{0,1,2\}\}\$)

  • \$\{\{0,1\},\{0,2\},\{1,2\}\}\$ (Ditto)

Falsy

  • \$\{\{0,1\}\}\$ (Generates \$X = \{0,1\}\$ and \$\mathcal{T} = \{\emptyset,\{0,1\}\}\$)

  • \$\{\{0,1\},\{1\}\}\$ (Generates \$X = \{0,1\}\$ and \$\mathcal{T} = \{\emptyset,\{1\},\{0,1\}\}\$)

  • \$\{\{0\},\{1,2\}\}\$ (Generates \$X = \{0,1,2\}\$ and \$\mathcal{T} = \{\emptyset, \{0\},\{1,2\},\{0,1,2\}\}\$)

  • \$\{\{0,1\},\{1\},\{2\}\}\$ (Generates \$X = \{0,1,2\}\$ and \$\mathcal{T} = \{\emptyset, \{1\},\{2\},\{0,1\},\{1,2\},\{0,1,2\}\}\$)

\$\endgroup\$
5
  • 2
    \$\begingroup\$ This looks math-heavy. To get a better chance of having it reviewed (because people, including me, tend to skip long sandbox posts) you can ask in chat and leave it in for a while. \$\endgroup\$
    – DELETE_ME
    Feb 18 at 3:28
  • \$\begingroup\$ So, if I'm understanding correctly, defining U(S) as the union of all members of S and P(S) as the powerset of S, you are asking whether {U(x) for x in P(X)} == P(U(X))? In this case a more to the point description like this one could be useful... You can leave the math background in (maybe shorten it a little bit) for people interested, but it shouldn't be the only description for the challenge. \$\endgroup\$
    – Leo
    Feb 19 at 1:08
  • \$\begingroup\$ @Leo Figuring out a simple algorithm to solve the challenge can be part of it. (although after the first answer is posted people can just use the same algorithm, however nobody is forced to look at the answers; besides the "original" answer tend to be upvoted proportionally anyway) \$\endgroup\$
    – DELETE_ME
    Feb 19 at 9:13
  • 1
    \$\begingroup\$ @Leo (your notation is confusing because you use X for the input while OP uses it for U(input), but it looks correct) [please review other sandbox posts] \$\endgroup\$
    – DELETE_ME
    Feb 19 at 9:31
  • \$\begingroup\$ @user202729 I agree that figuring out the algorithm is part of the challenge, but having to understand several paragraph of relatively advanced math concepts is a bit detrimental to the challenge itself, in my opinion. Moreover, mine is not necessarily the best algorithm, just a simpler description of the requirements. You are right about the different notation, sorry for the ambiguity \$\endgroup\$
    – Leo
    Feb 19 at 12:37
0
\$\begingroup\$

Decode an 8086 MOD R/M

I think this might be fun. Or, it might be torture, idk. 😛 If this is popular, I might add a sequel for the significantly more complex 32-bit encoding 😏

Time for a mini objdump.

An 8086 MOD R/M field is laid out like so:

MOD  REG  R/M |  OPTIONAL DISPLACEMENTS
mm   rrr  rrm | (iiiiiiii) | (iiiiiiii)
76   543  210 |  76543210  |  76543210

REG is a register. Quite unintuitively, the register names are not in alphabetical order.

Note that you can safely assume a word register, not a half byte register, and that the destination is a register.

REG |  0 |  1 |  2 |  3 |  4 |  5 |  6 |  7 |
Name| AX | CX | DX | BX | SP | BP | SI | DI |

MOD determines the length and format of the instruction.

MOD | FORMAT
 0  | [MEM] or [ADDR]
 1  | [MEM+/-disp8] (signed 8-bit immediate)
 2  | [MEM+/-disp16] (signed 16-bit little endian immediate)
 3  | REG

MEM is parsed as so:

MEM  |    0    |    1    |    2    |    3    |   4  |   5  |   6   |   7  |
Name | [BX+SI] | [BX+DI] | [BP+SI] | [BP+DI] | [SI] | [DI] | [BP]* | [BX] |
*when MOD==0, [BP] is replaced by an absolute 16-bit address.

Just [BP] is encoded as [BP+0].

I am going to represent MOD R/M as octal, and addresses/displacements as hex. It really bugs me how few people write it this way, as it makes much more sense.

So, for example:

MOD  r  r/m
 3   0    0
reg  |    |
    AX,  AX

 0   2    0
mem  |    |
    DX,[BX+SI]

 1   3   7 , 23
M+D8 |   |   |
    BX, [BX+0x23]

 2   2   1 , BC 6A
M+D16|   |    | /
    DX,[BX+DI+0x6ABC]

Rules:

  • You may take your input as a packed integer, byte array, string in any mix of bases, or whatever. I'm not picky. I personally wrote them as mixed hex and octal.
  • You will always get 3 bytes, however, in true objdump spirit, those extra bytes will be random. The first byte is all you need to determine the length.
  • Not all cases will be the most efficient encoding.
  • In the output:
    • It may be returned as a single string, or printed.
    • It is case insensitive
    • It can have excess spaces or tabs, but it must be on one line.
    • It can have an optional trailing newline
    • Displacements and addresses can be in any base, however, do note that displacements are signed two's complement and will be subtracted if negative. So, for 100 FF, AX,[BX+SI+0xFF] is wrong.
    • Leading zeroes and displacements of zero are fine.

Test cases (irrelevant bytes are in italics):

300 73 A2 -> AX,AX
312 01 82 -> CX,DX
337 3E 1C -> BX,DI
020 24 AF -> DX,[BX+SI]
137 23 6B -> BX,[BX+0x23]
066 34 21 -> SI,[0x1234]
166 00 10 -> SI,[BP+0x00]
221 BC 6A -> DX,[BX+DI+0x6ABC]
124 FF EF -> CX,[SI-0x01]
224 FF FF -> CX,[SI-0x0001]
240 00 00 -> SP,[BX+SI+0x0000]
\$\endgroup\$
4
  • \$\begingroup\$ How is "300" 3 bytes? It looks like 3 octal digits. \$\endgroup\$
    – DELETE_ME
    Feb 20 at 9:43
  • \$\begingroup\$ Is that better? \$\endgroup\$
    – EasyasPi
    Feb 20 at 10:43
  • \$\begingroup\$ What is R/M? Why is MEM 3 bits long? \$\endgroup\$
    – DELETE_ME
    Feb 20 at 11:25
  • 1
    \$\begingroup\$ Since you list out the bytes as bits (appropriately), it would probably be clearer if you also included the binary values in the tables for reg/mod/mem. Using the octal/hex format is probably also going to confuse people - I think labeling your examples with what base is being used may help. \$\endgroup\$ Feb 20 at 18:19
0
\$\begingroup\$

Create a QR quine

(a "qruine" if you will)

Design a QR code that legibly spells with its pixels (or the space between them) the text that it scans to.

For example, this QR code scans to the letter A, and also spells out A in white:

enter image description here

It does not matter what the scanned and displayed text is; it does not have to be coherent or readable.

The winner is the person with the longest text.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ This is a really cool idea, but I'm not quite sure what you mean. (pulls out qr code scanner) Oh, never mind, it really does just scan as 'A'. This surprises me for how big it is. \$\endgroup\$
    – Beefster
    Feb 24 at 22:55
  • \$\begingroup\$ Does this count as code-golf? \$\endgroup\$
    – emanresu A
    Feb 25 at 4:08
0
\$\begingroup\$

Posted link

\$\endgroup\$
3
  • 1
    \$\begingroup\$ The test cases are rather confusing. Are they missing the expected output? In addition, your statement about "dots" is rather odd - do you mean all non-letter characters should be ignored, or just punctuation, or just periods? You should definitely also specify what characters can appear in the input. \$\endgroup\$ Feb 22 at 17:32
  • 1
    \$\begingroup\$ I think I get it, but it needs to be explained better. For each value of n less than the length of the word, the letters that are n slots from the beginning and n slots from the end of the word should both be made uppercase if either of them is upper case. \$\endgroup\$
    – Xcali
    Feb 22 at 19:04
  • 1
    \$\begingroup\$ Perhaps replacing "slot" by "position"/"character" is easier (perhaps it's a perl term? I don't know), but otherwise clear enough. [please review other sandbox posts] \$\endgroup\$
    – DELETE_ME
    Feb 24 at 4:27
0
\$\begingroup\$

Is this code in the same language as my answer? (WIP)

Probably a bad idea, but the goal here is to output a truthy value if a given input string is valid syntax in the same language as your answer.

\$\endgroup\$
3
  • \$\begingroup\$ Maybe use neural networks and allow answers to have approx. 80% accuracy? I personally don't think this is all that interesting (and it would be very hard to score), but that's completely subjective. \$\endgroup\$
    – user
    Feb 26 at 21:00
  • \$\begingroup\$ Terrible question in most languages. Either they use compile (eval might loop infinitely) or they just print a truthy value (in esoteric languages where all programs are valid) \$\endgroup\$
    – DELETE_ME
    Feb 27 at 12:21
  • \$\begingroup\$ nop in languages with no syntax \$\endgroup\$
    – l4m2
    Mar 16 at 2:06
0
\$\begingroup\$

I don't care how it started, but I'm going to end it!


Given a number between 0 and 10,000 (inclusive) as input, output that many arbitrary* printable ASCII characters, followed by the exact text:

I don't care how it started, but I'm going to end it!

* The arbitrary preceding text must not contain the ending text.

You do not need to verify the input value.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Nothing to review. (people will print sequence of a most likely) \$\endgroup\$
    – DELETE_ME
    Feb 27 at 12:20
0
\$\begingroup\$

Shortest and Asymptotically Fastest Sort of 3-Tuples

Tags:

Write the shortest and asymptotically fastest function or program that will sort a set of 3-tuples.

Input

Input is a set (or unique list, array, etc) of 3-tuples, containing positive integers.

Output

Output is a set (or unique list, array, etc) of 3-tuples sorted in the following way:

  • The first elements of each tuple are monotonically increasing.
  • For each value of the first elements, the second elements are monotonically increasing.
  • For each value of the second elements, the third elements are monotonically increasing.

Additional Rules

  • As well as a byte count, include the asymptotic time complexity spent by your program.
  • Explanations are encouraged! (Especially for showing the time complexity)
  • Standard loopholes are forbidden.
  • Input and output is flexible, as long as each 3-tuple is individually identifiable.
  • Scoring is time complexity, with byte length as a tie breaker.

Examples

Input - Output # Comment
[(1,2,3), (400,500,600), (0,0,0)] - [(0,0,0), (1,2,3), (400,500,600)]
[(1,0,255), (1,255,0), (1,10,123), (1,50,96)]
 - [(1,0,255), (1,10,123), (1,50,96), (1,255,0)] # sorted by second elements
[(1,0,255), (1,0,0), (1,0,123), (1,0,96)]
 - [(1,0,0), (1,0,96), (1,0,123), (1,0,255)] # sorted by third elements
[(1,0,255), (1,255,0), (1,10,123), (1,50,96), (2,0,255), (2,0,0), (2,0,123), (2,0,96)]
 - [(1,0,255), (1,10,123), (1,50,96), (1,255,0), (2,0,0), (2,0,96), (2,0,123), (2,0,255)] # sorting by first and second
[(1,0,255), (1,255,0), (255,23,232), (1,10,123), (1,50,96), (2,0,255), (2,0,0), (2,0,123), (2,0,96), (1,2,3), (400,500,600), (0,0,0)]
 - [(0,0,0), (1,0,255), (1,2,3), (1,10,123), (1,50,96), (1,255,0), (2,0,0), (2,0,96), (2,0,123), (2,0,255), (400,500,600), (255,23,232)]
\$\endgroup\$
6
  • \$\begingroup\$ Which scoring criterion would take priority? Or is there some way in which they are combined? \$\endgroup\$ Feb 27 at 23:30
  • \$\begingroup\$ @UnrelatedString I'll add that in, lower time complexity is better. \$\endgroup\$
    – bigyihsuan
    Feb 28 at 0:06
  • \$\begingroup\$ Because the input is bounded, all solutions will take O(1). \$\endgroup\$
    – DELETE_ME
    Feb 28 at 6:47
  • 1
    \$\begingroup\$ The scoring as written is ill-defined. Better saying "asymptotic time complexity is the winning criteria, the size is the tie-breaker" [please review other sandbox posts] \$\endgroup\$
    – DELETE_ME
    Feb 28 at 6:48
  • 1
    \$\begingroup\$ Otherwise, algorithms for sorting things are very well-studied already. Fastest-algorithm is not interesting. \$\endgroup\$
    – DELETE_ME
    Feb 28 at 6:50
  • \$\begingroup\$ Okay. The other comment (about well-studied) still applies. \$\endgroup\$
    – DELETE_ME
    Mar 1 at 3:08
0
\$\begingroup\$

First sequence with no square differences

\$\endgroup\$
3
  • \$\begingroup\$ Clear enough. (I can't find any with the OEIS name. Probably safe.) \$\endgroup\$
    – DELETE_ME
    Mar 3 at 11:16
  • \$\begingroup\$ By the way, it's recommended that challenges should be left for at least 72 hours before posting it on the main site (from the sandbox FAQ) \$\endgroup\$
    – DELETE_ME
    Mar 3 at 14:30
  • \$\begingroup\$ @user202729 I'm aware, but I used my judgement that the challenge is simple enough that it shouldn't need the full 3 days. \$\endgroup\$
    – 79037662
    Mar 3 at 14:34
0
\$\begingroup\$

Lists of power

Generate the following list of lists.

[[0], [1], [2, 4, 8, 6], [3, 9, 7, 1], [4, 6], [5], [6], [7, 9, 3, 1], [8, 4, 2, 6], [9, 1]]

This is , so shortest answer (as measured in bytes) wins.

\$\endgroup\$
4
  • \$\begingroup\$ Definitely clear enough. But... (I guess most people would be able to figure out the pattern. It's okay to let answerers to deduce something) \$\endgroup\$
    – DELETE_ME
    Mar 4 at 2:21
  • \$\begingroup\$ Should I print the exact string (which kolmogorov-complexity implies) or is it fine to write a function that returns an equivalent structure (or print the equivalent structure in the chosen language's way)? \$\endgroup\$
    – Bubbler
    Mar 4 at 4:23
  • \$\begingroup\$ @Bubbler Ah, I thought kolmogorov-complexity just meant it does exactly one thing... The challenge is to write a program or function that creates the structure, not necessarily the string. \$\endgroup\$
    – hakr14
    Mar 4 at 6:44
  • 1
    \$\begingroup\$ @hakr14 I think you need to include the last sentence in your challenge. \$\endgroup\$
    – Bubbler
    Mar 6 at 20:39
0
\$\begingroup\$

Sequential Multiplication Magic Squares

(Inspired by this question for a 5x5 and this question for a 4x4 magic square on the Puzzling SE sites.)

For this challenge, a sequential multiplication magic square is an NxN square filled with numbers 1..N² where the product of any M-th row equals the product of the M-th column. That is, the product of the first row is equal to the product of the first column, the product of the second row is equal to the product of the second column etc.

For example, one such 3x3 square might be as follows, but other similar results are valid as well:

9 8 3
4 5 2
6 1 7

Notably, there is no such square for N=2.

Challenge

Given a side size N of 1 or larger, output a valid NxN sequential multiplication magic square, or any distinct falsy value if none exists.

Standard loopholes apply, any convenient input-output, this is so the shortest code in bytes wins.

Sample cases

1 → [1]

2 → any distinct falsy value

3 → [[9, 8, 3],
     [4, 5, 2],
     [6, 1, 7]]

4 → [[16,  3, 12,  4],
     [ 9, 10, 14,  1],
     [ 8,  7, 11, 15],
     [ 2,  6,  5, 13]]

5 → [[ 7, 16,  6,  3, 25],
     [ 5, 13, 22, 12, 24],
     [ 9, 11, 17, 14,  4],
     [20, 18, 21, 19,  1],
     [ 8, 10,  2, 15, 23]]
\$\endgroup\$
3
  • 1
    \$\begingroup\$ There's quite a lot of questions on magic squares already, I couldn't find one that addresses the above scenario though. I'm not sure whether this is unique enough? \$\endgroup\$
    – Etheryte
    Mar 4 at 16:47
  • \$\begingroup\$ I'm pretty sure it is not a dupe, but code-golf doesn't sound very interesting (mainly because one can generate all possible boards and find one that meets the condition). fastest-code would be more interesting, though in that case you'll need to run every single submission on your machine for fair comparison of speed. \$\endgroup\$
    – Bubbler
    Mar 4 at 23:15
  • \$\begingroup\$ May I error in place of a "distinct falsy value"? \$\endgroup\$
    – Bubbler
    Mar 4 at 23:27
0
\$\begingroup\$

Three, Three, No

\$\endgroup\$
10
  • \$\begingroup\$ Some test cases (with example outputs) would be nice. Also, it is discouraged to include input verification in a code golf challenge. \$\endgroup\$
    – Bubbler
    Mar 3 at 4:56
  • \$\begingroup\$ Do you want to allow programs to take input in unary? \$\endgroup\$
    – DELETE_ME
    Mar 3 at 6:05
  • \$\begingroup\$ @Bubbler Actually I think that the input verification is a part of the challenge in this case. Because of the asymptotic time complexity requirement, you need some case-working in the algorithm anyway. \$\endgroup\$
    – DELETE_ME
    Mar 3 at 6:06
  • \$\begingroup\$ @user202729 It does require some casework, but if the existence of an answer is guaranteed, you can still cut an entire if-branch (a test and a code to report failure, the latter of which is superfluous and closer to a boilerplate than a core task IMO). \$\endgroup\$
    – Bubbler
    Mar 3 at 9:32
  • \$\begingroup\$ @Bubbler Depends on what you consider to be valid input. The challenge is just "Given a sequence, print whether there exists a partition and the partition itself if there exists" \$\endgroup\$
    – DELETE_ME
    Mar 3 at 9:40
  • \$\begingroup\$ @Bubbler And op doesn't require some long error message to be printed, right? This is closer to the "general falsy value". \$\endgroup\$
    – DELETE_ME
    Mar 3 at 9:40
  • \$\begingroup\$ @Bubbler So I should change it to assume that all inputs have a permutation that works? \$\endgroup\$
    – user101295
    Mar 3 at 20:42
  • \$\begingroup\$ @Bubbler I've added some test cases. \$\endgroup\$
    – user101295
    Mar 3 at 20:47
  • \$\begingroup\$ @user101295 So I should change it to assume that all inputs have a permutation that works? -- You don't need to strictly follow it. You'll need to include a few more test cases for the "impossible" situation though. \$\endgroup\$
    – Bubbler
    Mar 4 at 4:28
  • \$\begingroup\$ @Bubbler Updated. \$\endgroup\$
    – user101295
    Mar 4 at 22:33
0
\$\begingroup\$

Syslog PRI Conversion

This is my first CodeGolf post, so I expect some errors my content.

The rsyslogd utility has been a tool used throughout time to handle and parse logs either over an IP network or even locally. As many of you might know, this tool utilizes the basic syslog protocol.

The syslog protocol handles both a Facility and a Severity level in one integer, called Priority. The formula to extract these levels is as follows:

Priority = Facility * 8 + Level

In this challenge, your task is to write an application that converts a Priority value from the syslog protocol into a human readable format. The application must take input from STDIN, and output both the Severity and Facility string associated with the numerical code.

The numerical code/type table is as follows:

Int     Severity
0       Emergency
1       Alert
2       Critical
3       Error
4       Warning
5       Notice
6       Informational
7       Debug

Int     Facility
0       kernel messages
1       user-level messages
2       mail system
3       system daemons
4       security/authorization messages
5       internal
6       line printer subsystem
7       network news subsystem
8       UUCP subsystem
9       clock daemon
10      security/authorization messages
11      FTP daemon
12      NTP subsystem
13      log audit
14      log alert
15      clock daemon
16      local0
17      local1
18      local2
19      local3
20      local4
21      local5
22      local6
23      local7

The format of the outputted text may be any style you like, as long as it retains its human readable characteristics.

Examples

mail system, Critical\n

mail system\n
Critical\n

mail system - Critical\n

mail system Critical\n

Example

Given a PRI value of 103, your program must output:

NTP Subsystem, Debug

The shortest answer in bytes wins!

\$\endgroup\$
2
  • \$\begingroup\$ I don't see any glaring issues, though it isn't particularly interesting (outputting strings based on a lookup table has been done multiple times). \$\endgroup\$
    – Bubbler
    Mar 9 at 0:34
  • \$\begingroup\$ Do you happen to have any suggestions that would make it more appealing? Also, Thanks for the feedback. \$\endgroup\$
    – booshlinux
    Mar 9 at 15:09
0
\$\begingroup\$

Interpret the next answer

This is an challenge where the aim is to write an interpreter for a specific language ("language X") in another language ("language Y"). Languages X and Y must be completely distinct, that is they must not be different versions of the same language, nor the same language itself. The next answer should then write an interpreter for language Z in language Y, and so on.

Interpreters do not need to fully implement the language, just a Turing-complete subset. In order to be a valid interpreter, it must have some way of inputting a string of code and a number (potentially zero) of inputs. One example may be a function that takes the code and inputs as an argument.

You may not reuse languages (so each language will be in exactly 2 answers - as an interpreter and being interpreted). Different versions of languages count as the same language, so long as they are considered to be different versions of the same language (e.g. Python 2 and 3, or Seriously and Actually)

You must wait 3 hours between posting and cannot post twice in a row. The challenge ends after a week has passed with no new answers. Your score is equal to the number of answers you have posted, with a higher score being better

\$\endgroup\$
4
  • \$\begingroup\$ I'm confused. Do you mean that you first write an interpreter for language Y in language X, and then an interpreter for Z in Y? Or do you just write interpreters for X, Z, etc. all in Y? Could you give a small example to make it clearer? \$\endgroup\$
    – user
    Mar 10 at 3:46
  • 1
    \$\begingroup\$ I think as well that you have "X" and "Y" swapped in your first sentence. Regarding "Interpreters do not need to fully implement the language, just a Turing-complete subset.", have you considered requiring the next answer to use the same Turing-complete subset in order to be interpretable by the previous one? \$\endgroup\$
    – Leo
    Mar 10 at 4:15
  • 1
    \$\begingroup\$ This seems like a good challenge, but it's currently worded in a confusing manner. An example would probably fix that. Also, would making some sort of custom language be allowed? \$\endgroup\$ Mar 10 at 4:21
  • 1
    \$\begingroup\$ If I’m writing a Python interpreter in JavaScript, can I write a polyglot implementation of Rule 110 and submit eval as my interpreter, since the “Turing complete subset” of Python I support is that single program? \$\endgroup\$ Mar 10 at 15:17
0
\$\begingroup\$

SSD optimize

Given \$n\$ pages, each page containing \$m\$ sectors, write three functions: (Here x and y are sectors)

  1. insert(x) that stores the input(temporary sector) into a sector,
  2. remove(x) that removes one, and
  3. get(x) that return a sector containing the element.

You can call these functions:

  1. copy(y,x) that copy a sector from x to y, and
  2. clear(x) that clears the page containing x, can only be called \$k\$ times for each page.

There'll never be more than(can equal to) \$p\%mn\$ elements required to store. Your score is the numbers of call before you fail. Everyone can provide test case for any program.

\$n=256, m=16, p=75, k=100\$.

For example, if a solution don't do any clear and just place inputs into \$(1,1), (1,2), \cdots, (n,m)\$, someone else can write and remove till you use up all space:

insert\*3072, (delete, insert)*1025, get

The last get can't get anything and is a fail, so the score is 5122.

Highest score wins. Robber's winning criticia TODO.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ I work with SSD firmware as my job. I just wanted to point out a real story: it is a real PITA to optimize SSD lifetime depending on the user workload. The relevant components include multiple dozen C files, each file being up to tens of kilobytes. The algorithms involved have been accumulated for over a decade, and are still evolving. (This doesn't mean the challenge is inherently bad, as we can explore possible optimizations at the amateur level, which is interesting in its own right.) \$\endgroup\$
    – Bubbler
    Mar 16 at 4:14
  • \$\begingroup\$ It is somewhat unclear how \$p=75\$ is applied in the insert\*3072, (delete, insert)*1025, get workload. Did you mean 75% of the entire space? (in which case \$p=3072\$ or \$p=0.75mn\$ would be more accurate) \$\endgroup\$
    – Bubbler
    Mar 16 at 4:35
  • \$\begingroup\$ @Bubbler the % is missing \$\endgroup\$
    – l4m2
    Mar 16 at 4:36
  • \$\begingroup\$ For the winning criteria: you could make it a single-challenge CnR (like this). Initially, a cop posts a submission with their own estimate of the score. Then a robber tries to reduce the cops' scores by finding worse scenarios, and the robber takes the reduced score as their own score. A cop with the highest final score wins; a robber with the highest "robbed" total score wins. (Check out more specific rules in the linked challenge) \$\endgroup\$
    – Bubbler
    Mar 16 at 4:55
  • \$\begingroup\$ You should really add some background story to your question. Currently, I cannot understand anything in it. What are pages? What are sectors? How are these 5 functions works? What does clear mean? And why should I clear it? What does get do? Am I designed to storage some data between each invokes? \$\endgroup\$
    – tsh
    Mar 17 at 9:18
  • \$\begingroup\$ Your example \$ (1,1), (1,2), \cdots, (n,m) \$ is a list with 4096 elements in it. Won't it run up after 4096 iterations? What is 5122 here? Are \$ n=256, m=16, p=75, k=100 \$ some given parameter to these 3 functions? \$\endgroup\$
    – tsh
    Mar 17 at 9:25
  • 1
    \$\begingroup\$ @tsh It's a promise that you don't store more than n*m*p% datas, so when reaching 3072 you have to erase some, adding movements \$\endgroup\$
    – l4m2
    Mar 17 at 9:29
0
\$\begingroup\$

Build a Markdown to HTML converter


The Stack Exchange network uses Markdown as the syntax for writing posts. For example, using a # at the beginning of a line creates a heading (<h1>) while two hashes ## creates a subheading (<h2>).
Your task is to write a program which takes input as a syntactically valid Markdown string and outputs its HTML equivalent. (This program might find use as a means to transfer SE posts to one's own website.)
The only Markdown "commands" you need to support are the backtick (becomes a tag named code, styling provided), the hashes (# becomes h1, ## becomes h2 and ### becomes h3), and the > (blockquote). The rest may be left intact.

For example, if the input is

# Some text
## Part 1
Lorem `ipsum` dolor sit amet
> consectetur adispicing

Then the output should be

<h1>Some text</h1>
<h2>Part 1</h1>
Lorem <code>ipsum</code> dolor sit amet
<blockquote>consectetur adispicing</blockquote>

Leading spaces are acceptable for the headings as they are mandatory in Markdown, but trailing spaces are not (you may assume the input has no trailing spaces). Except for the inline code, all commands will be displayed as blocks and will be on separate lines. For example

# Some text ## Another

is not a valid input because there is a block command on the same line as another block command. You may assume that the input contains no < or > except for blockquote notation, you must also follow the guidelines exactly, so no outputting HTML which renders the same result but in a different way.

Second test case:

### Subheading
> This is some heading with `code` in it.

becomes

<h3>Subheading</h3>
<blockquote>This is some heading with <code>code</code> in it.</blockquote>

This is , so the shortest answer in bytes wins.

\$\endgroup\$
6
  • \$\begingroup\$ HTML use <code> instead of <shortsnippet>. Are you defining yet another target language? \$\endgroup\$
    – tsh
    Mar 16 at 11:34
  • \$\begingroup\$ May I assume input will never contains <> other than block quote notation? Or, what should I do if input contains one? For example, for input 3 < 2, should I yield something like 3 &lt; 2? \$\endgroup\$
    – tsh
    Mar 16 at 11:36
  • \$\begingroup\$ @tsh Oops, didn't know about that one, editing that in. You may assume that the input will never contain < or > except for blockquote notation. \$\endgroup\$
    – user100690
    Mar 16 at 12:10
  • \$\begingroup\$ "but trailing spaces are not" should I assume the input will not contains trailing spaces too? or should i strip spaces at end of inputs when i generate html? Does this only apply to space (U+0020) or any whitespace characters? \$\endgroup\$
    – tsh
    Mar 17 at 1:32
  • \$\begingroup\$ Should I output exactly same string as example output? Or may I output something HTML may render same results? \$\endgroup\$
    – tsh
    Mar 17 at 3:21
  • \$\begingroup\$ Will the code ever contain unmatched backticks on a line? \$\endgroup\$ Mar 24 at 4:28
0
\$\begingroup\$

Output a random pair of twin primes. Every pair should possibly appear and the program should have zero possibility to fall into infinite loop. Notice that we don't know if there are infinite many pairs so you need some fallbacks to avoid finding a not-existing pair.

\$\endgroup\$
1
  • \$\begingroup\$ Define twin primes \$\endgroup\$
    – Beefster
    Mar 22 at 19:25
0
\$\begingroup\$

Finding Distant Primes

\$\endgroup\$
2
  • \$\begingroup\$ I'm a bit confused, why is 23 a 9-distant prime when |2⁴ - 23| = 7. Why did you raise 2 to specifically the fifth power? Or is both, and also a 22, 21, 19, 15, 7, 9, 41, etc... distant prime? \$\endgroup\$ Mar 17 at 4:22
  • 1
    \$\begingroup\$ @Medix2 yes it is all of those. \$\endgroup\$ Mar 17 at 4:50
0
\$\begingroup\$

Add trailing whitespace

Sometimes, we accidentally have trailing whitespace in test cases, and some helpful person notices and fixes that. Thank you, helpful people.

But what if we want to take a string without trailing whitespace and add some?

Your challenge is to write a program that takes a string as input and adds between 1 and 10 spaces (randomly) to the end of each line.

Rules

Between 1 and 10 (inclusive) spaces (" ") must be added to each line. There must be a nonzero chance of getting any number of spaces on any line.

This is , shortest wins.

Apologies if this already exists - It's really hard to search.

\$\endgroup\$
3
  • \$\begingroup\$ "just before each newline and the end of file" "trailing whitespace"? \$\endgroup\$
    – tsh
    Mar 23 at 1:42
  • \$\begingroup\$ @tsh Sorry for being confusing. Rewrote. Is this a good challenge? \$\endgroup\$
    – emanresu A
    Mar 23 at 8:08
  • \$\begingroup\$ Maybe to make the challenge a bit harder require an additional line to the file with random number of spaces, because then less trivial answers \$\endgroup\$
    – user100690
    Mar 23 at 16:16
0
\$\begingroup\$

2D Pathfinding with Momentum

Posted to main

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

Posted

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

Count What You See

You may have heard of the Look-and-say sequence, which is generated by reading off the digits of previous entries in the sequence. Here, you will be tasked to generate the "Count-and-say sequence".

In general, the sequence can be generated as follows:

  1. Start with an arbitrary sequence of numbers (e.g. 1, 1, 1, 3, 2, 1, 2).
  2. Count the occurrences of each number as adjective noun pairs -> "four 1, one 3, two 2", in order of 1st appearance. In the example, this means that you must first count 1s, then 3s, then 2s, since that is the order in which the numbers first appear in the sequence.
  3. Write out the result from step 2 numerically ("four 1, one 3, two 2" -> 4, 1, 1, 3, 2, 2).
  4. Append the result from step 3 to the original sequence to get 1, 1, 1, 3, 2, 1, 2, 4, 1, 1, 3, 2, 2.
  5. Repeat the steps above to continue the sequence.

Task

Your task is to output the "Count-and-say sequence", such that the sequence starts with 1. You may choose to:

  • Take an input \$ n \$ and output the first \$ n \$ integers.
  • Take an input \$ n \$ and output the \$ n \$-th integer.
  • Output the sequence indefinitely.

For convenience, here are the first 100 numbers in the sequence (also A217780):

1, 1, 1, 3, 1, 4, 1, 1, 3, 6, 1, 2, 3, 1, 4, 8, 1, 3, 3, 2, 4, 1, 6, 1, 2, 11, 1, 5, 3, 3, 4, 2, 6, 3, 2, 1, 8, 13, 1, 8, 3, 4, 4, 3, 6, 5, 2, 2, 8, 1, 11, 1, 5, 16, 1, 10, 3, 6, 4, 4, 6, 7, 2, 4, 8, 2, 11, 3, 5, 1, 13, 18, 1, 12, 3, 9, 4, 6, 6, 9, 2, 5, 8, 3, 11, 4, 5, 2, 13, 1, 16, 1, 10, 1, 7, 22, 1, 14, 3, 11
\$\endgroup\$
1
99 100
101
102 103
117

You must log in to answer this question.

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