571
\$\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\$
1
  • \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$
    – None1
    May 15 at 14:05

4690 Answers 4690

1
150 151
152
153 154
157
-2
\$\begingroup\$

Wuhan Xi Estimates

Challenge
Create a program that takes two base-ten integer number inputs (w,x). The program should output the closest integer number that is x order of magnitude smaller than w, rounded downwards. The output should be zero if the result is less than 1.

Test cases

f(10,1) = 1
f(10,2) = 0
f(1000000, 3) = 1000
f(888, 2) = 8
f(99999, 4) = 9
f(7777777, 8) = 0
f(123455, 5) = 1
f(123455, 4) = 12345
f(123455, 0) = 123455

Example Code
Here's an ungolfed example in Lua:


b=io.read()
a,b=b:match("([^,]+),([^,]+)")

if (b+0 > #a) then 
    print(0)
else 
    d = (a+0)/(10^b)
    print (math.floor(d))
end

Try it online!

General rules

  • This is , so shortest code in bytes in its respective language wins.

  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN (with the specification above)/STDOUT, functions/method with the proper parameters and return-type, full programs.

  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code (TIO).

\$\endgroup\$
8
  • \$\begingroup\$ Can we take input as string where the two numbers are separated by "E-" ? \$\endgroup\$
    – Adám
    Jun 22, 2020 at 21:52
  • \$\begingroup\$ @Adám, Is "E-" executable code? If so, I guess that's fine, but it has to be part of the byte count. If it is just a glorified separator, or a switch of some kind, then yes and doesn't have to be included in the byte count. \$\endgroup\$
    – ouflak
    Jun 23, 2020 at 5:55
  • \$\begingroup\$ My idea what that one could do something like floor(input) where input is e.g. 888E-2 thus trivialising the challenge. \$\endgroup\$
    – Adám
    Jun 23, 2020 at 5:57
  • \$\begingroup\$ @Adám, That would be fine, and the challenge will have many 'trivial' answers in several languages. I'd be surprised if there isn't atleast a few 2/3 byte solutions. \$\endgroup\$
    – ouflak
    Jun 23, 2020 at 6:00
  • \$\begingroup\$ Maybe mention in the challenge text that this amounts to computing \$⌊w×10^{-x}⌋\$? \$\endgroup\$
    – Adám
    Jun 23, 2020 at 6:10
  • \$\begingroup\$ @Adám, There are other ways to look at it. My Turing Machine Code solution certainly won't be computing any powers. \$\endgroup\$
    – ouflak
    Jun 23, 2020 at 6:34
  • \$\begingroup\$ Is that integers or positive integers? ;) \$\endgroup\$
    – Trebor
    Jun 23, 2020 at 16:07
  • 1
    \$\begingroup\$ The wording 'closest integer number that is \$x\$ order of magnitude smaller than \$w\$' is ambiguous. I initially interpreted it to mean, e.g., f(1000000, 3) = 9999 (closest integer to 1000000 that is 3 orders of magnitude smaller). As Adám said above, it seems that you're just asking for \$\lfloor w\times 10^{-x}\rfloor\$. \$\endgroup\$
    – Dingus
    Jun 25, 2020 at 0:22
-2
\$\begingroup\$

Meta-golfing Numbers

The Esolangs Wiki has a page here cataloging the shortest known programs in Brainf*** to generate a given number. A similar catalog could exist for any language: it would simply be a list of the shortest known programs in that language outputting a given constant. By extension, we can assume that for any given language, a catalog like this could be generated programmatically, by creating a program that given a constant outputs another program outputting that constant.

The Challenge

Your challenge is to create a program in any language \$A\$, such that when that program is given an input \$N\$, it outputs a program in language \$B\$ that will ouput \$N\$.

  • Languages \$A\$ and \$B\$ need not be different; you can output a program in the same language as your source code.
  • All outputted programs must be in the same language \$B\$.
  • \$N\$ is guaranteed to be a positive integer. It may be \$0\$.

I/O

  • Input and output can be done with any of the default I/O methods.
  • \$N\$ should be inputted as an integer, the string representation of an integer, or an array of digits. Programs should be outputted as a string or a list of characters.

Restrictions

  • Your program must handle values of \$N\$ at least up to \$255\$.
  • Trailing whitespace and newlines are allowed, as long as they do not make any program invalid; ie., I can have trailing newlines and whitespace as long as the implementation of \$B\$ allows them in programs.

Scoring

This question is a , so the answer with the most votes wins!

