567
\$\begingroup\$

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

Sandbox FAQ

Posting

To post to the sandbox, scroll to the bottom of this page and click "Answer This Question". Click "OK" when it asks if you really want to add another answer.

Write your challenge just as you would when actually posting it, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

When you think your challenge is ready for the public, go ahead and post it, and replace the post here with a link to the challenge and delete the sandbox post.

Discussion

The purpose of the sandbox is to give and receive feedback on posts. If you want to, feel free to give feedback to any posts you see here. Important things to comment about can include:

  • Parts of the challenge you found unclear
  • Comments addressing specific points mentioned in the proposal
  • Problems that could make the challenge uninteresting or unfit for the site

You don't need any qualifications to review sandbox posts. The target audience of most of these challenges is code golfers like you, so anything you find unclear will probably be unclear to others.

If you think one of your posts requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

It is recommended to leave your posts in the sandbox for at least several days, and until it receives upvotes and any feedback has been addressed.

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

To add an inline tag to a proposal, use shortcut link syntax with a prefix: [tag:king-of-the-hill]. To search for posts with a certain tag, include the name in quotes: "king-of-the-hill".

\$\endgroup\$
0

4472 Answers 4472

1
143 144
145
146 147
150
-2
\$\begingroup\$

Feedback Wanted

  • Is this too vague? should I change it to something like "create a quine with the fewest unique bytes", or perhaps adapt another existing challenge that might otherwise use lots of repeated bytes?
  • Maybe the idea is just too boring on its own and I should create a new proper challenge based around it?
  • Should I change the scoring system (votes - unique_bytes) - should it be divided instead, or use a more complex formula?

Introduction

This is , but not as you know it. Instead of every byte, This is sort-of also a question.

Challenge

Write an interesting program that uses the fewest unique bytes. This is not really about what the program does, but what you can do with a limited set of characters.

Rules

  • Your program must run on Try It Online
  • Programming languages with only a few permissible bytes anyway like Brainfuck's +-.,[]<>, are allowed, but officially considered boring

Apart from this, you can write anything.

Scoring

  • Hybrid of and "fewest-unique-bytes". Score is calculated as votes - unique_bytes
  • Unique bytes is based on bytes, not characters or whatever. You can calculate unique bytes using this Python snippet: len(set(b"your code here"))
\$\endgroup\$
4
  • 4
    \$\begingroup\$ It's definitely too vague. "Interesting" could mean anything, and you'd have to argue with several people over whether their ignore-input-and-print-0 program counts as interesting before the challenge is closed as too broad or unclear. [popularity-contest] is also a dangerous tag, in that it's very hard to do well and has fallen out of favor long ago. This extends to all scoring systems that involve votes. \$\endgroup\$
    – Zgarb
    Aug 21, 2020 at 19:33
  • 1
    \$\begingroup\$ I think this idea has been largely covered by Fewest (distinct) characters for Turing Completeness. Many languages require surprisingly few characters to run arbitrary code, so I expect there's not much interesting room for specific programs that use fewer characters than needed for that. \$\endgroup\$
    – xnor
    Aug 21, 2020 at 22:39
  • 1
    \$\begingroup\$ As far as I remember, there exists a Lenguage quine (that uses only 1 unique byte). I think combining popularity-contest with something else is even worse than simply using popularity-contest. \$\endgroup\$ Aug 22, 2020 at 3:00
  • 1
    \$\begingroup\$ For future reference, start your sandbox entries with the title of your challenge rather than a generic "feedback wanted". It's the prevailing convention and doing something different is a little confusing to scroll past. \$\endgroup\$
    – Beefster
    Aug 24, 2020 at 16:18
-2
\$\begingroup\$

Solving P=NP!

Today, we are going to solve P=NP, kinda...

Input

A guaranteed prime positive integer, P.

Output

The smallest composite number (NonPrime,NP) which sum of digits equals P.

Examples

Input (P)    Output (NP)      Why? (for reference)
  2              20          2+0=2 and 11 is prime
  3              12                 1+2=3
  5              14                 1+4=5
  7              16                 1+6=7
  11             38          3+8=11 and 29 is prime
  13             49                 4+9=13
  17             98          9+8=17 and 89 is prime

Check OEIS A073868 for more results.

Challenge

Write a function or program that, given a positive prime number P as input, calculates NP, the smallest composite number which sum of digits equals P.

  • Range of input: any integer prime number greater than 1, up to the limit of the chosen language.
  • Range of output: also according to the limits of the chosen language.
  • Means of input/output: free to choose.

Winning condition

This is a challenge. The shortest code wins!

Tags

Meta

I have searched if this was already posted, but with no success.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ To me, this isn't all that interesting of a challenge because it's a mash-up of "find a number whose digit sum is X" and "check if a number is prime." If a language has a built-in for primality, it's done. If not, it's still been done over and over again. The fact that the input is prime doesn't really add anything here for me. And skipping over primes as possible answers doesn't either. Why not do "find the smallest number whose digits add to X?" or "Find the Yth number whose digits add to X" where both x and y are inputs? \$\endgroup\$
    – Xcali
    Dec 23, 2020 at 20:37
  • \$\begingroup\$ The challenge itself looks to be well specified but I dislike the title. I'm all for using clever/controversial titles to attract attention, but not at the expense of accurately conveying what the challenge is about. \$\endgroup\$
    – Dingus
    Jan 1, 2021 at 1:38
