560
\$\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

4329 Answers 4329

-4
\$\begingroup\$

Popularly print the input

Goal

Write a program or function in a language of your choice that takes input and outputs that exact input.

Specifications

  • Your program/function should output the exact input in any reasonable way.
  • Your program does not have to end after printing the input. It may end up in an infinite loop if you wish, as long as that loop doesn't output any extraneous characters.

Winner

The winning answer will be the one that has the highest score. Voters should look for answers that use an unique way to print the input, have a special source code or use neat language features.

\$\endgroup\$
6
  • \$\begingroup\$ Plain "do X in a creative way" popularity contests have fallen out of favour and will likely immediately get closed as being too broad or not having an objective winning criterion. \$\endgroup\$ Apr 4, 2017 at 18:33
  • \$\begingroup\$ @MartinEnder: Yeah, I noticed. How do you think I should change the challenge so that it won't be closed? \$\endgroup\$
    – Luke
    Apr 4, 2017 at 18:35
  • 1
    \$\begingroup\$ Can't really help you there. If I knew of a good way to make popularity contests work, I'd write some myself. ;) \$\endgroup\$ Apr 4, 2017 at 18:39
  • \$\begingroup\$ Probably a duplicate of codegolf.stackexchange.com/q/62230/34718 \$\endgroup\$
    – mbomb007
    Apr 4, 2017 at 18:43
  • \$\begingroup\$ @mbomb007: No, this is not a code-golf challenge. \$\endgroup\$
    – Luke
    Apr 4, 2017 at 18:54
  • \$\begingroup\$ But there's nothing separating the answers this might receive. Please read this: codegolf.stackexchange.com/tags/popularity-contest/info \$\endgroup\$
    – mbomb007
    Apr 4, 2017 at 18:57
-4
\$\begingroup\$

Make a Login Screen

Challenge: make code that asks the user to enter a username and password. The username and password should be hard coded, but they must not be visible: you cannot have the entire username or the entire password in plain text in the code. Both the username and the password must be 8 characters long. Upon the incorrect username or password, some error should be displayed. It would be good if there are multiple "accounts" that would display different text on login. The password field should not be visible (Only asterisks or something).

This is Code-Golf, Shortest answer wins.

Standard loopholes are forbidden.

\$\endgroup\$
4
  • \$\begingroup\$ you can't say that answer doing something "would be good" if the shortest answer wins \$\endgroup\$ Apr 18, 2017 at 7:05
  • \$\begingroup\$ underhanded challenges are off-topic. \$\endgroup\$ Apr 18, 2017 at 8:36
  • \$\begingroup\$ It's not underhanded. \$\endgroup\$ Apr 18, 2017 at 14:15
  • \$\begingroup\$ I'm sure this might be a dupe of an obfuscation challenge \$\endgroup\$
    – Beta Decay
    Apr 18, 2017 at 23:36
-4
\$\begingroup\$

Of numbers of letters

there is something special the number 4. When spelled in English the word 'four' uses exactly 4 letters. I wonder whether there are further such numbers Your task is to identify whether there exist further such numbers and output them in any human readable format. To make this more of a challenge you can do the task in any regional Language of your choice (Say Russian or Portuguese or Spanish or Mandarin or Hindi etc.).

The Best entry will be selected by the most number of such numbers regardless of language used

Best of Luck

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

No strings code bowling

I created this challenege idea with @redwolfprograms. In the challenge, you would create the longest program possible (code-bowling) it can do anything, but it cannot:

  • Contain any strings, or quotation marks/apostrophes/backticks
  • Contain the same alphanumeric byte more than twice
  • Conatin the same non alphanumeric byte more than three times
\$\endgroup\$
9
  • 2
    \$\begingroup\$ What is the task we have to solve? Is it really alphanumeric character but non alphanumeric byte? \$\endgroup\$
    – Dennis
    Apr 17, 2018 at 13:50
  • \$\begingroup\$ Why do you mix characters and bytes? \$\endgroup\$
    – DELETE_ME
    Apr 17, 2018 at 14:01
  • \$\begingroup\$ I feel like there are a lot of languages that would score the maximum (768) by not (strictly speaking) having alphanumeric characters, and then just wrapping everything in a string: "[3x each other byte value]"". \$\endgroup\$ Apr 17, 2018 at 14:08
  • \$\begingroup\$ I think you got bytes and characters mixed up. Both should be bytes, and make sure you specify the program can do anything. \$\endgroup\$ Apr 17, 2018 at 14:26
  • \$\begingroup\$ People, the point of the sandbox is to add suggestions. This question has been downvoted several times. Why? \$\endgroup\$ Apr 17, 2018 at 22:39
  • 4
    \$\begingroup\$ @RedwolfPrograms downvotes are a way for people to say that this challenge in the current state shouldn't be posted to main. If the challenge gets changed enough to make it viable and interesting the downvotes will be reverted (or upvotes from other people will outweigh them). \$\endgroup\$
    – Leo
    Apr 18, 2018 at 1:32
  • \$\begingroup\$ Maybe this challenge should have a "No strings" rule? \$\endgroup\$ Apr 18, 2018 at 1:59
  • \$\begingroup\$ Not being able to use e is not really that much of a big deal. Even in C you can get around it easily. (It would prevent you from returning values from functions, but you could just use pass by reference instead.) So that restriction wouldn't really add much to the challenge. \$\endgroup\$
    – N. Virgo
    Apr 18, 2018 at 8:35
  • \$\begingroup\$ Now that strings are forbidden, one could just create a huge variable whose name is all the alphanumeric characters twice. This is the bane of any longes code that... challenge. Consider adding some more interesting restrictions. \$\endgroup\$ Apr 18, 2018 at 14:35
-4
\$\begingroup\$

[Posted, but reference kept]

Given a function with boolean inputs a1, ..., an and a boolean output, output an array of numbers 0 to n satisfying:

For each item in the truth value, if (from the array you output, we repeatedly remove two adjacent numbers x and y satisfying that, for each integer n between x+0.5 and y+0.5, an=1), we can get an empty result array iff the given function's output is 1. You can assume the result exist.

Sample input:

a[1] a[2] result
0    0    0
0    1    0
1    0    0
1    1    1

Sample output: 0 2

Sample input:

a[1] a[2] result
0    0    0
0    1    1
1    0    1
1    1    1

Sample output: 0 1 2 0 1 2

Sample input:

a[1] a[2] result
0    0    1
0    1    1
1    0    1
1    1    1

Sample output: (empty)

