484
\$\begingroup\$

What is the Sandbox?

This "Sandbox" is a place where Code Golf users can get feedback on prospective challenges they wish to post to the main page. This is useful because writing a clear and fully specified challenge on the first try can be difficult. There is a much better chance of your challenge being well received if you post it in the Sandbox first.

To post to the Sandbox, scroll to the bottom of this page or click on the "Add Proposal" link below, 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. 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, replace the post here with a link to the challenge and delete it.

See the Sandbox FAQ for more information on how to use the Sandbox.

The Sandbox works best if you sort posts by "active".

Add Proposal

Search the Sandbox

Browse your pending proposals

Get the Sandbox Viewer to view the sandbox more easily

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]

| |
\$\endgroup\$

2920 Answers 2920

1
22 23
24
25 26
98
2
\$\begingroup\$

Decode the password

Given a printable ASCII string separated with spaces, output the specified index of every word. E.g.

"are turbas unsafe ?!", 1

will yield run!

  • When the index is out of bounds, this index should yield the null string (which can be joined with other strings).

More test cases

"Is Pascal truly unloyal to users?",3 -> "sure"
"I'd pass kittens to anyone stopping by!!",4 -> "stop!"
| |
\$\endgroup\$
  • 1
    \$\begingroup\$ The definitive answer here is yes. \$\endgroup\$ – Lyxal Feb 3 at 6:58
  • \$\begingroup\$ I assume this was just meant to be laying out the idea not to forget about it. But just in case I figured I should say that you definitely need to specify what happens when the index is too large for one of the substrings, and that the rest of the string will be printable ascii / whatever you choose. \$\endgroup\$ – FryAmTheEggman Feb 5 at 17:19
  • 1
    \$\begingroup\$ The first test case in the more test cases section seem wrong should it not yield "sule" and not "sure"? \$\endgroup\$ – Mukundan314 Feb 11 at 15:56
  • 2
    \$\begingroup\$ And the last test case only works for 1-indexing, while all others are 0-indexed. \$\endgroup\$ – AlienAtSystem Feb 11 at 16:10
  • \$\begingroup\$ What happened to this user? \$\endgroup\$ – S.S. Anne Feb 11 at 23:58
2
\$\begingroup\$

Is this entire list likewise-modulus-aligned?

A pair of numbers are aligned in a modulus when they all share the same remainder when they can be put under the modulus function against an integer greater than or equal to 2 and less than or equal to the absolute value of both.

For example,

13 and 22 are aligned numbers under 3 because
13%3 = 1
22%3 = 1

3<=13, 3<=22, and 3>=2

All our requirements are met.

A list is likewise-modulus-aligned when all the elements are aligned under the same modulus base.

Challenge

Take in a list (not necessarily non-empty) of non-zero integers (not necessarily positive nor unique), and check if all the elements are likewise-modulus-aligned. Output is a truthy or falsy value.

Note; This is a "true-until-proven-otherwise" problem, meaning a single value in the list or an empty list will return TRUE.

Example I/O

      In      | Out | Why
--------------|-----|---------
         [5 7]|TRUE |1 mod 2
     [7 12 18]|FALSE|(7,18) are not mod-aligned
     [7 11 19]|TRUE |1 mod 2
  [5 13 28 44]|FALSE|(5,28) are not mod-aligned
[10 13 37 108]|FALSE|(37,108) aren't aligned in any base below 10
            []|TRUE |No disproven pairs
          [42]|TRUE |No disproven pairs
    [-5 13 16]|TRUE |1 mod 3
      [1 9 18]|FALSE|Arrays of size 2 or greater with 1 or -1 will always be false
    [14 17 19]|FALSE|Every pair is modulus-aligned, but not under the same base
[17,22,32,107]|TRUE |2 mod 5
      [4,8,12]|TRUE |0 mod 2
        [-1,1]|FALSE|No mod 1 allowed
           [1]|TRUE |No disproven pairs
       [7,7,7]|TRUE |Numbers >=2 are always mod-aligned with themselves
     [2,2,8,8]|TRUE |0 mod 2
   [3 9 22 22]|FALSE|Pairs don't suddenly make (9,22) mod-aligned.

Sandbox Questions

I'm gauging the interest to this question and seeing if this is an acceptable and unique challenge, just want to make sure I haven't missed another post doing a similar thing.

I changed the rules to be a lot more lenient on the comparisons, might do the pairwise comparison as a bonus or follow-up challenge later. But this is a compromise I can live with.

Extra Hints/Tips

For all non-1 derivations, a number will be aligned with its negative self.
1 is never aligned with any other number, nor will -1.
A number that is a multiple of another will be aligned with that number in all its factors.
Numbers that share factors will always align, but numbers that don't share factors also may.
All odd numbers are aligned with each other, as are all even numbers.

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ I'm not clear on why this challenge asks to compare all pairs of a list, rather than just a single pair. The condition covers pairs of numbers, so it would be more natural to just receive a pair of numbers as input. \$\endgroup\$ – isaacg Feb 19 at 18:21
  • \$\begingroup\$ Because it's a combination of that function and a list-pair function with interesting shortcuts that can overlap. Asking for a pair could take X bits, and pushing all pairs to a function could take Y, but the combination of the two isn't necessarily X+Y. In my going at it, I saved like 8 bytes in the mix by being clever. This way, there are several ways to solve while still being a challenge. \$\endgroup\$ – Mathgeek Feb 19 at 18:24
  • 2
    \$\begingroup\$ Some test cases that are not 1 mod x would be good \$\endgroup\$ – Jo King Feb 20 at 5:21
  • \$\begingroup\$ Good suggestion, Jo. I just added one, and I'll add a few more in a bit - I hadn't even caught that! \$\endgroup\$ – Mathgeek Feb 20 at 13:32
  • 2
    \$\begingroup\$ While what you observed can be true, in my experience it is not usually a source of interest in golfing to combine tasks unnecessarily. Similarly, does including negative numbers make this task more interesting? In most languages this will not make a difference, but it will make answering in some languages (consider Retina) substantially more difficult - to the point where people probably won't answer. I always try to recommend making a challenge as simple as possible - just like writing a proof. \$\endgroup\$ – FryAmTheEggman Feb 20 at 18:59
  • \$\begingroup\$ I made negative numbers allowed because negative modulus is still a valid application of modulus - but that argument of "combining two things" is applicable to like literally every other code golf question. The string-wise calculus question could have just been "print out which of two characters is the largest", but then there was added difficulty to comparing pairs and assigning those values to distinct characters. This isn't just an arbitrary expansion, it's a setwise comparison of several elements applied over a function; You see these "expansions" all the time, so why is this one an issue? \$\endgroup\$ – Mathgeek Feb 20 at 19:24
  • \$\begingroup\$ I agree that the part of the challenge where you check every pair seems unnecessary, and was going to comment on this independently. I think just having two numbers as inputs would make a better challenge overall. Or, have all numbers in the list need to be aligned by the same modulus, which seems like a more natural extension. \$\endgroup\$ – xnor Feb 20 at 19:33
  • 2
    \$\begingroup\$ Okay, what about a fairer follow-up instead - instead of checking if all pairs are modulus-aligned, a list is modulus-aligned if all the entries share an identical mod-point. ie: They all have to be n mod m together for the list to be valid. Think that's still a more fair question? I think submitting pairs only is a very low-level simple problem that doesn't have any real puzzle or golfing elements to it, so I'd like it to be slightly more complex somehow. \$\endgroup\$ – Mathgeek Feb 20 at 19:37
  • 2
    \$\begingroup\$ What you and xnor propose sounds good to me. I tried to phrase what I said as suggestions and opinions, because that is all they are. There isn't anything wrong with what you have, but I know I'd be more likely to answer if you changed some things about it. The same is true for many challenges on this site (including my own). Over time, I've come to see that including requirements that are technically valid but aren't necessary rarely adds interest to a challenge. \$\endgroup\$ – FryAmTheEggman Feb 20 at 20:29
  • 1
    \$\begingroup\$ Doesn't [10 13 37 109] satisfy 1 mod 3 (and therefore it is modulus-aligned)? \$\endgroup\$ – Bubbler Feb 20 at 23:45
  • \$\begingroup\$ You're correct fixed! \$\endgroup\$ – Mathgeek Feb 21 at 13:14
  • 1
    \$\begingroup\$ @KevinCruijssen But that's fine. If I have a list [7, 14], they are aligned under Base 7. \$\endgroup\$ – Mathgeek Feb 21 at 14:40
  • 1
    \$\begingroup\$ I also just read the "(not necessarily positive nor unique)" part of your challenge, so you might want to add a few test cases containing multiple of the same number in that case. \$\endgroup\$ – Kevin Cruijssen Feb 21 at 14:46
  • 1
    \$\begingroup\$ Nice challenge btw. And good choice on explicitly mentioning "Note; This is a "true-until-proven-otherwise" problem, meaning a single value in the list or an empty list will return TRUE.", since those [1]/[-1] test cases are really annoying in my approach. ;) I had a prepared solution which worked for all initial test cases in 10 bytes, but now it's 50% larger to 15 bytes just to fix those two test cases, haha. Looking forward to when it goes live. I would leave it in the sandbox for a little while longer for others to give feedback though, just in case. Oh, and welcome to CGCC! \$\endgroup\$ – Kevin Cruijssen Feb 21 at 15:05
  • 1
    \$\begingroup\$ @xnor yes, the question then dissolves to finding whether the gcd of the differences of consecutive elements is >1. \$\endgroup\$ – Don Thousand Feb 21 at 16:09
