556
\$\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".

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

3988 Answers 3988

1
122 123
124
125 126
133
-1
\$\begingroup\$

Find the nth positive integer m for which \$\tan(m) > m\$

Task

Write a program/function that when given an integer \$n\$ as input outputs the \$n\$th positive integer \$m\$ for which \$\tan(m) \gt m\$.

Note: \$m\$ is in radians

Scoring

This is so shortest bytes wins.

Sample Testcases

# n -> m
1   -> 1
2   -> 260515
3   -> 37362253
5   -> 534483448
9   -> 214112296674652
10  -> 642336890023956
16  -> 4285797387061825747646013

Find more at A249836


Inspired by What is the biggest tangent of a prime?

\$\endgroup\$
9
  • \$\begingroup\$ +1 for referencing a MegaFavNumbers video. \$\endgroup\$
    – Razetime
    Aug 20, 2020 at 3:24
  • 4
    \$\begingroup\$ I don't understand the point. Are you asking us to find the nth number such that tan(x) > x? Is there any approach that will be shorter than iterating over all numbers until you find the nth number such that tan(x) > x? \$\endgroup\$ Aug 20, 2020 at 3:33
  • 1
    \$\begingroup\$ Where is n in the equation? I'm lost. \$\endgroup\$ Aug 20, 2020 at 9:07
  • 2
    \$\begingroup\$ @Razetime On the channel Stand-up Maths, right? \$\endgroup\$
    – Rosie F
    Aug 20, 2020 at 18:49
  • 1
    \$\begingroup\$ replace "nth" with "first" "second" etc -> "first/second/etc number m for which ..." i.e. n is not in the equation @V.Courtois \$\endgroup\$
    – golf69
    Aug 20, 2020 at 20:30
  • 1
    \$\begingroup\$ @Mukundan314 maybe indicate that n is the input? \$\endgroup\$
    – golf69
    Aug 20, 2020 at 20:31
  • 1
    \$\begingroup\$ @golf69 oh! So it has to be an integer, not a number. I see now :) And yes, indicating n is the input would be nice. \$\endgroup\$ Aug 21, 2020 at 6:50
  • 6
    \$\begingroup\$ I don't really see this being solved any way that taking the generic golfiest code for "find the n'th number meeting [predicate]", of which there's plenty of challenges, and sticking in tan(m)>m for the predicate. \$\endgroup\$
    – xnor
    Aug 22, 2020 at 7:04
  • 1
    \$\begingroup\$ Solutions relying on floating-point arithmetic will get the wrong answer starting around the 11th term. You’ll need to clarify whether that’s acceptable. \$\endgroup\$ Aug 22, 2020 at 22:14
-1
\$\begingroup\$

Is it a Pythagorean triple?

Given three numbers, determine whether they form a primitive Pythagorean triple. Here is the definition:

  • all three numbers are positive integers
  • they represent the side lengths of a right-angled triangle, that is, \$a^2 + b^2 = c^2\$ for any ordering of \$a\$, \$b\$, and \$c\$
  • no other primitive Pythagorean triple exists with the same ratio of side lengths, that is, they are coprime. For example, \$[6, 8, 10]\$ is not a primitive Pythagorean triple, even though it satisfies the above conditions, because the simper \$[3, 4, 5]\$ exists.

Rules

  • Unless your language doesn't support them, you must accept floating-point numbers (even though Pythagorean Triples use, by definition, integers)
    • meta: Is this necessary? Is it too restrictive?
  • You may be given negative numbers, \$0\$, or numbers that cannot form any triangle (right-angled or not, i.e. \$a + b \le c\$), in which cases you must return false.
    • meta: Is this necessary? Does it make it too difficult?
  • You can return any two distinct individual values, or any typical truthy/falsey values for your language.
  • Standard I/O and loophole rules apply.
  • This is , so shortest function or full program in bytes wins.

Test Cases

[0, 3, 3] => false
[3, 4, 5] => true
[5, 3, 4] => true
[3, 4, 6] => false
[3, 4, 10] => false
[6, 8, 10] => false
[3.0, 4.0, 5.0] => true
[3.1, 4.0, 5.0] => false
[-3, -4, -5] => false
[3, 4, -5] => false
[4.5, 6, 7.5] => false
[91, 60, 109] => true
[264, 265, 23] => true
[81, 210, 184] => false
[140, 221, 83] => false

Meta

  • Are the first two rules necessary, or do they restrict it too much?
  • Is it clear enough? Are there any additional rules I need to add? Are more test cases needed?
  • Does this suit the and tags? It's kind of tangential to both areas.
  • Is this too similar to the existing questions that want you to generate triples?
\$\endgroup\$
4
  • \$\begingroup\$ possible duplicate of this challenge \$\endgroup\$
    – Razetime
    Oct 18, 2020 at 13:38
  • \$\begingroup\$ @Razetime that challenge appeared on the front page today and inspired me to make this one. I thought it was different enough because of the coprime requirement and I added the extra rules about invalid values/floats to make it more interesting as well \$\endgroup\$
    – pxeger
    Oct 18, 2020 at 14:32
  • \$\begingroup\$ Input validation tends to make for a challenge that is less fun. The coprime requirement is nice, but I'm not sure if it completely changes the challenge. \$\endgroup\$
    – Razetime
    Oct 18, 2020 at 15:04
  • 2
    \$\begingroup\$ This seems to me to be too much a combination of two separate generic tasks, checking that a^2+b^2=c^2 when sorted, and that a and b are relatively prime. \$\endgroup\$
    – xnor
    Oct 19, 2020 at 9:40
-1
\$\begingroup\$

Am I A Perfect Two Integer?

A “perfect two integer” is an integer that works as x in the following equations:

Let i = integer, j = integer, x = perfect two integer:
2^i = x
j^2 = x

Example “perfect two integers”: 4, 16, 64, 256, 1024 (see a pattern here?)

Your answer should take a number from stdin or an argument. This should be relatively easy, but this is , so the shortest answer wins. (Note: there are ways to simplify these equations that aren’t listed here).


Sandbox Questions:

  1. Is this a duplicate?
  2. Is this too easy?
  3. Any other thoughts?
\$\endgroup\$
2
  • 3
    \$\begingroup\$ My personal feeling is that this is too easy. There's not really much scope for golfing the answer once you find the pattern. \$\endgroup\$
    – Sisyphus
    Oct 28, 2020 at 0:25
  • \$\begingroup\$ Yeah, you're probably right. It's kind of just like if it's a power of 4. I somehow didn't think about this while making the question. \$\endgroup\$
    – nthnchu
    Oct 28, 2020 at 0:34
-1
\$\begingroup\$

Undecidable halting set

Write a program such that the set of natural numbers on which it halts is not recursive.

Shorter is better.

You may assume natural numbers in your language are unbounded.

Example: Python 3 (52 chars)