\$\endgroup\$
6
  • 2
    \$\begingroup\$ A critique of the scoring system (and possibly the challenge as a whole): In some languages, the empty program outputs its input, and in some languages, a numeric literal outputs itself. So the optimal submission will be program A, 0 bytes, for a score of 0. But even if the scoring system is changed to prevent the multiplying-by-zero exploit, I don't see how any other approach will be better than the empty-identity-program approach. So as it stands, this challenge will gather multiple trivial answers--and probably some interesting ones, but with worse scores. \$\endgroup\$
    – DLosc
    Aug 21, 2020 at 1:52
  • \$\begingroup\$ I don't think lowest score wins is a good idea for a contest where you have the flexibility to choose how difficult the task it. Might be better as a popularity contest, or maybe it would be better with a list of difficult languages to print constants in. \$\endgroup\$
    – Razetime
    Aug 21, 2020 at 2:09
  • \$\begingroup\$ @Razetime yeah, I actually hadn't realized the multiplying by zero exploit, so this seems like the best course of action - I've updated the answer. \$\endgroup\$
    – sugarfi
    Aug 21, 2020 at 12:09
  • \$\begingroup\$ Righ now, this is not metagolf, this is just... meta? \$\endgroup\$ Aug 22, 2020 at 3:10
  • \$\begingroup\$ I guess so, yeah... But metagolf is a bit catchier, isn't it? \$\endgroup\$
    – sugarfi
    Aug 22, 2020 at 13:23
  • \$\begingroup\$ Program: any implementation of cat in any language A. Language B: cat. \$\endgroup\$ Aug 24, 2020 at 17:46
-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, 2023 at 19:25
  • 1
    \$\begingroup\$ Also, "no recursion" is an unobservable requirement. \$\endgroup\$
    – Ginger
    Jan 7, 2023 at 19:26
  • \$\begingroup\$ Related \$\endgroup\$
    – l4m2
    Jan 13, 2023 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, 2023 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, 2023 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, 2023 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, 2023 at 22:41
  • \$\begingroup\$ Why? It endlessly returns the input with a newline regardless of what it is \$\endgroup\$
    – Dadsdy
    Jun 15, 2023 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, 2023 at 12:14
  • \$\begingroup\$ @noodleman Really? My answer (in (,)) was very different. \$\endgroup\$
    – Dadsdy
    Jun 15, 2023 at 18:18
  • \$\begingroup\$ Exact dupe restricted-source version fastest-code version \$\endgroup\$ Jul 19, 2023 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\$
4
-2
\$\begingroup\$

Spaceman Simulator

The song A Spaceman Came Travelling presents a fictional story about an alien coming to earth and singing; it is loosely based on the account of the birth of Jesus. The spaceman first says this:

Then the stranger spoke, he said "Do not fear
I come from a planet a long way from here
And I bring a message for mankind to hear,"
And suddenly the sweetest music filled the air
And it went
"La la la la la la la la la la la
La la la la la la la la
La la la la la la la la la la la
Peace and goodwill to all men, and love for the child
La la la la la la la la la la la
La la la la la la la
La la la la la la la la la la la"

The next day, he returns:

And just before dawn at the paling of the sky
The stranger returned and said "Now I must fly
When two thousand years of your time has gone by
This song will begin once again, to a baby's cry."

Write a program that prints this string, followed by two newlines:

Do not fear
I come from a planet a long way from here
And I bring a message for mankind to hear

La la la la la la la la la la la
La la la la la la la la
La la la la la la la la la la la
Peace and goodwill to all men, and love for the child
La la la la la la la la la la la
La la la la la la la
La la la la la la la la la la la

Then, wait until just before dawn at the paling of the sky (approximated by 06:00 system time), and print this, also followed by two newlines:

Now I must fly
When two thousand years of your time has gone by
This song will begin once again, to a baby's cry

(If the program is run exactly at 06:00, you may either do this immediately or wait 24 hours.)

Finally, wait until two thousand years of our time has gone by, and begin the song once again. (This goes on in an infinite loop; it will print everything three times if you run it for six thousand years.)

Since it's not feasible to wait thousands of years to see if a program works properly, also include an explanation of why the full version works. If you golf the text generation for any of the parts, please also include a copy of the code for each part to generate the text, separate from the main program; this way it can be determined that your code works without waiting for the paling of the sky or the return of the spaceman.

For the 2,000 year delay, wait until the same time (within a second or so accuracy) and date as when the program was started (not after the dawn), 2,000 years later.

You may assume that system time will increase monotonically throughout eternity, and that the time zone will never change.

If there is no way to wait for a duration or until a time in your language, then you may only output the text, as a complete submission would have printed 2,000 years after dawn. This will make the challenge easier in these languages, but will not give them an advantage in competing because submissions only compete within one language.

Example implementation

Here's an example in ungolfed Python. It will not work on Windows.

import datetime
import time