2
\$\begingroup\$

Square-Cube Digit Usage

| |
\$\endgroup\$
  • \$\begingroup\$ In response to the first sentence: nice. \$\endgroup\$ – Lyxal Feb 20 at 0:43
  • \$\begingroup\$ I'm not exactly sure how your title relates to the challenge. Obviously "Square-Cube Digit Usage" won't exactly roll off the tongue, but what you have now seems misleading. \$\endgroup\$ – FryAmTheEggman Feb 20 at 20:22
  • \$\begingroup\$ Nice challenge. I prepared a solution for when it goes live. I would add a few more test cases first, though. One suggestion: 1333 (or 3133/3313/3331) -> 111 (first positive integer as input that has a 3-digit number as output). Here the results for the first 10,000 inputs. \$\endgroup\$ – Kevin Cruijssen Feb 21 at 10:53
2
\$\begingroup\$

Draw an American flag for any amount of states

The flag of the United States of America goes by many names. The Stars and Stripes. Old Glory. The Last Known Non-Erotic Usage Of The Verb 'To Spangle'.

It is also one of the few flags semi-regularly updated. The red and white stripes represent the 13 original states, but one more star has been added to the blue canton for every state that joined the union later. This last happened in 1960, when Hawaii got in. Flag designs with 51 stars are already waiting for when Puerto Rico or Washington D.C. are made states, but this vexillologist is lazy. You are to make a program that can draw the flag with any number of stars desired!

Specification

Here's a neat image of the official, government-standardised design for the current U.S. flag: flag design

Disregard the contents of the canton for now. Your program must draw a flag that adheres to only the ratios I give here:

  • A (the height of the flag) = 1
  • B (the width of the flag) = 19/10
  • C (the height of the canton) = 7/13
  • D (the width of the canton) = 19/25
  • L (the height of any stripe) = 1/13

Because raster solutions are not exact and this flag is commonly misdrawn anyway, there's tolerance of 2% for every ratio, taking the flag height as the base.

Furthermore, the correct colours must be used.

  • Every odd-numbered stripe must be this shade (hex): #B22234
  • The blue canton must be in this shade: #3C3B6E
  • Every even-numbered stripe, and every star, must be in this shade: #FFFFFF

Conversions to other colour coordinate systems can be found on the wiki page as well.

Stars

Your program must takes as input any integer between 0 and 200, and draw that number of stars within the canton. The following rules apply.

  • Each star must have five outer points and be five-fold rotationally symmetrical.
  • Each star must be the same size.
  • The bounding circles of stars may overlap, but the surface of the stars itself may not overlap.
  • The bounding circles of the stars may go outside the canton, but the surface of the stars itself may not go outside the canton.
  • I don't want solutions that just place every star on the same line; that would leave a lot of blue canton untouched, which would be a waste. So, as a rule, the combined surface area of the bounding circles of every star in the canton must be at least 20% of the surface area of the canton.

    Since overlapping bounding circles still count, you get a formula for the minimum width w of the star, where a is the area of the canton and n the number of stars: formula. See here for how it's derived.

Other specifications

There's no minimum or maximum size for your output image, though I recommend something that will allow 200 stars to fit but still be demonstrably star-shaped. When they are only a few pixels high, it becomes hard to argue that they have the required amount of points. Obviously, for vector solutions any size is permissible.

This is , so the smallest program wins!

Test cases

Because I gave no specific arrangement of the stars (you may arrange them however you want), there is an infinite number of correct and incorrect solutions for each number of stars. These are just examples of valid and invalid solutions:

Valid:

valid1

Invalid (stars too small):

invalid1

Valid:

valid2

Invalid (stars of unequal size, going out of the canton):

invalid2

Invalid (stars have too many points, stripes have wrong colours, colours are the wrong hue, proportions are wrong):

invalid3

Sandbox

Do I need more test cases? Any other feedback?

| |
\$\endgroup\$
  • 2
    \$\begingroup\$ If you really want to allow 0 as an input, you'll need an exception to the rule that the combined areas of the bounding circle must be at least 20% of the area of the canton. (If there aren't any stars, there aren't any bounding circles, so the combined areas would be 0.) \$\endgroup\$ – Mitchell Spector Mar 7 at 2:19
  • 4
    \$\begingroup\$ I know it's less thematic, but maybe the task could be just to draw the canton? Arranging and drawing the stars is the interesting part, whereas the stripes aren't changing, so in terms of golfing the stripes seem somewhat extraneous. I guess you could also have the number of stripes be variable. \$\endgroup\$ – xnor Mar 7 at 17:40
2
\$\begingroup\$

Symmetrical difference

Post'd.

| |
\$\endgroup\$
  • 2
    \$\begingroup\$ If a language supports it, can we take output and input as sets instead of a lists? \$\endgroup\$ – Chas Brown Apr 9 at 8:08
2
\$\begingroup\$

Posted on the main site.

| |
\$\endgroup\$
  • \$\begingroup\$ I don't think it's a dupe. Post it. \$\endgroup\$ – HighlyRadioactive Apr 27 at 0:02
2
\$\begingroup\$

Help, I've mixed my week up!

My dog ate my calendar, and now my days are all mixed up. I tried putting it back together, but I keep mixing up the days of the week! I need some help putting my calendar back together, with the days in the correct order.

And since I need my calendar put together as fast as possible, don't waste my time by sending me superfluous bytes. The fewer bytes I have to read, the better!

Input

The days of the week, in any order. Input can be taken as a list of strings, or a space separated string, or any reasonable way of representing 7 strings (one for each day of the week).

The strings themselves are all capitalized, as weekdays should be, so the exact strings are:

Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday

Output

The days of the week, in sorted order (Monday - Sunday). Output can be as a list of strings, or printed with some delimiter.

Disclaimer

Note that this is a challenge, with the added benefit of being able to use the input to shorten your code. You are not required to use the input if you don't want to.

Examples

To see example input and output, you can consult this python script.

For the sandbox

If there are any issues with the input/output specification, or if anything is unclear, please leave a comment.

Tags:

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ You cannot use 6 tags, and this still needs [code-golf]. Otherwise this seems to be a nice challenge. (I can see a 4-6 Jelly solution by sort-nth permutation though) \$\endgroup\$ – my pronoun is monicareinstate Apr 28 at 1:03
  • \$\begingroup\$ @mypronounismonicareinstate I forgot about the code-golf tag, but of course it should be there. I have my own solution in MathGolf (not quite 4 bytes), but I'm interested in different approaches. \$\endgroup\$ – maxb Apr 28 at 6:19
2
\$\begingroup\$

Fold my ACGT proteins

Quoting Wikipedia, "Protein folding is the physical process by which a protein chain acquires its native 3-dimensional structure, a conformation that is usually biologically functional, in an expeditious and reproducible manner.". I don't know what that means but by means of a game called Foldit it seems we can use protein folding in some way to help and fight diseases.

Please bear in mind that the task described was inspired by the isolated meaning of the words in "protein folding" and doesn't necessarily translate into how protein folding really works! i.e. the title is just a pun.

Task

Your task is to take a string matching the regex /^[ACGT]+$/ and return the number of times the string can be "folded". A string can be folded if and only if:

  • It's length is even;
  • The first half of the string is the reverse of the second half of the string.

Input

Acceptable input formats include but are not limited to:

  • strings
  • character lists
  • codepoint lists

Output

The output is an integer; I don't think there's much room to wiggle here, but let me know if you really wanted to return something else.

Test cases:

Python reference implementation