lambda n:eval(n.to_bytes(n.bit_length()//8+1,'big'))
\$\endgroup\$
6
  • \$\begingroup\$ This boils down to "emulate a Turing-complete language", which is the same as eval in any Turing-complete language that supports the feature (as you already showed in the example). I don't think it's an interesting challenge. \$\endgroup\$
    – Bubbler
    Jan 19, 2021 at 6:37
  • \$\begingroup\$ @Bubbler Eval is only half the battle (assuming the language has eval in the first place). You still need to handle the fact that the inputs are natural numbers, not arbitrary strings. That is, you need to surject the natural numbers onto a set of strings sufficient to get the undecidable behavior under eval. \$\endgroup\$
    – user76284
    Jan 19, 2021 at 7:08
  • \$\begingroup\$ @Bubbler I'd consider an eval-free version of the challenge though, if you have any suggestions. Not sure how that restriction is usually phrased/enforced. \$\endgroup\$
    – user76284
    Jan 19, 2021 at 7:09
  • 1
    \$\begingroup\$ Eval is half of the battle, but the other half is converting a natural number to a string, which is just a matter of base conversion (which gives ALL strings, maybe except strings starting with null bytes, which doesn't matter in most languages). Unfortunately, banning built-ins is discouraged, and we already had a challenge about simulating a different Turing-complete language, so I don't think banning eval will make the challenge better. \$\endgroup\$
    – Bubbler
    Jan 19, 2021 at 7:36
  • \$\begingroup\$ @Bubbler Is banning eval not an objective restricted-source criterion, as opposed to “no built-ins”? \$\endgroup\$
    – user76284
    Jan 19, 2021 at 19:28
  • \$\begingroup\$ Banning built-ins means banning a specific feature of a language, like some old challenge banned exponentiation. It is different from restricted source, which is about restrictions in the source code as text, not looking at the features it uses. There are various classes of eval, e.g. interpret the whole language (Python's exec), interpret the subset of the language (Python's eval and ast.literal_eval), interpret a different language (you can't even count how many Turing-complete mini languages are out there; if Perl regex is Turing-complete, would you ban it?), etc. \$\endgroup\$
    – Bubbler
    Jan 21, 2021 at 0:53
-1
\$\begingroup\$

Here is the problem, for which I can only think of an iterative solution and have not found a closed formula.

This problem was found on : https://www.codingame.com/ in the shortest codemode.

You need to paint a house with R rooms.

For each room there are four walls and one ceiling, which all have the same dimensions and need C coats of paint.

You can't paint the next coat until the previous one has dried. You're finished when every wall is dry. Time taken to move between walls, ceilings, rooms is negligible.

It takes you M1 minutes to paint each coat, and M2 minutes for the paint to dry on each. You must finish in the least possible time, otherwise they will not pay you.

NOTE DON'T FORGET, THE PAINT MUST ALL BE DRY BEFORE YOU CAN RECEIVE YOUR PAYMENT!

In :

Line 1: R, C, M1, M2 separated by spaces.
R: Number of rooms in the house
C: Coats of paint needed for each wall/ceiling
M1: Minutes taken to paint each coat
M2: Minutes taken for paint to dry on each coat (measured from when you've finished the entire coat)

Out :

The time taken to paint the entire house in the format H:MM

Contraints

1 ≤ R ≤ 10
1 ≤ C ≤ 20
1 ≤ M1 ≤ 10000
1 ≤ M2 ≤ 10000

Dataset:

input: 1 1 12 0

output: 60

input: 5 2 5 30

output: 280

input: 1 5 5 200

output: 1045

\$\endgroup\$
5
  • 4
    \$\begingroup\$ Is this a problem from another site? If so, you need to state where the problem comes from. Also, unlike other online judge sites, we tend to allow submissions to be functions or full programs, and allow a wide range of I/O methods for both. Having to convert the minutes to hours/minutes and format as h:mm is not so related to the core (and requiring such formatting is discouraged on our site), so I suggest to simply output a number in minutes. \$\endgroup\$
    – Bubbler
    Jan 28, 2021 at 0:16
  • \$\begingroup\$ @Bubbler I have taken your remarks into consideration. I hope it's what you expected. \$\endgroup\$ Jan 28, 2021 at 9:31
  • 3
    \$\begingroup\$ Do you have permission to repost this challenge? CodinGame's rules state (Article 9): 'The reproduction, representation or use of all or part of the components proposed in the CodinGame Contests is strictly prohibited.' \$\endgroup\$
    – Dingus
    Jan 28, 2021 at 12:15
  • 2
    \$\begingroup\$ Posting a challenge from elsewhere so that you can be shown an answer is engaging with this community in bad faith. You can ask for programming help in places such as SO, but this isn't intended to be one of them. \$\endgroup\$
    – xnor
    Jan 28, 2021 at 17:05
  • \$\begingroup\$ @xnor I am not acting in bad faith or such. I found this problem interesting and I wanted to share with the community to find an optimal answser. There is nothing for me it this except extending my own knowledge as well as community knowledge \$\endgroup\$ Jan 29, 2021 at 9:00
-1
\$\begingroup\$

Hello World! - Generation 3392

Your job is to create a genetic algorithm that slowly evolves and mutates its string until the output is equivalent to "Hello World!".

The genetic algorithm should start with a random string generated, and continue for generations, making random mutations to its code, like this:

Gen 3393 - Hemmo World!

To:

Gen 3394 - Hemko World!

Heres how the randomization algorithm works:

  1. Create a function named randint(n), import the time module.
# Written in Python 3.8
import time # imports time
def randint(n): # create function
  1. Get the current time since Jan 1. 1970, multiply by n and assign it as var "t". Make t an integer not a float.
t=int(time.time()*n) # Set time, and multiply by n.
  1. Use the "%" operation on var "t" (var t is the first argument), with var n as the second argument, assign it as "rand". Code in python should look like this:
rand=t%n #setup a psuedorandom number, since you already have a counter, use n as the limit number, and reset the counter once the counter reaches the limit number. This generates a psuedorandom number within n.
  1. Return rand.
return int(rand) #return results as integer.

Your program should have:

  • A randomized start string (using the rand_int algorithm)
  • A point it reaches "Hello World!"
  • Mutation, using "parents". You are not allowed to completely change a string, only modify 1 character each generation.
  • Mutations are not allowed to be repeated twice/No mutation backtracking.
  • Once a genetic algorithm has a correct letter in its correct position (such as "e" in "reJ" and "Hes"). It is forced to stay as that letter in that position and the genetic algorithm is forced with that string forever, this repeats for all other positions. This way the time increases additionally instead of exponentially. So you cannot do this: ["Hlllr" -> "Hellr" -> "Hfllr"]

So I can do this:

Herlo Wcrld
Herlo Wrrld

But you cannot change >1 character/byte at a time:

Herto Wcrld
Heflo World

You can do whatever else you want with it if it satisfies those requirements.

Scoring:

This is , so the answer with the least amount of bytes wins.

\$\endgroup\$
12
  • \$\begingroup\$ For code golf to work, the rules must be very clearly defined. At the current state people will do do (s:=randomString()); while(s!="Hello world!"); print(s); (pseudocode): (you can make this a popularity contest, but that's even harder to get right. I don't know why) \$\endgroup\$
    – DELETE_ME
    Feb 6, 2021 at 13:46
  • \$\begingroup\$ @user202729 I want the person to make a genetic algorithm, where it starts with a random string. mutates the previous string randomly by 1 character during each generation, and eventually outputs "Hello World!" \$\endgroup\$
    – fr4cew
    Feb 6, 2021 at 13:55
  • 3
    \$\begingroup\$ Besides being poorly-defined, it is also an non-observable behavior. \$\endgroup\$
    – DELETE_ME
    Feb 6, 2021 at 14:02
  • \$\begingroup\$ No, (hey, that's a link. Read it.) \$\endgroup\$
    – DELETE_ME
    Feb 6, 2021 at 14:09
  • \$\begingroup\$ Wait, that's not what I mean. I'll explain it later. \$\endgroup\$
    – DELETE_ME
    Feb 6, 2021 at 14:47
  • \$\begingroup\$ @user202729 Right... \$\endgroup\$
    – fr4cew
    Feb 6, 2021 at 14:53
  • \$\begingroup\$ But if the mutations between generations are random, there's no guarantee that the program will ever generate a specific string. You have to add a constraint like "the program should not generate a given string twice" \$\endgroup\$
    – anotherOne
    Feb 6, 2021 at 17:11
  • \$\begingroup\$ @Davide I think that rule already existed in the "A point it reaches 'Hello World!'" but I'll add that anyway. \$\endgroup\$
    – fr4cew
    Feb 6, 2021 at 19:26
  • \$\begingroup\$ A few things that I find missing from the rules: How long is the string? How do you mutate space/punctuation marks? I agree that is has non-observable behavior, because you can't see it mutating the string. Does the code have to be in python? Why should it randomize its input and why should it be random during the process? Wouldn't it be better if you get a string from user input (defined length) and then transform it to "Hello World!" (because that would allow bf and other languages to work) \$\endgroup\$
    – Deadbeef
    Feb 7, 2021 at 6:37
  • \$\begingroup\$ @Deadbeef 1. The length of hello world, 2. It works with base 64, 3. No, 4. Because I liked it that way. 5. I do not know. \$\endgroup\$
    – fr4cew
    Feb 7, 2021 at 15:22
  • \$\begingroup\$ Okay, about the unobservable behavior, what I mean is... \$\endgroup\$
    – DELETE_ME
    Feb 7, 2021 at 15:59
  • \$\begingroup\$ It's relatively hard to define what exactly "having a string stored internally" means (what if the string is stored as a list of int values (char codes)? What about encoded in the exponent like in FRACTRAN?) Instead, you can require the programs to output the generations (i.e., print the random strings, each subsequent string has one character changed, etc.) [please review other sandbox posts] \$\endgroup\$
    – DELETE_ME
    Feb 7, 2021 at 16:02
-1
\$\begingroup\$

Return all elements around an index forming sun

Define a function that takes in a 2D array and a 2D index, and return all the elements of the 2D array that are directly vertical to, horizontal to, and diagonal to the given index, and the returned list must omit the index itself.

External modules, like numpy, as allowed. The most efficient program wins.

enter image description here

\$\endgroup\$
7
  • \$\begingroup\$ ... while we do have [fastest-code] on this site, there are specific requirements; restricting allowed programming languages is another problematic thing; \$\endgroup\$
    – DELETE_ME
    Feb 8, 2021 at 14:38
  • \$\begingroup\$ besides, this definitely sounds like that you're outsourcing your homework to this site. \$\endgroup\$
    – DELETE_ME
    Feb 8, 2021 at 14:38
  • \$\begingroup\$ @user202729 I already have a numpy solution... this is definitely not homework XD \$\endgroup\$ Feb 8, 2021 at 15:34
  • \$\begingroup\$ @user202729 Okay, removed language restriction. \$\endgroup\$ Feb 8, 2021 at 15:35
  • \$\begingroup\$ Okay, the other problem is with "most efficient code win". Code golf is popular around here because it's easy to measure, but with this you have to install all sort of weird programming languages on a test machine. \$\endgroup\$
    – DELETE_ME
    Feb 9, 2021 at 2:07
  • 2
    \$\begingroup\$ I don't think this is very interesting to do fastest code anyway, because it can be done in linear time anyway (with the array given); besides the general consensus is to allow "full program or function" [please review other sandbox posts] \$\endgroup\$
    – DELETE_ME
    Feb 9, 2021 at 2:11
  • \$\begingroup\$ @user202729 Okey. \$\endgroup\$ Feb 9, 2021 at 2:27
-1
\$\begingroup\$

Create a Screw

There are a variety of code cad languages, as well as other 3d API's that allow you to define shapes with code. Some of these are limited, while others are Turing complete and/or use a popular programming language such as Python or JavaScript.

The Challenge

Output a 3d model of a screw. Acceptable formats include .stl files and .obj files. A screw is defined as a shorter, wider cylinder on top of a taller, thinner cylinder, which should be threaded at least 5 times. Winner is whoever has the shortest code by two weeks after this question is posted. Standard rules and loopholes apply, with the exception that anything that allows you to programmatically define a 3d object is treated as a program language.



Changes

Should I add a spot for the screw driver to my definition of a screw? On the one hand, that would be more realistic, but on the other, it might just add bloat to answers, since I don't think there's anything interesting you can do with it.

I plan to include an example of a minimal screw under whatever definition I end up using, with pictures and outputs in every allowed format.

For the purpose of sorting and answer headers, should each langauge/framework combo be treated as a separate language? I'm leaning towards this, since It would be cool to have an easily searchable set of code for a bunch of different frameworks.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ While the challenge is probably clearly defined enough, it might not allow solutions more interesting than hardcoding compressed output. \$\endgroup\$
    – DELETE_ME
    Feb 15, 2021 at 2:04
  • \$\begingroup\$ How could I make sure that it does without fundamentally changing it? Or do you think that's not possible? I feel like there might be some potential for interesting ways of doing the threading, but I haven't used very many of these languages.. \$\endgroup\$
    – import huh
    Feb 15, 2021 at 2:40
  • \$\begingroup\$ No idea... I think that (1) if there's a lot of boilerplate in the file format, using a library might be shorter (2) if the structure of the output file is not very repetitive, computing the coordinates might be shorter than hard coding + compressing it. I'm not familiar with either file format so I can't tell. -- -- nevertheless the challenge is on-topic; what I've said only concerns whether it's interesting [please review other sandbox posts] \$\endgroup\$
    – DELETE_ME
    Feb 15, 2021 at 2:46
  • \$\begingroup\$ I think both formats basically just contain the points for every triangle used to represent the 3d object. To be honest I didn't really think about directly creating the file. Compared to using a library, it seems incredibly inefficient. That could make for an interesting challenge on it's own, though... \$\endgroup\$
    – import huh
    Feb 15, 2021 at 2:58
  • \$\begingroup\$ You should probably add a specific diagram with the proportions for the screw, or maybe ask the program to take it as input \$\endgroup\$
    – Razetime
    Feb 15, 2021 at 2:58
  • \$\begingroup\$ @Razetime There's no specific proportion, just "larger" and "smaller". \$\endgroup\$
    – DELETE_ME
    Feb 15, 2021 at 3:06
-1
\$\begingroup\$

Print your PPCG avatar

This is a graphical output question.

You have to connect to the codegolf.stackexchange.com in your homepage, scrape and download your avatar and show it in your default image viewer or some other way.

Standard loopholes apply, connections only allowed to codegolf.stackexchange.com

One language can be only used once, but a user can post multiple answers in different language

Tags: ,,

\$\endgroup\$
2
  • 3
    \$\begingroup\$ This is probably a dupe of this. Finding the avatar instead of the id wouldn't affect most of the code. Your final line is odd, do you mean that if I answered in a language it would prevent anyone else from using that language? That seems like a bad rule - what if I started on my answer and someone posted while I was working? I can't see any benefit, but perhaps I am not understanding. \$\endgroup\$ Feb 20, 2021 at 18:10
  • \$\begingroup\$ I think it would be interesting if you have to print the ascii representation of the user before you , without scraping. With a standard way to produce the ascii image so people can't differ. i.e. img to ascii \$\endgroup\$
    – Alex bries
    Feb 20, 2021 at 21:13
-1
\$\begingroup\$

See who can write the longest code in order to print "Hello World!". The rule is that if you remove any single character from the code, it should NOT run.

\$\endgroup\$
2
  • \$\begingroup\$ I think we have a similar challenge already. It's pretty easy to get an infinite score with these rules. \$\endgroup\$ Feb 25, 2021 at 1:23
  • 3
    \$\begingroup\$ It is a weaker version of Programming in a Pristine World and a different variant of Biggest Irreducible Hello World. But note that, in many languages, it is possible to add arbitrarily long no-op code that breaks when exactly one char is removed. For example, Python's ''+''+''+... causes syntax error when any of ' or + or a newline surrounding it is removed. \$\endgroup\$
    – Bubbler
    Feb 25, 2021 at 1:41
-1
\$\begingroup\$

Output function from one to another

I tried to post this twice and I gained negative feedback, so I will put what I have in mind here if anyone is interested.

Get a certain output function from one programming language and transfer to another. You'll be recreating an output function that came from a different programming language. There is a certain criteria in order for the answer to be valid:

  1. It should function the same way as the original function. All things that function can do should be applied to the recreated one. For example, Python's print() has certain keywords like end.
  2. Syntax doesn't matter. Example, if you can't use the << for cout, don't use it. Use what's available.
  3. The function should be able to output the same errors like the original. Replicate the same errors from the original function. If impossible, leave it out.

An answer example would be making printf() from C using Python or making Console.WriteLine() (or just WriteLine() if incapable) from C# using Ruby. Any output functions that are already similar to 2 languages don't need to be replicated in any of them.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ "Get a certain output function from one programming language and transfer to another." To clarify, is the challenge to write source code which works in two different languages and does the same thing? What's the winning condition because this sounds very trivial. For example, print does the same thing in many languages. \$\endgroup\$
    – 79037662
    Feb 24, 2021 at 20:25
  • 2
    \$\begingroup\$ Actually that doesn't mesh with "syntax doesn't matter". The point of this challenge is completely unclear, could you please clarify it? \$\endgroup\$
    – 79037662
    Feb 24, 2021 at 20:26
  • 1
    \$\begingroup\$ I see you edited this post but the point of the challenge is still completely unclear. What exactly would a valid submission look like? \$\endgroup\$
    – 79037662
    Feb 25, 2021 at 20:56
  • \$\begingroup\$ I don't really get the point of this task. Sure, someone could write code that does this, it might take some work to get exactly right, but is there a challenge underneath it? Is it code golf? \$\endgroup\$
    – xnor
    Feb 26, 2021 at 3:08
  • \$\begingroup\$ @xnor It isn't code golf, nor king of the hill. It's an ordinary coding challenge if they can replicate a function from one language to another. \$\endgroup\$ Feb 26, 2021 at 5:53
  • 1
    \$\begingroup\$ @MarkGiraffe That's not really a thing on this site -- challenges need to have an objective winning criterion. From the close reason: "Questions without an objective primary winning criterion are off-topic, as they make it impossible to indisputably decide which entry should win." \$\endgroup\$
    – xnor
    Feb 26, 2021 at 8:13
-1
\$\begingroup\$

Random Roman Numerals

Printing a random number is easy, but what about roman numerals? Your task is to output a random roman numeral from 1 to 1000, both inclusive.

Requirements:

  • Each number has to have the same chance of appearing
  • The program should use the language's random module or other random algorithm

Remember, I is 1, II is 2, III is 3. V is 5, X is 10, L is 50, C is 100, D is 500, and M is 1000. Also note that IV is 4, IX is 9, XL is 40, XC is 90, CD is 400, and CM is 900. For more information see the Wikipedia page.

This challenge is , so try to have the shortest program possible!

\$\endgroup\$
2
  • \$\begingroup\$ I'd really recommend loosening the restrictions for the random numbers. What if the language's random module doesn't guarantee exactly equal chances? Can we assume it does? What about an implementation of an algorithm typically used by language's random modules, like xorshiro or the mersenne twister? A much better restriction in my opinion would be requiring that every result is possible, and it's unlikely people will deviate too far from a uniform distribution anyway. \$\endgroup\$ Mar 10, 2021 at 5:43
  • 1
    \$\begingroup\$ Sounds like you're combining two or more unrelated core challenges into one ― consider splitting the challenge up into separate challenges ― or dropping unnecessary parts. Just watch out for duplicate challenges: random number generation and Roman numeral conversion are popular tasks. \$\endgroup\$
    – Adám
    Mar 10, 2021 at 6:01
-1
\$\begingroup\$

Is this an one-one function?

, , ,


Two sets given as input, one is the domain of a function, and other one is the co-domain of a function. As an example

$$ \{1,2,3,4\} $$ $$ \{5,6,7,8,9\} $$

Now if the range set of the function, i.e. set of each element in the co-domain set which maps to the domain set (1 -> 5, 2 -> 6, ......) is equal to the co-domain set, then it is a one-one function.

For the above example, the range set is

$$ \{5,6,7,8\} $$

So the range set is not equal to co-domain set, the function is not a one-one function.

Challenge

Inputted two domain and co-domain set of function, output a truthy value if the function is one-one or falsey if not.

Test cases

{1,2,3,4} {5,6,7,8,9} -> Falsey
{a,b,c} {b,c,d} -> Truthy
{4,8,2} {3,4} -> Falsey

Standard loopholes apply, , so shortest code wins

Pre-defining the input sets in the header section of TIO is not allowed.

\$\endgroup\$
3
  • 5
    \$\begingroup\$ Is this challenge simply asking if the two sets have equal length? If not, can you include counterexamples? \$\endgroup\$ Mar 21, 2021 at 18:03
  • \$\begingroup\$ @water_ghosts yes i feel it is like that \$\endgroup\$
    – Wasif
    Mar 22, 2021 at 5:14
  • 1
    \$\begingroup\$ not particularly interesting \$\endgroup\$
    – rak1507
    Mar 22, 2021 at 12:11
-1
\$\begingroup\$

Remaking Kernel

I made a program as a final project in the main CS50 Harvard course, and it was named Kernel, written in C alsongside CS50's library.

Functions

It has 7 functions: 4 main (talk, count, calculate, build) and 3 advice functions (error, feedback, help).

What each function does:

  • Talk asks for a prompt to the user and outputs the same thing. Talk Function
  • Count asks for a number to count from 1 to there. If the number is bigger than 50, it will lead to an error. Count Function
  • Calculate asks for 2 numbers and an operator (must be either +, -, * or /) then will calculate the value. If the result is a number is greater or equal to 999999999, it leads to an error. However, 0 / 0 = 0 and other division rules still apply. Calculate Function
  • Build asks for a size and something that it can build, which could be either a line, tower, wall, or pyramid. If the size is more than 20, it leads to an error. It would then ask for the character you want to use to build it, then it will be used to build the final product. There are multiple errors here, which is explained at the Error function.
    Build FunctionDisappointed that I can't make a proper pyramid.
  • Error is a library that shows all 14 errors, which is listed in the Error page of this post.
  • Feedback asks for feedback from the user and they can type whatever they want. The input will then be transferred in a new file called Feedback.list.

Feedback Function

Inside Feedback.list: What's in here?

  • Help displays the info of the entire app. Help Function

Errors

There are 14 written errors to prevent writing the real errors.

  1. NO_FUNCTION_ADDED: When asking for which function to use, entering a non-existent one will result to this error.
  2. ERROR_CLASS_NONE: In Error, entering a number which doesn't have its error will pop this up.
  3. COUNT_MAX: Well, typing a number greater than 50 won't put up the error, but counting up to 50 will.
  4. INVALID_DIVIDE: Anything divided by 0 in Calculate (except 0 / 0) will put up this error.
  5. ExTREME_VALUE: In Calculate, earning a final number of 999,999,999 or more will result to this error.
  6. OVERSIZE_CHUNK: Entering a size larger than 20 in Build will result to this error.
  7. UNKNOWN_STRUCTURE: Also in Build, inputting a structure unavailable will pop this up.
  8. UNCLEAR_INSTRUCT: If the input for Build's line is not vertical, horizontal or diagonal, they wouldn't know what it is.
  9. OVERWIDTH_COUNT: Building a tower with a width of 20 or more is invalid.
  10. INVALID_PYRAMID: Similar to Build's line, inputting a pyramid unavailable pops this up.
  11. OPERATE_BAD: Inputting an operator unavailable in Calculate is invalid.
  12. MORE_NAMES: If you didn't know, to run Kernel, you need to add your name alongside running it. Me, I use ./Kernel MarkGiraffe. If I use Mark Giraffe instead, it is invalid.
  13. SECRET_USER: Even NOT putting a name is not allowed.
  14. BAD_ALIGNMENT: Not choosing left or right for a diagonal line in Build is invalid.

For this challenge, I want you to remake the program the most designed way, while still keeping low bytes.

In case you are interested, I will post the source code somewhere where you can view it.

\$\endgroup\$
2
  • 5
    \$\begingroup\$ This has LOTS of quality issues. 1) Being a multipart challenge with unrelated subtasks. 2) Rigid I/O (command line arguments AND interactive stdin/stdout AND file output). 3) Input validation and error handling in arbitrary ways. 4) Lack of specification in certain cases. 5) Putting I/O examples in images instead of code blocks. \$\endgroup\$
    – Bubbler
    Mar 23, 2021 at 4:10
  • 2
    \$\begingroup\$ I think the outstanding question is, why would people want to code and golf here? Like, it's cool that you wrote a thing, but it seems like a lot of work for someone to re-do on a recreational programming site without a really compelling reason. \$\endgroup\$
    – xnor
    Mar 26, 2021 at 3:29
-1
\$\begingroup\$

Given a program as input. If the program ever output a '1', output a truthy value and halt; if it halts without ever outputting a '1', output a falsy value and halt; if it falls into infinite loop without outputting a '1', fall into infinite loop.

\$\endgroup\$
3
  • \$\begingroup\$ This is unclear, for example: what language will the program be in? Do we take it as a string? And for a turing-complete language, this is impossible (at least if it can take input). \$\endgroup\$
    – Wezl oOvOo
    Apr 2, 2021 at 15:45
  • \$\begingroup\$ @Wezl Why not?? \$\endgroup\$
    – l4m2
    Apr 2, 2021 at 16:09
  • \$\begingroup\$ You didn't specify the above ^ points, which are important. \$\endgroup\$
    – Wezl oOvOo
    Apr 2, 2021 at 16:17
-1
\$\begingroup\$

Poly-functional Polyglots

I don't have a ton of time to work on this, so I decided to remove it temporarily while I rework the scoring.

\$\endgroup\$
2
  • \$\begingroup\$ I think the scoring system is too convoluted. Optimizing for the bonuses seems like more of a challenge than completing the core task. And if number of languages is the denominator, it’s hard to know how to calculate that upfront. How many shells does echo “Hello World” work in? If I later learn about another one, does that retroactively lower my score? \$\endgroup\$ Apr 2, 2021 at 16:53
  • \$\begingroup\$ @water_ghosts thanks for saying so. I was worried that that would be the case, especially after reading the discussion on things to avoid in questions. I'm going to try and rework this. \$\endgroup\$ Apr 8, 2021 at 19:26
-1
\$\begingroup\$

Generate a Printing Program In Some Language

Task

Given some rules:

1: Hello
2: World
4: Code
7: Golf
9: Whatever

Your program should output a program or a function (the output), which should be a valid program (or function) in some language. When the output is run, it should

  1. Ask for some input (i),
  2. Then output the string in the ith index in rules. (If there are none, don't output anything - even an error.)
  3. Return to step 1.

Example:

Rules:

1: Hello
5: World
19: Code

One possible output (python):

while True:
  i = int(input())
  if i == 1:
    print("Hello")
  if i == 5:
    print("World")
  if i == 19:
    print("Code")

Scoring

Your score is the bytes in your answer (not the output).


Obviously this question should be clarified.

\$\endgroup\$
6
  • \$\begingroup\$ Can we take input as an array of rules (2d, like [[1, "hello"], [2, "weijfiwef"]])? If the index is not in the rules list, can we output an empty string? \$\endgroup\$
    – user100690
    May 16, 2021 at 7:42
  • \$\begingroup\$ Well I thought about that, but some strong-type languages don't allow different types in a same array. If the index is not in the rules list, you can't output anything (as said in step 2). \$\endgroup\$ May 16, 2021 at 8:33
  • \$\begingroup\$ Is my output required to be a full program or it is allowed to be a function? \$\endgroup\$
    – tsh
    May 17, 2021 at 7:21
  • \$\begingroup\$ Yes @tsh, can be either full program or function. \$\endgroup\$ May 17, 2021 at 14:09
  • \$\begingroup\$ Why downvotes? Could you please explain why? I'll improve \$\endgroup\$ May 17, 2021 at 14:19
  • \$\begingroup\$ @SketchySketch Not a downvoter, but it seems to be a boring challenge. \$\endgroup\$
    – Xwtek
    May 20, 2021 at 9:18
-1
\$\begingroup\$

Given two reals \$a\$ and \$b\$, output some reals \$r_i\$, such that \$\sum r_i=a\$ and \$\prod\left(r_i+1\right)=b\$. You can assume that it's possible. You can also assume that your float type have infinite precision.

Test cases:

2,3 => 2 or etc.
2,4 => 1,1 or 1/2,(sqrt(57)+9)/12,(9-sqrt(57))/12 or etc.
2,5 => 1/3,1/2,2/3,1/2,0 or etc.
2,8 => sqrt(17)+2,2-sqrt(17),-2 or etc.
2,2 => sqrt(2)+1,1-sqrt(2) or etc.
e,2e => 1,e-1 or etc. (e is natural base, though any number>1 work)
-4,9 => -2,-2 or etc.
0,-1 => sqrt(2),-sqrt(2) or etc.

Shortest code wins.

Notes

  • Though I only removed two positives from the existing question, it's a huge change to the result.
  • I decide to keep the assume possible part just to make the note above correct. It can actually be proven that it's always possible.
\$\endgroup\$
-1
\$\begingroup\$

Breaking BogoBogoSort (In Badness)

The title says it all - make a sorting algorithm with a time complexity of \$O(n!^{n!})\$ or higher in the fewest bytes possible - as far as I can tell, that will require you to make a double exponentiatial formula or worse: that is, \$O(a^{b^n})\$, where \$a, b > 1\$.

Rules (since there must be some)

The list must be returned sorted in a finite time. This can be as high or as low as you want.

The algorithm must work for any real numbers (-30% if you can sort any single type given it's non-mixed).

The algorithm must work of any list length, and must eventually outpace ALL \$O(n!^{n!})\$ formulas, not just BogoBogoSort, and you must state the exact \$O\$ growth rate (for example, \$O(2^{3^n})\$). It may start off slow, but must eventually outpace all other expo-factorial functions (as I now name this growth rate).

Shortest code wins.

\$\endgroup\$
2
  • \$\begingroup\$ What prevents someone from doing a loop just to make it slower (or calculating \$ n!!!! \$, etc.), and then just sorting the array with quicksort? \$\endgroup\$ Jun 5, 2021 at 8:00
  • \$\begingroup\$ Logic. Logic prevents them from doing something that the question didn't mean you to do. Standart loopholes are forbidden by default \$\endgroup\$ Jun 7, 2021 at 8:25
-1
\$\begingroup\$

Get the Collatz Sequence

The Challenge

Write a full program or function that, when given an integer \$n \ge 0\$, outputs all steps of the Collatz Sequence (A006577) of \$n\$.

The Collatz Sequence

The Collatz Sequence is defined as: $$ a(n) = \begin{cases} n/2, & \text{if $n$ is even} \\ 3n+1, & \text{if $n$ is odd} \end{cases} \text{while n > 1} $$

Input

Input is some integer \$n \ge 0\$.

Output

Output is the sequence of numbers visited while calculating the Collatz Sequence, while the output is greater than 1.

Additional Rules

Test Cases

n -> sequence
0 -> [0]
1 -> [1]
2 -> [2, 1]
3 -> [3, 10, 5, 16, 8, 4, 2, 1]
4 -> [4, 2, 1]
5 -> [5, 16, 8, 4, 2, 1]
6 -> [6, 3, 10, 5, 16, 8, 4, 2, 1]
7 -> [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
8 -> [8, 4, 2, 1]
9 -> [9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
10 -> [10, 5, 16, 8, 4, 2, 1]
15 -> [15, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1]
20 -> [20, 10, 5, 16, 8, 4, 2, 1]
25 -> [25, 76, 38, 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
30 -> [30, 15, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1]
35 -> [35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1]
40 -> [40, 20, 10, 5, 16, 8, 4, 2, 1]
45 -> [45, 136, 68, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
100 -> [100, 50, 25, 76, 38, 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
9329 -> [9329, 27988, 13994, 6997, 20992, 10496, 5248, 2624, 1312, 656, 328, 164, 82, 41, 124, 62, 31, 94, 47, 142, 71, 214, 107, 322, 161, 484, 242, 121, 364, 182, 91, 274, 137, 412, 206, 103, 310, 155, 466, 233, 700, 350, 175, 526, 263, 790, 395, 1186, 593, 1780, 890, 445, 1336, 668, 334, 167, 502, 251, 754, 377, 1132, 566, 283, 850, 425, 1276, 638, 319, 958, 479, 1438, 719, 2158, 1079, 3238, 1619, 4858, 2429, 7288, 3644, 1822, 911, 2734, 1367, 4102, 2051, 6154, 3077, 9232, 4616, 2308, 1154, 577, 1732, 866, 433, 1300, 650, 325, 976, 488, 244, 122, 61, 184, 92, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1]
4637823 -> [4637823, 13913470, 6956735, 20870206, 10435103, 31305310, 15652655, 46957966, 23478983, 70436950, 35218475, 105655426, 52827713, 158483140, 79241570, 39620785, 118862356, 59431178, 29715589, 89146768, 44573384, 22286692, 11143346, 5571673, 16715020, 8357510, 4178755, 12536266, 6268133, 18804400, 9402200, 4701100, 2350550, 1175275, 3525826, 1762913, 5288740, 2644370, 1322185, 3966556, 1983278, 991639, 2974918, 1487459, 4462378, 2231189, 6693568, 3346784, 1673392, 836696, 418348, 209174, 104587, 313762, 156881, 470644, 235322, 117661, 352984, 176492, 88246, 44123, 132370, 66185, 198556, 99278, 49639, 148918, 74459, 223378, 111689, 335068, 167534, 83767, 251302, 125651, 376954, 188477, 565432, 282716, 141358, 70679, 212038, 106019, 318058, 159029, 477088, 238544, 119272, 59636, 29818, 14909, 44728, 22364, 11182, 5591, 16774, 8387, 25162, 12581, 37744, 18872, 9436, 4718, 2359, 7078, 3539, 10618, 5309, 15928, 7964, 3982, 1991, 5974, 2987, 8962, 4481, 13444, 6722, 3361, 10084, 5042, 2521, 7564, 3782, 1891, 5674, 2837, 8512, 4256, 2128, 1064, 532, 266, 133, 400, 200, 100, 50, 25, 76, 38, 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]

Tags:

For Meta

  • Is it clear?
  • Any corrections?
\$\endgroup\$
3
  • \$\begingroup\$ I'd consider this a duplicate of the current Collatz challenge, as the only way to find the length is to generate the sequence, so the answers will all be doing the same thing, just without a length call tacked on the end \$\endgroup\$ Jul 31, 2021 at 16:38
  • \$\begingroup\$ That is what I've always wondered, though, is how we have a length of Collatz challenge but not a Collatz sequence generation challenge \$\endgroup\$
    – bigyihsuan
    Jul 31, 2021 at 19:58
  • \$\begingroup\$ Because there is no way to determine the length of a Collatz sequence without generating it, so the core of the challenges would be the same - generating the Collatz sequence. \$\endgroup\$ Jul 31, 2021 at 20:00
-1
\$\begingroup\$

Shortest common superstring

Your challenge is to find the shortest common superstring (SCS) for a sequence of English words. The SCS for a sequence is the smallest string that contains all the words in the sequence. The words should be passed as a function parameter.

Answers should be posted in the following format:

<Language name>, <Byte count>

<code>

This is code-golf, so the answer with the least bytes wins.


Any suggestions?
\$\endgroup\$
3
  • 1
    \$\begingroup\$ I wouldn't suggest using a popularity contest for a task that looks like it can be code-golf. However, this is likely a duplicate. caird will be around in a while with a more length message and a link to a dupe :P \$\endgroup\$
    – user
    Aug 18, 2021 at 18:53
  • 1
    \$\begingroup\$ Welcome to Code Golf, and thank you for using the Sandbox first! Unfortunately, this is a duplicate. \$\endgroup\$ Aug 18, 2021 at 19:03
  • \$\begingroup\$ Ok, well that's fine. \$\endgroup\$
    – Bgil Midol
    Aug 18, 2021 at 19:04
-1
\$\begingroup\$

Tac-Tok-Toe

Tac-Tok-Toe is just like tic-tac-toe, but instead of three in a row, the winning condition is three in a row but each letter is exactly one space apart horizontally, vertically, or diagonally. The win can also go in any direction.

The games

Each team (X and O) will make their own tac-tok-toe AI's. 10000 games will be played.

The moves

AI.PUT_TILE(board: List[List[str]], place: List[int])
    Places a tile at the specified location

AI.DECIDE_MOVE(board: List[List[str]])
    Decides and returns the index the AI wants to move depending on the current board situation.

AI.GET_WINNER(board: List[List[str]])
    Returns the winner of the board.

The board

The starting board looks like this:

 | | 
 | | 
 | | 

(Yes, I know, that indeed is a horrible tac-tok-toe board.) For example, place [0, 0] is in the upper left square, and place [1, 1] is in the middle. If the X AI places an X at [2, 2], the board would now look like this:

 | | 
 | | 
 | |X

An example of a completed grid could look like this:

X|X|O
O|X|X
O|O|X

We see that X has won, so the game should print: "X wins!"

Game files

[Your side]AI.py:

class [Your side]AI:  # Maybe change to something more meaningful?
    def PUT_TILE(board, place):
        pass
    def DECIDE_MOVE(board):
        pass
    def GET_WINNER(board):
        pass

startboard.txt:

 | | 
 | | 
 | | 

Meta

Any suggestions?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Given that tic-tac-toe is a solved game, you're going to get a lot of near-identical submissions that play perfectly and always end in a draw. Unless you can put some kind of extra spin on tic-tac-toe that makes it more challenging, I'd pick a different game for a KotH. (Maybe one of these variants could work.) \$\endgroup\$
    – DLosc
    Sep 23, 2021 at 19:16
  • \$\begingroup\$ If you want some tips on writing KotHs with interesting gameplay, check out the king-of-the-hill tag wiki! \$\endgroup\$ Sep 23, 2021 at 19:20
  • 1
    \$\begingroup\$ Can you explain the win condition a bit better? How can you have 3 in a row with 1 space between them unless the board is 5x5 or larger? \$\endgroup\$
    – hyper-neutrino Mod
    Sep 23, 2021 at 19:26
  • \$\begingroup\$ It can go in different directions. \$\endgroup\$
    – Bgil Midol
    Sep 23, 2021 at 19:26
-1
\$\begingroup\$

Randombility of number

The aim of golf is to calculate score of how random 10 inputs given by users were. The Criteria is given below.

  • Points Rule
  • 5+(1.1)^n If inputted numbers are not in Arithmetic OR Geometric progression for n cnsecutive terms
  • 5+(1.1)^n if inputted numbers are not strictly increasing or decreasing for n>2
  • 5*n if number is prime number > 100 here n is number of such terms
  • -5-(1.1)^n if number is substring of $\pi$$ (3.1415926535897932384626433) for n>2
  • 5 if difference between largest and smallest input is greater than 1000
  • -5*n for n repeated inputs
  • -5 + ln(log(p)) if number is square or cube of any number beetween -100 and 100 here p is number
  • -5 if any three input ressemble any valid date (dd/mm/yyyy or mm/dd/yyyy) time(hh/mm or mm/hh) format
    • -Additional
  • (1.5)^n if time interval between two inputs is less than 1.5 seconds

Improvements required Score system.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Can you please clarify your challenge? I don't get even the point of the challenge or how to win. \$\endgroup\$
    – Seggan
    Oct 26, 2021 at 15:05
-1
\$\begingroup\$

Secretary Problem - Cops and Robbers

Both threads

(Link to other thread)

The Secretary Problem is a famous problem. In this challenge, it’s a little different:

  1. You need a new secretary that asks for the least salary
  2. You have a lot of applicants that you can interview one at a time, but don’t know how many applicants there are
  3. Each applicant will tell you how much salary they want (they’ll want at least $1 salary, but may all want $5)
  4. Applicants do not ever request the same salary for some weird reason (not sure if they’re robots or eavesdroppers)
  5. After you interview an applicant, you must give an immediate "yes, I accept you" (truthy) or "no, go away" (falsey)
  6. You want the applicant that asks for the lowest salary, so you can stay rich
  7. No applicant ever requests more than 1 million dollars (for obvious reasons)

In the maths world, it’s actually that you want the highest leveled applicant, but I put it this way because who doesn’t want to stay rich

Cops Thread

Your challenge is to write a program that takes two inputs: the previous applicants’ salaries, the current applicant’s salary, and outputs whether to accept the applicant (truthy) or deny him/her (falsey).

The robbers will attempt to find a list of applicants (and the salaries they demand) that forces your program to accept a person with a high salary demand. You need to attempt to make your program only accept the applicant which asks for the LEAST salary (that way you can stay rich)

The answer that (when answered against by a robbers thread - [link]) accepts the person with the least salary wins/gets accepted (i.e. the answer that accepts a $1, if that doesn’t exist, then the answer that accepts a $2, if THAT doesn’t exist ... and so on)

If your answer does not accept any, (up to the last applicant) you automatically get

Robbers thread

Each answer in the cop’s thread is a program that takes two inputs: the previous applicants’ salaries, the current applicant’s salary, and outputs whether to accept the applicant (truthy) or deny him/her (falsey).

Your challenge is to find a program in the cop’ thread (insert link here) and attempt to give it an input such that it accepts a person with a HIGH salary request. Answer that forces an algorithm to accept the highest amount of money gets accepted (i.e. the answer that forces a cop answer to accept a $1000000 salary applicant, if that doesn’t exist, the answer that forces a cop answer to accept a $999999 salary applicant, if THAT doesn’t exist ... and so on)

Put a link cop answer you are attempting to make go broke in your answer.

You must have at least 100 applicants (with at least one applicant that requests <$100)

Both threads (again)

To stop people getting free points, you cannot make a robbers answer for your own cop answer. 1 answer per thread (you can have both a robber answer and a cop answer as long as the robber answer is against a different cop answer)

Sandbox questions

  • Is this too far-fetched?

Somewhat shamelessly stolen Derived from this question

\$\endgroup\$
3
  • \$\begingroup\$ If the cop is forced to accept the last applicant if they haven't previously accepted anyone, isn't having exactly one applicant with a salary of $1m an unbeatable strategy for a robber? \$\endgroup\$
    – Dingus
    Oct 24, 2021 at 3:49
  • \$\begingroup\$ Changed - "at least 100 applicants" and "at least one applicant that requests <$100" \$\endgroup\$
    – W D
    Oct 27, 2021 at 5:27
  • 1
    \$\begingroup\$ The cops can consider only the bound of $100, as at least one robber will be <$100. \$\endgroup\$
    – pajonk
    Oct 27, 2021 at 9:03
-1
\$\begingroup\$

Output a random integer in a range that is a multiple of all in one set and not a multiple of any in another set

Given an integer range and two sets of integers, generate a random integer inclusive within the range that is a multiple of all the numbers in the first set but is not a multiple of any number in the second set, or specify that such a value does not exist.

Examples:

  • Range: 100 - 200
  • Divisors: 3, 5
  • Non-divisors: 9, 10

Possible values are: 105, 165, 195 (output one at random)

Rules

  1. Mathematically elegant solutions are preferred, but brute force solutions are accepted.
  2. If outputting one of multiple values is possible (as shown above), the solution should return a different value with each execution so that, probabilistically, all possible values are eventually output.
  3. This is code golf, so lowest byte count wins.

NOTE I have a solution for this in C#, but I'm curious of what other solutions there are. I had a heck of a time working out the math for this and thought it would be a good bit of puzzling for this community.

\$\endgroup\$
5
  • \$\begingroup\$ The First Rule is unnecessary. \$\endgroup\$
    – Fmbalbuena
    Nov 5, 2021 at 18:49
  • \$\begingroup\$ Why do you say so? If not included, I expect only brute force solutions will be provided. \$\endgroup\$ Nov 7, 2021 at 19:12
  • 1
    \$\begingroup\$ If the first code is included and others may think is fastest-code tag \$\endgroup\$
    – Fmbalbuena
    Nov 9, 2021 at 15:32
  • \$\begingroup\$ I suppose that is one of the end goals. Maybe that's a win condition I need to add. I've never seen that in code golf. I'll have to research that tag for examples. \$\endgroup\$ Nov 9, 2021 at 19:26
  • \$\begingroup\$ This needs testcases (pick one at random) and add tag random. \$\endgroup\$
    – Fmbalbuena
    Nov 11, 2021 at 21:59
-1
\$\begingroup\$

Quantum boolean

Background

Have you ever dream of quantum state? If that's true for you, you are probably weird...

Anyway, I came up with an idea: what if we make a quantum in code?

Task

Create a data type, function, or class, anything that can be put in a condition.

What should it do:

(def your thing here, I'll name it "X" for now)


if X:
  part a
else:
  part b

part a and b should both be executed, although the chance of which being first should be 50/50.


if X:
  a=5
else:
  a=10
  b=5

a should have 50% chance to be 5, 50% 10, but b will always be 5

x can be different everytime mention, or always the same on parallel universe

if X:
  part a
else if X:
  part b
else:
  part c

Could be:

execute a,b,c with a 50% being first execute,b,c 25% each.(second X and first X both being quantum)

In this case a will never be the second one executed.

possible case:

a,b,c
a,c,b
b,c,a
c,b,a
     / a True 50%
init           / b True 25%
     \ a False 
               \ b False - c 25%
     First X     Second X

Or:

X True for a

X False for c

b will never be executed.

     / X True - a
init 
     \ X False - c

Example

X as your submit

if X: # or X()
  print(1)
else:
  print(2)

return

1
2

or

2
1

Extra

A whole compiler/transpiler (changing code to fit in quantum state) is allowed, but will compete on it's own(with other compiler style anwser).

Rule

  • Standard rules.

Goal

golf your quantum as smaller as possible!

Meta

  • Is this clear?
  • Is this hard?
  • Is this fun?
\$\endgroup\$
2
  • \$\begingroup\$ This doesn't make a whole lot of sense to me. You seem to be describing a code construct that takes a list of statements and executes them all in random order. By design that isn't how if/else statements work: 'part a and b should both be executed' can't happen no matter how you define X. \$\endgroup\$
    – Dingus
    Nov 18, 2021 at 3:30
  • \$\begingroup\$ @Dingus one of the possible way is to have function X read self source code, you don’t have to run excatly same code on excatly position, you can copy statement and execute it at other file/place, or just rerun program with modifications upon called. \$\endgroup\$
    – okie
    Nov 18, 2021 at 5:50
-1
\$\begingroup\$

Silly Sentence Generator

Your challenge is to input a sentence and find all words enclosed within angle brackets. (< and >)

Here is an example:

The <adjective> <noun> biked across the bridge.

Next, replace all <noun>s with a random noun, all <verb>s with a random verb, all <adjectives>s with a random adjective, and all <adverb>s with a random adverb.

According to the above rule, The <adjective> <noun> biked across the bridge. could become The daring monkey biked across the bridge.

Your program will input a list of nouns, verbs, adjectives, and adverbs.

Make sure the words follow capitalization. So if the random noun in <noun> <verb>ed is monkey, it should then become Monkey. Another rule is that if a verb (like slide) ends with e, and the bit after the <verb> is ing or s, (e. g <verb>ing) do not keep the final e. (e. g slideing becomes sliding).

Examples

Note that these examples assume the nouns are monkey and ai, the verbs jumped and sliding, the adjective daring, and any list of adverbs (since the examples don't use them.)

The <noun> was <verb>ed by the <adjective> <noun>. => The monkey was jumped by the daring ai.

<verb>ing <noun>s play together. => Sliding monkeys play together.

Shortest code wins!

\$\endgroup\$
6
  • \$\begingroup\$ I would suggest replacing the "Test cases" section with "Examples" to show some possible outputs. \$\endgroup\$ Sep 17, 2021 at 17:44
  • \$\begingroup\$ @AaronMiller Added some test cases and additional rules. \$\endgroup\$
    – Bgil Midol
    Sep 17, 2021 at 17:53
  • \$\begingroup\$ You don't specify in these cases whether you want to be including the propagation of the word lists, etc. into the code golf challenge. If this is a requisite that the population of the lists be included in the bytes, this is going to make every 'golfed' solution pretty huge, even with small word lists you've provided. \$\endgroup\$ Sep 17, 2021 at 18:15
  • \$\begingroup\$ @ThomasWard Edited. \$\endgroup\$
    – Bgil Midol
    Sep 17, 2021 at 19:00
  • \$\begingroup\$ I think it would be better to instead take the lists of words as additional inputs \$\endgroup\$
    – Mayube
    Dec 1, 2021 at 18:33
  • \$\begingroup\$ It's still not clear if we're hardcoding the words or not \$\endgroup\$ Dec 1, 2021 at 18:34
-1
\$\begingroup\$

Output sequence from a name

You are given a sequence of numbers(0-9) which you have to convert to its literal form.

Example

Input : 1246
Output : 26666

We interpret the input as one 2 four 6, thus giving the output 2 one time and 6 four times

Testcase

Input Output
1234567809 2444666668888888
2345 335555

P.S.

  1. Is this descriptive enough?
  2. Would it be fun to do?
\$\endgroup\$
1
-1
\$\begingroup\$

Can I obtain this Minecraft item?

Given a list of items I have access to, determine if I can obtain a certain amount of some other item via crafting, mining, trading, and some other actions.

Actions

This is a list of all actions which may be performed, and what items they involve

Crafting:

  • Log × 1 to Planks × 4
  • Planks × 2 to Stick × 4
  • Dirt × 2, Gravel × 2 to Coarse Dirt × 4
  • Glass × 6 to Glass Pane × 16

Mining:

The following require a wood pickaxe, or above:

  • Stone × 1 to Cobblestone × 1
  • Coal Ore × 1 to Coal × 1

The following require an iron pickaxe, or above:

  • Diamond Ore × 1 to Diamond × 1
  • Emerald Ore × 1 to Emerald × 1

The following do not require a tool:

  • Coarse Dirt × 1 to Dirt × 1
  • Gravel × 1 to Flint × 1

Smelting:

Smelting requires fuel, see below. These are the items that can be smelted:

  • Cobblestone × 1 to Stone × 1
  • Sand × 1 to Glass × 1
  • Coal Ore × 1 to Coal × 1
  • Iron Ore × 1 to Iron Ingot × 1
  • Diamond Ore × 1 to Diamond × 1
  • Emerald Ore × 1 to Emerald × 1
  • Kelp × 1 to Dried Kelp × 1

(unfinished)

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

Biggest 25 byte number

You are allowed 25 bytes of source code.

With these you have to calculate the biggest finite number possible, assuming infinite number precision[1], runtime and memory.

You will not be taking input and do not have to output the final result.

You are not allowed to use a String representation, so "9".repeat(BIG_NUMBER) is disallowed.

Scoring will be based of the final number, bigger numbers ranking higher.

[1]: This means that for example in java you do not need to use BigInteger to represent big numbers, but using an int would be sufficient. Over- and underflows are ignored as if the int had infinite precision.

\$\endgroup\$
1
122 123
124
125 126
133

You must log in to answer this question.

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