-2
\$\begingroup\$

English Grammar Checker

Being tired of checking English grammar, I decided to write an English grammar regular expression.

Notations

  1. All capital letters denote an expression.
  2. Quoted strings (like "a") and lower-case letters denotes literals.
  3. AB means concatenating expressions / literals A and B together.
  4. (...) groups the expression inside the parentheses, as a whole expression.
  5. A* means repeating the expression A zero or more times.
  6. A? means the expression A is optional here.
  7. A|B means either A or B can be placed here.
  8. A=B means all expression A should be replaced by B.

Grammatical Rules

Parts of Speech

For simplicity, all parts of speech are substituted using symbols.

Symbol Part of Speech
a article
b verb
j adjective
m numeral
n noun
r pronoun
v adverb

Rules

There's a whole bunch of rules in English grammar. For simplicity, I only chose a tip of the iceberg. Your RegEx should only match all valid S's.

  1. S=N+V
  2. N=((a|m)?j*n(pN)?)|r
  3. V=b((pN)*|N)?v?

Examples

These should be matched Real-life example
anb The man runs
rbpajjnv He dives into the deep blue sea quickly
anpanbpr The wave on the sea came towards me
mnpambv Two friends of the man walks slowly
anpmjjnbajjnv The robot of two tall thin girls greets the young handsome man repeatedly
These shouldn't be matched Real-life "wrong" sentences example
nn Man child
nabr Student a told me
arbv The you laughed happily
anbvv The woman sang slowly beautifully
rbvj He is very funny

Notice that the last example is a valid English sentence, but it doesn't match our simplified rules. You shouldn't match them.

Tips

You can assume that there's no whitespaces and line feeds in the input.

You can assume that you only need to match 1 input per time.

You can use any RegEx dialects no newer than this challenge.

Scoring

Your score is the bytes in your RegEx. Flags are not counted.

The least score wins!