'A' -> 0
'AAA' -> 0
'AAAAA' -> 0
'TAAAAAAA' -> 0
'ATAAAAAA' -> 0
'AATAAAAA' -> 0
'AAATAAAA' -> 0
'AAAATAAA' -> 0
'AAAAATAA' -> 0
'AAAAAATA' -> 0
'AAAAAAAT' -> 0
'TGCAACGTTGCAACGT' -> 2
'ACGTTGCAACGTTGCAACGTTGCAACGTTGCA' -> 3
'TGCAACGTTGCAACGTTGCAACGTTGCAACGTTGCAACGTTGCAACGTTGCAACGTTGCAACGT' -> 4
'TACCCCATTACCCCAT' -> 2
'TTTT' -> 2
'TATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTATTAT' -> 5
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' -> 6
'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC' -> 6
'GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG' -> 6
'TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT' -> 6
'TAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAAT' -> 5
'GCCGGCCGGCCGGCCGGCCGGCCGGCCGGCCGGCCGGCCGGCCGGCCGGCCGGCCGGCCGGCCG' -> 5
'CATTACCATTACCATTACCATTAC' -> 3
'CATTACCATTACCATTACCATTAC' -> 3
'CATACCATACCATACCATACCATACCATACCATACCATAC' -> 3
| |
\$\endgroup\$
  • \$\begingroup\$ Where did you get the "The first half of the string is the reverse of the second half of the string." requirement from? \$\endgroup\$ – Lyxal Apr 28 at 0:25
  • \$\begingroup\$ @Lyxal I do not understand the question \$\endgroup\$ – RGS Apr 28 at 5:58
  • \$\begingroup\$ Protein folding is usually related to amino acids, which are based on groups of 3 nucleic bases. And usually, it doesn't really matter what order they are in. I say this because the ATCGs you have aren't amino acids. They are nucleic bases which, when converted into RNA (which uses U instead of T) become amino acids. \$\endgroup\$ – Lyxal Apr 28 at 6:15
  • \$\begingroup\$ @Lyxal ah I understand what you mean. I have added this sentence: Please bear in mind that the task described was inspired by the isolated meaning of the words in "protein folding" and doesn't necessarily translate into how protein folding really works. This addresses your issue, right? Also, this probably means the tag you added doesn't really make sense here, no? What do you think? (On the other hand if you know how PF works I'm glad to talk with you to forge a more closely related challenge) \$\endgroup\$ – RGS Apr 28 at 6:20
  • \$\begingroup\$ it's been a while since I last studied PF, but if it's an isolated meaning/simplified approach, then that seems fine to me. \$\endgroup\$ – Lyxal Apr 28 at 6:23
  • 4
    \$\begingroup\$ I think it's just a pun isn't it? Not literally "folding" proteins in the usual complicated 3 dimensional fashion, but just folding them a string supposedly representing a protein in half. \$\endgroup\$ – Steve Bennett Apr 30 at 7:08
  • \$\begingroup\$ @SteveBennet dang it! I missed the joke. \$\endgroup\$ – Lyxal May 1 at 23:54
2
\$\begingroup\$

Integers in cosine

Posted

| |
\$\endgroup\$
  • 1
    \$\begingroup\$ I might be completely wrong, but doesn't \$\sin(x) = -\cos(x+\frac{\pi}2)\$? \$\endgroup\$ – my pronoun is monicareinstate May 3 at 4:25
  • \$\begingroup\$ You are right, it's either -cos or -k \$\endgroup\$ – Gábor Fekete May 3 at 9:51
  • \$\begingroup\$ I think the question would be clearer if you stated that \$\sin(a) = -\cos[a+(4m+1)\frac{\pi}{2}]\$ for integer \$m\$. Also, the sentence 'Instead of pi/2 we could use integers that are near the actual value of sin(a)' is not correct: \$|\sin(a)|\le1\$. I guess you mean values of \$k\$ that are close to \$(4m+1)\frac{\pi}{2}\$ for some \$m\$. But in that case, \$k=14\$ is better than \$k=11\$ for 2 digits. (I haven't checked all 2-digit values.) \$\endgroup\$ – Dingus May 4 at 0:39
  • \$\begingroup\$ I based my challenge on this blog post: iquilezles.org/blog/?p=4760 It's for reducing coding in shader live coding session mostly. I calculated myself the closest values and |cos(33)| is much bigger than |cos(11)| so I changed that and the 5 digit one, but the other values are minimal. \$\endgroup\$ – Gábor Fekete May 4 at 8:36
  • \$\begingroup\$ You seem to be seeking integer values of \$k\$ for which \$|\cos(k)|\$ is minimal. That's a very different question from finding values of \$k\$ such that \$\sin(a)\approx-\cos(a+k)\$, which is the question you've actually posted here and what the blog post describes (with missing minus signs). \$\endgroup\$ – Dingus May 4 at 9:44
  • \$\begingroup\$ yeah sorry, I got confused how those values got calculated, let me rephrase the challenge then \$\endgroup\$ – Gábor Fekete May 4 at 15:45
  • 1
    \$\begingroup\$ Thanks for the edits. This looks better now, though I'd suggest using MathJax (\\\$ delimiters) for the maths. What is the scoring/winning criterion for this challenge? (Is it code-golf? fastest-code?) \$\endgroup\$ – Dingus May 4 at 23:10
  • 1
    \$\begingroup\$ Almost there... but you have \$\pi\$ in the wrong place. It should be in the numerator: \$\frac{(4m+1)\pi}{2}\$. \$\endgroup\$ – Dingus May 5 at 23:20
  • \$\begingroup\$ Thanks, this is my first challenge and I haven't used latex in a while so every help is appreciated :) \$\endgroup\$ – Gábor Fekete May 6 at 10:23
2
\$\begingroup\$

Bilibili AV/BV Code Conversion

| |
\$\endgroup\$
  • \$\begingroup\$ Can I share part of the two functions? (though it likely make them search) \$\endgroup\$ – l4m2 May 14 at 16:53
  • \$\begingroup\$ I would say no, because the two functions should be independent. I will clarify this in the requirements. You may have identical parts in both function, but they will be double-counted. \$\endgroup\$ – Shieru Asakoto May 15 at 1:11
  • \$\begingroup\$ Oh I meant each code should work even without the code from the other. Hope this will be clear enough for the requirement \$\endgroup\$ – Shieru Asakoto May 15 at 1:19
  • \$\begingroup\$ Consider deleting this post, as the challenge is already on main \$\endgroup\$ – RGS May 20 at 16:50
2
\$\begingroup\$

Minimise my List of Error Codes

SANDBOX - One Option for a Challenge

Given a set of error codes, formed of letters (A-Z) and numbers (0-9), output a string that represents the set of error codes in a concise format, as follows:

  • Where two or more error codes share some first characters, there is no need to repeat those characters in the output
  • Individual errors in the output are comma-separated (or in separate array indices, if preferred)

e.g:

  • E1,E2 -> E1,2
  • E1,W1 -> E1,W1
  • ERR001, ERR002, ERR101, WAR001 -> ERR001,2,101,WAR001 or WAR001,ERR001,2,101
  • WARN001, ERR001 -> WARN001,ERR001
  • EAR001, ERR001 -> EAR001,RR001
  • E001, E001 -> E001,
  • A, B, C01, D002 -> A,B,C01,D002
  • D002, DC01, DC0A, DC0B -> D002,C01,A,B or DC01,A,B,002 or DC0A,B,1,002etc.

Basically, when decoding, each character after the comma replaces the characters at the end of the previous error code.

SANDBOX - Alternative Challenge?

Decode a string of error codes, as per the above format, to extract the individual list of error codes again

SANDBOX - Questions

I know the spec is incomplete above - this is a placeholder for when I have time to write a better spec.

Is this an interesting challenge? Which of the two options would work best? Or could it be the sum of the two (encoder and decoder)?

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

Inspired by Draw this planar graph.

Your input represents an ascending sequence, e.g. 1 2 3 4. You can require the sequence as input, or you can just input the length. The explanation assumes 1-indexing but you can use 0-indexed or even a-indexed input if you adjust the algorithm appropriately.

At each step, you can exchange any digit of value n with the digit n places to its right. So the valid second steps are 2 1 3 4 and 1 4 3 2. Eventually you want to end up at the reverse sequence 4 3 2 1, which is the only permutation that has no legal steps.

Please output all possible sequences of steps from the input sequence to its reverse.

You should support sequences of up to at least 10 elements.

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

| |
\$\endgroup\$
  • \$\begingroup\$ I really like this graph's symmetries, so +1! "All such sequences"? For n=1,2,3,4 there are 0,1,2,82 such paths through the graph; I don't think enumerating all of them will be practical even for n=6. \$\endgroup\$ – retzler May 26 at 0:26
  • \$\begingroup\$ There might be some questions that can be answered for this special graph more efficient (in terms of code-size) than general graph-searching algorithms: Shortest path, longest path? - I assume there is be a function f on the graph such that f(v)<f(w) iff there's a path from v to w (but right now I don't know) - if that's interesting enough, implement that? \$\endgroup\$ – retzler May 26 at 0:47
2
\$\begingroup\$

Inspired by Wizard creating a jewelry.

Given an input list of positive integers, calculate the minimum cost of creating the list from the following operations:

  1. Appending a positive integer costs the value of the integer.
  2. Incrementing the entire list costs 2.
  3. Exchanging two consecutive elements of the list costs 1.

Example: The list 1 4 9 16 25 could be constructed as follows:

  • Append 1
  • Append 8
  • Append 17
  • Increment
  • Increment
  • Increment
  • Increment
  • Increment
  • Append 1
  • Swap 22 with 1
  • Swap 13 with 1
  • Swap 6 with 1
  • Increment
  • Increment
  • Increment
  • Append 1
  • Swap 25 with 1
  • Swap 16 with 1
  • Swap 9 with 1
  • Swap 4 with 1

This costs 51, which is an improvement over simply appending the integers, as that is a cost of 54.

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

| |
\$\endgroup\$
  • \$\begingroup\$ Seems clear, but another test case or two might be helpful. \$\endgroup\$ – Dingus May 29 at 7:32
2
\$\begingroup\$

Reduce the entropy of the input...

Spec

Given two arguments:

  • A list containing 2 or more positive integers (from 0 to artificial limit of 2^32)
  • A positive number defining the 'entropy allowance'

Return a sublist containing elements up until the entropy allowance is used up.

For this challenge, we define 'entropy' as the difference in bits between numbers in the list; also known as the Hamming distance.

Note that no 'entropy' is used up when flipping the bits in the first number, only used when flipping subsequent bits.

Examples

Worked example (MSB...LSB), keeping the numbers low to keep things simple:

Example 1:

List: [1, 2, 3, 4, 5, 6] Allowance: 4

1 => 0000 0001 - ignore implicit change from 0, total used = 0
2 => 0000 0010 - change of 2 bits, total used = 2
3 => 0000 0011 - change of 1 bit, total used = 3 
4 => 0000 0100 - change of 3 bits, total used = 6 (would exceed allowance)
5 => 0000 0101 - change of 1 bit, total used = 7
6 => 0000 0110 - change of 2 bits, total used = 9

Output: [1, 2, 3]

Example 2:

List: [255, 0, 127, 64, 32, 100] Allowance: 23

255 => 1111 1111 - ignore implicit change from 0, total used = 0
0   => 0000 0000 - change of 8 bits, total used = 8
127 => 0111 1111 - change of 7 bit, total used = 15
64  => 0100 0100 - change of 6 bits, total used = 21
32  => 0010 0000 - change of 2 bit, total used = 23
100 => 0110 0100 - change of 2 bits, total used = 25

Output: [255, 0, 127, 64, 32]

Meta

Is this interesting enough a challenge? Is it just a chameleon (is it just the hamming distance with extra steps)? Thoughts?

If it's not shot down for being a plain, any ideas for a better title?

| |
\$\endgroup\$
  • \$\begingroup\$ Guess allowing removing arbitary least item is more interesting \$\endgroup\$ – l4m2 Jun 19 at 2:38
  • \$\begingroup\$ What about a slight pivot - given a list and an allowance, return the list that maximise length of the list? \$\endgroup\$ – streetster Jul 29 at 11:55
2
\$\begingroup\$

The smallest positive integer that cannot be printed in fewer than %NUMBER% bytes of %LANGUAGE%

All numbers mentioned below are positive integers. All programs mentioned below output exactly 1 number (including functions that return it).

For every number, there must be at least one program in your language that outputs it. Besides, the problem of determining what number the program outputs must be undecidable without making the assumption that the program halts.

The challenge itself is to choose a number \$N\$ and find the smallest number \$M\$ that cannot be output by a program shorter than \$N\$ ordinary units of measurement used for your language (usually bytes). You have to prove your solution correct. A strong mathematical proof is not necessary, but it should be reasonably convincing for somebody knowledgeable in your programming language.

The answer with the largest \$M\$ wins.

Sandbox stuff

  • In this challenge, non-golfing languages seem to have a serious advantage. I think scoring by \$M\$ instead of \$N\$ is better at reducing the advantage of Lenguage-like languages to manageable levels and preventing ties; is that correct?
  • Is the tag appropriate?
  • Title suggestions?
| |
\$\endgroup\$
  • \$\begingroup\$ I feel like I misunderstand. Let's say print M (where M is a normal base 10 integer) is the only valid way to output integers in my language. I take \$N=7\$, then \$M=1\$. What's to stop me repeatedly increasing \$N\$ by 1 and adding a zero on to \$M\$ each time? \$\endgroup\$ – Dingus May 28 at 2:23
  • \$\begingroup\$ @Dingus I used to have a complicated rule to prevent exactly this; I'll try to think of a simpler one. \$\endgroup\$ – my pronoun is monicareinstate May 28 at 2:35
  • \$\begingroup\$ I'm worried that the proof will just be an exhaustive search for most language, as \$M\$ has to be the smallest number. Alternatively, we could make \$M\$ a lower bound of the smallest value, and score a solution based on both \$M\$ and \$N\$. Another way is to flip this challenge to find the largest printable number in \$N\$ bytes, but that has already been done here and here. \$\endgroup\$ – Surculose Sputum May 29 at 15:18
  • \$\begingroup\$ @Dingus I think you will have to stop when you can't prove whether whatever precedes print M halts or doesn't halt. I still think this is too cheap a way to get a high-scoring answer, but I am not sure how to formalize things better. \$\endgroup\$ – my pronoun is monicareinstate Jun 2 at 16:01
  • \$\begingroup\$ @mypronounismonicareinstate I think my question is probably not relevant. I overlooked a critical condition - 'the problem of determining what number the program outputs must be undecidable without making the assumption that the program halts'. \$\endgroup\$ – Dingus Jun 4 at 0:18
  • \$\begingroup\$ I'm worried that some ridiculously large numbers will show up here. Also, as \$N\$ gets too large, maybe we will encounter problems like \$M\$ cannot be calculated assuming axioms of ZFC, what will happen then? \$\endgroup\$ – Trebor Jun 18 at 7:29
  • \$\begingroup\$ @Trebor As far as I understand, each program either does output a number within finite time or doesn't output a number within finite time. If the program outputs a number, its result is known, and if it doesn't, the program is not valid because it doesn't output a number in finite time. Can you think of any particular way to obtain a ridiculously large number? \$\endgroup\$ – my pronoun is monicareinstate Jun 18 at 10:03
  • \$\begingroup\$ A simple example is a program that enumerates all the valid proofs in ZFC and outputs the Godel encoding of the first proof it encounters of \$A \wedge \neg A\$. Since ZFC cannot prove its own consistency, it is not decidable in ZFC whether this program terminates. Worse still, if the program do terminate, ZFC cannot compute the return value either, because it is now inconsistent, rendering its deductions unreliable. \$\endgroup\$ – Trebor Jun 18 at 11:00
  • \$\begingroup\$ @Trebor Halting and printing a single number is completely binary. Are you sure you are reading the challenge correctly? I'm asking not for the largest number that can be printed, but for the smallest number that can't be printed. \$\endgroup\$ – my pronoun is monicareinstate Jun 18 at 11:27
  • \$\begingroup\$ @mypronounismonicareinstate Yes, that's why I'm "worried" instead of "sure". Also, these problems will not show up if we keep it small... \$\endgroup\$ – Trebor Jun 19 at 0:42
2
\$\begingroup\$

Can this month tell the day-of-the-week?

June 2020 is a month in which June 1st corresponds to Monday, June 2nd corresponds to Tuesday, ... June 7th corresponds to Sunday. For reference, here's the cal of June 2020.

      June 2020     
Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30            

Given a year and a month in the format [year, month], output two distinct values that tell whether this month can tell the day-of-the week.

Test cases

[2020,6] -> True
[2021,2] -> True
[1929,4] -> True

[1969,1] -> False
[1997,5] -> False
[2060,1] -> False
```
| |
\$\endgroup\$
  • 5
    \$\begingroup\$ Have you considered "Does this month start on Monday?" \$\endgroup\$ – Domenico Modica Jun 6 at 14:06
2
\$\begingroup\$

Self-distances completion - Minimum k to get them all

Related minor code-golf challenge

Consider \$A = (a_1,\dots,a_k)\ k\ge2 \$ a sequence of positive integers, in which all elements are different.

The self-distances completion of a sequence like \$A\$ it's performed recursively as follow:

Starting from \$i=2\$, while \$a_i\in A:\$ (loop until the last element)

  • If \$d=|a_i-a_{i-1}|\$ is not already in \$A\$, append \$d\$ to \$A\$
  • Increase \$i\$

The resulting sequence \$A^\circ\$ is presumably longer than \$A\$, nevertheless can't contain more than \$n\$ terms.

Examples

$$ A = (2,\ 9,\ 13,\ 15) \mapsto A^\circ = (2,\ 9,\ 13,\ 15,\ 7,\ 4,\ 8,\ 3,\ 5)\\ A = (2,\ 9,\ 13) \mapsto A^\circ = (2,\ 9,\ 13,\ 7,\ 4,\ 6,\ 3)\\ A = (2,\ 9) \mapsto A^\circ = (2,\ 9) $$

Task

If we pick a number \$n\ge 2\$, we can ask what's the minimum length \$k_n\$ of \$A\$ such that \$A^\circ\$ contains all the numbers up to \$n\$.

(Note that \$\max A = \max A^\circ\$ so \$n\$ has to be in \$A\$)

  • Generate the sequence of \$k_n\$ starting from \$n=2\$.

This is .

I'll run your code on my machine (Windows 10, i7-7500U) for 30 minutes.
Obviously longer sequence is better. In case of a tie, who gets to the last term faster wins.
Your submission must not use more than 8GB of memory.
Please include instructions for how to compile/run your code.

First values and more info

 n. k_n - first A* example found (how many A of lenght k_n that satisfy the condition)

 2.  2  - 1 2 (2)
 3.  2  - 1 3 2 (4)
 4.  2  - 4 1 3 2 (2)
 5.  2  - 5 4 1 3 2 (1)
 6.  3  - 1 6 2 5 4 3 (19)
 7.  3  - 3 1 7 2 6 5 4 (10)
 8.  3  - 6 1 8 5 7 3 2 4 (3)
 9.  4  - 6 1 9 2 5 8 7 3 4 (80)
10.  4  - 10 1 8 3 9 7 5 6 2 4 (39)
11.  4  - 6 8 1 11 2 7 10 9 5 3 4 (18)
12.  4  - 8 12 1 10 4 11 9 6 7 2 3 5 (7)
13.  4  - 5 3 12 13 2 9 1 11 7 8 10 4 6 (2)
14.  5  - 6 14 3 1 13 8 11 2 12 5 9 10 7 4 (68)
15.  5  - 9 13 3 1 15 4 10 2 14 11 6 8 12 5 7 (17)
16.  5  - 11 16 2 15 12 5 14 13 3 7 9 1 10 4 8 6 (9)
17.  5  - 14 15 9 13 17 1 6 4 16 5 2 12 11 3 10 8 7 (1)
18.  5  - 15 18 6 16 17 3 12 10 1 14 9 2 13 5 7 11 8 4 (1)
19.  6  - 16 10 18 1 4 19 6 8 17 3 15 13 2 9 14 12 11 7 5 (38)
20.  6  - 14 5 20 17 1 19 9 15 3 16 18 10 6 12 13 2 8 4 11 7 (8)
21.  6  - 12 19 3 21 20 6 7 16 18 1 14 9 2 17 13 5 15 4 8 10 11 (1)
22.  6  - 20 12 19 3 21 22 8 7 16 18 1 14 9 2 17 13 5 15 4 10 11 6 (1)
23.  7  - 22 4 23 14 16 1 21 18 19 9 2 15 20 3 10 7 13 5 17 6 8 12 11 (46)
24.  7  - 15 21 1 23 13 10 24 6 20 22 3 14 18 2 19 11 4 16 17 8 7 12 9 5 (14)
25.  8  - 19 23 2 22 9 1 25 7 4 21 20 13 8 24 18 3 17 5 16 6 15 14 12 11 10 (942)
26.  8  - 18 25 8 2 24 1 21 26 7 17 6 22 23 20 5 19 10 11 16 3 15 14 9 13 12 4 (254)
27.  8  - 27 1 25 20 6 22 18 3 26 24 5 14 16 4 15 23 2 19 9 12 11 8 21 17 10 13 7 (74)

The veeery elementary program I used. There aren't any optimizations, it's just for reference.

For the purpose of the challenge you don't have to output examples nor the count. k_n is sufficient

(It doesn't appear in OEIS).

Conjectures

  • The sequence of \$k_n\$ is monotonically increasing
  • \$k_{n+1}=k_{n}\lor k_{n+1}=k_{n}+1\$

Sandbox

  • It's all clear and does it makes sense?
  • Any suggestion for a "lighter" name of the process other than "self-distance completion"?
| |
\$\endgroup\$
  • \$\begingroup\$ The alignment of Examples is fine in the main post preview :) \$\endgroup\$ – Domenico Modica Jun 1 at 8:46
  • \$\begingroup\$ A k-permutation of n seems to be a permutation of some k-element subset for {1, ..., n}, right? \$\endgroup\$ – retzler Jun 4 at 20:13
  • \$\begingroup\$ @retzler Exactly, equivalently a non-repetitive sequence of integers. And then we consider its max element n. I prefer to keep the notation of k-permutation of n containing n since doesn't require the notion of max and also it's more linear for what comes next \$\endgroup\$ – Domenico Modica Jun 4 at 20:36
  • \$\begingroup\$ If the growth of k_n is unknown, an algorithm's complexity might come in the form f(k_n). Edit Ah well, tagged fastest-code. Maybe there's another ambiguity: Maybe still require an example for each n - otherwise what's to prevent printf("2,2,2,2,3,3,3,4,4,4,4,4,5,5,5,5,5,6,6,6,6,7"); \$\endgroup\$ – retzler Jun 4 at 21:39
  • \$\begingroup\$ @retzler I decided to go for fastest-code since looking around fastest-algorithm are not so popular. And as you spotted, the complexity of the algorithm wouldn't be straightforward (and I know almost nothing how it's calculated). About the output I think that to hardcode a sequence it's automatically seen as cheat. Look \$\endgroup\$ – Domenico Modica Jun 4 at 22:09
  • \$\begingroup\$ Some comments: (1) The description is a little difficult to follow, but I think it's because the problem is that hard to define. You can't probably get the description much clearer than it is now. (2) In the "Task" section you ask for the minimum k such that its completion contains all numbers up to n. However, the math section right afterwards requires, if I'm interpreting it correctly (four quantifiers in a row is a little too much for me), that k and all numbers above it satisfy that property. (3) Maybe give a few more details about your computer: RAM, even cache memory \$\endgroup\$ – Luis Mendo Jun 5 at 20:15
  • \$\begingroup\$ (4) Your submission must not use more than 8GB of memory: isn't that platform-dependent to some extent? (5) Typo: "lenght" \$\endgroup\$ – Luis Mendo Jun 5 at 20:15
  • \$\begingroup\$ @LuisMendo (1) The question was very instinctive, but maybe I've convoluted it too much. Playing with the completion I asked myself how can I "generate" all the number up to a certain one. Of course is interesting to find the minimum requirements that is the minimum (starting) length. Now one particular thing to notice is that the new terms added are always smaller that the max element in the input string (that's because we are always adding distances). So if I hope to generate all the number up to 20, of course 20 has to be within the input string \$\endgroup\$ – Domenico Modica Jun 6 at 13:05
  • \$\begingroup\$ @LuisMendo That's why I define \$\mathcal{A}_{n,k}\$ to be all the sequences of length \$k\$ having \$n\$ as their max element. All the completion of all the sequences in one of these sets always keep the same max element \$n\$, (the only thing that can change is the resulting length). It's in these sets that make sense to search if it exists one sequence that maps to the "full" \$n\$-sequence. It's a guideline not a rule (maybe it does more harm than good) \$\endgroup\$ – Domenico Modica Jun 6 at 13:09
  • \$\begingroup\$ @LuisMendo (2) Yes, you've interpreted it correctly. It's nothing special, basically when you find the smaller k that works, all the numbers above it automatically work as well. Take the working sequence you found of length k, you can find a k+1 sequence if you incorporate the first \$d\$ appended, you can find a k+2 long sequence incorporating also the second \$d\$ appended in the original one. So, they will all work above a certain threshold. (3-4) I was borrowing from this post \$\endgroup\$ – Domenico Modica Jun 6 at 13:23
  • \$\begingroup\$ @DomenicoModica (2) Ah, maybe clarify that in the text then. On the face of it, they seem different statements \$\endgroup\$ – Luis Mendo Jun 6 at 13:33
  • 1
    \$\begingroup\$ @LuisMendo I've pared it down substantially. I don't know why I thought all that notation was fundamental ahahaha. Anyway I'll wait sometimes to post it because I want to experiment a bit with it to have a bigger picture and maybe find some useful reductions \$\endgroup\$ – Domenico Modica Jun 6 at 14:00
2
\$\begingroup\$

Pi or Phi?

Task

Given a positive integer \$n\$ where \$n \geq 10\$ as input, determine whether \$n\$ occurs in the first 100 digits of pi (after the decimal), the first 100 digits of phi, or both.

Reference

"The first 100 digits" refers to the 100 digits after the decimal place in each number

First 100 digits of Phi:

(1.)6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374

First 100 digits of Pi:

(3.)1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679

Input

  • You can assume that the input will appear in the first 100 digits of at least one of the two numbers (pi or phi)

  • Input can be taken as a number, string or any other reasonable format

  • The input number will have 2 or more digits and won't exceed 100 digits

Output

Output should be one of three consistent values:

  • One to represent that the number appears in (the first 100 digits of) Pi (but not phi)

  • Another value to represent that the number appears in (the first 100 digits of) Phi (but not pi)

  • Another value to represent that the number appears in Both

Examples

Input: 113

Output: Phi since the substring 113 appears in the first 100 digits of phi, but not in the first 100 digits of pi.


Input: 793

Output: Pi since the substring 793 appears in the first 100 digits of pi, but not in the first 100 digits of phi.


Input: 84

Output: Both since the substring 84 appears both in the first 100 digits of pi and in the first 100 digits of phi.


Test Cases

113 -> Phi
793 -> Pi
84 -> Both
618 -> Phi
141 -> Pi
86 -> Both
3398 -> Phi
3993 -> Pi
39 -> Both
374 -> Phi
679 -> Pi
35 -> Both
072 -> Phi
078 -> Pi
117 -> Both
1798057628621 -> Phi
71693993751058209 -> Pi
803 -> Both
811 -> Phi
10 -> Pi
11 -> Both
| |
\$\endgroup\$
  • \$\begingroup\$ This seems like mostly a challenge to compute digits of pi or phi, which feels like a chameleon challenge. \$\endgroup\$ – xnor Jun 8 at 7:51
  • \$\begingroup\$ I think at 100 digits I agree with xnor, but if you made the number of digits smaller I would expect some kind of compression to be a better approach. That said, I'm not sure it is then terribly different from other compression based questions since I don't think phi or pi have any exploitable structure. I do think there is a good idea somewhere in here, I'm just not sure this is it. \$\endgroup\$ – FryAmTheEggman Jun 9 at 16:33
2
\$\begingroup\$

Print the SARS-Cov-2 (COVID-19) genome

Background

As you probably learned in biology class, DNA and RNA are composed of strands of nucleotides; each nucleotide consists of a chemical called a base together with a sugar and a phosphate group. The information stored in the DNA or RNA is coded as a sequence of bases. DNA uses the bases A, C, G, and T (standing for adenine, cytosine, guanine, and thymine), while RNA uses A, C, G, and U (with uracil replacing thymine).

Challenge

The genome of SARS-Cov-2, the virus that causes COVID-19, has been fully sequenced. This genome is a sequence of 29,903 bases, each base being one of A, C, G, or U, since it's an RNA virus.

The challenge is to output that sequence using as few bytes in your program as possible (code golf). You can write either a full program or a function.

Because the names A, C, G, and U are arbitrary, you can use any 4 characters you want instead:

  • You must use exactly 4 characters (they must be pairwise distinct--two or more can't be equal).
  • Each one of the 4 characters must be a printable ASCII character in the range from '!' to '~', inclusive (ASCII 33 to 126). In particular, this does not include the space character or the newline character.
  • Each of the 4 characters you use must always represent the same one of A, C, G, and U -- no changing in the middle!

Your output should be the precise text at the following link, with A, C, G, and U replaced by whichever 4 characters you selected, and you may optionally follow the entire sequence with one or more newline characters (but no newlines or other extraneous characters at the beginning or in the middle are allowed):

Click to see the required output. (Including all 29,903 characters here would cause this to exceed a StackExchange maximum size.)

Because you can use any 4 distinct characters you want, it's acceptable to use, for example, lower-case instead of upper-case, or to use T instead of U, or to use 0123 instead of ACGU, or even to output the complementary strand (with A and U switched, and C and G switched).

Restrictions

Standard loopholes are prohibited as usual. In particular, it's not allowed to retrieve information online or from any source other than your program. You also can't use any built-in which yields genomic data or protein data (these would generally retrieve data from the Internet so they wouldn't be allowed anyway, but some languages may have this facility built in internally; use of such functionality is prohibited whether implemented internally or externally).

Verifying Your Program

I've set up a way to check that your program's output is correct. Just copy and paste your program's output into the argument in this verification program on TIO and run it.

Other Info

Some facts that may or may not be of help:

  1. There are 29,903 bases in the sequence. The counts for the individual bases are:

    • A 8954
    • C 5492
    • G 5863
    • U 9594
  2. If you simply code each of the 4 bases in 2 bits, that would get you down to 7476 bytes (plus program overhead), so any competitive answer is likely to be shorter than that.

  3. The source for the data can be found at this web page at NIH; scroll down to ORIGIN. The data is written there in lower-case letters, and 't' is used instead of 'u', apparently because DNA sequencing techniques were used.

  4. There are variant strains of SARS-Cov-2 known (the base sequences are slightly different, and the length varies a bit); I believe the one here is the first one sequenced, from Wuhan.

  5. Groups of 3 consecutive bases code for particular amino acids, so it might be useful to analyze the data in groups of 3. But there are non-coding areas where the number of bytes isn't necessarily a multiple of 3, so you may not want to just divide the data into groups of 3 starting at the beginning. If it might be useful, you can find more info on the structure of the virus RNA here (but this probably isn't needed).

Disclaimer: I'm not a biologist. If anyone has any corrections or improvements on the underlying biology (or anything else, of course), please let me know!

Happy golfing!

| |
\$\endgroup\$
  • \$\begingroup\$ Mathematica has ResourceData["Genetic Sequences for the SARS-CoV-2 Coronavirus"]. It fetches data from the internet, but somebody like me could argue that it's allowed because it's sort of built-in, so I think you should disallow coronavirus genome built-ins here. I get 7846 bytes for Bubblegum with zopfli (probably because the raw storage mode in DEFLATE always stores >=1 byte per source byte, and the other ones have various LZ77 stuff in the Huffman tree, increasing overhead for non-compressible parts, assuming I understand DEFLATE correctly) \$\endgroup\$ – my pronoun is monicareinstate Jun 7 at 13:30
  • \$\begingroup\$ @mypronounismonicareinstate Thanks for pointing that out -- I added in something to handle that. The challenge now specifically prohibits any use of built-in genomic data or protein data. This should take care of somebody somehow getting, for instance, a related virus genome and then just compressing the diff. \$\endgroup\$ – Mitchell Spector Jun 7 at 18:23
  • \$\begingroup\$ I'm sorry to say that somebody has beaten you to it. \$\endgroup\$ – Dingus Jun 10 at 1:28
  • \$\begingroup\$ @Dingus Yes, I just noticed that. I voted to close the other question as a duplicate. Posting in the Sandbox for a couple of days first is the recommended procedure, after all, so my challenge has priority. I've gone ahead and moved it to the main site. (And I think it's better though thought out, and it has a verification program -- plus it benefited from mypronounismonicareinstate's comment about Mathematica built-ins.) \$\endgroup\$ – Mitchell Spector Jun 10 at 1:43
  • \$\begingroup\$ @MitchellSpector I agree that yours is better thought out. The verification program is a great feature - obviously a bit of work went into creating it. I'll leave my answer posted pending the outcome of the close vote. Not because I don't support your claim to priority, but for the sake of my own priority in posting the first answer. \$\endgroup\$ – Dingus Jun 10 at 1:52
  • 1
    \$\begingroup\$ @Dingus -- Thank you! I have no problem with answers being posted to both challenges as long as they're still open. (I think the other one should be closed, but I also don't believe in penalizing answerers for problems with a question.) If I had let it linger in the Sandbox for a month, it would be fair game, but it's only been there for a couple of days, which is the right way to do it. \$\endgroup\$ – Mitchell Spector Jun 10 at 1:55
2
\$\begingroup\$

Posted.

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

Pwning Passwords

Alice decided to improve the security of her website by sending first five characters of an SHA-1 hash to Bob's Leaked Password Detection Service. However, she made two mistakes that let Eve decode the passwords: sending passwords over HTTP and checking the password after each character of a password is typed. Eve asked you for help in decoding the passwords, however she cannot really program, so needs your help in implementing password cracking algorithm as a computer program or function.

Eve eavesdropped the requests for following hashes from Alice.

516B9
379FC
19C2A
9D4E1
08506
F808E
A7F93
5BAA6

How could you decode this password? Well, you can brute-force all lowercase letters. In this case the only letter whose hash starts with 516B9 is p. The hash of letter p is 516B9783FCA517EECBD1D064DA2D165310B19759.

Knowing that the password starts with p, you can brute-force the second character. In this case, the only possible character is a. The hash of pa is 379FC0D5299A71AC0F171FBB5AFB262829B4E765

You can continue to brute-force letters one by one to figure out the password was password (5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8). Well, that was simple.

Not all passwords are that simple however. Consider the following requests:

4DC7C
A84FD
467D7
BD79D
12D83

First three characters of this password are simple: rxr (467D7856C648A79A096D339A2CE5FC929658967D).

With the fourth character it gets more complicated. BD79D matches for rxrf (BD79DEC8435B8BA509A25F419F31CC2ACDE2FF0A) and rxrp (BD79DC20901B11468F8369B5B0D15894F3D96A5E). There is an ambiguity, but as it turns out, it can be resolved by trying both ways. If you assume the password starts with rxrp there is no valid letters to continue with. However, if you assume the password starts with rxrf, then it's possible to append a, resulting in rxrfa (12D83D3A429CD7D64E9A532C05C2C00C35032A94), which is a valid solution.

All passwords will be composed entirely out of lowercase letters. You can assume all inputs have a solution and there are no inputs that could possibly resolve to multiple passwords (for instance ["4DC7C", "A84FD", "467D7", "BD79D"] is an invalid input because it can match both "rxrf" and "rxrp").

There are no case requirements on the input. Your program is allowed to assume the input is lowercase. Your program is allowed to assume the input is uppercase.

The program must not take longer to execute than 24 hours for a 25 characters long password.

It is allowed to use external libraries or language built-in functions for computation of SHA-1 hash.

Example Input and Output

This is a JSON.

[
  {
    "input": [
      "516B9",
      "379FC",
      "19C2A",
      "9D4E1",
      "08506",
      "F808E",
      "A7F93",
      "5BAA6"
    ],
    "output": "password"
  },
  {
    "input": [
      "07C34",
      "593B7",
      "0262F",
      "CED65",
      "23612",
      "4EF76",
      "B7A87"
    ],
    "output": "letmein"
  },
  {
    "input": [
      "84A51",
      "87DDA",
      "83F67",
      "E6FB0",
      "5157D",
      "82CD7",
      "6F655",
      "43426"
    ],
    "output": "codegolf"
  },
  {
    "input": [
      "7A81A",
      "DB3D4",
      "FE05B",
      "E7280",
      "32726",
      "30AE9",
      "2C61A",
      "A9E46",
      "15D98",
      "F780A",
      "3E949",
      "F4BF2",
      "6A5C4",
      "C4554",
      "FA2EA",
      "48A40",
      "5DD7F",
      "5284E",
      "C0B8D",
      "20D59",
      "9184C",
      "32AD9"
    ],
    "output": "onetwothreefourfivesix"
  },
  {
    "input": [
      "84A51",
      "87DDA",
      "26CA7",
      "9D925",
      "08A23",
      "BE075",
      "3179A",
      "5D904",
      "54C70",
      "47790",
      "5D3B5",
      "0E4CE",
      "004C7",
      "EC8A8",
      "131A6",
      "7F47F",
      "41BC6",
      "FCF07",
      "D62BD",
      "DD14F",
      "6A141",
      "EE184",
      "595F8",
      "9D303",
      "BFD36"
    ],
    "output": "correcthorsebatterystaple"
  },
  {
    "input": [],
    "output": ""
  },
  {
    "input": [
      "4DC7C",
      "A84FD",
      "467D7",
      "BD79D",
      "12D83"
    ],
    "output": "rxrfa"
  },
  {
    "input": [
      "4DC7C",
      "A84FD",
      "467D7",
      "BD79D",
      "7B743"
    ],
    "output": "rxrpa"
  }
]
| |
\$\endgroup\$
  • \$\begingroup\$ I wonder whether MD5 might be preferred over SHA1 - as in, more likely to exist in the language without having to load external libraries? \$\endgroup\$ – streetster Jun 18 at 16:25
  • 1
    \$\begingroup\$ Languages without a hashing builtin or library would have effectively two challenges: implementing the hash and doing the key part of the challenge. There are already challenges for MD5, SHA-1, and SHA-256 e.g. codegolf.stackexchange.com/questions/81195/implement-sha-256. I see two resolutions to this: 1. not count byte count of the hash; or 2. use a simple hash, such as the digits after the decimal point in the square root of the sum of code points \$\endgroup\$ – fireflame241 Jun 18 at 22:19
  • \$\begingroup\$ You could allow a black-box function as input that computes the SHA256 hash to make this more competitive for languages without builtins. \$\endgroup\$ – S.S. Anne Jun 24 at 2:32
2
\$\begingroup\$

Posted at Baba if you, flag is win

| |
\$\endgroup\$
  • \$\begingroup\$ There are a lot of possible rules (I think a little less than 2^9, as for each X and Y either X is Y or X is not Y, and there are 3*3=9 (X, Y) choices). Is there any documentation on what's the behavior of each rule combination? // i.e., even in this simplified version there are still a lot of fuzzy details on how the rules behaves. \$\endgroup\$ – user202729 Jun 22 at 15:04
  • \$\begingroup\$ @user202729 , Thank you for your input. I’ll take out the clause about “no non-core packages” as suggested. In terms on the moves after win, I think the easiest thing will be to say that one can assume the input sequence to end on a winning move. If a longer sequence is given, that’s undefined behaviour and the program can do whatever. \$\endgroup\$ – MarcinKonowalczyk Jun 22 at 16:55
  • \$\begingroup\$ @user202729 Finally, I admit I'm not certain what is your source of confusion. The rules work just like in the main game (with the caveat of everything is stop), and I've specified a lot of tricky cases both in this post and in the accompanying GitHub repo. Arguably, the code on GitHub specifies the problem precisely (as it is an execution of it). I've also added test cases to allow one to check the behaviour. I'm not sure what else could I do? \$\endgroup\$ – MarcinKonowalczyk Jun 22 at 17:00
2
\$\begingroup\$

Logo Pack LAPACK (Posted)

| |
\$\endgroup\$
  • 2
    \$\begingroup\$ The default for kolmogorov-complexity is that the exact, constant string must be output, so I suggest no leading spaces allowed. Some languages can't output in certain forms (e.g. printing) without a trailing newline, so I'd say it's okay (instead of "print this logo", I'd suggest saying "output this logo exactly as the following string") \$\endgroup\$ – fireflame241 Jun 27 at 7:45
2
\$\begingroup\$

Posted: Laguerre Polynomials

| |
\$\endgroup\$
  • \$\begingroup\$ Do you mean \$L_n(x)\$ by y(x) (under The Challenge)? Also, the challenge and rules have a conflict (four or five decimal places?) \$\endgroup\$ – Bubbler Jul 9 at 23:56
  • \$\begingroup\$ hopefully it is clearer now @Bubbler \$\endgroup\$ – golf69 Jul 10 at 1:20
  • \$\begingroup\$ You realize that when x get huge, that means arbitrary-precision arithmetic?... perhaps require "4 decimal places for the provided examples" instead. \$\endgroup\$ – user202729 Jul 10 at 2:20
  • \$\begingroup\$ triangle of coefficients: oeis.org/A021010 \$\endgroup\$ – qwr Jul 10 at 3:54
2
\$\begingroup\$

Posted: The Cantor Function

| |
\$\endgroup\$
  • \$\begingroup\$ I think the definition of \$f_n\$ would be clearer if defined recursively like in the Wikipedia page section "Iterative construction". \$\endgroup\$ – xnor Jul 19 at 10:14
2
\$\begingroup\$

Posted: Verify a Superpermutation

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

Implement the Polygamma function

The Polygamma function of order \$m\$, \$\psi^{(m)}(z)\$, is the \$(m + 1)\$th derivative of the logarithm of the gamma function, which is also the \$m\$th derivative of the digamma function. Your task is to take an integer \$m\$ and a positive real number \$z\$ and output \$\psi^{(m)}(z)\$

Definitions

For those unfamiliar with the functions above (Gamma, Digamma and Polygamma), here are a few different definitions for each:

\$\Gamma(z)\$

  • The gamma function is an extension of the factorial (\$x! = 1\cdot2\cdot3\cdots(x-1)\cdot(x)\$) to real numbers
  • \$\Gamma(z) = \int_{0}^{\infty}x^{z-1}e^{-x}dx\$
  • \$\Gamma(n) = (n - 1)! \:,\:\: n \in \mathbb{N}\$
  • \$\Gamma(n+1) = n\Gamma(n) \:,\:\: n \in \mathbb{N}\$$

\$\psi(z)\$

  • The digamma function is the logarithmic derivative of the gamma function
  • \$\psi(z) = \frac{d}{dz}\ln(\Gamma(z))\$
  • \$\psi(z) = \frac{\Gamma'(z)}{\Gamma(z)}\$
  • \$\psi(z + 1) = \psi(z) + \frac{1}{z}\$

\$\psi^{(m)}(z)\$

  • The polygamma function of order \$m\$ is the \$m\$th derivative of the digamma function
  • \$\psi^{(m)}(z) = \frac{d^m}{dz^m}\psi(z)\$
  • \$\psi^{(m)}(z) = \frac{d^{m+1}}{dz^{m+1}}\ln(\Gamma(z))\$
  • \$\psi^{(m)}(z+1)= \psi^{(m)}(z) + (-1)^m\frac{m!}{z^{m+1}}\$

Task

You are to take two inputs, a natural number \$m\$ and a positive real number \$z\$, and output \$\psi^{(m)}(z)\$. The inputs and outputs will always fit within the number bounds of your language, but your algorithm must work theoretically for any and all inputs.

As the output is usually going to be a real number, rather than an integer, the output should show at least 5 decimal places. This may be optionally ignored if the output is an integer, but not if the decimal part of the output begins with .00000. For example, \$\psi^{(6)}(20) = -0.000002172607350\$, so an output of \$-0.00000\$ is acceptable, but \$0\$ is not. Note that the sign is required.

This is so the shortest code in bytes wins.

Test cases

Results may differ due to floating point inaccuracies, Python's scipy library was used to generate the values. Values are rounded to 15d.p., unless otherwise stated.

 m,                  z -> ψ⁽ᵐ⁾(z)
17,                  2 -> 1357763223.715975761413574
 5,                 40 -> 0.000000249389435
 9,           53.59375 -> 0.000000000012010
35,                  9 -> 469354.958166260155849
46,                  5 -> -7745723758939047727202304.000000000000000
 7, 1.2222222222222222 -> 1021.084176496877490
28,               6.25 -> -2567975.924144014250487
 2,               7.85 -> -0.018426049840992

This table has the values of \$\psi^{(m)}(z)\$ for \$0 \le m \le 9\$ and \$1 \le z \le 20\$:


+---+------------------------+---------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+
|   |           1            |          2          |         3          |         4          |         5          |         6          |         7          |         8          |         9          |         10         |         11         |         12         |         13         |         14         |         15         |         16         |         17         |         18         |         19         |         20         |
+---+------------------------+---------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+
| 0 |   -0.577215664901533   |  0.422784335098467  | 0.922784335098467  | 1.256117668431800  | 1.506117668431800  | 1.706117668431800  | 1.872784335098467  | 2.015641477955610  | 2.140641477955610  | 2.251752589066721  | 2.351752589066721  | 2.442661679975812  | 2.525995013309145  | 2.602918090232222  | 2.674346661660794  | 2.741013328327460  | 2.803513328327460  | 2.862336857739225  | 2.917892413294781  | 2.970523992242149  |
| 1 |   1.644934066848227    |  0.644934066848227  | 0.394934066848226  | 0.283822955737115  | 0.221322955737115  | 0.181322955737115  | 0.153545177959338  | 0.133137014694031  | 0.117512014694031  | 0.105166335681686  | 0.095166335681686  | 0.086901872871768  | 0.079957428427324  | 0.074040268664010  | 0.068938227847684  | 0.064493783403239  | 0.060587533403239  | 0.057127325790783  | 0.054040906037696  | 0.051270822935203  |
| 2 |   -2.404113806319188   |  -0.404113806319189 | -0.154113806319189 | -0.080039732245115 | -0.048789732245114 | -0.032789732245115 | -0.023530472985855 | -0.017699569195768 | -0.013793319195768 | -0.011049834970802 | -0.009049834970802 | -0.007547205368999 | -0.006389797961592 | -0.005479465690312 | -0.004750602716552 | -0.004158010123959 | -0.003669728873959 | -0.003262645625435 | -0.002919710097314 | -0.002628122402315 |
| 3 |   6.493939402266829    |  0.493939402266829  | 0.118939402266829  | 0.044865328192755  | 0.021427828192755  | 0.011827828192755  | 0.007198198563125  | 0.004699239795945  | 0.003234396045945  | 0.002319901304290  | 0.001719901304290  | 0.001310093231071  | 0.001020741379219  | 0.000810664701232  | 0.000654479778283  | 0.000535961259764  | 0.000444408525389  | 0.000372570305061  | 0.000315414383708  | 0.000269374221340  |
| 4 |  -24.886266123440890   |  -0.886266123440879 | -0.136266123440878 | -0.037500691342113 | -0.014063191342113 | -0.006383191342113 | -0.003296771589026 | -0.001868795150638 | -0.001136373275638 | -0.000729931168235 | -0.000489931168235 | -0.000340910050701 | -0.000244459433417 | -0.000179820455575 | -0.000135196191875 | -0.000103591253604 | -0.000080703070010 | -0.000063799959344 | -0.000051098643488 | -0.000041405977726 |
| 5 |  122.081167438133861   |  2.081167438133896  | 0.206167438133897  | 0.041558384635954  | 0.012261509635954  | 0.004581509635954  | 0.002009493175049  | 0.000989510004771  | 0.000531746332896  | 0.000305945162117  | 0.000185945162117  | 0.000118208290511  | 0.000078020533309  | 0.000053159387985  | 0.000037222150950  | 0.000026687171526  | 0.000019534614153  | 0.000014563111016  | 0.000011034967722  | 0.000008484266206  |
| 6 |  -726.011479714984489  |  -6.011479714984437 | -0.386479714984435 | -0.057261607988551 | -0.013316295488551 | -0.004100295488551 | -0.001528279027645 | -0.000654007738836 | -0.000310684984930 | -0.000160150871077 | -0.000088150871077 | -0.000051203486564 | -0.000031109607963 | -0.000019635233198 | -0.000012804988755 | -0.000008590996985 | -0.000005908787970 | -0.000004154139804 | -0.000002978092040 | -0.000002172607350 |
| 7 |  5060.549875237640663  |  20.549875237639476 | 0.862375237639470  | 0.094199654649073  | 0.017295357774073  | 0.004392957774073  | 0.001392271903016  | 0.000518000614207  | 0.000217593204539  | 0.000100511115987  | 0.000050111115987  | 0.000026599144024  | 0.000014877714841  | 0.000008699205352  | 0.000005284083130  | 0.000003317553637  | 0.000002144087193  | 0.000001421585007  | 0.000000964233099  | 0.000000667475582  |
| 8 | -40400.978398747647589 | -80.978398747634884 | -2.228398747634885 | -0.179930526327158 | -0.026121932577158 | -0.005478092577158 | -0.001477178082416 | -0.000478010895205 | -0.000177603485537 | -0.000073530517936 | -0.000033210517936 | -0.000016110901963 | -0.000008296615840 | -0.000004494456155 | -0.000002542957742 | -0.000001494142013 | -0.000000907408791 | -0.000000567407762 | -0.000000364140247 | -0.000000239189714 |
| 9 | 363240.911422382690944 | 360.911422382626938 | 6.536422382626807  | 0.391017718703625  | 0.044948382766125  | 0.007789470766125  | 0.001788099024012  | 0.000503455497598  | 0.000165497161722  | 0.000061424194120  | 0.000025136194120  | 0.000011145599233  | 0.000005284884641  | 0.000002652620244  | 0.000001398085550  | 0.000000768796112  | 0.000000438758675  | 0.000000258758130  | 0.000000157124373  | 0.000000097937278  |
+---+------------------------+---------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+
| |
\$\endgroup\$
  • \$\begingroup\$ Mathematica: PolyGamma. \$\endgroup\$ – my pronoun is monicareinstate Jul 27 at 3:37
  • \$\begingroup\$ Looks good, except that I have no idea where to start. \$\endgroup\$ – Bubbler Jul 31 at 1:00
2
\$\begingroup\$

Play a Game of Minigolf

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

Convert LifeOnTheEdge to LifeOnTheSlope

Your task here is to take a LifeOnTheEdge pattern and convert it to LifeOnTheSlope.

A LifeOnTheEdge pattern is composed of these four characters: |_L . A pattern corresponds to a certain arrangement of "on" edges in a square grid. The pattern is placed in the grid first with the characters in the cells, and each of the four letters specifies the state of the edges on the left and the bottom of that cell. | means the edge on the left is on, _ means the bottom edge is on, L means both of them are on and means neither of them are on.

For example the following LifeOnTheEdge:

|_L
 |

translates to:

. . . . .
|   |
. ._._. .
  |
. . . . .

Your task is however convert it to LifeOnTheSlope. LifeOnTheSlope is a LifeOnTheEdge equivalent but only uses three symbols: /\ . You should rotate the pattern 45-degree clockwise, for example the above example translates to:

/

/\/
  \

Sandbox

I'm not sure if I described the problem clearly. Improvements on the wording and other things?

| |
\$\endgroup\$
  • \$\begingroup\$ Nice challenge! The task is clear, I just think you may specify if and how leading/trailing newlines/spaces are allowed, for example in the example there may be a trailing space. And also.. Are the set of characters strictly fixed? People usually ask for free sets, for example some values [1,2,3,0] instead of |_L but since this is ascii-art I think it's fine to have a fixed set. Let's see if anyone else has any opinion. \$\endgroup\$ – AZTECCO Aug 2 at 12:35
  • \$\begingroup\$ @AZTECCO For the second question I'm fine with both options. This convertion is a thing that annoys me in my CA exploration. \$\endgroup\$ – HighlyRadioactive Aug 2 at 12:38
2
\$\begingroup\$

The Turing Text Tape

Introduction

Ah, INTERCAL...
As much as I'd like encourage everyone to Try it Online sometime, text output is just painful.
According to the docs it uses the "Turing Text Model". While an... interesting concept, using it is about as much fun as shooting yourself in the foot. And what do we do with a task like this? Automate it.

The Turing Text Model

The characters INTERCAL knows are printed on a circular tape that can only be moved in the positive direction. Printing is done by passing tape head movement commands in an array to the READ OUT statement. Every ASCII character is written on the inside of that tape (The outside has the characters for the input on it, duh). This results in the characters' bytes being on the tape in reverse. Also the tape head moves backwards along the character list, because its positioning is based on the outside of the tape.
The head starts at position 0.

Now the magic starts. I'll be using Truttle1's explanation on how to achieve output.

  1. Set up an array with the output length.
  2. Fill the entries in the array with tape head movement values.
    1. Find the current character's ASCII value in binary
    2. Reverse it and convert back a number n.
    3. Subtract n from the current head postion and modulo by 256 if needed, resulting in a value r
    4. r is the value you need to store in the array
    5. The head is now at position n.
  3. DO READ OUT the array.

PLEASE NOTE

  • Array is pre-initialized with 0, first index is 1
  • INTERCAL uses extended 8-bit ASCII characters, hence the tape length of 256.
  • Between 1/3rd and 1/5th of all lines have to start with PLEASE

Challenge

Given an input string, output a valid INTERCAL program that prints that string and terminates.

Examples

Prints "BUZZ"

DO ,1 <- #4
DO ,1 SUB #1 <- #190
DO ,1 SUB #2 <- #152
DO ,1 SUB #3 <- #336
PLEASE READ OUT ,1
PLEASE GIVE UP

Whitespace is optional. The following prints "FIZZ"

DO,1<-#4DO,1SUB#1<-#158DO,1SUB#2<-#208DO,1SUB#3<-#312PLEASEREADOUT,1PLEASEGIVEUP

(Examples shamelessly stolen from Truttle1's FizzBuzz program from the video.)

You can find an ungolfed reference implementation in python 3 here

Rules

  • No standard loopholes
  • This is , shortest code wins.
  • You can expect input >= 1, ASCII characters only
  • Output optimisation is optional.
  • The program may not throw any errors apart from the RANDOM COMPILER BUG
  • You may not use compiler flags, e.g. to turn off politeness checking

Sandbox stuff

This better not be a duplicate. I didn't find anything though, so it shouldn't be.

  • Is there anything that can be worded better?
  • Are there some edge-cases that need an example?
  • Should I add any rules; if so, which?
| |
\$\endgroup\$
1
22 23
24
25 26
98

You must log in to answer this question.

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