464
\$\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\$
  • \$\begingroup\$ How are tags added to questions? \$\endgroup\$ – guest271314 Jan 9 '19 at 7:51
  • \$\begingroup\$ @guest271314 You can use this markup to create a tag in a draft: [tag:code-golf] \$\endgroup\$ – DJMcMayhem Aug 29 '19 at 15:19
  • \$\begingroup\$ Why no featured anymore? Can't we have it auto-added or something? \$\endgroup\$ – S.S. Anne Sep 26 '19 at 15:57
  • 1
    \$\begingroup\$ @JL2210 We now have a permanent info box that links to the Sandbox, so the featured tag isn't necessary \$\endgroup\$ – caird coinheringaahing Sep 29 '19 at 13:43

2665 Answers 2665

-1
\$\begingroup\$

A Quine that Grows!

Challenge

Create a quine that, when run, outputs itself but copied larger in the next one. The output should be able to be run, and get larger each time the output is run. The output must consist only of characters from the original quine!

EX:

abc //original
abcabc //output

or

abc //original
aabcc //output

What not to do

abc //original
abcgef //output

abc //original
abcoooooooooooo //output

An example I created

Try it Online! It replicates pretty fast if I do say so myself!

Points

This challenge is meant to be a codegolf, but also emphasize on how fast it replicates. So perhaps something like the speed at which it gets bigger divided by the number of bytes.

I really don't want loopholes like just repetitively adding characters to a section of the code, making infinite loops, and things of the like.

Any input on how to make this a good challenge? I'm open to suggestions!!!

\$\endgroup\$
  • 1
    \$\begingroup\$ Related, related (probably a dupe) \$\endgroup\$ – Jo King Feb 10 '19 at 10:25
  • \$\begingroup\$ @JoKing What about a polyglot that gets bigger? It runs, making another program that runs and outputs a bigger version of the original, and vice versa. \$\endgroup\$ – KrystosTheOverlord Feb 10 '19 at 16:02
  • \$\begingroup\$ where's the polyglot part come from? otherwise that sounds like the second one \$\endgroup\$ – Jo King Feb 10 '19 at 22:04
  • \$\begingroup\$ @JoKing The output has to be in a different programming language, and then create a larger version of the original, then this larger original makes a larger of second program etc... Also to prevent easy loopholes, no using program languages that are derivatives of eachother \$\endgroup\$ – KrystosTheOverlord Feb 10 '19 at 22:32
-1
\$\begingroup\$

Just idea. Not sure what to do exactly.

Evolutionary Golf

Make simple (not golfed at all at first) code for (some program) with language (something).

Now, change a little bit (maximum 3 byte) of code to make it shorter.

Altered code must work properly (this is how evolution work).

(Maybe here will be starting code).

Sandbox

First. What program would be best? For example, 'Hello World' program is not proper, because it is too short, and can't golf that much.

Second. What language would be best? Esolang like BF? Or something like C?