shortest code win, but optimizing running time and result length is encouraged(I won't accept but I may upvote)

You may check your answer here

\$\endgroup\$
2
  • 2
    \$\begingroup\$ The spec makes absolutely no sense to me. What does it mean to remove a number from a truth table? \$\endgroup\$ Apr 25, 2018 at 12:13
  • 3
    \$\begingroup\$ Still makes no sense. Maybe if you give a detailed worked example I would be able to reverse engineer the spec and propose some changes to the wording. \$\endgroup\$ Apr 25, 2018 at 14:59
-4
\$\begingroup\$

Write a function that takes compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.

Static visualization of bubble sort and a gif explanation.

Bubble sort explanation Bubble sort gif

The steps go from left to right. At each stage, an exchange is made. The darkest color has the most value and finds its final place (bottom) first.


The rules

  • The function must take a list of integers that shall be sorted (less than 20 elements)

  • The function must print each step of the sort.

  • Yes, built-in Bubble sort algorithms are permitted.

  • No, you can not assume only positive integers or unique integers.

  • It's so the shortest code wins!


Test cases

input list
5 4 3 1 2
1 2 3 5 4
11 4 2 1 5

Optional

Add an interpreter so the submission can be tested. It is allowed to write this interpreter yourself for a previously unimplemented language.


Note

It's my first code-golf idea I'm fully open to improving it with more experienced users if I missed something.

This is not a duplicate of Bubble sorting in progress.

Thanks to @Erik the Outgolfer for encouraging me to post my idea in the sandbox.

\$\endgroup\$
5
  • 3
    \$\begingroup\$ Can you add one walked-through example? I.e. show each pass. \$\endgroup\$
    – Adám
    Jun 20, 2018 at 13:04
  • \$\begingroup\$ You note it isn't a duplicate of the in-progress bubble sort, but what distinguishes it from Golf me a bubble sort, which was closed as a dupe of that? \$\endgroup\$
    – Geobits
    Jun 20, 2018 at 13:10
  • \$\begingroup\$ @Geobits This was not a dup but unclear. \$\endgroup\$
    – DIDIx13
    Jun 20, 2018 at 13:12
  • \$\begingroup\$ Here's my c# non-golfed solution : dotnetfiddle.net/ZFkl5y \$\endgroup\$
    – DIDIx13
    Jun 20, 2018 at 14:01
  • 7
    \$\begingroup\$ You claim it's not a duplicate of codegolf.stackexchange.com/q/92753 but you don't adduce any argument to support that claim, and I can't see any significant difference. (The upper limit is a trivial difference IMO). \$\endgroup\$ Jun 21, 2018 at 6:14
-4
\$\begingroup\$

Once, I thought of this. Rules:

1: You must make a fractal that looks like the specified thing.

2: One thing per round.

3: Algorithms are rated by two scores: Resemblance and Compactness. The one that gets the highest scores wins!

4: Only I can tell what thing must be made.

5: Only one entry per user. Do not plagiarize.

6: One may code in anything they wish.

7: Have fun!

Round 1: Squidward's head!

\$\endgroup\$
10
  • \$\begingroup\$ Erchh! OK OK Remove the PM stufs. didnt know \$\endgroup\$
    – Ikura
    Jul 31, 2018 at 0:12
  • 2
    \$\begingroup\$ On this site, winning criteria has to be objectively defined. (by tradition, I have to admit... there is popularity-contest (read the tag info page for more details), but if you really want to make a pop-con, be careful) "Resemblance" is quite... subjective, unless you can define an objective formula. Also, what is a fractal exactly? \$\endgroup\$
    – DELETE_ME
    Jul 31, 2018 at 4:05
  • \$\begingroup\$ For example, how many points would I score if I just made the initial fractal look like the image and have it spiral inwards? What is the objective formula of Compactness/Resemblance \$\endgroup\$
    – Jo King Mod
    Jul 31, 2018 at 6:04
  • \$\begingroup\$ A fractal is a shape that recurses. It has copies of itself in it. Analyze the Mandelbrot set, you'll see mandelbrots in mandelbrots. What is a pop-con? Sounds like a soda convention. I'd love to go there! JK \$\endgroup\$
    – Ikura
    Jul 31, 2018 at 14:32
  • 1
    \$\begingroup\$ @user202729, experts are unable to agree on the definition of a fractal. That aside, this looks more like a forum game than a good fit for this site. \$\endgroup\$ Jul 31, 2018 at 14:46
  • \$\begingroup\$ Oh, popularity? No. No voting. I will work on my formula, with a new parameter: Mandelbrottiness, which is more or less Goldilocks. \$\endgroup\$
    – Ikura
    Jul 31, 2018 at 14:54
  • \$\begingroup\$ I attempted doing this on Encyclopedia Spongebobia, then went here. \$\endgroup\$
    – Ikura
    Jul 31, 2018 at 14:55
  • \$\begingroup\$ Then maybe a Stack Exchange for off-topic? \$\endgroup\$
    – Ikura
    Jul 31, 2018 at 14:57
  • \$\begingroup\$ @Ikura There are no such SE site, because it would generate low-quality content. Try Quora or Reddit... \$\endgroup\$
    – DELETE_ME
    Jul 31, 2018 at 15:15
  • \$\begingroup\$ Ergo! Goin' to the Kongregate Off-topic forum! \$\endgroup\$
    – Ikura
    Jul 31, 2018 at 18:48
-4
\$\begingroup\$

This question is a simplified description of the requirement described at Permutations to the nines


Given input integer (minimum) where the first digit is always 1 and the adjacent digits are increasing in value, e.g.,

12

123

1234

12345

with the ability to handle up to the integer

123456789

where the maximum integer is always the input integer in reverse order, e.g.,

21

321

4321

54321

987654321

Task

Return a list (array) of each number between the input minimum and maximum integer which satisfies three conditions

  1. the resulting integer list item includes only the individual numbers comprising the input number
  2. the resulting integer list item does not contain any duplicate individual digits
  3. the resulting integer list item is greater than the preceding integer list item and not greater than a following integer in the list

Test cases

Valid list items

12 -> [21] // done

123 -> [132,213,231,213,312,321] // done

Invalid list items

12345 -> 12344 // contains duplicate digits in whole number

123456789 -> 13256789 // not the next integer by increasing numeric value order

123456789 -> 987654322 // greater than maximum integer and duplicate digits

Winning criteria

The algorithm which uses the least amount of operations to compute the complete resulting list of items.

Examples

123 -> 123+5+4=132 // two mathematical computations

123 -> 123+9=132 // one mathematical computation (winning criteria)

(@JoKing suggested fastest-algorithm tag; math and code-challenge tags are also applicable)

\$\endgroup\$
28
  • \$\begingroup\$ @PeterTaylor Pared down version of the original question. \$\endgroup\$ Oct 8, 2018 at 18:30
  • \$\begingroup\$ Am not as yet well-versed in Big-O notation. If the phrase "the least amount of operations to compute the complete resulting list of items" can be translated into Big-O notation, kindly suggest and edit the language used in the question. We are not interested in code length (this is not a code-golf question), but rather, that the code produces the expected result in the fewest, or least amount of total computational operations. \$\endgroup\$ Oct 8, 2018 at 18:35
  • \$\begingroup\$ Ok, so if I understand the challenge, you give me a number N. I need to generate a list of numbers between N and M, where M = reverse(N). Each number in the list cannot have duplicate digits, can only consist of digits in N, and must be in strictly increasing order. Is this correct? \$\endgroup\$ Oct 8, 2018 at 18:52
  • \$\begingroup\$ Assuming my above comment is correct: 1. Why is 123456789 -> 13256789 invalid, as the maximum is 987654321, which is bigger than 13256789? 2. You need a list of all possible operations. 3. Use the word digit when referring to the individual parts of a number. \$\endgroup\$ Oct 8, 2018 at 18:57
  • \$\begingroup\$ @NathanMerrill Yes. Originally included using only the number 9 within the prerequisite criteria, though that inclusion appears to be challenging in itself to explain how the single number 9 can be employed to derive all list items. You are correct about 123456789 -> 13256789 being invalid. Was attempting to include invalid examples and to indicate that 13256789 should not be the next integer in the list following 123456789; the list should be in order from least to greatest integers. Ok, will use the term digit. \$\endgroup\$ Oct 8, 2018 at 18:57
  • \$\begingroup\$ Thinking about this more, there's a really simplified way to describe this: You want the all permutations of the digits of N in strictly increasing order. Permutation \$\endgroup\$ Oct 8, 2018 at 19:09
  • \$\begingroup\$ @NathanMerrill Yes, that is one way to put it. From perspective here, we are trying to use a number - the indexes of the initial input as a whole number - to generate all lexicographic permutations by using only math and the initial number (the current number) to do so. No loops, swaps, recursion, etc. Which am able to achieve using the code at the linked question, though the approach used there adds 9 to the initial (current) number. The challenge is to reduce the mathematical operations necessary to achieve the result - is at all possible. \$\endgroup\$ Oct 8, 2018 at 19:12
  • \$\begingroup\$ I think describing it that way will make this challenge much clearer. Also, to be a fastest-algorithm, you really need to list all possible operations. \$\endgroup\$ Oct 8, 2018 at 19:13
  • \$\begingroup\$ @NathanMerrill "I think describing it that way will make this challenge much clearer." Well, did that exhaustively in the linked question - with links to OEIS and previous inquiries which lead to here PPCG for context - which was closed due to "unclear what you are asking" votes codegolf.stackexchange.com/q/173145/31257, codegolf.meta.stackexchange.com/questions/16959. Posted this version of the question as users appear to not gather the original, more detailed question. Is this question codegolf.meta.stackexchange.com/a/16961/31257 clear to you? \$\endgroup\$ Oct 8, 2018 at 19:15
  • \$\begingroup\$ No. That question is much too long. I don't think it is the word "Permutation" killing you there, it's everything else. \$\endgroup\$ Oct 8, 2018 at 19:21
  • \$\begingroup\$ @NathanMerrill Well, here we are back to square 1. "too long" is a subjective measurement, though have been advised that users actually do have some means to time the "read" of a question, which will more than likely never do, here. This question is the bare minimum, and yet you suggest including more details. Cannot glean every individual users' idea about what is "too long" or does not include enough details. Perhaps somewhere in the middle that am as yet unable to reach. If a user takes the time to read the original question without protesting the length thereof - the details are there. \$\endgroup\$ Oct 8, 2018 at 19:25
  • \$\begingroup\$ @NathanMerrill What edits to the original question or this question do you suggest? \$\endgroup\$ Oct 8, 2018 at 19:26
  • \$\begingroup\$ All of the close reasons are subjective: "Unclear" is subjective, "Off-topic" is subjective, etc. I can give a full analysis of the other post, but I'd rather focus on this one. My first suggestion is to get rid of most of the requirements in favor of all permutations of the digits of N in strictly increasing order. The second thing you need to do is define what "operation" means. \$\endgroup\$ Oct 8, 2018 at 19:28
  • 1
    \$\begingroup\$ "The requirement is to add, subtract, divide, multiply, or use other mathematical procedure, the number 9 to the current number to generate the next number" is (a) not anywhere that I can see in the text of the requirements; and (b) an non-observable requirement, as described in the link I posted of things to avoid when asking questions. \$\endgroup\$ Oct 11, 2018 at 7:16
  • 1
    \$\begingroup\$ A requirement is only observable if you can verify it given a black box implementation, so I don't see how any code snippet can demonstrate that it is observable unless it's a test framework which verifies it by black-box testing. \$\endgroup\$ Oct 11, 2018 at 7:30
-4
\$\begingroup\$

All numeric substrings

I like numbers. Really, really, like numbers. If you give me a string with numerals in it, I want to get all the numbers out of it that I can.

Input:

A string.

Output:

Every numeric substring, in any order, but only one of each. Numeric here means anything with Unicode General Category Nd (because I'm no xenophobe).

I/O

Any reasonable format. But languages that don't allow for multibyte-character I/O should use some numeric or other representation.

Test cases

(input → one ordering of the correct output)

  • 1212 → [1212, 121, 212, 12, 21, 1, 2]
  • 123٤٥6 ‪→ [1, 2, 3, ٤,‪ ٥, 6, 12, 23, 3٤,‪ ٤٥,‪ ٥6,‪ 123, 23٤,‪ 3٤٥,‪ ٤٥6,‪ 123٤,‪ 23٤٥,‪ 3٤٥6,‪ 123٤٥,‪ 23٤٥6,‪ 123٤٥6]‪
  • 12t45 → [1, 2, 4, 5, 12, 45]
  • abc → []
\$\endgroup\$
2
  • \$\begingroup\$ @JoKing, thanks, done. \$\endgroup\$
    – msh210
    Feb 27, 2019 at 5:35
  • \$\begingroup\$ I am not convinced by this challenge. To me, it essentially boils down to filtering a unicode string on a character-by-character level, followed by generating all substrings of non-split substrings of the original string. Is ‪٥6 supposed to have any semantic meaning or are those simply two unicode characters? \$\endgroup\$ Mar 2, 2019 at 4:36
-4
\$\begingroup\$

Fastest prime printer up to 500,000,000 with gapes


Write a program that takes no input and prints the first 26,355,867 prime numbers, from 2 to 499,999,993 inclusively. Or in other words, print all the prime numbers smaller the 500,000,000.

The fastest code wins!

Since it will take a long time to print all the numbers, print only every 26355 primes starting with 2 separated by a new line. So the output should look like this:

2
304417
648391
1007681
1376449
1752323
2133689
2520983
2910797
3304633
3702269

The output should not be hardcoded, or there is no fun in it.

The results will be tested on my machine, so please also output in the last line how long it took to run the program and give me some instructions about how to run it locally. I will then share the last line output with you that should contain the time it took to run.

Here is my machine system specs, note that it's Windows.

enter image description here

\$\endgroup\$
14
  • 4
    \$\begingroup\$ Can be trivially hard coded. \$\endgroup\$
    – DELETE_ME
    Aug 4, 2020 at 2:06
  • 1
    \$\begingroup\$ Also it's going to be nearly instantaneous, and might be duplicate of some existing (not sure about this part) \$\endgroup\$
    – DELETE_ME
    Aug 4, 2020 at 2:07
  • \$\begingroup\$ tnx @user202729, I edited the question \$\endgroup\$ Aug 4, 2020 at 2:17
  • 1
    \$\begingroup\$ A [kolmogorov-complexity] challenge won't work as [fastest-code]. The fastest solution will be a huge puts in C or C++. "The output should not be hardcoded" is not objective (for example, what stops me from storing 2p for each prime in the output?). \$\endgroup\$ Aug 4, 2020 at 2:46
  • \$\begingroup\$ @mypronounismonicareinstate how about asking for the code size to be smaller than the output size? So such methods would not be possible? \$\endgroup\$ Aug 4, 2020 at 2:54
  • 1
    \$\begingroup\$ @IlyaGazman okay, then I can do something like that but with the numbers stored in binary, or computed at compilation time. \$\endgroup\$ Aug 4, 2020 at 2:58
  • \$\begingroup\$ Ok, how about that I ask your program or a library your program is using to have a code that checks for prime numbers? Something like: "You program can only print numbers that it tested to be primes" \$\endgroup\$ Aug 4, 2020 at 3:15
  • 1
    \$\begingroup\$ Okay, then my program can also run a primality test on them before printing. I also wonder if the sieve of Eratosthenes counts. This requirement is unobservable. \$\endgroup\$ Aug 4, 2020 at 5:11
  • \$\begingroup\$ Is the idea of doing every k'th prime that programs would otherwise be limited on time printing for all the primes rather than computing them? \$\endgroup\$
    – xnor
    Aug 4, 2020 at 8:02
  • \$\begingroup\$ @xnor printing 26 million primes take a ridiculously long time \$\endgroup\$ Aug 4, 2020 at 10:36
  • \$\begingroup\$ Another issue is that the run time is so fast (the C++ sieve answer (I think) takes only less than a second to run) that it's going to be hard to accurately measure the runtime. \$\endgroup\$
    – DELETE_ME
    Aug 4, 2020 at 13:37
  • \$\begingroup\$ @user202729 that I would like to see! I bet you can't get it run below 2 seconds \$\endgroup\$ Aug 4, 2020 at 17:50
  • \$\begingroup\$ This is essentially a duplicate of your earlier challenge, with the rather trivial modification of introducing gaps. As for your sense of how long it takes to print 26 million primes, you are mistaken. My submission on your earlier challenge printed all 26 million of them in under a minute on my laptop. The (now-deleted) C++ answer was even faster. \$\endgroup\$
    – Dingus
    Aug 5, 2020 at 1:28
  • \$\begingroup\$ This is heavily downvoted and will require a great deal of work and specification to get to a point where it'd be considered on-topic on main. Furthermore, as other users have pointed out, this appears to be a duplicate of an existing challenge. If you don't intend to post this, would you mind editing this post down and deleting it in order to save space? \$\endgroup\$ Sep 25, 2020 at 0:47
-4
\$\begingroup\$

Mystery Numbers Challenge

Here are some sample inputs and outputs:

IO

Test 1

Input: 102
Output: 10404 1061208 14002414191924244276669361796022272

Test 2

Input: 10
Output: 100 100000

Test 3

Input: 50
Output: 2500 312500000 312500000

BONUS

If there are two inputs, here are the corresponding inputs and outputs:

Test B1

Input:

50
12

Output: 144 248832 248832

Test B1

Input:

2310
9

Output: 81 729 59049 4782969 31381059609

Notes

If you pass all bonuses too, feel free to third your score. Also add a * to the end.

\$\endgroup\$
6
  • \$\begingroup\$ Maybe you should add kolmogorov-complexity, as if you don't explain how those outputs are generated you need to find the shortest way to generate these. Also how does the program need to preform on stuff not defined? \$\endgroup\$ Dec 31, 2020 at 17:10
  • \$\begingroup\$ This seems not to be a serious submission but if it is, 'I'm not outlining what the program should do' is problematic. How does one write any program without an outline of what it should do? \$\endgroup\$
    – Dingus
    Dec 31, 2020 at 22:35
  • \$\begingroup\$ @Dingus There are sample inputs and outputs. \$\endgroup\$
    – Someone
    Jan 1, 2021 at 20:09
  • 1
    \$\begingroup\$ Questions involving hidden patterns and bonuses are discouraged here. If there's no hidden pattern and these are just random outputs, then the challenge is just compressing those output numbers and using the input as an index, which isn't very interesting. \$\endgroup\$ Jan 1, 2021 at 20:49
  • \$\begingroup\$ @Someone Yes, I can see that. What should the code do for inputs of 1, -123456.789, or abcdefg? \$\endgroup\$
    – Dingus
    Jan 1, 2021 at 22:32
  • \$\begingroup\$ Some kind of non-array-like output that indicates an error. I haven't thought of that. (Also, this is my first ever question, so it's likely garbage.) \$\endgroup\$
    – Someone
    Jan 2, 2021 at 18:44
-4
\$\begingroup\$

Your challenge is to write a small compiler/interpreter to a small language. This language can be of any level. Example: brainf*ck or Turing.

Example submission:

languageName : “name” 
GitHub : “https/GitHub.com/Lang”

a language is valid if it contains the folowing systems:

1: varibles of any type
2: a method of declaring and using functions
3: definable parameters
4: a update loop
5: loops
6: classes(optinal)

a compiler/interperater is valid if it can:

1: run/compile code
2: is fast (less than a minute to compile/initialize)
3: give error messages(optional)
4: written in java

The smallest compiler/interpreter wins

please tell me how i can fix this post if you intend on downvoting it in the comments

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Literally none of the requirements you've listed are observable or are formally specified. I would recommend reading through this thread. \$\endgroup\$
    – hyper-neutrino Mod
    Jul 15, 2021 at 2:50
  • \$\begingroup\$ @2 - I would recommend you to specify the language in the challenge. Here, in code golf, we always have a criteria (like code-golf (shortest code)). If you don't specify the language, some small languages like HQ9+ will take less bytes to make, but other small languages like chicken will take more bytes to make. Take your time reading the existing challenges and good luck on your second idea! \$\endgroup\$
    – math scat
    Jul 15, 2021 at 8:05
  • 1
    \$\begingroup\$ Welcome to Code Golf, and thanks for using the Sandbox! I'm going to be honest: I don't think you can fix this challenge idea. That's not a bad thing, some ideas just don't work well with our format. I'd be happy to elaborate more on the issues I see with this if you'd like me to, but overall, this is just far too broad to work. Many languages don't have any of the listed points (for example, brainfuck only has 5, and maybe 4), and the listed points seem very arbitrary \$\endgroup\$ Jul 15, 2021 at 19:41
-4
\$\begingroup\$

Find the square of a number without using the multiplication sign or division sign

e.g. "/" "//" "*" "**" are not allowed

no imports are allowed either

An integer will be given in the input

Test cases:

5 -> 25

6 -> 36

10 -> 10

724 -> 524176

\$\endgroup\$
6
  • \$\begingroup\$ Can you add test cases and information? \$\endgroup\$
    – Fmbalbuena
    Jan 10, 2022 at 10:07
  • \$\begingroup\$ added accordingly fmbalbuena \$\endgroup\$
    – DialFrost
    Jan 10, 2022 at 10:10
  • \$\begingroup\$ Are we allowed to use * if it doesn't mean multiplication? \$\endgroup\$
    – Adám
    Jan 10, 2022 at 10:25
  • \$\begingroup\$ If our language has "square" as a built-in, can we use it? \$\endgroup\$
    – Adám
    Jan 10, 2022 at 10:32
  • \$\begingroup\$ that's interesting code challange, but i think it's easily bypassed by some esolang like vyxal that is using ² as square, you can try disabling square or multiply function, so that people don't just simply use other symbol to complete the task \$\endgroup\$
    – okie
    Jan 10, 2022 at 23:45
  • \$\begingroup\$ May I use character if it is the operator or keyword for multiplication in my language? \$\endgroup\$
    – tsh
    Jan 11, 2022 at 6:53
-4
\$\begingroup\$

Prime strings

Your task is to find the string consisting of all the words in the give input whose lengths are prime numbers

Test cases:

The quick brown fox jumps over the lazy dog.
->
The quick brown fox jumps the
Omicron Effect: Foreign Flights Won't Resume On Dec 15, Decision Later.
->
Omicron Effect: Foreign Flights Won't On Dec 15,

You may assume that only ascii characters are allowed and that uppercase, lower case, punctuation, and spaces are allowed in the input and output

You may assume that the words whose lengths are prime numbers do not include spaces

\$\endgroup\$
1
  • \$\begingroup\$ Is essentially equivalent to finding the prime numbers in a list of integers which is essentially equivalent to running a few primality tests. \$\endgroup\$
    – ophact
    Jan 31, 2022 at 12:33
-4
\$\begingroup\$

Outgolf me with the custom scoring

Cops:

You post two codes, a code is that you wanted to do, another is used to size the code.

Rules

Example:

# [Python 3](https://docs.python.org/3/), score 21 

# Code

    print("""s""")

# Sizer

    print(len(input())/2)

Scoring (Cops)

\$s + \lfloor\frac{(m)}3\rfloor\$

Where \$s\$ is the size of actual code and \$m\$ is the size of code used for sizing the code.

The lowest Score of uncracked Cop wins

Robbers

Your task is to find code, If the code size is less than the Cop's code, Then Post an answer That cracks the Cop's answer.

Rules

Example:

# [Python 3](https://docs.python.org/3/), [Cracks username Cop](https://codegolf.stackexchange.com/questions), 2 score saved

    print("s")

The Poster with most cracks wins

Meta

  • Any feedback?
\$\endgroup\$
2
  • \$\begingroup\$ Do you mean make a program that does whatever (how is whatever defined?) and another that scores it? \$\endgroup\$
    – Alan Bagel
    Feb 13, 2022 at 23:15
  • \$\begingroup\$ @BgilMidol Yes, This is what I mean, Robbers must outgolf. \$\endgroup\$
    – Fmbalbuena
    Feb 13, 2022 at 23:18
-4
\$\begingroup\$

Python Interpreter

Mimic the python interpreter.
Running python <filename>.py should be the same as running python in the terminal (or python3, python27, and other similar pythons)
It's really hard. Especially complying with the following STDIN test cases.

(SANBDOX - should I add ? What other tags should/shouldn't I add?)

Also, it seems ast is too overpowered, as the main hard part (sys.ps2 compliance) can be fixed by checking for IndentationError: expected an indented block when calling ast.parse. Any ideas?

Test cases

Copy this and test this with your program.
Make sure the output is identical to the interpreter.

Simple code

for i in range(5):
    print(i)
<a blank line>
print(i)
i
_
while False:
    print("Will not be executed")
<a blank line>

When sys.ps1 and sys.ps2...

import sys
sys.ps1 = 'ps1> '
print("sys.ps1!")
sys.ps2 = 'ps2> '
for i in range(1):
    print("sys.ps2!")
<a blank line>
print("end")

Errors

raise ValueError

Handling crashes (this is optional)

def a():
    try:
        a()
    except:
        a()
<a blank line>
a()

Sandbox sanbdox things

Repeated: (SANBDOX - should I add ? What other tags should/shouldn't I add?)

Also, it seems ast is too overpowered, as the main hard part (sys.ps2 compliance) can be fixed by checking for IndentationError: expected an indented block when calling ast.parse. Any ideas?

  • Any things that needs to be changed?
  • Any unclear bits? Probably a lot...
  • Any other things?
  • Any reason all my sanbdox questions start with "Any"?
  • Any idea whether I should remove the "Any" before every sanBDox thing?
  • Any sanbdox template so I don't have to copy from my evolution of trust sanbdox post?
  • Any way to stop misspelling sanbdox?

WD

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Just to be sure I'm not misunderstanding this, you want us to reimplement Python? \$\endgroup\$
    – Ginger
    Mar 4, 2022 at 21:21
  • \$\begingroup\$ TL;DR it's not as simple than it looks - the main reason this is a challenge is sys.ps2. To get that, you need to print it when there are loops, but checking for a colon at the end fails due to print("fake colon") # sneaky! :, so you need to check for comments, but to do that, you need to check for strings and string escapes, and so on (beacause without checking for strings, for i in "#": is a false negative) as well as finding if it is an expression or an equation (a=[3,4,5] vs len([3,4,5])) \$\endgroup\$
    – W D
    Mar 5, 2022 at 8:05
  • 1
    \$\begingroup\$ You didn't answer my question. \$\endgroup\$
    – Ginger
    Mar 5, 2022 at 11:35
  • \$\begingroup\$ TL;DR Well, yes, but actually no - there's a difference between Python files and the Python interpreter. It's not reimplementing Python file execution; it's reimplementing the interactive Python interpreter. Also, it seems ast is a big loophole... \$\endgroup\$
    – W D
    Mar 5, 2022 at 21:10
  • \$\begingroup\$ @W D This challenge is not very good for code-golf. \$\endgroup\$
    – Ginger
    Mar 9, 2022 at 12:38
-4
\$\begingroup\$

Generate a random string of length 8

The challenge is pretty simple. Generate a random (non-zero chance) string of length 8, using ASCII characters from 33-126 (! to ~). (1-32 and aren't included because they don't show up/may cause interference.)
Remember that this is , so shortest answer wins!

Rules

  • All standard rules apply
  • All characters must be in one continuous string, so no line breaks, spaces, etc.

Example code

import random
i=8
j=""
while i!=0:
    j+=(chr(random.randint(33,127)))
    i-=1
print(j)

Try it online!

Tags

\$\endgroup\$
7
  • \$\begingroup\$ I'm guessing by "characters from 33-254 are allowed" you mean only those characters. The way it's worded currently it sounds like you might allow answers to output a subset of those \$\endgroup\$
    – pxeger
    Mar 18, 2022 at 16:43
  • \$\begingroup\$ Please specify what you mean by "random": do you mean (A): all possible outputs must have an equal chance of being output (so uniformly random)? (B): all possible outputs must have a non-zero chance of being output? or (C): something else? Personally I would suggest going with B. \$\endgroup\$
    – pxeger
    Mar 18, 2022 at 16:46
  • \$\begingroup\$ ASCII only goes up to 128. Did you mean "all ASCII characters from 33-127", instead of 255? \$\endgroup\$
    – pxeger
    Mar 18, 2022 at 16:46
  • \$\begingroup\$ @pxeger 1. yes, only those, 2. I was thinking more of option A but B works, 3. Yeah i meant that \$\endgroup\$ Mar 18, 2022 at 16:49
  • \$\begingroup\$ @pxeger I have gone with option letter B for randomness. \$\endgroup\$ Mar 18, 2022 at 18:32
  • \$\begingroup\$ ~ (the last printable ASCII value) is 126, not 127. \$\endgroup\$
    – Nitrodon
    Mar 21, 2022 at 21:35
  • \$\begingroup\$ @Nitrodon fixed. Man i really need to get better at this stuff \$\endgroup\$ Mar 21, 2022 at 21:46
-4
\$\begingroup\$

Longest code to output "Hello World"

Rules

  1. The program should take no input, and only print Hello!, World? to STDOUT with exact same capitalization and punctuation and in single line. Trailing whitespaces and newlines are allowed.
  2. The output should not be in the form of error message
  3. The accepted answer will be the 'most points' answer but try to be as creative as possible

Point System

  1. +1 for each character of code in your program, eg:print("Hello World") is 20
  2. -1 for each repeated character(case sensitive, i.e. 'h' is not same as 'H'), eg:print("Hello World") is 20-1(o)-2(l) = 17
\$\endgroup\$
8
  • \$\begingroup\$ "Most creative" is subjective. \$\endgroup\$
    – Alan Bagel
    Mar 24, 2022 at 17:56
  • \$\begingroup\$ It's trivial to get an arbitrarily high score. Just increment a number a couple billion times, then use some one-line function to turn that number into a string. if any of the incrementing lines are removed, the string is different, so they're "contributing". \$\endgroup\$ Mar 24, 2022 at 18:00
  • \$\begingroup\$ Also, just putting it all on one really long line would trivially defeat your requirement that all lines 'contribute". \$\endgroup\$ Mar 24, 2022 at 18:01
  • \$\begingroup\$ @RadvylfPrograms I hope the second point in scoring system can help discourage repetitive assignment of number, let's say n+=123, 'n','+','=' must be repeated a billion times and on top of that only 1-9 are present to choose to increment(basic case) \$\endgroup\$
    – Saphereye
    Mar 24, 2022 at 18:05
  • \$\begingroup\$ What, +1 is based on bytes and -1 is based on characters? Then I can get arbitrarily high score by repeating multibyte characters, right? \$\endgroup\$
    – Bubbler
    Mar 24, 2022 at 23:03
  • \$\begingroup\$ @Bubbler I was perhaps used the wrong wordings. I used bytes and character interchageably. I meant for every character in your code you get +1 and for every repeated character you get -1 \$\endgroup\$
    – Saphereye
    Mar 25, 2022 at 3:05
  • \$\begingroup\$ But still, it is equivalent to counting unique characters (like, if you have a 10 times, you add 1 ten times and then subtract 1 nine times, giving a +1), so it is very easy to get perfect score: use all 1114111 Unicode codepoints in the source code. And then the challenge becomes extremely boring. \$\endgroup\$
    – Bubbler
    Mar 25, 2022 at 3:22
  • \$\begingroup\$ Also, why does it say the string is "Hello!, World?" at the top but "Hello World" further down? Wouldn't it be better just to use the normal "Hello, World!"? \$\endgroup\$
    – Lecdi
    Mar 27, 2022 at 11:23
-4
\$\begingroup\$

Calculate the day of the week from a given date without using built-in functions that do so. For example C#'s DateTime.DayOfWeek is not allowed. Anything along the lines of DateTime.Year.IsLeapYear or DateTime.Month.TotalDaysInThatMonth (pseudocode) is also disallowed. Anything other built-in functionality for getting the number of days in a month or year is disallowed. You have to build that functionality yourself.

Input: a 1 dimentional array of integers with length 3. The array has the the form {year, month, day}
Output: A string such as "Monday", "Tuesday", etc. Case insensitive.

This is code gold so the shortest answer wins!

Test Cases:

Input Output
{1000, 3, 31} "Monday"
{1969, 4, 20} "Sunday"
{1980, 2, 29} "Friday"
{1979, 2, 29} empty string, or null or throws an error. (This date does not exist)
\$\endgroup\$
2
  • \$\begingroup\$ Why so many downvotes, you may ask? Do X without Y challenges are generally discouraged. \$\endgroup\$
    – pajonk
    Apr 1, 2022 at 4:59
  • \$\begingroup\$ @pajonk Gotcha, thanks. This is why I posted to the sandbox \$\endgroup\$
    – Nigel
    Apr 1, 2022 at 17:44
-4
\$\begingroup\$

Is it a Homestuck handle?

In the interactive webcomic Homestuck, the in-universe chat clients require users to have chat handles. These handles always consist of two words in camelCase. The heroes in the story almost all have handles where both words start with a DNA base (A, C, T, or G), with one exception.

A chart of homestuck hero chat handles (Taken from https://mspaintadventures.fandom.com/wiki/Handle)

Your challenge is, given a string (or list of characters), determine if it's one of the heroes' handles -- in other words, if it's in the set {gardenGnostic, gallowsCalibrator, grimAuxiliatrix, ghostyTrickster, ectoBiologist, gutsyGumshoe, golgothasTerror, carcinoGeneticist, cuttlefishCuller, caligulasAquarium, centaursTesticle, arachnidsGrip, arsenicCatnip, apocalypseArisen, adiosToreador, turntechGodhead, terminallyCapricious, twinArmageddons, tentacleTherapist, tipsyGnostalgic, timaeusTestified}. You can output any two distinct values for "yes" and "no".

Standard loopholes are forbidden. The shortest code wins.

Questions

I actually don't know anything about Homestuck, so I probably messed something up in the question.

\$\endgroup\$
-4
\$\begingroup\$

Do you trust this site?

title is a work in progress

This challenge is simple. Your program must take a URL (which will always exist) as input, download the file, and execute its contents as a program in the language your answer is in. The file will always be a valid program in your language.

Example

Language: Python
Input: https://gist.githubusercontent.com/GingerIndustries/d6f25007b45071e901b2b9057388d8f8/raw/25f838879fdc93f07394afc080eeef0993f55cbe/helloworld.py
Result: Program should print "Hello World!"
\$\endgroup\$
3
  • \$\begingroup\$ It'd probably benefit from more test cases; and how is it guaranteed that the webpage is a file? \$\endgroup\$ Oct 12, 2022 at 12:17
  • 1
    \$\begingroup\$ @py3programmer All webpages are files. \$\endgroup\$
    – Ginger
    Oct 12, 2022 at 15:25
  • \$\begingroup\$ As in, the URLs will have an extension in the end? \$\endgroup\$ Oct 12, 2022 at 16:33
-4
\$\begingroup\$

Is the UTF-1 string shorter than its UTF-8?

Backgrounds

  • explain utf-1 and utf-8

Problem

Given a Unicode string, output a two distinct truthy or falsey value to represent whether its representation in UTF-1 is shorter than that in UTF-8.

I/O restriction

Input can be list of code point for each letter or string with consistent encoding except UTF-1. Output can be as in decision problem rule.

todo rules

todo test cases

  • Falsey for any string with nothing other than c such that U+0000<=c<=U+007F
\$\endgroup\$
-4
\$\begingroup\$

This is a famous mathematical problem, Named as Bridges of Königsberg

Task

The bridges of Königsberg is a problem in mathematics which states that the path required for crossing each bridge exactly once without using a boat

Bridges of https://cdn.britannica.com/77/74877-050-F5DD4C34/Leonhard-Euler-route-each-question-bridges-Swiss.jpg

You have to find out if there is any path which uses each bridges exactly once without using a boat, if the time exceeds 36000 seconds or 10 hours the program should print no path found yet

Rules

Standard rules of fastest-code

Expected Output: Paths possible: [7, 2, 3, 1, 5, 6, 4], [2, 1, 7, 3, 4, 6, 5], etc.

This is fastest-code so the answer with shortest time is accepted, Even if the code will take a many days without a Quantum Computer

\$\endgroup\$
7
  • 1
    \$\begingroup\$ I'm really confused by the "programing languages starting from b" rule. What does it even mean? And what a extremely arbitrary restriction \$\endgroup\$
    – mousetail
    Nov 29, 2022 at 14:55
  • \$\begingroup\$ Thanks, @mousetail I mean unofficial languages which is not included in the Wikipedia Article \$\endgroup\$
    – user115781
    Nov 29, 2022 at 14:59
  • 1
    \$\begingroup\$ What does it mean for a language to be unofficial? See codegolf.meta.stackexchange.com/a/8058/91213 our guidelines for arbitrary restricting languages. \$\endgroup\$
    – mousetail
    Nov 29, 2022 at 15:02
  • \$\begingroup\$ Thanks @mousetail, For the guidelines link \$\endgroup\$
    – user115781
    Nov 29, 2022 at 15:26
  • \$\begingroup\$ This question isn't very specific. What exactly are we supposed to do? \$\endgroup\$
    – Ginger
    Nov 29, 2022 at 18:09
  • \$\begingroup\$ Thanks, @Ginger, You have to find out if there is any path which uses each bridges exactly once without using a boat, if the time exceeds 36000 seconds or 10 hours the program should print no path found yet \$\endgroup\$
    – user115781
    Nov 30, 2022 at 6:44
  • \$\begingroup\$ What is input and what is output? Without input, how can you prevent someone write a program which simply print "[7, 2, 3, 1, 5, 6, 4]"? \$\endgroup\$
    – tsh
    Dec 15, 2022 at 7:21
-4
\$\begingroup\$

Output a googol

Your challenge today is to output this exact number:

10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

We call this a googol. A googol is 1 followed by a 100 zeroes, or basically just \$10^{100} \$. However most programs wouldn't be able to do a simple print(10**100) because it will take forever to do so. And sometimes it might end up with an OverflowError, so you'll have to be creative.

Input:

None.

Output:

The googol. However, if your language will not be able to store \$ 10^{100} \$, you'll have to find some way of printing it, maybe by string manipulation (the shortest I got was print('1'+'0'*100))

This is , so shortest answer wins!

\$\endgroup\$
7
  • 3
    \$\begingroup\$ This challenge is trivial and boring. Your answer is probably already the most efficient way. No golfing possible. \$\endgroup\$
    – mousetail
    Dec 5, 2022 at 13:03
  • \$\begingroup\$ Well, I've posted a lot other trivial&boring challenges, nothing doable about that \$\endgroup\$ Dec 5, 2022 at 13:06
  • \$\begingroup\$ Maybe you should try writing interesting challenges \$\endgroup\$
    – mousetail
    Dec 5, 2022 at 13:07
  • \$\begingroup\$ Everytime I did, it never made it \$\endgroup\$ Dec 5, 2022 at 13:07
  • \$\begingroup\$ Maybe they where not actually interesting \$\endgroup\$
    – mousetail
    Dec 5, 2022 at 13:08
  • \$\begingroup\$ personal opinion. Which is why I tend to technical issues more than "boring" \$\endgroup\$ Dec 5, 2022 at 13:08
  • 1
    \$\begingroup\$ Suggestion: Output 3**1000 in base 2. It creates a interesting non repeating pattern that should be somewhat interesting to golf in languages without arbitrary precision arithmetic. \$\endgroup\$
    – mousetail
    Dec 5, 2022 at 13:23
-4
\$\begingroup\$

Write a proper quine.

Community decided that you're not allowed to claim you're not reading source code but data, and read a stored string.

To be consistent, reading a stored infinite precision number is also not allowed. (should this, or only apply to highbase?)

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Almost certain this is a duplicate of codegolf.stackexchange.com/questions/69/… \$\endgroup\$
    – noodle man
    Jan 7 at 16:37
  • \$\begingroup\$ @Jacob They're all improper quine under this definition \$\endgroup\$
    – l4m2
    Jan 9 at 22:12
  • \$\begingroup\$ Are this and this improper quines? (It doesn't push the visible constant as a number. Each digit multiples the current number by 10 and adds itself.) Or this? (The first i changes the mode to "insert mode", and each character inserts itself to the buffer in insert mode.) Or this? (Same argument as V quine applies, and every character is run as code as well) \$\endgroup\$
    – Bubbler
    Jan 19 at 6:40
  • \$\begingroup\$ Also there are already quines in languages like 1+ where string is not a thing and the only number literal is 1. \$\endgroup\$
    – Bubbler
    Jan 19 at 6:44
-4
\$\begingroup\$

This is a problem I solved, but now I am curious whit what techniques it can be improved. The original language is Java but here it doesn't matter.

You start with a list of n strings with a length of 7 characters. What is the most efficient algorithm (fastest) to determene the longest substring all the elements have in common, excluding the first character.

example 1:
input: "S000001", "S000002", "S000003", "S000004"
expected output: "00000"

example 2:
input: "S020011", "S020012", "S020013", "S020014"
expected output: "02001"

example 3:
input: "S010001", "S000002", "S000003", "S000004"
expected output: "000"

example 3:
input: "S109001", "S22090", "S090003", "S090004"
expected output: "090"

When there are no common substrings the output is null, an empty string etc. but not a caracter [a-zA-Z]|[0-9]

The input is an array of strings, texts or equivalent in your preferred language (not a char[] or binary, etc).

\$\endgroup\$
12
  • \$\begingroup\$ pls, If you downvote leave a comment why. \$\endgroup\$
    – Bjop
    Mar 22 at 9:33
  • \$\begingroup\$ I believe this question is a duplicate of an existing question. \$\endgroup\$
    – Ginger
    Mar 22 at 11:00
  • \$\begingroup\$ Can you provide me the link? I have searched for sommethig simmular but couldn find it. \$\endgroup\$
    – Bjop
    Mar 22 at 13:56
  • 1
    \$\begingroup\$ In any case this would be very boring, the optimal answer is obviously O(n) and except in the most esoteric languages this is also the one that's easiest to implement. Reminder that fastest-algorithm scores by big-o running time. \$\endgroup\$
    – mousetail
    Mar 23 at 5:44
  • 2
    \$\begingroup\$ Also excluding the first character and limiting to a total of 7 characters adds nothing, just tedious exception handing \$\endgroup\$
    – mousetail
    Mar 23 at 5:45
  • 1
    \$\begingroup\$ Duplicates: codegolf.stackexchange.com/questions/62752/… This is not fastest algorithm but as I explained fastest algorithm is a terrible choice for a scoring criteria for this type of question \$\endgroup\$
    – mousetail
    Mar 23 at 5:50
  • \$\begingroup\$ @mousetail the question you sent talks about the longest common prefix, not the longest common substring. It can still be done in O(n), but it's a much more complicated algorithm. \$\endgroup\$ Mar 23 at 7:56
  • 1
    \$\begingroup\$ @CommandMaster Oops, you are right. That would make it a exact duplicate of this question: codegolf.stackexchange.com/questions/47249/… \$\endgroup\$
    – mousetail
    Mar 23 at 7:57
  • \$\begingroup\$ @mousetail It's not an exact duplicate because there are more than two strings here, and it requires non-trivial modifications to adapt. Additionally, that one is restricted-complexity code-golf, while this one seems to be fastest-code, although the scoring isn't very clear. \$\endgroup\$ Mar 23 at 8:04
  • 2
    \$\begingroup\$ If this is fastest-algorithm, then it's basically a duplicate since O(1) is optimal. If it's fastest code this question requires a lot more specification on how it will be measured \$\endgroup\$
    – mousetail
    Mar 23 at 8:09
  • \$\begingroup\$ I dont know where else to ask the question (stack overflow is not the right one I think). I made my own code to solve it but it has 4 for loops (1 parrent loop the others are child loops) still O(n). I think it can be better, more efficient and i dont know how to express more efficient, probably least amount of work to calculatethe solution? \$\endgroup\$
    – Bjop
    Mar 23 at 8:28
  • 2
    \$\begingroup\$ Take a look at the question I linked, it gives details and links about the O(1) algorithm. This site should be used if you think a challenge will be fun to solve, not if you want a actual answer. It can be both of course. \$\endgroup\$
    – mousetail
    Mar 23 at 8:41
-5
\$\begingroup\$

Make a search engine!

Background

You are now the first employee of DuckDuckGoogle, a company founded by a Google employee and a DuckDuckGo employee! They have a new vision for search engine! But obviously, they need to make a search engine first! However, they are bad programmers (nobody knows how they were even hired at DuckDuckGo and Google!). So you are assigned the task of making a search engine.

Search engines

There are three parts to a search engine, a web crawler, an indexer, and a searcher.

The web crawler takes a link, and saves the page and stores the page data (the HTML code). It then looks for links in the page and visits those webpages and does the same. It will continue to do this until there are no more links left.

The web indexer will take the text from each page, take each word, and add it to a dictionary of words and the pages it is associated with. If the word is already in the dictionary, it adds the page as a value of that word that is found in the page. For example, lets say www.example.com/index.html contains the text "hello. thanks! goodbye." and the ww.example.com/index.html is linked to www.example.com/hello.html with the. text "hello. goodbye." The crawler would extract the text from the index.html, and find hello.html, and extract the text from hello.html. The indexer would make a dictionary like this:

dictionary ={"hello.": ["www.example.com/index.html","ww.example.com/hello.html"], "goodbye.":["www.example.com/index.html","ww.example.com/hello.html"], "thanks!": ["ww.example.com/index.html"]}

The simplest part of the search engine is the searcher, or retriever. It simply retrieves the value for the search term (i.e. the list of pages the search term is found in) and prints it. That is the final result of the program. So if the search term is "hello.", the program will print ["www.example.com/index.html","ww.example.com/hello.html"]

Now, here is the difficult part. You must take into account punctuation. So "hello" returns the same as "hello." Also the search engine should be case-insensitive. So "Hello" is the same as "hello", which, as we said, is the same as "hello." which was ["www.example.com/index.html","ww.example.com/hello.html"]

Challenge

The challenge is to write a search engine in the least number of bytes as possible. Why? Because your bosses have decided to use 90% of the one hard drive they have (budget problems!) for the Holy Grail part of their project and you only get 10%.

Rules

  1. The input is the "seed", a url at which the crawler should start at, and also the search term.
  2. The output is a list of webpage urls where the search term is found.
  3. The program cannot use builtins for a search engine or even a crawler (or related, like a scraper or spider library).
  4. No need to worry about Javascript at all. Assume that the pages will not have Javascript.
  5. The webpages are assumed to have HTML 4.0.1 Strict.

Testing

I am pretty sure people know how search engines work. So I will only include two testcases. You can use the websites in the testcases for testing purposes as well.

> "https://www.udacity.com/cs101x/index.html" "crawl"
["https://www.udacity.com/cs101x/index.html","https://www.udacity.com/cs101x/crawling.html"]

> "https://www.udacity.com/cs101x/urank/index.html" "hummus"
["https://www.udacity.com/cs101x/urank/index.html","https://www.udacity.com/cs101x/urank/hummus.html","https://www.udacity.com/cs101x/urank/arsenic.html","https://www.udacity.com/cs101x/urank/kathleen.html","https://www.udacity.com/cs101x/urank/nickel.html","https://www.udacity.com/cs101x/urank/zinc.html"]
\$\endgroup\$
13
  • 3
    \$\begingroup\$ The first bonus doesn't make sense, as the terms localhost and @PHASE COME BACK WE ARE YOUR FRIEEEEENDS, just themselves, are 49 bytes. The language would need to do string-delimiter/comparison/output all in one character. ... Separately, how many iterations does the search need to travel? Meaning, if index1.html has a link to index2.html which has a link to index3.html which ... has a link to indexN.html, what's the limit on N? \$\endgroup\$ Jan 13, 2016 at 13:59
  • 2
    \$\begingroup\$ 1. I don't even understand what the second bonus is trying to say. 2. What syntax should we assume? Do we need to handle tag soup, or can we refuse to index pages which aren't valid XHTML? Do we need to support JS execution which affects the page content, web components, etc.? \$\endgroup\$ Jan 13, 2016 at 14:30
  • \$\begingroup\$ What counts as "visible text"? If there is white text on a white background, is that considered invisible? If there is another element stacked on top of the text, is that invisible? What if it is only visible on odd days of the month (because of some JavaScript)? If I have to scroll inside of a scroll pane in order to see it, is that considered visible? \$\endgroup\$
    – Rainbolt
    Jan 13, 2016 at 14:39
  • \$\begingroup\$ Can we assume that all links on the page will be valid links? If not, how should we handle errors like HTTP 404 (Not Found)? \$\endgroup\$
    – Rainbolt
    Jan 13, 2016 at 14:44
  • \$\begingroup\$ @Rainbolt all links are assumed to be valid. \$\endgroup\$
    – TanMath
    Jan 13, 2016 at 20:12
  • \$\begingroup\$ @TimmyD I didn't take "localhost" into account and now the bonus will be -75 bytes. Also, do you really think a limit on N is needed? \$\endgroup\$
    – TanMath
    Jan 13, 2016 at 20:15
  • \$\begingroup\$ @PeterTaylor syntax will be regular HTML.No need to handle JS. What I am saying in thr second bonus is that you would need to build a search engine that only puts text within the paragraph element (i.e. no tags will be counted as words) in the index. Also, other tags like <b> cannot be counted as words although it is part of the paragraph element. \$\endgroup\$
    – TanMath
    Jan 13, 2016 at 20:17
  • \$\begingroup\$ @Rainbolt visible text, for the sake of simplicity will be anything in the paragraph element. \$\endgroup\$
    – TanMath
    Jan 13, 2016 at 20:18
  • \$\begingroup\$ So only text in <p> elements should be counted? Text in titles etc should be ignored? (And what is "regular" HTML?) \$\endgroup\$ Jan 13, 2016 at 20:24
  • \$\begingroup\$ @PeterTaylor HTML 4 will be "regular" HTML (since HTML5 has to still work dominating the world!) although thst reslly wouldn't affect the crawling that much. The paragraph, preformatted text, and header will be counted as visible text. \$\endgroup\$
    – TanMath
    Jan 13, 2016 at 20:32
  • \$\begingroup\$ "HTML 4" still isn't very precise. Can answers require input to be conforming HTML 4.01 Strict? \$\endgroup\$ Jan 13, 2016 at 23:31
  • \$\begingroup\$ @PeterTaylor ok. \$\endgroup\$
    – TanMath
    Jan 13, 2016 at 23:31
  • \$\begingroup\$ This sandbox post has had little activity in a while and little positive reception from the community. Please improve / edit it or delete it to help us clean up the sandbox. \$\endgroup\$
    – user58826
    Jun 9, 2017 at 14:13
-5
\$\begingroup\$

Calculate Hello World!

Your goal is to calculate the simple string "hello world" or any other variant.

Rules

  • You may not use the characters in this set (inside your code): hHeElLoOwW rRdD!, in any form (character codes, hex codes, etc. not allowed) [only applies for direct use].
  • Your program may not take any input from any source.
  • Your program may only print hello world or any other variant to standard output (for your language). Again, it may not print anything else.
  • Standard loopholes apply (to clarify, they are not forbidden).
  • This challenge is underhanded.
  • Your program may not use any built-in string of printable characters (for example, string.printable in Python).
  • I recommend you be creative.

Remember, this is ! Have fun!

\$\endgroup\$
4
  • 3
    \$\begingroup\$ This is a trivial variant on stuff which has been done to death. It's also a Do X without Y question with obvious loopholes. \$\endgroup\$ Jun 12, 2016 at 21:50
  • \$\begingroup\$ @Peter, I wrote this for creativity. I wanted to see the community's creative answers. \$\endgroup\$
    – user36215
    Jun 12, 2016 at 21:56
  • \$\begingroup\$ This is not creative even remotely. I would even go as far as saying this is a duplicate of antoher challenge \$\endgroup\$
    – Bálint
    Jun 12, 2016 at 22:03
  • \$\begingroup\$ Underhanded contests are off topic by community consensus. \$\endgroup\$
    – Dennis
    Jun 14, 2016 at 3:19
-5
\$\begingroup\$

Letter Grade Challenge

Create a program that allows the user to input an int between 1 and 100, then grades that number based on standard US letter grades, printing the grade character as a result. Please use Java for this challenge, and like usual code golf challenges, the smallest answer (bytes) wins. For example, if input is 90, then you display A.

\$\endgroup\$
13
  • 6
    \$\begingroup\$ Welcome to PPCG and thank you for sandboxing. Please include the exact cut-off points. Is the input an integer or a floating point? Are the extremes included or excluded. We generally frown on language-specific challenges. Do you have any particular reason for restricting answers to Java? \$\endgroup\$
    – Adám
    Feb 28, 2018 at 23:11
  • \$\begingroup\$ Don't restrict which languages you can use. All it does is keep people who don't know Java from answering your past. Also, you should include the definition of the letter grade scale in your challenge, rather than along readers to look it up. \$\endgroup\$
    – Pavel
    Feb 28, 2018 at 23:11
  • \$\begingroup\$ You don't need to include the clause about multiple files. At PPCG, we include all necessary code in the byte-count. \$\endgroup\$
    – Adám
    Feb 28, 2018 at 23:13
  • 2
    \$\begingroup\$ What are "standard US letter grades"? \$\endgroup\$
    – Shaggy
    Feb 28, 2018 at 23:25
  • \$\begingroup\$ 90-100: A; 89-80: B; 79-70: C; 69-60: D; 59-0: F \$\endgroup\$
    – OCDkirby
    Mar 1, 2018 at 0:02
  • \$\begingroup\$ @Pavel Sorry about that. I saw a few people posting python only challenges a while back, so I assumed specific languages are the norm. \$\endgroup\$
    – OCDkirby
    Mar 1, 2018 at 0:03
  • 1
    \$\begingroup\$ @OCDkirby >_> Because people did that more often "A while back" doesn't mean it's still the norm, just look at the questions on the main page \$\endgroup\$
    – ASCII-only
    Mar 1, 2018 at 0:28
  • \$\begingroup\$ That's several years back. What was on-topic several years back can be off-topic now. Remember to see the timestamp. /// Stack Overflow has the same problem: see this (first revision). Now the title is not valid. \$\endgroup\$
    – DELETE_ME
    Mar 1, 2018 at 3:51
  • \$\begingroup\$ Please edit necessary information into the post. / Some example I/O please? \$\endgroup\$
    – DELETE_ME
    Mar 1, 2018 at 3:51
  • 1
    \$\begingroup\$ Probable dupe \$\endgroup\$
    – Jo King Mod
    Mar 1, 2018 at 5:21
  • \$\begingroup\$ @JoKing They use different letter grades. There is no 'E' in this grading system, and the number value requirements are different. \$\endgroup\$
    – OCDkirby
    Mar 1, 2018 at 16:05
  • \$\begingroup\$ @OCDkirby But still, if the algorthm on the other question can be adapted for this question with small modification, it's considered a dupe. \$\endgroup\$
    – DELETE_ME
    Mar 2, 2018 at 7:22
  • \$\begingroup\$ @user202729 Is editing every condition in an if statement and removing one condition considered a "small modification"? \$\endgroup\$
    – OCDkirby
    Mar 2, 2018 at 14:37
-5
\$\begingroup\$

Shortest Possible 240 Sided Die Program: Using No Constant Greater than 6

Have you ever played Yahtzee with a 240-sided die? No, probably not. Anyway, I came up with the idea of a 240-sided die program, but to make it hard, you cannot use a constant with an absolute value greater than 6. For example, randInt(1,240) wouldn't work. The chances of any number 1-240 must be completely equal, and using expressions that represent numbers with an absolute value larger than 240 is not allowed. For example, randInt(1,4*6*2*5) is against the rules, since 4*6*2*5 evaluates to 240. Standard loopholes prohibited, and you're code golfing.

\$\endgroup\$
1
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – DJMcMayhem
    Apr 27, 2018 at 20:19

You must log in to answer this question.

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