\$\endgroup\$
18
  • 3
    \$\begingroup\$ Are you sure that this grammar is really decidable with a regex? \$\endgroup\$
    – DELETE_ME
    Feb 19, 2021 at 9:12
  • \$\begingroup\$ YES @user202729 and I've already made one; but not decided to make it public yet. \$\endgroup\$
    – atzlt
    Feb 19, 2021 at 9:14
  • \$\begingroup\$ It's better if you explain what format the rules are specified in. (while I can understand it, it isn't obvious) The standard is Backus-Naur form I guess? \$\endgroup\$
    – DELETE_ME
    Feb 19, 2021 at 9:20
  • \$\begingroup\$ Any dialect restriction? \$\endgroup\$
    – DELETE_ME
    Feb 19, 2021 at 9:21
  • \$\begingroup\$ I wrote the format for rules in Notation section; is it unclear? \$\endgroup\$
    – atzlt
    Feb 19, 2021 at 9:22
  • \$\begingroup\$ Originally I overlook that = can be recursive and I can't find capital N in the table. \$\endgroup\$
    – DELETE_ME
    Feb 19, 2021 at 9:24
  • \$\begingroup\$ Err, yes, but I don't have good ideas about how to explain ='s. It's just kind of, substitution? But it can be recursive? Anyone have ideas? \$\endgroup\$
    – atzlt
    Feb 19, 2021 at 9:26
  • \$\begingroup\$ Perhaps you can show an example of a simple (recursive) pattern matching a simple string. \$\endgroup\$
    – DELETE_ME
    Feb 19, 2021 at 9:30
  • \$\begingroup\$ Not sure if you're asking an example regex matching a recursive rule. For A=(yA)|x using the same notation, regex: y*x. \$\endgroup\$
    – atzlt
    Feb 19, 2021 at 9:37
  • \$\begingroup\$ Does "without flags" mean ", flags are not counted"? That sentence can be interpreted as "regex flags are not allowed" too. \$\endgroup\$
    – DELETE_ME
    Feb 20, 2021 at 8:44
  • 2
    \$\begingroup\$ English grammar is not regular and cannot be matched with a regular expression. At best, you can tease out some subset that is context-free, but realistically, this is not a good challenge as it is written. Natural languages tend to be riddled with all sorts of crazy complexity that makes them highly context-sensitive and possibly undecidable. \$\endgroup\$
    – Beefster
    Feb 22, 2021 at 16:55
  • 1
    \$\begingroup\$ @Beefster As I wrote in the challenge you should only match the simplified "rules", as in section Rules. There're only 3 rules. As I commented before I already wrote a regex that can match these rules, so the challenge is absolutely solvable. \$\endgroup\$
    – atzlt
    Feb 23, 2021 at 2:54
  • \$\begingroup\$ @Beefster And op did do that. (op claim that the chosen subset is context-free, but I didn't verify it) \$\endgroup\$
    – DELETE_ME
    Feb 24, 2021 at 3:52
  • \$\begingroup\$ @user202729 if you want to verify, <S> ::= <N><V>, <J> ::= "j"<J> | "", <N> ::= "r" | "a"<J>"np"N | "a"<J>"n" | "m"<J>"np"N | "m"<J>"n" | <J>"np"N | <J>"n", <P> ::= "p"N<P> | "", <V> ::= "b" | "bv" | "b"<N> | "b"<N>"v" | "b"<P> | "b"<P>"v". Really verbose. \$\endgroup\$
    – atzlt
    Feb 24, 2021 at 4:08
  • \$\begingroup\$ Even with this limited subset, reducing it to a regex really only has one optimal approach and isn't particularly interesting in lending itself to many different approaches. \$\endgroup\$
    – Beefster
    Feb 24, 2021 at 16:31
-2
\$\begingroup\$

Given a positive even integer \$n\$, generate a random Brainfuck snippet of length \$n\$, containing only +-<>, that do no modify to the tape or tapehead.

To avoid random generation and try again or fallback into a trivial nop for invalid nops, your solution should run in polynomial time, and the ratio of possibility returning any two nops should be below polynomial.

\$\endgroup\$
-2
\$\begingroup\$

Solve any NPC problem. Shortest code win.

Sandbox Notes

  • Will every submission tend to single NPC problem?
  • How many builtins are known to solve this in Mathematica?
  • Do 0-byte solution exist?
\$\endgroup\$
3
  • 3
    \$\begingroup\$ I think this is too broad to be a good challenge \$\endgroup\$
    – pxeger
    May 4, 2021 at 12:44
  • \$\begingroup\$ Dyalog Extended can solve it in two bytes: ⌂X (Knuth's X algorithm which solves the Exact Cover problem). \$\endgroup\$
    – Bubbler
    May 6, 2021 at 8:59
  • \$\begingroup\$ @Bubbler Lots of language will have builtin for this question I guess \$\endgroup\$
    – l4m2
    May 6, 2021 at 17:45
-2
\$\begingroup\$

Compress La Campanella.

Notice that music theory may give you more rules than general compress give, but I don't know music theory that much, so I won't post this

\$\endgroup\$
-2
\$\begingroup\$

Self-Obfuscator Program

According to Wikipedia,

obfuscation is the deliberate act of creating source or machine code that is difficult for humans to understand.

In this challenge, you need to create a program that'll be able to obfuscate itself and produce a program with the same functionality, using the shortest amount of bytes required.

Rules

  • Standard loopholes are prohibited.
  • The output must always be consistent for each input. If you take the original code (iteration 0) and run it through itself 10 times to get a very long obfuscated code (iteration 10), running the initial code through it should give a code identical to iteration 1 code.
  • The output must be at least twice as long from the input for each iteration.

Obfuscated, not verbose

  • The obfuscation process must make the code longer, but it mustn't add any comments, no-op or no-effect statements, or any statements or expressions that don't directly affect the output code.
  • The output should have minimal resemblance to the input. No sequence of 5 bytes should repeat in the output.
  • The code must be able to obfuscate itself, obfuscations of itself from further ahead iterations and code from earlier iterations. It's not required to be able to obfuscate anything else.
\$\endgroup\$
2
  • 4
    \$\begingroup\$ Bonus in code golf is highly discouraged. And "the output should have minimal resemblance to the input" should be more rigorously defined. \$\endgroup\$
    – Bubbler
    Nov 13, 2021 at 23:19
  • \$\begingroup\$ The idea is fine, but you need more detailed and cleaner define about obsfucate and the meaning of statement that don't directly affect the output code \$\endgroup\$
    – okie
    Nov 22, 2021 at 8:43
-2
\$\begingroup\$

The number of alphabets in 3 seconds

In 3 seconds, output as many alphabets as possible. The output may be separated by consistent character.

An alphabet here is this:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

Meta

  • Is this clear?
  • I'm not really sure about the tagging.
\$\endgroup\$
2
  • \$\begingroup\$ This should be closed, because machine code can do this with a lot of "A" prints without loops and win. this is off-topic \$\endgroup\$
    – Fmbalbuena
    Jan 10, 2022 at 15:50
  • 1
    \$\begingroup\$ I don't think this is off-topic as it have a clear "objective winning criteria". But I am afraid that this question may be marked as a duplicate to codegolf.stackexchange.com/questions/215216/… \$\endgroup\$
    – tsh
    Jan 11, 2022 at 6:51
-2
\$\begingroup\$

TDG - Test Driven Golf

Our company requires unit testing before code can be deployed to production. Unfortunately, my code is written in esoteric programming languages, none of which have test runners.

Please help me get to production!

Challenge

Write a test runner for a programming language (here after called Language X) that takes Language X source code and Language X test cases then outputs the results of running the test cases.

NOTE: The language used to write the test runner does not necessarily have to be Language X.

Specification

Input

The runner should take in:

  • Code written in Language X
  • Test cases written in Language X

Output

The runner should produce:

  • At least a list of test cases. For each test case, include:
    • The test case name
    • A Truthy value if the code executes without errors and no assertions failed
    • A Falsey value if the code errors or an assertion failed

Test Runner

  • The test runner can be written in any language. The only constraint is that the source and test code language be the same
  • Each test runner must at least provide a helper/utility/function to assert that a value is truthy
    • Assert.True(false) => Fails test
    • assertTrue(1 == 3) => Fails test
    • is_truthy 1 => Doesn't fail
    • [[ "a" = "a" ]] => Doesn't fail

Test Cases

  • Each test case must have a name/be name-able
    • it("does stuff", _ => ...) => it does stuff
    • it_does_stuff = _ => ... => it_does_stuff
    • func ItDoesStuff() {...} => ItDoesStuff
  • A code block of language X code

Submissions

For consistency, here are some recommendations:

  • Title should be: # Language X runner written in Language Y
    • Where Language X is the source and test code language
    • And Language Y is the language the runner is written in
  • Runner code in a ## Runner section
  • Example input source code in a ## Example Source section
  • Example input test code in a ## Example Tests section
  • Example output in a ## Example Output section

Sandbox Questions

  • Is this challenge too board?
  • Is this challenge too big?
  • I've created some basic test runners in a single file before and with some elbow grease, I think you could say small (submit-able on CGCC) and add a few nice things
  • Does fit here?
  • Is there room for creativity?
    • The testing syntax and features for the test cases are left up to the implementation
      • How golf-able the test syntax is
      • How the code and test cases interact
      • What asserts/helpers are provided
      • Syntax for skipping test cases
      • Syntax for beforeEach/afterEach
      • Harder features like parameterized tests and fixtures are possible
    • Similarly, the features for the test runner are left pretty open ended
      • TAP output
      • JUnit output
      • Test isolation and parallelization
      • Harder features like specific failure messages and code coverage aren't impossible
\$\endgroup\$
4
  • \$\begingroup\$ "Input: Source code written in language X, Test cases written in language X" I don't understand. Are we providing the input to our own programs? Or are we meant to detect the language? \$\endgroup\$ Jan 21, 2022 at 20:02
  • \$\begingroup\$ This doesn't make sense as a pop-con, there's very little room for creativity \$\endgroup\$ Jan 21, 2022 at 21:55
  • \$\begingroup\$ @thejonymyster, I've added some clarity (hopefully). The test runner should be for testing a specific language (no detecting) and it would take in some code (not it's own source) and some tests in that language. \$\endgroup\$ Jan 22, 2022 at 2:31
  • \$\begingroup\$ @cairdcoinheringaahing, there is a fair spectrum of test runners and testing syntaxes out there. So I was thinking there was some room for creativity (especially since I don't think any of them are made for golfing). I've added some comments to that end. I couldn't think of a better tag \$\endgroup\$ Jan 22, 2022 at 2:37
-2
\$\begingroup\$

Alternate brackets

Given a matched string containing only ()[]{}, apply the following:

  • If [] is next to () or {}, replace the () or {} with [].
  • If a () follows [] or {}, remove the ().

Test cases

()[]{} => [][][]
{}(){} => (){}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ This doesn't have a scoring criterion, and is also in need of some more explaining - if we have [](), which rule should apply?- The first is second? Your second test case also makes no sense as it doesn't follow either of the rules... \$\endgroup\$
    – Lecdi
    Apr 1, 2022 at 9:05
-2
\$\begingroup\$

Task

Make a program that finds the first IP address that responds to pings after a certain IP address.

Requirements

Your program should take an IP address as a string in the form xx.xx.xx.xx. It should find the first IP greater than the input (incrementing least significant byte first) that responds to pings, and output it in the form xx.xx.xx.xx.

Scoring

This is code-golf, so shortest answer in bytes wins.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ This... feels morally unsafe. Although responding to a ping is generally not-malicious, IP scrapping doesn't feel right to me. \$\endgroup\$
    – ATaco
    May 19, 2022 at 2:24
-2
\$\begingroup\$

Write a program on any language that accepts some input and give some different output. The challenge is that the text of the program must form a square: all rows must be the same length and the number of rows must equal the number of columns (ie length of rows). Adding extra spaces, dead code, or comments to pad lines is not allowed.

This is Code Golf so the one with the shortest functioning program (ie smallest square) wins!

\$\endgroup\$
2
  • \$\begingroup\$ First I would recommend adding title using # markdown. Then adding tags code-golf and source-layout using [tag:name] markdown. Also you should probably specify output a bit better. Does it need to be different for every input or can it be always same? Also in some programming languages spaces are actually instructions. \$\endgroup\$
    – Jiří
    Aug 7, 2022 at 20:37
  • \$\begingroup\$ I believe a square code challenge has been done. Also, this is ultimately about the features of the language rather than any particular skill of the programmer. The minimum score is the length of whatever the language's equivalent of "print" is. \$\endgroup\$
    – Xcali
    Aug 8, 2022 at 2:28
-2
\$\begingroup\$

Self-Debugger.

Suddenly, someone comes and deletes a character from the program. From analyzing the output and error messages (if any), you quickly know which character was deleted.

Your job is to create a function that does this. For every character deletion, you will get one point if feeding the output and error message(s) to the undamaged function does not give the correct deleted character. You attempt to minimize the score of your program. Your program must have a function, i.e. if must not be empty.

Default loopholes forbidden, as always.

Example program:

lambda a,aa:'a'

Score: the program is not correct when we take away a character that is not a. Thus, the score is 9. (We intend to minimize this score.)

\$\endgroup\$
14
  • \$\begingroup\$ Meta: we need tags!!! \$\endgroup\$ Aug 26, 2022 at 7:48
  • \$\begingroup\$ Why even take the stdout as input? What could you possibly do with this info that would improve your score? \$\endgroup\$
    – mousetail
    Aug 26, 2022 at 8:34
  • \$\begingroup\$ stdout could be useful \$\endgroup\$ Aug 26, 2022 at 9:57
  • \$\begingroup\$ The entire second paragraph makes no sense to me \$\endgroup\$
    – mousetail
    Aug 26, 2022 at 10:48
  • \$\begingroup\$ Ouch, let me explain it a bit more \$\endgroup\$ Aug 26, 2022 at 10:56
  • \$\begingroup\$ Done, @mousetail \$\endgroup\$ Aug 26, 2022 at 14:00
  • \$\begingroup\$ Ok I see what you are going for, fix the name and remove the first sentence though since they have nothing to do with the challenge \$\endgroup\$
    – mousetail
    Aug 26, 2022 at 14:01
  • \$\begingroup\$ Now?sdkvwoefjowejfojweojfowepjfpowejpofwe \$\endgroup\$ Aug 26, 2022 at 14:06
  • \$\begingroup\$ I'd name it what the challenge actually is "from the output and error determine what character was removed from your code" \$\endgroup\$
    – mousetail
    Aug 26, 2022 at 14:08
  • \$\begingroup\$ But I think it is too long \$\endgroup\$ Aug 26, 2022 at 14:09
  • \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$ Aug 26, 2022 at 14:09
  • \$\begingroup\$ Dupe of this? \$\endgroup\$ Aug 26, 2022 at 14:10
  • \$\begingroup\$ No. We give the unradiated program the output and error of the radiated program. \$\endgroup\$ Aug 26, 2022 at 14:18
  • \$\begingroup\$ Ohh so it's more of a narcisist type thing, that makes sense. Interesting \$\endgroup\$ Aug 26, 2022 at 18:40
-2
\$\begingroup\$

🤖 Robotics competition

You're entering a robotics competition! There are 3 types of parts for you to choose for your robot: wheels, legs and sensors. A robot:

  • can have up to 8 parts in total
  • can only have 4 legs
  • must have at least 2 parts
  • must have at least one leg or one wheel

You can't decide what robot to build, so you'll just make all of the possible ones. How many robots will you build?

The challenge

Write a program which calculates the number of possible robots (the answer is 134). Shortest program wins.

The output of your program can be its return code. The program needn't take any input (undefined behaviour if input is provided).

Bonus swag points for a point-free solution in APL 😉

Example

A non-competitive python example:

from itertools import chain, combinations_with_replacement

options = list(filter(
    lambda option: \
        len(option) >= 2 and \
        option.count('leg') <= 4 and \
        (option.count('leg') + option.count('wheel') > 0),
    chain(*(combinations_with_replacement(('leg', 'wheel', 'sensor'), j) for j in range(9)))
))

for option in options:
    print(option)
print("Number of valid options: {}".format(len(options)))

META

  • Is the question original enough, or has there been any challenges like this
  • Is the python example a useful thing to include?
\$\endgroup\$
2
  • \$\begingroup\$ Seems like print(134) would be a valid answer. Challenges that require no input need to be careful to be more difficult than just printing the answer. Limiting answers to just one specific strategy is also discouraged since it reduced the creative freedom and subjective rules are annoying when trying to get the best possible answer. \$\endgroup\$
    – mousetail
    Sep 7, 2022 at 11:45
  • \$\begingroup\$ @mousetail thanks for the input! :)) i'll have a think on how to modify the challenge and see if i can make it work. cheers. \$\endgroup\$ Sep 7, 2022 at 11:52