\$\endgroup\$
  • \$\begingroup\$ If I understand the challenge idea correctly you will post an ungolfed answer that does something in some (probably verbose) language (i.e. FizzBuzz in C#). And then answers after that should have a Levensteihn distance change \$c\$ where \$1\leq c\leq3\$ (at least 1 delete) that does the same thing (in any language). And the shortest answer that's at the end of the answer chain wins if no other answers are posted within 2-3 weeks (which is usually the case with answer-chaining challenges)? Or do you mean that anyone can post an ungolfed program, and others using the same language chain it? \$\endgroup\$ – Kevin Cruijssen Jun 26 '19 at 9:04
  • \$\begingroup\$ @KevinCruijssen I'm thinking of both. This is just brief outline, so everything can be changed. \$\endgroup\$ – LegenDUST Jun 26 '19 at 12:10
  • \$\begingroup\$ this is just game of nim with extra steps \$\endgroup\$ – Kenneth Taylor Aug 2 '19 at 17:51
-1
\$\begingroup\$

Print all the commands

META Just a rought idea, needs to be worked out.

Write a program that prints all the keywords and commands that are available in your langauge when you do not import/add anything

Details

  • require full program or standard code-golf?
\$\endgroup\$
  • 2
    \$\begingroup\$ Understanding that this is a rough idea, what happens in languages without commands corresponding to single tokens e.g. ///? \$\endgroup\$ – lirtosiast Jul 18 '19 at 15:49
  • 7
    \$\begingroup\$ It is my opinion that this sort of challenge will likely never be clear. \$\endgroup\$ – Post Rock Garf Hunter Jul 18 '19 at 16:08
  • \$\begingroup\$ I'd imagine for /// you'd output all valid non-text characters, so \ /. \$\endgroup\$ – bigyihsuan Jul 18 '19 at 17:08
  • 1
    \$\begingroup\$ Another thing is that language version would be specified. For example, Python 2 has print as a keyword, while Python 3 has print() instead. \$\endgroup\$ – bigyihsuan Jul 18 '19 at 17:10
  • \$\begingroup\$ Pretty sure this (or something similar enough to be a dupe) has been done before. Lemme see if I can find it .... \$\endgroup\$ – Shaggy Jul 21 '19 at 21:11
  • \$\begingroup\$ Found it! codegolf.stackexchange.com/q/162384/58974 \$\endgroup\$ – Shaggy Jul 21 '19 at 21:13
  • \$\begingroup\$ One way to do this might be to make it language specific? While that isn't usually popular, outputting all of, say, Python's commands in most languages besides python is a dupe of the Rickroll challenge. However, in python itself that isn't the best approach. I can't say how well reveived it'd be, but you could try "output these MATLAB commands in MATLAB" and see what people think. \$\endgroup\$ – FryAmTheEggman Jul 23 '19 at 19:45
-1
\$\begingroup\$

Here's a challenge I'd like post because I'm curious to see what people will come up with. It's a bit of an anti-code-golf question because the code should look normal.

Is it clear what the constraints? Did I miss anything?


Introduction

Write a piece of unsuspicious code that does the following:

Let's say you've written a parser that parses it's input line by line and somewhere in your code is

find_string(line, "[start]", "[end]") // returns string between [start] and [end]

This program, when given it's own source code plain text as input, will match that line (twice actually); but we don't want that. It should still parse what it was designed for but not match any line of it's own source code.

Rules

  • It's preferred that your code makes it obvious that one of it's intended uses is to parse (and not match) itself. This is so anyone 'refactoring' the code will not accidentally undo the trick that made it work.
  • Your source code as input will be reduced to a single line.
  • Your program should be able to handle large input (~10mb) and perform reasonably (for your chosen language).
  • Your program does not need to parse the input line by line but that just seems like something reasonable code would do.
  • Points are awarded for code that looks like a normal parser and contains as little assumptions about the input as possible. Bonus points for solutions that contain the start and end delimiters in that order.

Easy solutions are to swap the start and end token arguments or to pre-treat the tokens in some way but that would look suspicious. Someone will come along and refactor your code and break the 'trick'.

I'm interested in reasonable solutions because this is a reduction of a real life problem.

Example Input and Output

  • Input lines may or may not contain [start] or [end], only return it in the output when it occurs in a pair.
  • Input lines will never contain more than one pair of [start] and [end] tokens.
  • Input lines may contain additional content before [start] or after [end]
  • Your source code plain text will be inserted at a random line in the input.

Input #1:

[start]hello[end]
<<your source code plain text>>
dont output this[start]world[end]

Output #1:

hello world

Input #2:

lorem[start]i solemnly[end]
[start]false start
[start]swear[end]
ope, sorry just passing through
this is not the[end]
[start]that i'm up to[end]ipsum
[start]no[end]dolor
<<your source code plain text>>
[start]good[end]

Output #2:

i solemnly swear that i'm up to no good
\$\endgroup\$
  • \$\begingroup\$ What is the objective winning criterion? \$\endgroup\$ – Unrelated String Aug 9 '19 at 5:16
  • 1
    \$\begingroup\$ This could be a good challenge if it was just 'Write a program that takes a line of input and returns the concatenation of anything between [start] and [end] on each line, otherwise an empty string', with the restriction that if it was fed itself, it wouldn't return anything \$\endgroup\$ – Jo King Aug 9 '19 at 6:05
  • \$\begingroup\$ I'm a little confused about what Bonus points for solutions that contain the start and end delimiters in that order. means, since I thought the point was that we're not allowed to have that? \$\endgroup\$ – Jo King Aug 9 '19 at 6:07
  • 2
    \$\begingroup\$ "unsuspicious code" will raise red flags in the minds of a number of old-timers, for historical reasons which I won't explain in detail. What I will say is that unsuspicious is subjective, and we insist on objective criteria. In terms of actual reasonable solutions to the real world problem: don't use magic strings. If "[start]" and "[end]" are both constants and defined on separate lines, the problem is averted, and anyone who refactors to inline them deserves all the bugs that causes. \$\endgroup\$ – Peter Taylor Aug 9 '19 at 10:45
-1
\$\begingroup\$

Make it improbable... BUT NOT IMPOSSIBLE

You must make a program that outputs truly once in a while. However, making it have output falsy all the time is not acceptable.

Rules

  • Standard loopholes are forbidden.
  • You may use any of accepted I/O formats.
  • Your program must be possible to output a truly value.
  • When not outputting a truly value, you may either output a falsy value or not output anything at all.
  • You may output two or more values, however if it contains a truly value, then the output is considered truly.
  • The probability of outputting a truly value must be at most 1/2.
  • Your program must not take/use an input.
  • Using non-deterministic but non-random(Such as getting the time) is prohibited. However, if date etc. is used in the builtin random function, it is allowed.
  • The program must theoretically always terminate or stop outputting anything.
  • You may assume that you have a fast enough computer and large enough memory.
  • Your program should not be affected by raising the maximum value of a data type. You may still use unaffected constants.
  • Data types must be following its spec: ie. for an unbounded arbituary precision integer type, you may assume that it can go as high as you want(but you are not allowed to increment until an error as in the rule above), but a double-precision floating-point format still has 22-bit fraction and 8-bit exponent.
  • Score is calculated as: Pl-1.5l, where P is the probability and l is the byte length.

Example(s)

JavaScript
alert(Math.random()<0.1)
P=0.1, l=24 => Score=23.534

The lowest score wins!

\$\endgroup\$
  • \$\begingroup\$ So is it acceptable for just a program that always outputs truly? You need to define improbable. (I assume this probability must be at least lest than 1/2.) Providing a few examples will be helpful. So is there only output and no input? In addition, you need an objective winning criterion, which is a criterion that posts for this challenge will need to comply in order for it to be a valid answer. (Usually this criterion is making the source code shortest.) \$\endgroup\$ – a'_' Sep 24 '19 at 13:37
  • \$\begingroup\$ Sorry, I posted this incomplete. \$\endgroup\$ – Naruyoko Sep 24 '19 at 16:14
  • \$\begingroup\$ I don't think your scoring method works particularly well, unless I'm making an error. For any \$ l > 1 \$ your score cannot be less than 1. Achieving a score arbitrarily close to 1 is relatively easy. So the only way to beat that is to have a one or zero byte solution. It is easy to make the probability increase exponentially with linear code additions. It might be necessary to penalise length massively, like \$ P \times e^{l!} \$, to avoid similar problems. \$\endgroup\$ – FryAmTheEggman Sep 24 '19 at 18:39
  • \$\begingroup\$ I see. I guess P^l^k is too penalizing but Pk or Pe^k is too forgiving. Pe^l! looks simple enough but is is the middle so it may work. \$\endgroup\$ – Naruyoko Sep 24 '19 at 20:11
  • 1
    \$\begingroup\$ The problem with any of scoring methods for this challenge is that it is possible for any increasing computable function f, a program with length l can have P around 1/f(l). The only non-broken formula could be uncomputable, i.e. P/BB(l), where BB is the busy beaver function. \$\endgroup\$ – Naruyoko Sep 24 '19 at 20:15
-1
\$\begingroup\$

Title: Transposition

** The challenge **

Given a set of notes (as a string, or a list, or any other reasonable input - but as letters and accidentals, not a numerical equivalent), the key those notes are in, and a target key; output the notes transposed into the new key. Some of the notes may not exist in the scale for the given key (e.g Eb in the key of C).

** Inputs **

The complete set of input notes for this challenge will use the English naming convention, and so are as follows:

Ab,G##,A,A#,Bb,B,C,C#,Db,C##,D,D#,Eb,E,F,F#,Gb,F##,G,G#

where "b" represents a flattened note (down one semitone per b), and # represents a sharpened note (up one semitone per #). Theoretically all notes can be extended further with more #s and bs; but for the purposes of this program that won't happen beyond what is already given.

** What is transposing? **

Transposing a song involves "moving" the song into a different key, by finding the equivalent note of the scale in that key.

We will assume Major scales for the purposes of this challenge.

** Scales **

The scales for this challenge are officially as follows:

  • C: C, D, E, F, G, A, B, C
  • C#: C#, D#, E#, F#, G#, A#, B#, C#
  • Db: Db, Eb, F, Gb, Ab, Bb, C, Db
  • D: D, E, F#, G, A, B, C#, D
  • D#: D#, E#, F##, G#, A#, B#, C##, D#
  • Eb:Eb, F, G, Ab, Bb, C, D, Eb
  • E: E, F#, G#, A, B, C#, D#, E
  • F: F, G, A, Bb, C, D, E, F
  • F#: F#, G#, A#, B, C#, D#, E#, F#
  • Gb: Gb, Ab, Bb, Cb, Db, Eb, F, Gb
  • G: G, A, B, C, D, E, F#, G
  • G#: G#, A#, B#, C#, D#, E#, F##, G#
  • Ab: Ab, Bb, C, Db, Eb, F, G, Ab
  • A: A, B, C#, D, E, F#, G#, A
  • A#: A#, B#, C##, D#, E#, F##, G##, A#
  • Bb: Bb, C, D, Eb, F, G, A, Bb
  • B: B, C#, D#, E, F#, G#, A#, B

For simplicity, we can assume that both notes in the pairs A#/Bb, C#/Db, D#/Eb, F#/Gb, G#/Ab, C##/D, F##/G, G##/A are enharmonically equivalent (i.e. interchangeable - although they're not, always).

For scales with double-sharps, I will accept the enharmonic equivalents as an alternative implementation:

  • D#: D#, E#, G, G#, A#, B#, D, D#
  • G#: G#, A#, B#, C#, D#, E#, G, G#
  • A#: A#, B#, D, D#, E#, G, A, A#

but for all other notes in the scale, they must match. If the note isn't in the scale, either can be used.

e.g.

  • F in the key of C should transpose to F# in the key of C#, and not to Gb, because that option in the pair is explicitly in the scale
  • but D in the key of C# could transpose to either C# or Db in the key of C, because it's an incidental anyway and so there's no easy rule to determine which it should be.

BONUS feel-good points *: normally it's # if you're going up, and a b if you're going down - feel free to implement this if you want!

For double-sharps (e.g F##) in all cases, It's OK if the program "resolves" these (e.g.to G in that case) even if they are in the scale; but again, some BONUS feel-good points * if you keep the double-sharps in.

Examples

  • CDEFGABC in C to A -> ABC#DEF#G#A
  • C# in C to A -> A# OR Bb
  • ABCDEFGBAF#Bb in Bb to Gb -> FGAbBbCDbEbGFDGb
  • CCGGAAAAGFFEEDDCGGGFFEEEDCGGGFFFFEEED in C to G# -> G#G#D#D#E#E#E#E#D#C#C#B#B#A#A#G#D#D#D#C#C#B#B#B#A#G#D#D#D#C#C#C#C#B#B#B#A#

Websites like http://www.logue.net/xp/ can be used to test your answers to other inputs

* Bonus feel-good points don't get you anything extra, unless someone can come up with a quantifiable difference that it should make to the score?

\$\endgroup\$
  • \$\begingroup\$ This is kind of similar but doesn't use scales and has a different set of chords, so I think this is effectively different? \$\endgroup\$ – FryAmTheEggman Sep 24 '19 at 18:47
  • \$\begingroup\$ Yes, I agree it's similar but doing a different thing to me (they're using chords, and so have the extra text to worry about; but I'm doing notes, like sheet music; and so you have accidentals to worry about) \$\endgroup\$ – simonalexander2005 Sep 25 '19 at 8:48
-1
\$\begingroup\$

Interpret Unneccesary (Not quite)

Unneccesary is a joke language created by Keymaker. The source is unneccesary, and if given, it will error out.

Your task here is similar. If there is input, your program should error out. If the input is empty, your program should do nothing and terminate.

\$\endgroup\$
  • 1
    \$\begingroup\$ What does it mean to error out? \$\endgroup\$ – Beefster Oct 24 '19 at 19:14
  • \$\begingroup\$ @Beefster throw a runtime error... Or? \$\endgroup\$ – HighlyRadioactive Dec 1 '19 at 10:15
  • \$\begingroup\$ What if I'm using a language that does not have terminal errors such as Bash? \$\endgroup\$ – Beefster Dec 2 '19 at 19:34
  • \$\begingroup\$ @Beefster Are there any specifications for, something like error quine? \$\endgroup\$ – HighlyRadioactive Dec 21 '19 at 10:54
-1
\$\begingroup\$

Mirror, Mirror, on the wall. Who's the fairest of them all?

Well, you know it's Snow White, and the evil Queen is at it again. Will Snow White be saved? Will she fall asleep once again? Will the Prince find her?

Challenge:

Given an arbitrary number (>= 2) of possibly duplicated hexadecimal color values (ranging from #000000 to #FFFFFF) and paired strings, calculate the following:

  • If #FF0800 (Candy apple red) appears in the input, return "Return to Sleeping Death"
  • If #000000 appears in the input, return "Saved by Grumpy"
  • If #A98AC7 or #111111 appears in the input, return "Saved by Happy"
  • If #21E88E or #222222 appears in the input, return "Saved by Sleepy"
  • If #32DCD5 or #333333 appears in the input, return "Saved by Bashful"
  • If #43D11C or #444444 appears in the input, return "Saved by Sneezy"
  • If #54C563 or #555555 appears in the input, return "Saved by Dopey"
  • If #65B9AA or #666666 appears in the input, return "Saved by Doc"
  • If #76ADF1 or #777777 appears in the input, return "Saved by the Seven Dwarfs"
  • If #FFFAFA (Snow) appears in the input, return "Saved by Love's first kiss"
  • If an F variant appears in the input, return "Press F to pay respects to Snow White"
    • An F variant is any number that contains at least one F in its hexadecimal form, and is otherwise all 0s (e.g. #0FF0F0, #FFFFFF, #00000F, #F00F00)
  • If multiple of the preceding occur, return the "fairest" answer. The "fairest" answer is calculated as follows:
    • For all N occurrences of special color values, choose the (N-1)/2-th (truncating division) occurrence. The associated special output is the "fairest" answer.

"Appears in the input" here refers to only the hexadecimal color values, and not to the paired strings.

  • If none of the preceding occur, return the "fairest" answer. The "fairest" answer is calculated as follows:
    • Take the hexadecimal color value at the end of input values, write it down, and exclude that single color-string pair from consideration as the "fairest" answer
    • Show its binary form to the mirror, computing a reflection of only the last 24 (#FFFFFF is the mask) bits.
    • Choose the hexadecimal color with least Hamming distance from the reflection. If there are multiple (N) such colors, choose the middle ((N-1)/2-th, truncating division) instance of the color. The "fairest" answer is the associated string for the color.

Inputs:

A sequence of hexadecimal color values and String values separated by a space. The input may also be read as two separate sequences of hexadecimal color values and String values, or a single sequence of 2-tuples (either (hexValue, stringValue) or (stringValue, hexValue) is permissible, as long as the ordering is consistent across all 2-tuples). Input order matters - for each index, the corresponding element in the supply of color values is "associated" with the corresponding element in the supply of String values, and duplicates can affect the "fairest" answer. The effect is something like Function(List(HexColorValue),List(AssociatedStrings)) -> "fairest" answer. Hexadecimal color values may be represented as either (your choice of) a String "#"+6 digits, or 6 digits alone, as long as the representation is consistent across all color values.

Here's an example input:

76ADF1 Return to Sleeping Death
2FE84E Return whence ye came!

Here's another example input:

2FE84E Return to Sender
4FFAFC Return of the Obra Dinn
2FE84E Return to the house immediately, young lady!
2FE84E Return to Sleeping Death
2FE84E Return of the Jedi

Here's the third example input:

2FE84E Return to Sender
4FFAFC Return of the Obra Dinn
2FE84E Return to the house immediately, young lady!
2FE84E Return to Sleeping Death
7217F8 Return of the King

Here's the final sample input:

F4A52F Eating hearts and livers
F4A52F Eating apples
F4A52F Eating porridge
F4A52F Eating candy houses
F4A52F A Modest Proposal

Outputs:

The "fairest" answer as computed by the specified logic. For example, on the first sample input, the "fairest" answer would be Saved by the Seven Dwarfs, due to the special hex color 76ADF1 appearing within the input.

In the second sample, there are no special inputs. First, we take "2FE84E Return of the Jedi", which has value #2FE84E. In binary, this is:

001011111110100001001110

We take the reflection from the mirror, getting:

011100100001011111110100

We compare it against 2FE84E (001011111110100001001110) and 4FFAFC (010011111111101011111100), which have Hamming distances of 18 and 12 from the reflection, respectively. Since #4FFAFC has the uniquely lowest Hamming distance from the reflection, the "fairest" answer is Return of the Obra Dinn.

In the third sample input, there are no special inputs. First, we take "7217F8 Return of the King", which has value #7217F8. In binary, this is:

011100100001011111111000

We take the reflection from the mirror, getting:

000111111110100001001110

We compare it against 2FE84E (001011111110100001001110) and 4FFAFC (010011111111101011111100), which have Hamming distances of 2 and 8 from the reflection, respectively. All 3 instances of hexadecimal color value #2FE84E have minimum Hamming distance from the reflection, so we take the (3-1)/2=1th instance (0-indexed) of #2FE84E. Therefore, the "fairest" answer is Return to the house immediately, young lady!.

In the last sample input, there are no special inputs. First, we take "F4A52F A Modest Proposal", which has value #F4A52F. In binary, this is:

1111010011001100101111

We take the reflection from the mirror, getting:

1111010011001100101111

We compare it against F4A52F (1111010011001100101111), which has Hamming distance 0 from the reflection. All instances of hexadecimal color value #F4A52F have minimum Hamming distance from the reflection. There are FOUR instances of #F4A52F, because we always exclude the last hexadecimal color instance from evaluation. Therefore, we take the (4-1)/2=1th instance (0-indexed) of #F4A52F, and the "fairest" answer is Eating apples. If you don't exclude the last value from consideration, you actually get the (5-1)/2=2th instance of #F4A52F (Eating porridge), which is wrong.

Rules:

  • No standard loopholes
  • Input/output taken via standard input/output methods.
  • The output must be exactly equal to the "fairest" answer

Scoring:

This is code golf, so shortest program wins.

Posted~ you can see it here

\$\endgroup\$
  • \$\begingroup\$ Going to need tag suggestions :) \$\endgroup\$ – Avi Sep 30 '19 at 20:57
  • \$\begingroup\$ Can each entry be taken as a tuple, i.e. ("#FFFFFF","Return the Slab")? Can the label part also have a hex number in it or are we guaranteed it wont? Rules has the # but the examples do not, is either form fine? Can we get a worked example of a list containing multiple matching entries? \$\endgroup\$ – Veskah Oct 1 '19 at 12:33
  • \$\begingroup\$ @Veskah You can take tuples as input. You can choose whether to keep # in your input hex colors or not, as long as you keep it the same for every single input (no sneaky stuff like putting a # before the correct answer every time). I've added more sample inputs/outputs with explanation. \$\endgroup\$ – Avi Oct 1 '19 at 14:28
  • \$\begingroup\$ -1: This has way too many hardcoded input/output mappings. This challenge is more about encoding those than solving a problem. \$\endgroup\$ – Beefster Oct 24 '19 at 19:10
-1
\$\begingroup\$

CMC: Cross-Multiplication Calculator

In this task you should create a Cross-Multiplication Calculator.


Cross-multiplication is a way of factoring an algebraic expression. This is the expression form that this way can solve:

$$x^2 + ax + b$$

\$a\$ and \$b\$ are constants here, and \$x\$ is a variable.

Anyway, as far as I can tell, this expression form is only solvable in this method.

Anyway, how do I do Cross-Multiplication? (TODO)

You first take the number \$b\$ and factor this number into integral factors.

Okay. We are using the expression \$x^2 + 8x + 16\$ as an example.

(Although 16 is not a prime) let us assume that 16 only has 2 possible factors:

  • \$-1 \times -16\$ (because \$-x \times -x = x^2\$)
  • \$1 \times 16\$ (Obviously this is 16)
  • And the above 2 with the factors reversed.

Now you sum these possible two factors and check this against the number \$a\$.

  • Check 1. So \$-1 + (-16) = -17\$. And unfortunately -17 is not 8, we proceed to the next check.
  • Check 2. So \$1 + 16 = 17\$. And unfortunately 17 is not 8, we proceed to the next check. There are no checks left.

Did I make a mistake? Of course, I need to change the factors.

  • \$-2 \times -8\$ (because \$-x \times -x = x^2\$)
  • \$2 \times 8\$ (Obviously this is 16)
  • And the above 2 with the factors reversed.

We sum those values, and they are -10 and 10 respectively. So I should change the factors to another value:

  • \$-4 \times -4\$ (because \$-x \times -x = x\$)
  • \$4 \times 4\$ (Obviously this is 16)
  • And the above 2 with the factors reversed.

Finally! \$4+4 = 8\$, and here is the factorization:

$$(x+4)(x+4)$$

Now you will probably realize why I desperately need a program to automate this.

Test cases

You can assume that the input is always valid. You do not have to specify the variables, only the numbers. Therefore the expression

$$x^2 + ax + b$$

is converted into:

$$+a \, +b$$

The expected output is not:

$$(x+\alpha)(x+\beta)$$

but:

$$+\alpha \, +\beta$$

a, b => α, β
8, 16 => 4, 4
-5, -24 => 3, -8

Scoring

This is , so shortest answer in bytes wins.

Meta

  • Is this clear enough?
  • I haven't found a duplicate, but anything? (Although unlikely, I found nothing by searching "Cross Multiplication".)
  • Tags are code-golf, string and interpreter. Anything else?
  • Any further feedback?
\$\endgroup\$
  • 1
    \$\begingroup\$ I've edited your post to use MathJax for the mathematical formula/workings. In addition, I've edited out the rather strict input/output format (leading + etc.) as it's generally recommended to allow the most natural output format. Feel free to revert these changes if you dislike them. Also, your tags bullet point in the Meta section appears to be different to the tags in the title? \$\endgroup\$ – caird coinheringaahing Oct 21 '19 at 17:48
  • \$\begingroup\$ Finally, I'd vote to close this as a duplicate of this or this challenge (as it is a subset of both) \$\endgroup\$ – caird coinheringaahing Oct 21 '19 at 17:51
-1
\$\begingroup\$

Parse a regex

Grep is a wonderful tool. It can find stuff in files, it can help you spell stuff correctly (grep 'whatever' /usr/share/dict/words or wherever that file is), and it can even test if something is a prime number!

However, the first version was implemented back in the golden age, when FORTRAN was respected, Pascal was the language for beginners, and object orientation was just starting out in on its great adventure.

One could argue that modern developers have nowhere near that much talent or skill, what with their flashy "IDEs" and "frameworks". If they would be asked to implement something similar, they would just jump at the nearest library or cloud thingimabob and say "Done!".

At least, that is what some would say.

Prove them wrong! Golf grep!

Parse a regular expression without calling any built-in functions or operators explicitly meant for this.

input:

Basically the same as a simple grep: a regular expression as a command line parameter, followed by an optional filename or a dash. If the filename is not present, or it is a dash, read for stdin.

This is the recommended way to do it, but if you can write an adapter (eg: post stuff to a php form for your program via a shell script), then that is OK as well. The adapter does not contribute to your score.

output

Lines that match the regular expression.

Notes:

The regex dialect is PCRE (perl compatible). Files use unix line terminators if it is relevant.

\$\endgroup\$
  • \$\begingroup\$ Closely related, but not quite a duplicate. \$\endgroup\$ – AdmBorkBork Nov 18 '19 at 20:42
  • \$\begingroup\$ Why the downvote? \$\endgroup\$ – Mark Gardner Nov 20 '19 at 8:16
  • \$\begingroup\$ You've likely been downvoted because you "ban built-in functions or operations explicitly meant for this." Consider this post for a lengthy discussion of why this has fallen out of favour. Beyond this being trivial besides parsing regular expressions, it also doesn't actually describe what a regex is or what it means to be PCRE. Challenges need to be self contained! I think your bet is to make a different matching language yourself and ask us to implement grep but with that language instead of regex. \$\endgroup\$ – FryAmTheEggman Nov 20 '19 at 19:09
-1
\$\begingroup\$

Predict the state of a Minecraft inventory after click events

Minecraft does inventory management over the network by sending packets describing the clicks that a player does. If you're caching these events, it can be non-trivial to predict what state the inventory is in after the clicks

Challenge

Take an inventory of 9 slots, each with an item and a type. Assume all items can stack up to 64 and that if a slot would be "overfilled" that the cursor will continue holding onto the items. Then, take a list of the slot index, button, and mode variables for the clicks to be done (mode and button are defined at https://wiki.vg/Protocol#Click_Window). Output the inventory afterwards.

Restrictions/Rules

You may input and output the inventory in any reasonable format. You may take click input in any reasonable format. You may ignore Mode==2, as the player inventory is not implemented correctly enough for this. You may ignore Mode==3 because this is a survival player You may ignore Mode==5 where Button==8, 9, or 10 for the same reason as Mode 3. Dropping the item is a delete. Your player won't pick it back up or anything silly like that. You may assume that input will have valid counts Don't use standard loopholes

Examples

Input:

[["diamond",64],[],[],[],[],[],[],[],[]]

[
 [0, 0, 0]
 [0, 0, 1]
]

Output

[[],["diamond",64],[],[],[],[],[],[],[]]

Input:

[["diamond",64],["dirt", 64],[],[],[],[],[],[],[]]

[
 [0, 0, 0]
 [0, 0, 1]
 [0, 0, 2]
]

Output

[[],["diamond",64],["dirt",64],[],[],[],[],[],[]]

Input:

[["diamond",64],[],[],[],[],[],[],[],[]]

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

Output

[["diamond",56],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1]]

Meta

I have no clue what I'm doing writing a question.

Tagged code golf

Critique goals:

  • Improve testcases
  • Improve description of problem
  • Determine if the problem is too complex
\$\endgroup\$
  • 1
    \$\begingroup\$ Challenges are meant to be self-contained. While information where the idea/process comes from can be nice, everything needed to solve the challenge should be in the description. This means you should write down what click does what, for all the people who don't remember what Minecraft clicks do by heart. \$\endgroup\$ – AlienAtSystem Nov 22 '19 at 6:43
-1
\$\begingroup\$

A very-very old (maybe early 2000s) problem:

Print out a decimal number \$n\$ such as \$n^2\$ ends with \$n\$ with maximal length your program can compute in 60 seconds

In other words it's needed to find some long enough \$n\$ such as \$10^{\lfloor\log_{10}n\rfloor+1}|(n^2-n)\$.
A hint may be that an \$n\$ ending with \$5\$ is more easy to compute than an \$n\$ ending with \$6\$.

code-challenge

\$\endgroup\$
  • \$\begingroup\$ How can this be king-of-the-hill? Do you mean code-challenge? And what stops us from hardcoding some extremely large number? \$\endgroup\$ – Jo King Nov 21 '19 at 23:36
  • \$\begingroup\$ king-of-the-hill needs interaction between submissions. I don't see any here \$\endgroup\$ – Jo King Nov 22 '19 at 1:43
  • \$\begingroup\$ @JoKing the problem becomes very simple with modular arithmetic: got 205k digits for free with ~len(n) time for each step imgur.com/ExPdwMb , so there's no need for hardcoding and it's not much interesting. ) \$\endgroup\$ – Alexey Burdin Nov 22 '19 at 14:11
-1
\$\begingroup\$

JavaScript: Free for All

This is a very experimental idea of mine: given a function which is provided a single function as an argument, try to run that function the most times possible in a browser environment while competing against other bots.

Bot submissions

Each bot consists of a function. This function takes a scoring function as input. Each bot has a state consisting of three values:

  • score: Number indicating score, winning criterion
  • locked: Boolean which, when true, prevents further score increases
  • calls: Number of times scoring function called in last 100ms (?), will set locked to true for the remainder of the round if it exceeds a certain value

The scoring function increments score and calls, as long as locked is not true.

Restrictions

If any of these restrictions are violated, a bot will have locked set to true.

No bot or bot-defined function may:

  • Run longer than 5ms
  • Attempt to modify the window location (location.href, location.assign, etc.)
  • Attempt to connect to the internet (AJAX, WebSockets, etc.)
  • Create web workers
  • Affect hardware (sound, microphone, camera, USB, gamepads, etc.)
  • Download files
  • Leave an impact which cannot be fixed by reloading the page

Notes

This is almost certainly a very bad idea on an assortment of levels. If you have any suggestions of restrictions or ways to make the challenge more interesting, be sure to comment.

I'm considering some sort of system to determine which bot runs first that adds to the strategy, and interesting attack angles for other bots.

To prevent this from becoming a "read the last answer and exactly cancel out its strategy" type thing, I'm open to any suggestions.

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

Digits of the sum of the reciprocal exponential factorials

The exponential factorial, \$n^!\$, is the extension of the factorial using exponentiation instead multiplication:

$$n^! = \begin{cases} 1, & \text{if }n = 0 \\ n^{(n-1)^!}, & \text{if }n \ge 1 \end{cases}$$

The first few exponential factorials are \$1, 1, 2, 9, 262144, \dots\$

The infinite sum of the reciprocals of the exponential factorials tends towards a constant:

$$\begin{align} \sum_{n=1}^\infty\frac{1}{n^!} & = 1+\frac{1}{2^!}+\frac{1}{3^!}+\frac{1}{4^!} + \cdots \\ & = 1+\frac{1}{2}+\frac{1}{9}+\frac{1}{262144} + \cdots \\ & = 1.611114925808376736\underbrace{111\dots111}_{183213\text{ times}}27224\dots \end{align}$$

The digits after the decimal point are OEIS A080219

You are to take a positive integer \$n\$ as input and output the \$n\$th digit after the decimal point of the above constant. Your program must work for an arbitrarily large \$n\$, but can fail due to language constraints for reasonably large \$n\$. You may choose 0 or 1 indexing. This is so the shortest code in bytes wins


Meta

  • Is this clear?
  • Is this a duplicate?
  • Tags are , and . Any suggestions?
  • Any further feedback?
\$\endgroup\$
  • 3
    \$\begingroup\$ The $ symbol makes it look like you made a latex-typo :P Maybe you can mention that this is oeis.org/A080219 \$\endgroup\$ – flawr Dec 5 '19 at 20:10
  • \$\begingroup\$ @flawr Given that it's the symbol used in the Wikipedia article, I think it's best to keep using it. And yes, I will include that OEIS sequence, thanks! \$\endgroup\$ – caird coinheringaahing Dec 5 '19 at 20:11
-1
\$\begingroup\$

Introduction

As programming languages reproduce are created, documentation is even more important for programmers. Your task is simple: output the esolangs.org documentation for your programming language.

With wikis being wikis, languages are heavily penalized in this challenge for being used often and for being interesting to write about, the goal here is to draw attention to languages that may not get utilized otherwise.

Challenge

For this task, you will need to output the source for the article on esolangs.org for your language, with greater than or equal to 95% accuracy. Your score is your program length in bytes, as in other challenges.

Languages not on this multi-page list of languages as of the time of this posting are ineligible.

Standard loopholes are forbidden.

Inputs

None

Output

The source (as of this challenge being posted), for the esolangs wiki page for your language, with at least 95% accuracy.

Example

Language: ///

Output:

{{featured language}}
'''///''' (pronounced "slashes") is a minimalist [[Turing-complete]] esoteric programming language, invented by Tanner Swett ([[User:Ihope127]]) in 2006 based on [[wikipedia:sed|the "s/foo/bar/" notation that everybody seemed to be using in IRC]]. The only operation is repeated string substitution, using the syntax <code>/''pattern''/''replacement''/</code>. Despite its extreme simplicity – there isn't even an obvious way to create a loop – it was proved [[Turing-complete]] by [[Ørjan Johansen]] in 2009, who created [[#Bitwise Cyclic Tag interpreter|an interpreter]] for the Turing-complete language [[Bitwise Cyclic Tag]].
...

\$\endgroup\$
  • 4
    \$\begingroup\$ -1: Interesting idea, but I don't think it can work as a challenge. I'm not convinced that kolmogorov-complexity-ing a volatile data source is a good idea. What happens if the page is edited two weeks from now? \$\endgroup\$ – Beefster Dec 13 '19 at 22:39
  • \$\begingroup\$ Loophole. I blanked the esolangs.org documentation of my language. Therefore I can output nothing to achieve my goal. \$\endgroup\$ – a'_' Dec 18 '19 at 4:07
  • \$\begingroup\$ @A̲̲ nope, you have to output what it was at the time of posting \$\endgroup\$ – iPhoenix Dec 18 '19 at 11:53
  • \$\begingroup\$ Obviously, you blank the page and then post before it gets fixed. \$\endgroup\$ – my pronoun is monicareinstate Dec 19 '19 at 13:55
-1
\$\begingroup\$

Bunda-Gerth parser for abstract APL-family language

Background

APL has four kinds of tokens: arrays, functions, monadic operators (mops) and dyadic operators (dops).1) Let's denote them A (arrays), F (functions), M (mops), and D (dops) respectively. Usually when programming in APL, we use a mental model like this:

  • Strand notation: A A ... A -> A
  • Monadic function application: F A -> A
  • Dyadic function application: A F A -> A
  • Mop with left operand: (A|F) M -> F
  • Dop with both operands: (A|F) D (A|F) -> F
  • Mops and dops bind first from left to right (producing functions), and then function applications are evaluated from right to left

But J.D.Bunda and J.A.Gerth proposed another way to parse APL expressions. In this method, each (ordered) pair of tokens is assigned a binding strength and a resulting token. Below is the translation of the above mental model. Note that some token pairs do not bind at all, and we have a new token type AF, which stands for a function with bound left argument.

Binding strength | Token pair(s) -> result
--------------------------------------------
               5 | A A -> A        # Strand notation
               4 | D (A|F) -> M    # Dop + Right operand -> Mop
               3 | (A|F) M -> F    # Left operand + Mop  -> Function
               2 | A F -> AF       # Array + Function    -> Left-bound function
               1 | (F|AF) A -> A   # Function + Array    -> Array

Then the actual parsing proceeds as follows: given a stream of tokens,

  1. Evaluate the binding strengths between adjacent tokens.
  2. Select the token pair whose binding strength is the rightmost local "peak", i.e. the x y pair in w x y z satisfying wx < xy >= yz. w and/or z can be empty. Note that the leftmost pair is bound first in A A ... A.
  3. Group the pair and produce a new token as specified in the transition table.
  4. Repeat from 1 until single token is left (successful parse) or no more reduction is possible (syntax error).

Challenge

Given a list of tokens, output the order of binding (refer to the I/O section for specification) using the transition table and algorithm described above.

Input and output

The input is a non-empty list of A/F/M/D tokens. You may use any number or single character to represent a token. You may assume that the input will always parse successfully, and the input won't contain any parentheses (since it isn't specified in the table above).

For the output, the order of binding represents in which order each gap between the tokens is closed:

Given the tokens:       A A F M A
Assign each gap an ID:   w x y z
Binding strength:        5 2 3 0
Rightmost local peak:       F M
Bind them first:        A A (F M) A     -> y = 1
Bind A-A next:         (A A) (F M) A    -> w = 2
Bind A-F next:        ((A A) (F M)) A   -> x = 3
Bind AF-A last:      (((A A) (F M)) A)  -> z = 4

Given the tokens:       A A F M A
The order of binding:    2 3 1 4  (the answer)

Note that, if the input contains L tokens, the answer is always a permutation of 1..L-1 (or 0..L-2 if you choose zero-based numbering).

Scoring and winning criterion

Standard rules apply. The shortest code in bytes wins.

Test cases

Input:  A A A A A
Output:  1 2 3 4
-----------------------------
Input:  A F F A A F F A
Output:  6 7 5 2 3 4 1
-----------------------------
Input:  A  F D A A  M  A A D F M F A
Output:  11 9 8 7 10 12 3 4 2 5 6 1

Footnote

  1. An actual implementation of APL has some special tokens, e.g. dot ., jot , and index notation [x]. We ignore them here for simplicity.
\$\endgroup\$
  • \$\begingroup\$ Maybe an easy answer format is simply inserting the order of binding? A F F A A F F A((A F) (F (((A A) F) (F A))))((A5F)7(F6(((A1A)2F)4(F3A)))) and maybe even returning the permutation vector 5 7 6 1 2 4 3? \$\endgroup\$ – Adám Dec 17 '19 at 8:42
  • \$\begingroup\$ @Adám That could work, but I don't think it's any easier to produce than a fully structured output. Also, alternative algorithms can produce the same tree with different binding order. \$\endgroup\$ – Bubbler Dec 17 '19 at 23:27
  • \$\begingroup\$ It will be really hard to verify with the broad output allowance. Maybe just require fully parenthesising? \$\endgroup\$ – Adám Dec 17 '19 at 23:55
  • \$\begingroup\$ @Adám IMO it's not a problem, as long as the answers specify which output format they're using. \$\endgroup\$ – Bubbler Dec 18 '19 at 0:16
  • \$\begingroup\$ On second thought, I decided to emphasize the algorithm itself (over the resulting parse tree). \$\endgroup\$ – Bubbler Dec 26 '19 at 2:04
-1
\$\begingroup\$

Potentially Prime Punch-Card Patterns


Punch-cards

Let us define a punch-card to be a set of 'open' and 'closed' holes which can slide over the positive integer number line:

    _________________________
   |   ___     ___     ___   | -->
   |  |   |   |   |   |   |  |
1  |  | 3 |   | 5 |   | 7 |  |  9   10  11  12  13  14
   |  |___|   |___|   |___|  |
   |_________________________| -->

When the first open hole is on the integer \$ p \$, then this punchcard (as it slides across the number line) yields the integers \$p, p+2,\$ and \$p+4\$. So, we can represent this card as the set \$\{0, 2, 4\}\$.

Admissibility

Given a punch-card we may wonder whether it is possible to slide the card to such a position that only prime numbers are under the 'open' holes.

Clearly, for \$\{0, 2, 4\}\$, we can position the punch-card to make 3, 5, and 7 visible. However, this is the only solution. Taking each element modulo 3 yields \$\{0, 2, 1\}\$, which contains every possible remainder under division by 3, so one visible integer must be divisible by 3. But we only want primes, and so 3 itself must be visible; this leaves a finite number of possible positions, of which only one is a valid solution.

More generally, if there exists a prime \$q\$ such that every integer \$0 \le n < q\$ appears in the punch-card set modulo \$q\$, then the punch-card is inadmissible and has a finite number of positions where all visible integers are prime: as we are bounded by the condition that \$q\$ must be visible. We can place \$q\$ in each hole in turn, and perform primality tests to count the valid solutions.

However, if there exists no such \$q\$, then the punch-card is admissible and we cannot assume there are finite solutions; the K-Tuple Conjecture in fact hypothesizes that every admissible punch-card can assume infinitely many positions where all visible integers are prime.

The Challenge

Your task is to write a program or function which, given a list of ordered positive integers representing a punch-card set, outputs the number of positions the punch-card can assume where all visible integers are prime. If the set is admissible, then give a distinct output such as -1, null, Inf - anything that is not a non-negative integer.

Test Cases

Coming soon.


Meta

There is a related challenge - testing for admissible sequences. However, I believe this is distinct enough to be a duplicate as rather than being a simple , if a set is admissible this program will have to then try different positions of the punch-card and count the valid solutions; whereas the previous challenge considers admissible sets in isolation, this challenge applies it to prime numbers.

\$\endgroup\$
  • \$\begingroup\$ Given that the admissibility test is already a challenge, how about you split off the two-challenge and special case part: The input can be assumed to be an admissible sequence, the task is simply finding the positions resulting in valid solutions. \$\endgroup\$ – AlienAtSystem Dec 28 '19 at 5:54
  • \$\begingroup\$ @AlienAtSystem i just feel as though that it is much less interesting to golf, and returning the distinct different output would open more interesting golfing opportunities. \$\endgroup\$ – FlipTack Dec 28 '19 at 6:09
  • \$\begingroup\$ Handling special cases is very rarely interesting to golf, for a quite simple reason: Checking if the special case is present requires bytes. Being told the simple case is the case saves those bytes. \$\endgroup\$ – AlienAtSystem Dec 29 '19 at 20:29
  • \$\begingroup\$ @AlienAtSystem but for there to be more golfing opportunities, don't there have to be more bytes to golf? \$\endgroup\$ – FlipTack Dec 29 '19 at 20:37
  • \$\begingroup\$ Not really. The issue is that for multiple task challenges, the byte count is 90% of the time optimal_bytes(task1)+optimal_bytes(task2). Often, one of the tasks is considerably longer to golf, to the point where optimizing the other task is almost irrelevant because it's so small compared to the other. Therefore, the site consensus is to split challenges into their individual components as much as possible, and especially avoid input validation, because it's boring and requires lots of bytes. \$\endgroup\$ – AlienAtSystem Jan 1 at 8:29
  • \$\begingroup\$ But it's not input validation in the sense of there being erroneous or invalid inputs: it's just that the answer to the question "how many prime positions does this have?" may be 0,1,2..., and also (probably) infinity. \$\endgroup\$ – FlipTack Jan 1 at 11:04
-1
\$\begingroup\$

How many ways can I count on n?

By using addition of natural numbers {1, 2, 3...} and multiplication of natural numbers larger than 1, we can reach the same outcome in several ways. For example 4 = 2 x 2 but also: 4 = 2 + 1 + 1. Using normal mathematical operator precedence, there are actually 6 ways to express 4 and 9 ways to express 5.

Since addition is commutative, a + b is counted as the same solution as b + a. The same holds for multiplication. So 7 = 1 + 2 x 3 is the same solution as 7 = 3 x 2 + 1.

The (trivial) solution n (using no addition or multiplication) is also counted as one of the solutions of n.

Multiplication with 1 is forbidden, because you can do this infinitely.

Task

For a given input n, output c(n), which is defined as the number of ways n can be uniquely expressed using zero, one or more additions and multiplications of natural numbers, using normal mathematical operator precedence and without multiplication with 1.

Rules

  • Input and output are integers (your program should at least support input and output in the range of 1 up to 32767)
  • Invalid input (0, floats, strings, negative values, etc.) may lead to unpredictable output, errors or (un)defined behaviour.
  • Default I/O rules apply.
  • Default loopholes are forbidden.
  • This is , so the shortest answers in bytes wins

Final note

I can think of several ways to approach this problem. I think it's interesting to see how the different approaches impact the length of the solution.

Sandbox questions

  • Please let me know if this task/problem is stated clear enough.
  • Please let me know if there are any loopholes that I should cover in the question.
  • I intentionally omitted more examples (because I hope contesters will think about solutions rather than just reproduce an OEIS sequence; although I'm not sure if this question had an OEIS sequence).
  • I will tag this question with .
\$\endgroup\$
-1
\$\begingroup\$

Quine Generator Generator... of any* length!

A Quine Generator Generator... is a quine when the input is empty or 0. Otherwise, for any other sufficiently large positive integer input, it should print a Quine Generator Generator... of that specified length (in the same language, same options).

Let S be the (most likely theoretically infinite) set of Quine Generator Generator... you can generate from your initial Quine Generator Generator....

Your score is the smallest N such that any Quine Generator Generator... in S can generate a Quine Generator Generator... of length N or longer (for reasonably sized N).

Input can be from standard input or as an argument of a function.

Lowest score wins.

Sandbox Meta:

Typically, code is scored by bytes, but now the length would depend on how that is interpreted, since it is included in the description of the question. Hence would it be a problem to put: "You may choose to define characters in terms of bytes or characters (should they differ) for purposes of the program length and scoring purposes."

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

Integer Keys and Duplicates

Given a list/vector of positive integers, write a function to check the following conditions in as few bytes as possible.

  1. Take the first integer (the key, or k1) and check that the next k1 values have no duplicate values, excluding k1.
  2. Take the last integer (the second key, or k2) and check that the k2 values before k2 have no duplicate values, excluding k2.

Note that both keys, k1 and k2, are elements of the list/vector as either key could contain the other.

Also, k1 and/or k2 can be greater than the number of integers within the list, which means you should check every element of the list besides the given key for duplicates, excluding the key.

If both steps return True, return True, else, return False.

Test Cases

[5,1,2,5,3,4,3] is TRUE because [k1=5][1,2,5,3,4] has no duplicates, nor does [5,3,4] have any duplicates, excluding 3

[6,9,12,15,18,19,8,8,3] is FALSE because [k1=6][9,12,15,18,19,8] has no duplicates while [19,8,8][k2=3] has a duplicate.

[100,100,100,100,101,102,3] is TRUE because [k1=100][100,100,100,101,102,3] has no duplicates, and [100,101,102][k2=3] has no duplicates.

[100,100,100,100,101,102,4] is FALSE. [k1=100][100,100,100,101,102,4] has no duplicates, but [100,100,101,102][k2=4] has duplicates.

[6,6,6,6,6,6,6,3,3,3,3] is TRUE. [k1=6][6,6,6,6,6,6] has no duplicates and [3,3,3][k2=3] has no duplicates.

[1,2] is TRUE (clearly)

[1] is TRUE (clearly)

[] the empty list is also TRUE (if you can make a valid argument why it should be FALSE then I might give it to you)
\$\endgroup\$
-1
\$\begingroup\$

Drum fill generator

Create a program that generates a drum fill. Your program will output a pattern of L (left hand hits), 'R' (right hand hits), and K for kick drum hits.

Rules

  • The pattern must never have more than 2 of the same hits consecutively.
  • The pattern must be loopable, so it mustn't have more than 2 of the same hits when it loops.
  • Your program accepts 1 argument which is the length of the pattern. You can assume this will always be an integer > 0.
  • Program output must be random each time it's ran.
  • IO can be used with any convenient method.
  • Standard loopholes are forbidden.
  • This is code-golf, so smallest program wins!

Example valid output:

RLRRKKLL
LRLLKKLR
LKKRLRKLRRKL
LRLR

Example invalid output:

LRLL // 3 characters when looped
LRLRRRLLR // 3 characters in a row
RRLRLLRR // 4 characters when looped
\$\endgroup\$
  • \$\begingroup\$ What's a paradiddle? You should include a description in your question \$\endgroup\$ – Jo King Jan 4 at 5:18
  • \$\begingroup\$ How's that? I added more detail on what the rules/patterns are. \$\endgroup\$ – TMH Jan 4 at 21:18
  • 1
    \$\begingroup\$ No it must be random each time the program is ran, I'll add that to the rules now, thanks :). \$\endgroup\$ – TMH Jan 5 at 21:16
-1
\$\begingroup\$

Theorem proving code golf: a+(b+c)=b+(c+a)

Notes

This challenge is restricted to the languages with dependent type support. Some examples include Idris, Agda, Coq, Lean (which are designed for theorem proving), and Haskell with certain extensions enabled.

In these languages, a theorem is considered equivalent to a type, and writing a proof of a theorem is equivalent to providing a value of the given type (due to Curry-Howard correspondence). For example, the "modus ponens" rule

$$ P,(P \rightarrow Q) \rightarrow Q $$

could be expressed as a function type

(p : P) -> (pq : P -> Q) -> Q

and have a proof by function application like the following:

thm : (p : P) -> (pq : P -> Q) -> Q
thm p pq = pq p

But a recursive definition requires an additional constraint that it is terminating, i.e. the recursive calls are done with smaller arguments so that it eventually reaches the base case. This is to prevent erratic proofs like a : False := a, which evokes an infinite loop to fake a value of empty type False.

A recursive proof is usually analogous to a proof by (weak or strong) induction.

Task

Given the Peano natural numbers and addition

$$ n : \mathbb{N} := \text{Zero } | \text{ Succ }n \\ a+ \text{Zero} := a, a+ \text{Succ } b := \text{Succ }(a+b) $$

express the following statement in code and prove it:

$$ \forall a,b,c\in \mathbb{N}, a+(b+c)=b+(c+a)$$

The theorem should have the type of (or your language's equivalent of)

forall a b c : nat, a + (b + c) = b + (c + a)

or, in function notation,

(a : nat) -> (b : nat) -> (c : nat) -> a + (b + c) = b + (c + a)

Condition

You're free to use a library provided with your language of choice. If the library uses the flipped definition of Peano addition, it's fine to use it instead. As usual for , you need to count the bytes used for imports.

For theorem-proving languages (where infinite loops are rejected by the compiler), a successful compilation usually means a correct proof. If it is not the case, you should provide an explanation that the definition is indeed terminating.

If you find a bug in some theorem-proving language that allows to prove anything, using it is not allowed, as it is not considered as a solution to the given task.

Scoring and winning criterion

Standard rules apply. The shortest code in bytes wins.


Meta

  • Is it a good idea for a CGCC challenge? I once learned Coq and a bit of Lean, and I thought minimizing code by clever usage of tactics and/or explicit definitions could be interesting.
  • Is the task appropriate for an introductory challenge in this topic? I just made up a statement that looks less likely to be in a standard library, but is easy enough to prove by commutativity and associativity.
\$\endgroup\$
  • 1
    \$\begingroup\$ There is already proof-golf, which has all well received questions (though they've all been asked by one user). This is a bit different, and I think you need to try to work out some of the kinks if you want to ask it this way. Mostly, your definition of "prove" feels a tad loose. I've not used such languages, but I recommend trying to find a common element amongst them so you can be more precise. Perhaps you will want to prove something over a finite field instead, so an exhaustive proof can terminate? \$\endgroup\$ – FryAmTheEggman Jan 7 at 21:41
  • \$\begingroup\$ @FryAmTheEggman Thanks for the suggestion. I tried to clarify what a proof means in this context. I initially thought about proof-golf too, but listing out the rules of entire CIC theory is probably out of the question. (Probably I could extract the needed rules if I limit to the natural number type; I'll think about it later.) \$\endgroup\$ – Bubbler Jan 8 at 0:44
-1
\$\begingroup\$

Interpret LCGFuck™

Introduction

LCGFuck™ is a Brainfuck-like esoteric programming language invented by me. Inspired by Brainfuck and linear congruential generators (LCGs), LCGFuck™ combined both things into one.

An LCG in LCGFuck™ is defined with 5 integers, namely multiplier a, adder b, modulus c, offset d and seed e. Let x be its current state, then the corresponding output will be x + d, and the next internal state x' of the LCG can be calculated by x' = (a * x + b) mod c. All numbers should be non-negative except for d. Moreover, b and e should be in the range [0, c).

Technical details

An LCG is defined with 5 numbers, like 12345 678 90 -123 45. The last two numbers are optional and default to 0.

LCGFuck™ has 3 storage variables, the LCG list, the number list and the number memory. The functions are as follows:

  • LCG list: Cyclic list that stores all LCGs created. Every entry is in turn a list of 5 numbers in the order [a, b, c, d, e] as notated in the introduction. It has a pointer that controls which LCG is chosen at the moment, and moves in a cycle through the list.
  • Number list: Ordinary list that stores the numbers for LCG definition. It can store at most 5 numbers.
  • Number memory: A single variable that can be read and written with an input or an LCG output.

LCGFuck™ has 14 operators, namely:

  • \n (newline): Creates an LCG with the numbers in the order of [a, b, c(, d(, e))] and clears the list if the number list contains 3 or more numbers. No-op if the number list contains no more than 2 numbers.
  • <: Shifts to the previous LCG circularly (back to the last when moving from the first).
  • >: Shifts to the next LCG circularly (back to the first when moving from the last).
  • +: Moves the current LCG to the next state (calculates x' = (a * x + b) mod c)
  • c: Prints the output of the current LCG as a character (with the output as the codepoint).
  • n: Prints the output of the current LCG as a number (with a trailing space)
  • o: Writes the output of the current LCG to number memory
  • i: Reads a value from the input and writes it to number memory. There is two input mode, one reading a character one time, and one reading a number one time. You do not need to implement this operator in this challenge.
  • s: Reads the value from number memory and seeds the current LCG with it
  • m: Reads the value from number memory and pushes it to the number list
  • []: Output loop. Executes the loop if the current LCG is non-zero
  • {}: State loop. Executes the loop if the state of the current LCG is non-zero

An integer, optionally with a negative sign at the front, pushes the number to the number list. Any characters other than the newline \n and any of -0123456789[]{}<>+cimnos are no-ops.

The code runs linearly from the first characters, except when loop ends are encountered. Loops can be nested but must be paired accordingly from the innermost loop to the outermost loop.

Challenge

Write an interpreter, making it as short as possible, that interprets the LCGFuck source code given as the input. You need not implement the i operator in this challenge. The output should be printed to STDOUT or returned in case of writing a function.

You may assume that your interpreter always receives valid programs, i.e.:

  1. An LCG is always defined before any of the commands that manipulate the LCG or the LCG list pointer
  2. At any moment the number list contains at most 5 numbers
  3. All brackets are paired accordingly

Standard loopholes are forbidden by default.

Sample implementation with operator i (Primality check)

Sample

The LCG list need not be printed out. It is just for illustration purpose.

  1. The "Hello world!" program in LCGFuck™ is as follows:

    1 29 30 72
    1 3 9 108
    1 1 2 32
    c+c>cc+co>c
    1 8 9 m
    >+c<<c+c+c<+c>>+c
    
    • Output: Hello world!

    • LCG list after execution:

      [1, 29, 30, 72, 28]
      [1, 3, 9, 108, 0]
      [1, 1, 2, 32, 1] < Current LCG
      [1, 8, 9, 111, 8]
      
  2. An example that outputs the values of x - 16, where x is the states of the LCG x' = (19x + 17) mod 32, starting with seed x = 4, until the output is 0:

    19 17 32 -16 4
    [n+]n
    
    • Output: -12 13 8 9 -4 5 -16 1 4 -3 -8 -7 12 -11 0

    • LCG list after execution:

      [19, 17, 32, 16, -16] < Current LCG
      
  3. An example that outputs all possible values of 5(x + 12), where x is the states of the LCG x' = (5x + 3) mod 8:

    5 3 8 12
    5 0 99
    o>s+n<+{o>s+n<+}
    
    • Output: 60 75 70 85 80 95 90 65

    • LCG list after execution:

      [5, 3, 8, 12, 0] < Current LCG
      [5, 0, 99, 0, 65] 
      
  4. An example illustrating the 3-number restriction of \n (the 9 in the 3rd line is pushed to the number list but the LCG is defined before the 9 is pushed):

    12 34
    56 78
    9
    n
    
    • Output: 78

    • LCG list after execution:

      [12, 34, 56, 78, 0] < Current LCG
      
  5. An example that determines whether 97 is a prime:

    1 -1 97 0 -1
    {o+1 1 m 0 97
    }>{>}o+{o+}<{<}s
    1 1 1 32
    1 4 12 69 4
    1 1 7 78 2
    {<+++++c+c+++++c+++
    <<c>>>{+}}<c++c<c+c+c
    
    • Output: PRIME

    • LCG list after execution:

      [1, -1, 97, 0, 0]
      [1, 1, 96, 0, 1]
      [1, 1, 95, 0, 2]
      [1, 1, 94, 0, 3]
      [1, 1, 93, 0, 4]
      [1, 1, 92, 0, 5]
      [1, 1, 91, 0, 6]
      [1, 1, 90, 0, 7]
      [1, 1, 89, 0, 8]
      [1, 1, 88, 0, 9]
      [1, 1, 87, 0, 10]
      [1, 1, 86, 0, 11]
      [1, 1, 85, 0, 12]
      [1, 1, 84, 0, 13]
      [1, 1, 83, 0, 14]
      [1, 1, 82, 0, 15]
      [1, 1, 81, 0, 16]
      [1, 1, 80, 0, 17]
      [1, 1, 79, 0, 18]
      [1, 1, 78, 0, 19]
      [1, 1, 77, 0, 20]
      [1, 1, 76, 0, 21]
      [1, 1, 75, 0, 22]
      [1, 1, 74, 0, 23]
      [1, 1, 73, 0, 24]
      [1, 1, 72, 0, 25]
      [1, 1, 71, 0, 26]
      [1, 1, 70, 0, 27]
      [1, 1, 69, 0, 28]
      [1, 1, 68, 0, 29]
      [1, 1, 67, 0, 30]
      [1, 1, 66, 0, 31]
      [1, 1, 65, 0, 32]
      [1, 1, 64, 0, 33]
      [1, 1, 63, 0, 34]
      [1, 1, 62, 0, 35]
      [1, 1, 61, 0, 36]
      [1, 1, 60, 0, 37]
      [1, 1, 59, 0, 38]
      [1, 1, 58, 0, 39]
      [1, 1, 57, 0, 40]
      [1, 1, 56, 0, 41]
      [1, 1, 55, 0, 42]
      [1, 1, 54, 0, 43]
      [1, 1, 53, 0, 44]
      [1, 1, 52, 0, 45]
      [1, 1, 51, 0, 46]
      [1, 1, 50, 0, 47]
      [1, 1, 49, 0, 48]
      [1, 1, 48, 0, 1]
      [1, 1, 47, 0, 3]
      [1, 1, 46, 0, 5]
      [1, 1, 45, 0, 7]
      [1, 1, 44, 0, 9]
      [1, 1, 43, 0, 11]
      [1, 1, 42, 0, 13]
      [1, 1, 41, 0, 15]
      [1, 1, 40, 0, 17]
      [1, 1, 39, 0, 19]
      [1, 1, 38, 0, 21]
      [1, 1, 37, 0, 23]
      [1, 1, 36, 0, 25]
      [1, 1, 35, 0, 27]
      [1, 1, 34, 0, 29]
      [1, 1, 33, 0, 31]
      [1, 1, 32, 0, 1]
      [1, 1, 31, 0, 4]
      [1, 1, 30, 0, 7]
      [1, 1, 29, 0, 10]
      [1, 1, 28, 0, 13]
      [1, 1, 27, 0, 16]
      [1, 1, 26, 0, 19]
      [1, 1, 25, 0, 22]
      [1, 1, 24, 0, 1]
      [1, 1, 23, 0, 5]
      [1, 1, 22, 0, 9]
      [1, 1, 21, 0, 13]
      [1, 1, 20, 0, 17]
      [1, 1, 19, 0, 2]
      [1, 1, 18, 0, 7]
      [1, 1, 17, 0, 12]
      [1, 1, 16, 0, 1]
      [1, 1, 15, 0, 7]
      [1, 1, 14, 0, 13]
      [1, 1, 13, 0, 6]
      [1, 1, 12, 0, 1]
      [1, 1, 11, 0, 9]
      [1, 1, 10, 0, 7]
      [1, 1, 9, 0, 7]
      [1, 1, 8, 0, 1]
      [1, 1, 7, 0, 6]
      [1, 1, 6, 0, 1]
      [1, 1, 5, 0, 2]
      [1, 1, 4, 0, 1]
      [1, 1, 3, 0, 1]
      [1, 1, 2, 0, 1]
      [1, 1, 1, 0, 0]
      [1, 1, 1, 32, 0]
      [1, 4, 12, 69, 0] < Current LCG
      [1, 1, 7, 78, 4]
      

Winning criteria

Since this is a code-golf challenge, the shortest solution for every language wins.

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

He. Might. Go. All. The. Way. Touchdown!

[in-progress]

Premise:

In American Football, a team has to drive up the field to their opponent's end-zone to score points. But here's the catch, they have 4 tries (called downs) to go at least 10 yards to gain a new set of downs. They repeat this until they score a Touchdown, or until they fail to get 10 yards and (at least in this challenge) punt it away or go for a Field Goal.

Your task is to simulate such a drive.

Challenge:

You are to output the state of each down, i.e. which down it is, how far to the next down (or the end-zone), and where the ball is. Football location counts up from a team's end-zone (0yd line) up to the 50yd line (the middle), then back down to 0 for the opponent's end-zone.

We differentiate the sides of the field by prefixing the location with the team's name. In this challenge, you can use a 1 character label or use positive and negative values. It must go 0-49,50,49-0 and have a way to differentiate between the sides. Your choice on who owns the 50yd line.

Sample Output: (Our team is A, the opponent's team is B)

1st & 7 on A 13
2nd & 10 on A 48
3rd & 12 on 50 OR 3rd & 12 on A 50 OR 3rd & 12 on B 50
4th & 8 on B 10
2nd & Goal on B 7 (read ahead)

Your team will start on your own 1 yard line on 1st & 10 (1st down, 10 yards to go for another first down). You will then gain a uniformly random number of yards between [-3,10] called N. If you didn't get enough for a 1st down, it will now be 2nd & (10 - N). Repeat drawing another number between [-3,10] and adding the yardage for 2nd and 3rd downs if it's still not enough for a 1st down. If you do gain enough for a 1st down, you simply go back to 1st & 10 on the next go and continue going down the field.

On 4th Down, your team is playing safe and will either punt or go for a Field Goal. If you are further away than their 40, output P. If you're within 40 yards, you will attempt a Field Goal with 100 - Yards Away% chance of success. If you succeed, output FG. If you miss, output NG ("No Good"). Afterwards, terminate.

However, there are two special situations that must be handled.

If you get within 10yd (inclusive) and gain a 1st Down, It will then be 1st & Goal and there are no more opportunities to gain 1st downs. Do or die! If you score, output TD and terminate, otherwise you'll follow the normal Field goal rules.

If you lose enough yards to go into your own end-zone, that's called a Safety. Simply output a S and terminate.

Rules:

  • No usable input will be provided
  • Output is flexible. Tuples and lists of lists are all fine.

Sample Runs:
To-Do

Tags: Code-golf, random, game


Feedback? Does the Field goal add enough meat to be worth including?

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

What order(s) can I fire my tonics in?


Helsing's Fire is a classic mobile game about light. You fire blasts of holy retribution (from chemicals called tonics), using cover to selectively hit enemies in the right sequence.

For this challenge, we're going to ignore the line-of-sight stuff and focus on just the tonic order. Each monster is represented by a string like RBBGB—this indicates that, in order to kill it, you need to hit it with a red tonic, followed by 2 blue tonics, then one green tonic and finally one more blue tonic.

Since you're allowed to ignore cover and pick any subset of the monsters to hit, any of the following sequences will kill it:

RBBGB
GRBBGBRR
RBBBBBBBBBBBBBBBGGGGBR
RRRBGGGBBRGRBB

Your goal is to take in a list of monsters as well as how many of each tonic you have, and output every possible ordering of tonics that kills every monster, including ones where not every tonic is fired. For instance:

R; 2 red -> R, RR
R; 1 red/1 blue -> R, RB, BR
No monsters, but tonics -> every possible permutation of the tonics listed
No tonics, but monsters -> no output, empty set output, or single trailing separator
Neither tonics nor monsters -> empty string
RB,BR; 2 red/2 blue -> RBR, BRB, BRBR, RBBR, RBRB, BRRB
RR,RR,GRG,R,GBR,GR,GRRR,GGR,GB,G,R,BBR; 3 red/2 blue/2 green -> BGRRBGR, BGRRGBR, BGRBRGR, BGRBGRR, BGRGRBR, BGRGBRR, BGBRRGR, BGBRGRR, GRRBBGR, GRRBGBR, GRRGBBR, GRBRBGR, GRBRGBR, GRBBRGR, GRBBGRR, GRBGRBR, GRBGBRR, GRGRBBR, GRGBRBR, GRGBBRR, GBRRBGR, GBRRGBR, GBRBRGR, GBRBGRR, GBRGRBR, GBRGBRR, GBBRRGR, GBBRGRR
BR,R,BR,RBBR,RBR,RGB,RGBR,GB,RGR,GG,GRB,G; 3 red/2 blue/2 green -> RBGRBRG, RBGRBGR, RBGRGBR, RBGGRBR, RGRBBRG, RGRBBGR, RGRBGBR, RGRGBBR, RGBRBRG, RGBRBGR, RGBRGBR, RGBGRBR, RGGRBBR, RGGBRBR, GRRBGBR, GRRGBBR, GRBRGBR, GRBGRBR, GRBGBR, GRBGBRR, GRGRBBR, GRGBRBR, GRGBBR, GRGBBRR

Would there be a duplicate for this?

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

Elect the Doge of Venice!

The Venetian election system was... complicated.

The Great Council came together and put in an urn the ballots of all the councilors who were older than 30. The youngest councilor went to St Mark's Square and chose the first boy he met who drew from the urn a ballot for each councillor and only those 30 who got the word ‘elector' remained in the room. The 30 ballots were then placed back in the box and only 9 contained a ticket, so the 30 were reduced to 9, who gathered in a sort of conclave, during which, with the favourable vote of at least seven of them, they had to indicate the name of 40 councillors.

With the system of ballots containing a ticket, the 40 were reduced to 12; these, with the favourable vote of at least 9 of them, elected 25 others, which were reduced again to 9 who would elect another 45 with at least 7 votes in favour. The 45, again at random, were reduced to 11, who with at least nine votes in favour elected another 41 that finally would be the real electors of Doge.

These 41 gathered in a special room where each one cast a piece of paper into an urn with a name. One of them was extracted at random. Voters could then make their objections, if any, and charges against the chosen one, who was then called to respond and provide any justification. After listening to him, they preceded to a new election, if the candidate obtained the favourable vote of at least 25 votes out of 41, he was proclaimed Doge, if they were unable to obtain these votes a new extraction took place until the outcome was positive.

Venice is no longer an independent republic, but if they were, they would be dying to automate this system! (because we all know electronic voting is the future!) Time for you to step in. Your program is to do the following.

  • Here is the list of members of the Great Council (who are all older than 30). Take this as input, by perhaps reading it from a file, or whatever you prefer. The number of councillors varied over time, so your program should work for any list of sufficient length.
  • Take the youngest member of the council. Because there are no ages given, you'll have to guess. Pick a person at random, and print: "[Name] goes to St Mark's Square".
  • The boy at the square will pick thirty members from an urn. So, randomly choose 30 people from the list (not including the youngest councillor). Print "1 selected 30: " followed by the names of each of the thirty members in this round, separated by ", ".
  • Of those thirty, nine are randomly selected to go to the next round. So randomly choose 9 from that group, and print "30 reduced to 9: " followed by those nine electors.
  • Those nine electors have to choose forty different councillors. So, from the list of councillors, excluding the electors (but including the twenty-one people from the previous round of thirty who did not become electors), pick forty members. Print "9 selected 40: " followed by those forty people.
  • The forty were reduced to twelve by lot. Pick twelve from these members at random, print "40 reduced to 12: " followed by the dozen.
  • The dozen elected twenty-five councillors. You know the rules by now: pick 25 councillors excluding the 12 (but including anyone not in the 12 who partook in previous rounds), and print "12 selected 25: " followed by the twenty-five.
  • The twenty-five got reduced to nine again. Pick 9 random people from the 25 and print: "25 reduced to 9: " followed by those nine.
  • Those nine selected forty-five councillors. Pick 45 people not in the 9, and print: "9 elected 45: " followed by those people.
  • The forty-five were reduced to eleven. Pick 11 random councillors from those 45, and print "45 reduced to 11: " followed by those 11.
  • The eleven picked forty-one councillors who would elect the doge. Pick 41 people not in the 11, print "11 selected 41: " followed by those people.
  • Finally, these people will elect the Doge of Venice. Pick 1 person, randomly, from the 41. Then print "The new doge is [Name]" And then you can rest and watch the sun set on a democratic universe.

This horrendously complicated system was made to reduce corruption; so however you implement it, every member of the Great Council must have an equal chance of getting elected in the end. I will run your implementation ten thousand times to ensure that's roughly what happens. Abberating programs are corrupt and therefore disqualified.

Other rules:

  • Capitalisation of names must be kept. Expect only names with readable ascii characters (I had to remove a few Nicolò's from the list to make the challenge mildly easier).
  • Always print a list of names separated by the string ", ". A period at the end is not necessary.
  • Print every new instruction on a new line.
  • The list will always have at least 54 people, so enough for this process.
  • For every non-overlapping Italian word of at least 4 characters that can be found in your source code, remove 3/4ths of the length of that word (round up) from your score. A word counts as a sequence of alphanumeric characters that does not have to be consecutive, so "new random: (am-m)[a]" would count because it contains "mamma". Recent English loanwords (words that originate in English, even if they happen to occur in modern Italian, and are still spelled the same way) are not allowed. For golfing languages, modifications/variants of letters like ʀ and ʁ are allowed to count as the letters they are recognisable as. I'll be the judge if it's ambiguous.
  • This is , so your score is the number of bytes in your code. Lowest score wins!

Will add example output later.

Tags:

\$\endgroup\$
  • 1
    \$\begingroup\$ This is rather full of unnecessary requirements that don't seem to add much of anything to the challenge. Why not just require each of these random selections to be unambiguously separated in any format? Why demand odd prefaces to each subtask? Finally the Italian bonus is very weird, and seems to require that you provide an entire lexicon of valid words to be fully specified. \$\endgroup\$ – FryAmTheEggman Jan 17 at 20:02
  • \$\begingroup\$ I have to be honest (not a native Anglophone): I am not sure I can understand what your first two concerns say. The reason I ask for every step to be printed out, if that's what you mean, is because I cannot read Malbolge or Befunge and if I didn't get an indication that this repeated selection is being followed to a tee, I would not be able to tell if the solutions were doing it at all. As for the Italian, that was just a creative addition similar to the even-or-odd puzzle that requires alternating cardinality for source code characters. I'm not married to it though; it just felt right to me. \$\endgroup\$ – KeizerHarm Jan 17 at 20:36
  • 1
    \$\begingroup\$ I'm sorry that I wasn't clear. I intend to ask why you require outputs like "30 reduced to 9:". Since the order of the operations is fixed, there's no reason to require this. I guarantee your challenge will be better received if you remove those requirements. The Italian addition would be fine, only it is deeply unclear. "I'll be the judge if it is ambiguous" isn't the standard we hold challenges to - you need to specify precisely what counts and what doesn't if you want to keep it. \$\endgroup\$ – FryAmTheEggman Jan 17 at 20:41
  • \$\begingroup\$ @FryAmTheEggman Alright. Funny, I did not expect the printing to be the less desirable requirement, but I'll follow your judgement. And I can specify the lexicon, sure - I'll take an Italian word list, and subtract an English one (because loanwords). Just, taking into account golfing languages is going to be ambiguous - they frequently use modifications of Latin letters, and I want to allow those to be treated as their equivalent letters, but you might run into ambiguous situations like whether a Cyrillic к (don't know if any language uses it) can be a regular k. \$\endgroup\$ – KeizerHarm Jan 17 at 21:00
-1
\$\begingroup\$

Fun with Lasers and Prisms (WIP)

Given a rectangular grid of objects, one or more laser pointers, and a target, determine if any laser beam will hit the target.

Objects

ASCII will be used for illustration purposes

  • Laser Pointer: ^, V, <, > - a beam will shoot up, down, left, right, respectively, starting from this cell.
  • Target: O - return true if a beam reaches this cell
  • Mirror: /, \ - reflects a beam 90 degrees
  • Prism: # - the laser will split into three beams, one for each direction
  • One-way block: A, U, (, ) - a beam will pass up, down, left, right, respectively, but not other directions
  • Corridor block: =, " - a beam will only pass horizontally or vertically, respectively
  • Gate block: I, H - a beam will pass through horizontally if another beam touches it vertically, or vice-versa, respectively

Rules

  • Use any convenient representation
\$\endgroup\$
  • \$\begingroup\$ I think it is likely that your gate blocks prevent this from being a dupe of other similar challenges, though I haven't thoroughly checked yet. \$\endgroup\$ – FryAmTheEggman Jan 18 at 3:19
-1
\$\begingroup\$

How low can you go?

Time to play so ascii-art limbo!

Here's the bar:

|--|
|  |
|  |

Can you fit under it?

Goal

Write a program or function that takes an ascii string representing a some shape, and a positive integer representing a bar height.

Output the shape from the input after it has attempted to do the limbo.

Details

In limbo you lean back to make yourself as small as possible to fit under the bar, and that is just what the input shapes will try and do.

If the input shape contains any repeating patterns in its lines, then you can remove all but the last of the repetitions that are in the pattern. In additions the pattern must start at the top line, and once the repeating pattern is broken no more sections can be removed.

If there is a repeating pattern that contains another repeating pattern, only the innermost pattern is stripped.

For example this is how the following inputs would look after "Leaning back":

1. XXX              2. xxx            3. xxx           4. xxx      
   YYY                 xxx       xxx     xxx              xxx      xxx
   XXX   -->   XXX     yyy  -->  yyy     xxx  -->         yyy      yyy
   YYY         YYY     zzz       zzz     xxx              yyy      yyy
   zzz         zzz     aaa       aaa     xxx      xxx     xxx  --> xxx
                                                          xxx      xxx
                                                          yyy      yyy
                                                          yyy      yyy

Note how in example number 4 there was a repetition ox xxx insinde of another repetition of xxx, xxx, yyy, yyy. In this case only the inner repeating lines got reduced.

The bars will be drawn as shown below for the given heights:

1 -> |--|    2 -> |--|   3 -> |--|  etc...
                  |  |        |  |
                              |  |

If the given input shape in its reduced form does not fit underneath the bar then the bar will be drawn on the ground like this |__|

Exmaples

Inputs:

a. height: 3      b.  height: 2     c.  height: 1
   shape: xxx         shape: xxx        shape: (emptystring)
          xxx                xxx
          xxx                xxx
          yyy                yyy

Outputs:

a. |--|           b. |  | xxx       c. |--| 
   |  | xxx          |__| yyy  
   |  | yyy

Notes

  1. You can assume only valid inputs will be given, handle invalid input however you want
  2. The input shape will be drawn 1 space after the bar, and the bottom of the input shape will always line up with the bottom of the bar.
  3. Extra whitespace after is fine as long as all the lines are properly aligned.
  4. If there is whitespace in the given input then that should be included in the output
  5. The shape will not necessarily always line up in a perfect rectangle as I drew it.

This is for code-golf so the answer using the fewest bytes wins.


Please let me know what you think / if anything is unclear and needs to be improved. Hope you guys like it!


EDIT: Would whoever down voted please explain whats wrong with it?

\$\endgroup\$
  • \$\begingroup\$ I'm not the voter, but I'd bet they voted because what you have right now is very difficult to understand. I had to read this three times to figure out what you wanted. It may be worth revisiting the concept of "leaning over" as it is deeply unintuitive to me at the moment. On top of that, this requires a lot of "boring" golfing for the required output format when true/false seems to be basically the same. I hope this is helpful! \$\endgroup\$ – FryAmTheEggman Jan 20 at 20:24
  • \$\begingroup\$ @FryAmTheEggman Hmm, I thought I'd explained it fairly clearly - its just removing any lines that form a repetitive pattern, but I will try to update it. The output is slightly more than just T/F because of wanting to see the "limbo'ed" input shape with the shaved lines, and having to draw the bar different if it fails... though maybe that is what you meant by boring golf? \$\endgroup\$ – Quinn Jan 20 at 20:30
  • \$\begingroup\$ @FryAmTheEggman I tried updating the explanation, though I'm not sure if it is any clearer, please let me know if it makes more sense now \$\endgroup\$ – Quinn Jan 20 at 20:33
  • \$\begingroup\$ Explaining things is often harder than one would guess. Here I think a big problem is that your definition of bending is not what I would expect, so it makes the whole idea harder to grasp - particularly the rules about which repetitions happen first. Since I don't get the why I struggle to get the what. Maybe try explaining this to someone verbally to see if you can get rapid and direct feedback. What you have now is better, but I still think I'd have a hard time following on a first read. \$\endgroup\$ – FryAmTheEggman Jan 20 at 20:35
-1
\$\begingroup\$

Make a Decompiler Bomb

Similar to the Make a Compiler Bomb challenge, but backwards.

The goal is to create the a 1KiB (1024 bytes) or smaller bytecode file that creates the largest output when decompiled.

Constraints

  • A binary is either an x86 binary (in the form of an ELF file, PE file (.dll/.exe), or Mach-O binary) or a virtual bytecode file (e.g. Python .pyc, Java .class, .NET CLR, etc.)

  • The decompiler can be any public (preferably free) decompiler of your choice. (e.g Snowman/Hex-Rays for x86 binarys, CFR/Fernflower/etc. for java, dotPeek for .NET, uncompyle6 for Python, etc.)

  • A decompiler is any tool that takes a binary and attempts to reconstruct human readable source code from it.

  • The largest output byte count wins, with the smallest input size as a tie-breaker

  • The binary must be executable, and print "Hello World!"

  • The decompiled code must be syntactically correct

\$\endgroup\$
  • 4
    \$\begingroup\$ I think you probably want to specify what a "decompiler" is, since really any file is "binary" and anything that takes that and produces some valid code probably arguable counts as a decompiler. Further, I think you might be better served by limiting the binary size, like the original challenge, as if someone finds a way that adding \$n\$ bytes adds more than \$n^{2}\$ bytes to the output they would achieve an arbitrarily large score. \$\endgroup\$ – FryAmTheEggman Jan 17 at 20:06
  • \$\begingroup\$ @FryAmTheEggman I put in a basic explanation and made the scoring based on largest output rather than a formula. Explaining a decompiler is tricky though, I'll think about that more and maybe edit for it later. \$\endgroup\$ – famous1622 Jan 21 at 14:15
  • \$\begingroup\$ I think the scoring change you made is good, only that kb is a tad ambiguous between being 1000 or 1024, and that it seems a tad large (but neither of those is critical and the second is just my opinion). Thinking about what to do with the problem of defining a decompiler, I realised it was probably a good idea to require that the resulting decompiled code does something. Maybe requiring that the decompiled code is a hello world variant or something will limit some problems like "this program converts to Unary source code". \$\endgroup\$ – FryAmTheEggman Jan 21 at 16:27
  • \$\begingroup\$ @FryAmTheEggman Made it so the decompiled code must have correct syntax, and made the size smaller, was going to post my java example but I just realized I have to make it fit in the new restrictions so... \$\endgroup\$ – famous1622 Jan 21 at 16:46
-1
\$\begingroup\$

I delete the input, you delete the source code

This is a new twist on the long running series on CGCC.

Your task, if you accept it, is to write a program/function that outputs/returns the contents of an input file. The tricky part is that if I delete the input file, your program must delete itself.

Rules

  • The source code file and the input file should be in the same directory.

  • The input file and source file can be named anything at all. I.e. The file names are your choice.

  • The contents of the input file will be restricted to printable ASCII.

  • The input file and the source file must be deletable.

  • This is code-golf, so the shortest (original) code in each language wins!

  • Default Loopholes apply.

Example

If your program is jspwjxnlow8229 and the input file exists, the program must print the contents of the file. If the file doesn't exist, the program must delete itself.

Feedback

In regards to file manipulation, have I specified the rules enough?

\$\endgroup\$
  • \$\begingroup\$ What about languages in which programs don't live in files but rather in binary blobs? Is it enough for the program to delete itself from the binary blob? \$\endgroup\$ – Adám 2 days ago
  • \$\begingroup\$ Can the program and/or source file also be named anything at all? \$\endgroup\$ – Adám 2 days ago
  • \$\begingroup\$ @Adam, forgive me for not knowing, but what's a binary blob? \$\endgroup\$ – Lyxal 2 days ago
  • 1
    \$\begingroup\$ It doesn't matter what a binary blob is. I just wanted you to be aware than not all languages use the same model. \$\endgroup\$ – Adám 2 days ago
  • \$\begingroup\$ @Adam sure. I'll add a part about that to the challenge \$\endgroup\$ – Lyxal 2 days ago
  • \$\begingroup\$ Parts of this feel a bit unclear. Can the submissions know the file names in advance? (If not then the name feels a bit odd, isn't it really write a cat program that deletes itself if the input name doesn't correspond to an existing file? They aren't really tied together in that case) Similarly, why mention the recycling bin? It isn't present on many systems, and behaves differently on those that do have one (most programmatic deletions will require more work to send the file to the temporary "are you sure" location). \$\endgroup\$ – FryAmTheEggman 2 days ago

You must log in to answer this question.

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