while True:
    now = datetime.datetime.now()

    if now.hour < 6:
        day_of_next_dawn = datetime.date.today()
    else:
        day_of_next_dawn = datetime.date.today() + datetime.timedelta(days=1)

    dawn = datetime.datetime(
        day_of_next_dawn.year,
        day_of_next_dawn.month,
        day_of_next_dawn.day,
        6,
        0,
    )

    in_two_thousand_years = now.replace(year=now.year + 2000)

    print(
        """Do not fear
I come from a planet a long way from here
And I bring a message for mankind to hear

La la la la la la la la la la la
La la la la la la la la
La la la la la la la la la la la
Peace and goodwill to all men, and love for the child
La la la la la la la la la la la
La la la la la la la
La la la la la la la la la la la
"""
    )

    time.sleep((dawn - now).total_seconds())

    print(
        """Now I must fly
When two thousand years of your time has gone by
This song will begin once again, to a baby's cry
"""
    )

    time.sleep((in_2000_years - datetime.datetime.now()).total_seconds())

\$\endgroup\$
3
  • \$\begingroup\$ This is a duplicate of [Sleep for 1000 years](codegolf.stackexchange.com/q/196917/108687 \$\endgroup\$
    – noodle man
    Dec 15, 2023 at 1:42
  • \$\begingroup\$ @noodleman would it be a non-duplicate if I changed it to "print the song, wait until the next morning in local time, print the 'Now I must fly' text, wait two thousand years, and start the cycle over"? \$\endgroup\$
    – Someone
    Dec 15, 2023 at 1:57
  • 1
    \$\begingroup\$ That would be further from a duplicate, but I'm not convinced it wouldn't be closed anyway. You may have noticed, but this site tends to close song-based kolmogorov-complexity challenges with high frequency. \$\endgroup\$
    – noodle man
    Dec 15, 2023 at 2:18
-2
\$\begingroup\$

Write an optimal Python program for distributed worknode to find prime.

Prime is defined as a number with no divisor but 1 and itself. Write an optimised for speed program for Pythons distributed worknode to check if an input is a prime.

The usual approach is to try possible divisors to see if they are, an optimisation begins at 2 (since we have to find n/2 anyway for a limit) and does not try multiples of a possible divisor, if a number does not divide by two then no even numbers divide that number, similarly if a number does not divide by three then it does not divide by three, six and nine. No number higher than n/2 need to be tried.

Entries in programming languages other than Python are acceptable for study.

\$\endgroup\$
6
  • \$\begingroup\$ Is 1 considered prime? \$\endgroup\$ Dec 28, 2023 at 23:21
  • \$\begingroup\$ @AlanBagel 1 is self prime. \$\endgroup\$
    – Willtech
    Dec 29, 2023 at 14:25
  • \$\begingroup\$ twitter.com/Willtech101/status/… \$\endgroup\$
    – Willtech
    Dec 29, 2023 at 14:27
  • \$\begingroup\$ ? (filler filler) \$\endgroup\$ Dec 29, 2023 at 14:31
  • \$\begingroup\$ Not popular? Probably there is already a real world solution I will work on it here github.com/Willtech/Prime \$\endgroup\$
    – Willtech
    Dec 31, 2023 at 5:25
  • \$\begingroup\$ @AlanBagel Actually I was looking even -3 is considered prime and 2. \$\endgroup\$
    – Willtech
    Dec 31, 2023 at 5:27
-2
\$\begingroup\$

Tiniest ELF under x64 Linux to perform ROT13

We already have a ROT13 challenge. But all those solutions, while short in source form, require/produce huge binaries in order to run. A simple C implementation ends up at around ~14 KiB! If that doesn't shock you, see the quoted text below from this article (emphasis mine):

The first version of UNIX was written in PDP-11 assembler; it had 34 system calls, it was written in 4,200 lines of code, and it ran on 12KB of main memory

Goal

Create the tiniest ELF executable you can that runs under x64 Linux (4.14+), takes input from stdin, performs ROT13 on it and writes the result to stdout.

Notes

  • You may use whatever language you want (C, C++, Rust, Assembly, Hex, ...), but please provide version numbers and your environment, as well as any extra necessities (compiler/linker flags, linker scripts, custom scripts, commands, etc.) so that we can reproduce the result.
  • You may assume input will always be in ASCII.
  • It has to be a relatively complete program. You must handle errors (mainly, a system call failing). The program must exit with exit code 0 on sucess and 1 on failure.
  • I encourage you to try higher-level languages. Answers in assembly will, no doubt, be shorter, but it's interesting to see how others will fare.

This is (no loopholes), the smallest binary wins!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I feel this is still a dupe of the rot13 challenge. a Tiny Elf binary would be valid for the Rot13 challenge. \$\endgroup\$
    – ATaco
    Jan 2 at 2:10
  • \$\begingroup\$ @ATaco A C (or any other language) answer that produces a tiny ELF can compete in this challenge but not in the original. \$\endgroup\$
    – pan
    Jan 2 at 2:20
  • \$\begingroup\$ I get it, but even a C answer is probably just going do directly emit assembly, which doesn't make for a very interesting change of the original challenge. \$\endgroup\$
    – ATaco
    Jan 2 at 21:02
-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
1
150 151
152
153 154
157

You must log in to answer this question.

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