-2
\$\begingroup\$

ABACABA pattern without recursion

ABACABA pattern on Wikipedia

Taking a number n as input, generate the ABACABA pattern with n symbols as stated in the above page, without using any form of recursion in your code. You can use any output method; characters, a list of numbers, an image, whatever is possible.

If taking input is not possible in your programming language, output the pattern forever. E.g.: ABACABADABACABAE...

Test cases:

input => output

1 => A / 1
2 => ABA / 1, 2, 1
3 => ABACABA / 1, 2, 1, 3, 1, 2, 1
4 => ABACABADABACABA / 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1
5 => ABACABADABACABAEABACABADABACABA / 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1
```
\$\endgroup\$
3
  • \$\begingroup\$ Please add some information on what exactly the ABACABA pattern is. \$\endgroup\$
    – Ginger
    Jan 7 at 19:25
  • 1
    \$\begingroup\$ Also, "no recursion" is an unobservable requirement. \$\endgroup\$
    – Ginger
    Jan 7 at 19:26
  • \$\begingroup\$ Related \$\endgroup\$
    – l4m2
    Jan 13 at 4:56
-2
\$\begingroup\$

Detect if a variable is declared

Create an expression which detects if a variable (named whatever you wish) has been declared yet. For languages that set undeclared variables to a type that can not be differentiated from a declared variable set to that type (e.g. nil in Lua), just detecting that type is enough. If the variable exists, the expression should return a truthy value, and if it doesn't it should return a falsy value. It should not output anything.

For example, the following expression in D detects if a variable named x has been declared in the current scope or not:

__traits(compiles, x)

PS: this challenge definitely wouldn't work for stack-based or assembly languages, and I'm also not sure if marking this as code-golf or popularity-contest would be better.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ code-golf is nearly always better. popularity-contests are really hard to write properly. Also, note that some stack based languages do have variables \$\endgroup\$
    – Seggan
    Jan 21 at 22:57
  • \$\begingroup\$ For languages that set undeclared variables to a type that can not be differentiated from a declared variable set to that type (e.g. nil in Lua), just detecting that type is enough. What does this mean? Are you saying a variable with a value of nil should return false, and a variable with a value of anything else should return true? If so, there are probably better ways to word it. \$\endgroup\$
    – chunes
    Jan 23 at 7:04
-2
\$\begingroup\$

PHPFuck Golf - Hello World

Like this

PHPFuck is an esoteric language in which any PHP statement can be accurately reproduced into another valid PHP program that uses only the 5 characters (^.9).

The PHPFuck converter, when given an input of echo "Hello World!", produces a block of code that is 74,450 characters long. Because the program used a lot of automatic conversions to create that block, I believe that the code can be made a lot shorter using manual optimizations.

Your task is to build a PHP program that performs the task echo "Hello World!", using only the characters (^.9). The shortest code to do so wins.

\$\endgroup\$
-2
\$\begingroup\$

Polishing off a Sudoku

Given a set of 8 numbers as input, output the missing one.

Examples

12346789 -> 5

94351726 -> 8

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I am fairly certain this is a dupe of a more general question. This was the first I could find, though I feel like there was one with an arbitrary range too. \$\endgroup\$
    – Giuseppe
    Feb 10 at 1:51
-2
\$\begingroup\$

Print the input times infinity

Make a program/function that prints the input of the function infinite times, separated be a line break. Do note that the output must be to stdout.
tags:

\$\endgroup\$
5
  • \$\begingroup\$ Might get marked as duplicate of Implement a truth-machine or Simple cat program \$\endgroup\$
    – noodle man
    Jun 14 at 22:41
  • \$\begingroup\$ Why? It endlessly returns the input with a newline regardless of what it is \$\endgroup\$
    – Dadsdy
    Jun 15 at 7:02
  • 1
    \$\begingroup\$ It’s not the same challenge, but I think it’s likely to be marked as a dupe of one of those since most answers to that can be easily ported to your challenge (this practice of handling duplicates is fairly common on this site) \$\endgroup\$
    – noodle man
    Jun 15 at 12:14
  • \$\begingroup\$ @noodleman Really? My answer (in (,)) was very different. \$\endgroup\$
    – Dadsdy
    Jun 15 at 18:18
  • \$\begingroup\$ Exact dupe restricted-source version fastest-code version \$\endgroup\$ Jul 19 at 3:57
-2
\$\begingroup\$

That is disproportionate!

You want to overwhelm your nasty boss with an error message so large that they quit their job. But your boss will fire you instead if it's too long.


Challenge

In this challenge, you have to write code that is more than 0 bytes long that produces the longest error message possible.

Scoring

Answers will be scored using this formula: $$\frac{\text{Error message length in bytes}}{\text{Programme length in bytes}}$$

Other

All answers must include the answer score, source code and error message.



Meta

  • Is this a duplicate?
  • Any other appropriate tags?
  • Anything else?
\$\endgroup\$
1
-2
\$\begingroup\$

KCMCK

Print this ASCII art:

  +--------------  +-+                   +-+   +--------------  |
 ++                | |                   | |  ++                |
 |                 |  \                  / |  |                 |
 |                 |   \                /  |  |                 |
 |                 |    \              /   |  |                 |
 |                 |     \            /    |  |                 |
 |                 |      \          /     |  |                 |
 |                 |       \        /      |  |                 |
 |                 |        \      /       |  |                 |
 |                 |         \    /        |  |                 |
 ++                |          \  /         |  ++                |
  +--------------  |           \/          |   +--------------  |
________________________________________________________________|
________________________________________________________________|

Shortest code in characters wins!

  • Any leading whitespace must be the same on every line.
  • No restrictions on trailing whitespace.
\$\endgroup\$
-2
\$\begingroup\$

Be a cat

I have not found a single challenge that asks for a plain cat programme. The closest I have found requires you to print cat goes meow when the input is cat.


In this challenge, you must read everything from STDIN, or an acceptable alternative, and print the exact text to STDOUT, or an acceptable alternative, with only the leading and trailing whitespace in the input.


Meta

  • Have I been so silly that I missed a duplicate?
\$\endgroup\$
1
-2
\$\begingroup\$

Type annotation

Given a function definition and a list of types, both valid in your language, output the function annotated with those types. Shortest code wins, since this is .

Meta

  • Is it a duplicate?
  • How should I include languages without type annotation support?
  • Does it need to be explained better?
  • Anything else?
\$\endgroup\$
-2
\$\begingroup\$

Execute... yourself!

Almost a duplicate, but only requires you to compile a subset, and is closed.


You work at a compiler factory, making compilers tailored to your customers.


Challenge

In a programming language of your choice, write a program that executes code in the chosen language. Snippets are allowed, but you may not hardcode the input.

This is , so shortest code wins!


Meta

  • To deal with languages like No, should I change it to a , or disallow languages like that completely?
  • Is it clear enough?
  • Are there any unclosed challenges this duplicates?
  • Anything else?

\$\endgroup\$
2
-3
\$\begingroup\$

Code-challenge: Guess my number

The challenge

You have a number from 1 to 10 in mind, and your program should ask questions to find out which number. These questions can be any questions, the program only has to find out the number as fast as possible.

Your program should ask a question, such as "Is the number a prime?", and the user must answer either y or n (yes or no). Ask questions until you know the number.

The scoring

To calculate the score, you need to take the sum of the question count for each number. For example, if you need 1 question to find the number 1, 2 questions to find the number 2, and so on, the score is 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, so the score is 55.

Important note: the question count for a specific number must always be the same. For example, if you need 4 questions to find out the number 10, then you have to ask always 4 questions to find out the number 10, otherwise it is impossible to calculate the score.

\$\endgroup\$
3
  • 6
    \$\begingroup\$ boooring. The Huffman tree for a uniform set is any perfectly balanced tree. The question asks us to perform a binary search on the usr device. Is the number greater than 5? Is the number greater than 2? Is the number greater than 1? Hey' I think it's 1. \$\endgroup\$ Jan 2, 2014 at 11:49
  • 3
    \$\begingroup\$ Maybe if this were a pop-contest and the goal was to make the most original set of questions while still keeping the score at its theoretical minimum. \$\endgroup\$ Jan 3, 2014 at 5:28
  • \$\begingroup\$ This is off-topic and AI is off-topic for this site \$\endgroup\$
    – Fmbalbuena
    Nov 12, 2021 at 17:39
-3
\$\begingroup\$

Popularity Contest: Implementation of a Hash Table

Create a class in some OOP language for a hash table that supports getting, setting, and removing values. You can't use the built in hash table/dictionary/map implementation. Highest votes in one week wins.

A key is any valid string. A value is any valid string, number, or boolean.

Example functionality:

hash.set("key","value");
hash.get("key"); // returns "value"
hash.set("key", 1234);
hash.get("key"); // returns 1234
hash.set("key2",hash.get("key"));
hash.get("key2"); // returns 1234
hash.delete("key");
hash.get("key"); // returns null/undefined/none/etc. or throws an error
hash.get("key2"); // still returns 1234

Definition of a hash table (from Wikipedia):

In computing, a hash table (also hash map) is a data structure used to implement an associative array, a structure that can map keys to values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the correct value can be found.

The hash table cannot be simply an array that is searched in linear time. It must be an actual hash table that uses a hash function to map the keys to the value.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Popularity contest and shortest don't mix. That aside, the spec is too vague. What is a "value"? What assumptions can be made about hashcodes? If the language makes all types nullable, should null be permitted as a key? What should the type be in languages which have co- and contravariance? And for that matter, what qualifies as a "hash table", bearing in mind that people will try to exploit any loophole? \$\endgroup\$ Jan 2, 2014 at 23:16
  • \$\begingroup\$ @PeterTaylor Thank you for the feedback! Please see my edits, and let me know what you think. Could you meant about co/contravaraince? I looked at the wikipedia article about it but I'm not really sure how that has anything to do with this question. \$\endgroup\$
    – hkk
    Jan 2, 2014 at 23:37
  • \$\begingroup\$ I think it's still vulnerable to the loophole of "I have a hashtable with one bucket" (i.e. it's really a list of (key, value) pairs which I traverse in linear time). The thing about variance is to do with static typing of the elements of the map. E.g. in Java Map<String, Integer>'s get method has signature public Integer get(Object); in C#, a Dictionary<string, int>'s Get method has signature public int Get(string). The edited version makes it clear enough that the hashtable isn't expected to be genericised. \$\endgroup\$ Jan 3, 2014 at 0:08
-3
\$\begingroup\$

Bovine Ignorance

I'm curious about code which still works after being mangled by figlet, toilet, cowsay et al, but I'm not sure whether this in any way sane.

What I'm toying with is a challenge in which a participant may submit any program in any language. It should be possible to use this program's source code as input to cowsay or whatever, and the result should be another valid program in any language, which still does a similar thing. For instance, the following bf program prints Hello world! with no newline:

+++++ +++++
[
> +++++ ++
> +++++ +++++
> +++
> +
<<<< -
]
> ++ .
> + .
+++++ ++ .
.
+++ .
> ++ .
<< +++++ +++++ +++++ .
> .
+++ .
----- - .
----- --- .
> + .
+++++++++++++++++++++++++++++++++++++++++

Running cat ./prog.bf | cowsay -e .. -T $'>.' yields the following output:

 _________________________________________
/ +++++ +++++ [ > +++++ ++ > +++++ +++++  \
| > +++ > + <<<< - ] > ++ . > + . +++++   |
| ++ . . +++ . > ++ . << +++++ +++++      |
| +++++ . > . +++ . ----- - . ----- --- . |
| > + .                                   |
| +++++++++++++++++++++++++++++++++++++++ |
\ ++                                      /
 -----------------------------------------
        \   ^__^
         \  (..)\_______
            (__)\       )\/\
             >. ||----w |
                ||     ||

Which is itself a valid bf program which prints Hello world!!!, followed by a newline.

The problem with using bf here is that it ignores most of the cow, making this a bit too easy. The problem with using any other language is that it doesn't ignore most of the cow, making this far too difficult. Is there a sensible middle ground I could pick for this? I don't think it's impossible, I'm fairly sure you can exploit cowsay's behavior on one-liners to produce valid svgs, but I'm not sure how best to pose this challenge. Any ideas?

\$\endgroup\$
6
  • 2
    \$\begingroup\$ I could not think of any language that falls in the middle ground. Even brainfuck is affected by the -----------------------------------------..>.---- inserted by cowsay. Most languages have strong parsing rules that would not cope with being post-processed by cowsay. The few exceptions for this will be either completely unaffected or badly affected, making the challenge uninteresting. \$\endgroup\$ Feb 19, 2014 at 12:32
  • \$\begingroup\$ Actually, you can't transform just any brainfuck program to cowsay-brainfuck. Namely those that can output fewer than three characters cannot be transformed at all. \$\endgroup\$ Feb 19, 2014 at 14:52
  • \$\begingroup\$ @JanDvorak, I was intending to allow competitors to choose the parameters of their calls to cowsay. For the uninitiated, -e controls the string used for eyes and defaults to oo, and -T controls the string used for the tongue, defaulting to ` U`. This is all yak-shaving, though, and having written this up and read the comments, I suspect that this idea has neither legs, horns nor udders. \$\endgroup\$
    – ymbirtt
    Feb 19, 2014 at 23:19
  • 2
    \$\begingroup\$ If I could propose a variant that is more feasible, you could do a challenge like "Write a program in your language of choice that draws ASCII art of a cow saying something (does not have to be identical or even similar to the cowsay art). The entire drawing must itself be valid source code that does something other than no-op. Post results of both programs." That gives people more leeway to work around the specific restrictions of their compiler. \$\endgroup\$ Feb 21, 2014 at 23:22
  • \$\begingroup\$ Ok, I found a language that falls within the middle ground: whitespace. Anyway, this question has a too narrow scope to develop an interesting challenge. \$\endgroup\$ Feb 22, 2014 at 18:31
  • \$\begingroup\$ @JonathanVanMatre That would be a subjective validity criterion, and would probably be closed as too broad. \$\endgroup\$
    – wastl
    Jul 2, 2018 at 13:55
-3
\$\begingroup\$

99 Bottles of Errors

While there are already many versions of "print 99 Bottles of Beer," I thought another one wouldn't hurt.


The challenge is fairly simple: print the lyrics to 99 bottles of Beer to STDERR. I don't care how you do it, so long as the entire lyrics show up. An entire program is required, so the following Java program would be invalid (even if it did do the correct thing):

System.out.println("99 Bottles of Beer on the Wall, take one down and pass it around...");

The scoring:

  • This challenge is , so shortest code by byte count wins.
  • If necessary, assume UTF-8 is the character encoding used.

The rules

  • All the code must be in one file.
  • Any language is allowed.
  • Reading input, whether it is from STDIN, a file, or the web, is not allowed.
\$\endgroup\$
1
  • 6
    \$\begingroup\$ This is trivial in some languages (Java), where it reduces to a simple kolmogorov challenge, and impossible in others (those that have no distinct STDERR) \$\endgroup\$ Mar 27, 2014 at 7:42
-3
\$\begingroup\$

Create an Identicon Generator

The challenge is to create an identicon generator. The identicons must be randomly generated, so we get a new identicon for each key the program receives. You can input a key using std-in or you can use your language's random number generator for the key.

In order to make your identicon look reasonably nice, it must generate a picture, then rotate that picture around the bottom right corner, the way this mockup shows:

enter image description here

The output must be to a PNG file. Shortest code wins.

\$\endgroup\$
3
  • 5
    \$\begingroup\$ Far too broad. As this stands I can create a 1-pixel image whose colour is just the key. I don't think this question will be ready to go until you've found a way to prevent me from making the images differ only in their palette (and to pre-empt, I think that adding a rule "Images may not differ only in their palette" isn't a real fix). \$\endgroup\$ Mar 28, 2014 at 14:50
  • 5
    \$\begingroup\$ If you just ask for "random" images, you'll get images that are either hardly random at all (a solitary pixel in a random location), or completely random (noise). To get something "reasonably nice", you'll have to provide very clear instructions on how to produce these images. I suggest you try creating a few of these yourself, and find a minimal set of rules that produces results that look OK. Include requirements on dimensions (100x100px?), selection of colours (at least 2, not too similar), and drawing method (e.g., "five triangles with random vertices and a minimum area of 20 px²"). \$\endgroup\$
    – r3mainer
    Mar 28, 2014 at 15:25
  • 1
    \$\begingroup\$ How important is the PNG file output? This will be a challenge in itself for many languages. Would you accept an uncompressed non-interlaced format like PPM? \$\endgroup\$ Apr 16, 2014 at 9:45
-3
\$\begingroup\$

Shortest Program that May or May not Terminate:

Write a program such that whether or not it terminates depends on the answer to an unsolved question in Computer Science or Mathematics. For example, your program might test the Goldbach conjecture for every N and quit if a counterexample is found, or hunt for odd perfect numbers. Please include an explanation of why your program may or may not terminate!

Note: assume infinite memory and stack size, because otherwise they all terminate. Your program must be self contained, take no input, and only use standard libraries. This is Codegolf, so shortest code wins!

\$\endgroup\$
6
  • \$\begingroup\$ What about "unsolvable" problems, e.g. halting problem? Can I take another code as input and terminate if that terminates? Because that other program may or may not terminate, and there's no way to tell. \$\endgroup\$ Nov 20, 2014 at 18:03
  • \$\begingroup\$ The intention was that the program isn't allowed to take input. I'll be more specific. \$\endgroup\$ Nov 20, 2014 at 18:50
  • 2
    \$\begingroup\$ Does this differ from this previous question in the sandbox? \$\endgroup\$ Nov 20, 2014 at 19:34
  • \$\begingroup\$ (even if not the comments explaining why that one wouldn't work as a question may help Taylor this one) \$\endgroup\$ Nov 20, 2014 at 19:35
  • \$\begingroup\$ The intent of this doesn't differ significantly from the question you linked, I searched posted questions but forgot to search the sandbox. \$\endgroup\$ Nov 20, 2014 at 19:41
  • \$\begingroup\$ Infinite memory isn't required. \$\endgroup\$
    – feersum
    Nov 20, 2014 at 21:46
1
143 144
145
146 147
150

You must log in to answer this question.

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