536
\$\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 needs more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended!

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

3505 Answers 3505

1
102 103
104
105 106
117
0
\$\begingroup\$

Conic Sections (simplified)


Given the equation of a non-parabolic conic section, output its characteristics.


Spec

This assumes prior knowledge of hyperbolas and ellipses, as well as their characteristics. (This includes circles; they are a special case of the ellipse with eccentricity of zero.)

Input

A non-parabolic (to simplify things) conic section given in the standard equation form. To simplify things further (because the main point is not to perform linear algebra magic) there will be no xy term. This is an example of a valid equation:

x^2+6x+y^2-8y+15=0 // string form
[1,6,1,-8,15]      // array form

These are not:

x^3+5x^2+7x+4=0 // because the degree of the equation is 2
x^2+5xy+y^2-4=0 // because there should be no `xy` term
x^2+3x+7=0      // because there should be `x` and `y` terms.

Note that the conic section can also be taken as an array as shown above. If so, please specify the order of the array; I am flexible when it comes to this format, As long as there are 5 elements with nonexistent terms represented by zero (like no y term in x^2+5x+y^2+14=0) and that the terms they represent are x^2 x y^2 y c where c is a constant. The equation will always be <expression> = 0.

Output

Output should be the type of section, center, horizontal radius, vertical radius, foci and eccentricity (in whatever desired order). This can be output as a string or an array as long as it is clear. A valid output for x^2+6x+y^2+8y+16=0 (or its array equivalent) would be:

["ellipse", [-3, -4], 3, 3, [[-3, -4]], 0]

or

ellipse
-3 -4
3
3
-3 -4
0

or similar.

(no need to output "circle" because it is a special case of the ellipse)

Meta:

  • duplicate?
  • should I edit in info on conic sections?
  • should I create the characteristics tag?
\$\endgroup\$
2
  • \$\begingroup\$ One issue with the x^2+5xy+y^2-4=0: It is a valid conic section (hyperbola). \$\endgroup\$ May 30 at 21:01
  • \$\begingroup\$ @fasterthanlight I know, but we are not considering xy terms in this challenge. \$\endgroup\$
    – user100690
    May 31 at 8:01
0
\$\begingroup\$

Is this a trivial brainfuck NOP?

Brainfuck is Turing-complete*, which means determining the behaviour of an arbitrary program is undecidable. However, we can get arbitrarily close to this if we limit ourselves to detecting a limited subset of programs.

For this challenge, we will detect a limited subset of NOPs - that is, snippets of programs which have no effect including on the brainfuck interpreter's state - which I have declared "trivial NOPs".

Here is a recursive definition of a trivial NOP:

  • the empty string is a trivial NOP
  • snippets consisting only of characters outside the set []<>+-,. (that is, characters which are ignored in Brainfuck), are trivial NOPs
  • the concatenation of two trivial NOPs is also a trivial NOP
  • snippets of any of the following forms, where X is another trivial NOP, are also trivial NOPs:
    • +X-
    • -X+
    • <X>
    • >X<

We will assume brainfuck has unlimited tape length. Overflow also does not need to be considered, because if a cell rolls over due to a +, a - can then underflow it back and it will still be a NOP.

Any snippet containing , or . is not a NOP because it performs impure I/O, and any snippet containing [ or ] is undecidable, so must be assumed to be not a NOP.

Your task is to, given a brainfuck snippet as a string or list of characters, determine whether it is a trivial NOP, and output two distinct values corresponding to true and false.

Test-cases

Truthy

(empty string)
a
+-
<>-+
<!>
+<-+>-
<<<+++a+--++>><-+>>

Falsey

<+>+<->-             (note: even though this is a NOP, it's not a trivial NOP)
+<-+>-[]
,+<-+>-
<.>

Rules


Meta

  • Can you think of any other classes of brainfuck snippet that are simple to detect as doing nothing?
  • Is this a duplicate?
  • Is this clear enough?
  • Any other feedback?
\$\endgroup\$
3
0
\$\begingroup\$

Back to the sandbox.

Challenge will be initially done on TBD, although I may do it again after that sometimes. Also, programs will be launched with a launcher shell script.

Background/story

You are a programmer who has been requested to create a program that wipes out other similar programs. However, you need to have your program fight others to see how it does in the field.

Requirements

You are to make a program that can run on a Debian 10 VM. If the language you use is not available by default on Debian 10, you must provide instructions or a link to the compiler.

Formatting

Submissions are to be formatted as follows:

# Name, Language

Description

```
Code
```

More description and explanation

Link to compiler download and/or download instructions for Debian 10 GNU/Linux (also add compiler options to use when compiling.)

Requirements for being included

Your answer must have at least one upvote. You also need to include an emergency off switch and test the switch to be included, and provide the source code and have tested it on a Debian 10 VM. Also, its growth rate must be hypothetically sub-exponential (this is to stop excessively laggy answers. If you don't know what growth rate to go with, go with linear (\$O(x)\$) or Polynomial (\$O(x^2)\$,\$O(x^3)\$,etc.).

Victory

To win, you need to be the last process of the bunch, by killing other processes through a system call. If you kill important processes that result in the VM breaking, that round is ignored for scoring. A total of 100 rounds will be run, and you get a point if you are the last "malicious" process around. If there's a tie, the tiers will be put in a tiebreaker.

Pseudocode for submission example

I don't know much about coding yet, so here's some pseudocode (feel free to convert it to a real programming language and mark it as such:

Example, Pseudocode

This program simply kills processes with the word "MalicousProcess", unless it's "MalicousProcess-Example"

def Example () {
  while (system(ps aux | grep "MalicousProcess") != null) {
    for each process != "MalicousProcess-Example" {
      kill process
    }
  }
  return 0

fictitious compiler

Please provide more recommendations.

\$\endgroup\$
12
  • \$\begingroup\$ "This is to stop joke answers, suicidal answers (sorry EmoWolf), and malware if it shows up." I doubt it will stop joke answers (including EmoWolf). \$\endgroup\$
    – Wezl
    May 25 at 21:17
  • \$\begingroup\$ Well, then it may stop bad joke answers and malware (like :(){ :|:& };: ). Also, I sure hope stack exchange doesn't run all inputs through bash. \$\endgroup\$
    – 4D4850
    May 25 at 21:25
  • 2
    \$\begingroup\$ @4D4850 Don't worry about malware; we follow riules here :p \$\endgroup\$ May 25 at 22:30
  • \$\begingroup\$ Ok Redwolf. I'll remove the justification part, but still keep the policy. \$\endgroup\$
    – 4D4850
    May 26 at 11:50
  • \$\begingroup\$ Also, this is a little off topic, but why's your comment the only one that appears when you don't expand the comments? \$\endgroup\$
    – 4D4850
    May 26 at 12:14
  • \$\begingroup\$ @4D4850 Redwolf's comment has been upvoted, so it is viewed by stack exchange as the most important/helpful/funny comment, and the others are less important \$\endgroup\$
    – Wezl
    May 26 at 14:16
  • \$\begingroup\$ Anyway, can any of you provide any more recommendations, or do you think it's ready to be posted? \$\endgroup\$
    – 4D4850
    May 26 at 18:01
  • \$\begingroup\$ Disallowing a rate of O(e^x) doesn't disallow all exponential solutions. Is that intended? If not you should probably require it tl be subexponential \$\endgroup\$ May 28 at 6:05
  • \$\begingroup\$ Thanks for pointing that out. I'll make that change now. \$\endgroup\$
    – 4D4850
    May 28 at 14:44
  • \$\begingroup\$ Provided no recommendations are made by Sunday 9:00 Central time, I'll post this question on the main site. \$\endgroup\$
    – 4D4850
    May 28 at 23:37
  • \$\begingroup\$ Ok, I'm posting the question. \$\endgroup\$
    – 4D4850
    May 31 at 13:11
  • \$\begingroup\$ Nevermind. Back to the Sandbox. \$\endgroup\$
    – 4D4850
    May 31 at 15:51
0
\$\begingroup\$

Demonstrate some easier abstract algebra

From my related challenge, Demonstrate some advanced abstract algebra

Consider a binary operator \$*\$ that operates on a set \$S\$. For simplicity's sake, we'll assume that \$*\$ is closed, meaning that its inputs and outputs are always members of \$S\$.

Let's define some basic terms describing the properties of \$*\$. We can say that \$*\$ can have any of these properties, if they hold for all \$a,b,c \in S\$:

  • Commutative: \$a*b = b*a\$
  • Associative: \$(a*b)*c = a*(b*c)\$
  • Distributive: \$a*(b+c) = (a*b)+(a*c)\$, for some binary operator \$+\$ on \$S\$

We can also define 3 related properties, for a unary operation \$-\$ on \$S\$:

  • Anti-commutative: \$a*b = -(b*a)\$
  • Anti-associative: \$(a*b)*c = -(a*(b*c))\$
  • Anti-distributive: \$a*(b+c) = -((a*b)+(a*c))\$

Finally, we define 3 more, that only describe \$*\$ if the complete statement is true for \$a,b,c \in S\$:

  • Non-commutative: There exists \$a, b\$ such that \$a*b \ne b*a\$ and \$a*b \ne -(b*a)\$
  • Non-associative: There exists \$a, b, c\$ such that \$(a*b)*c \ne a*(b*c)\$ and \$(a*b)*c \neq -(a*(b*c))\$
  • Non-distributive: These exists \$a,b,c\$ such that \$a*(b+c) \ne (a*b)+(a*c)\$ and \$a*(b+c) \ne -((a*b)+(a*c))\$

We now have 9 distinct properties a binary operator can have: commutativity, non-commutativity, anti-commutativity, associativity, non-associativity, anti-associativity, distributivity, non-distributivity and anti-distributivity.

This does require two operators (\$-\$ and \$+\$) to be defined on \$S\$ as well. For this challenge we'll use standard integer negation and addition for these two, and will be using \$S = \mathbb Z\$.

Obviously, any given binary operator can only meet a maximum of 3 of these 9 properties, as it cannot be e.g. both non-associative and anti-associative.


Let's create a "table" of these properties:

Commutative Associative Distributive
Regular Commutative Associative Distributive
Anti Anti-commutative Anti-associative Anti-distributive
Non Non-Commutative Non-associative Non-distributive

Your task is to write 3 programs (either full programs or functions. You may "mix and match" if you wish).

Each of these 3 programs will:

  • take two integers, in any reasonable format and method

  • output one integer, in the same format as the input and in any reasonable method

  • be a surjection \$\mathbb Z^2 \to \mathbb Z\$ (takes two integers as input and outputs one integer). This means that for any distinct output, there is at least one input that yields that output

  • has exactly 3 of the 9 above properties. However, those three properties muse be in different rows and columns in the above table from each other. This means that it can be (for example) commutative, non-associative, anti-distributive; non-commutative, anti-associative, distributive; or anti-commutative, associative, non-distributive. But, it cannot be (for example) commutative, associative, distributive; non-commutative, non-associative, non-distributive; or non-commutative, anti-distributive, anti-associative.

This is ; the combined lengths of all 3 of your programs is your score, and you should aim to minimise this.

Additionally, you should include some form of proof that your programs do indeed have the required properties and do not satisfy the other properties. Answers without these are not considered valid.


Meta

\$\endgroup\$
5
  • \$\begingroup\$ There exists no anti-distributive surjection when \$S=\mathbb Z\$. Maybe there exists one when \$S=(\mathbb Z/2\mathbb Z)^k\$, but I haven't found one yet. \$\endgroup\$ Jun 16 at 9:12
  • \$\begingroup\$ I would remove the constraint that the operator be a surjection, and just impose that it be non-constant. If you convince yourself that such an anti-distributive operator exists, you could post the challenge, but I would change it to "write 3-9 programs, such that each property is verified by (at least) one program". That would be an incentive to have programs which verify several properties at once, but make it more manageable. \$\endgroup\$ Jun 16 at 9:18
  • \$\begingroup\$ Also, there are problems with your "anti-associativity": if b = 1, then (a*b)*c = a*(b*c). \$\endgroup\$
    – anatolyg
    Jun 16 at 10:43
  • \$\begingroup\$ @RobinRyder If \$ S=(\mathbb Z / 2\mathbb Z)^k\$, aren't anti-distributive operators the same as distributive operators? \$\endgroup\$
    – Nitrodon
    Jun 16 at 14:21
  • \$\begingroup\$ @Nitrodon Yes, of course you are right. \$\endgroup\$ Jun 16 at 15:03
0
\$\begingroup\$

Pickleball Doubles Scoring

\$\endgroup\$
4
  • \$\begingroup\$ Welcome to Code Golf, and thanks for using the Sandbox! I've fixed some formatting for you - on our site, you have to use \$ instead of $ for MathJax. At the moment, this challenge is missing an objective scoring criterion - I'm guessing you want code-golf? \$\endgroup\$
    – pxeger
    May 31 at 7:17
  • \$\begingroup\$ @pxeger: Thank you. Yes, I was thinking code golf. Would it be better to take the END state as [0,0,0] so that the format of all inputs is the same? Is there a place to get the standard verbiage for code golf? \$\endgroup\$ May 31 at 13:43
  • \$\begingroup\$ Yes, I think [0, 0, 0] is a good idea - but I think the best option is to allow answers to choose a value to represent the END state depending on their language (in some it may be easier to use null, or take a string or something...). Re verbiage, there's Standard definitions of terms within specifications, but you can also just look at the various policy posts for more information. If you have specific questions, you can always ask in our chatroom, The Nineteenth Byte. \$\endgroup\$
    – pxeger
    May 31 at 14:51
  • \$\begingroup\$ I've edited this down to a stub now that it's been posted to save space \$\endgroup\$ Jun 1 at 15:15
0
\$\begingroup\$

What sequence?

Stack Exchange distinguishes users by a unique id that can be found in their their profile URL.

You can find your id by navigating to https://codegolf.stackexchange.com/users/current and finding the number after the /users/ bit in the resulting URL. For example, my profile URL is https://codegolf.stackexchange.com/users/99744/alex-bries, so my user ID is 99744

You can use this id to look up the number sequence of the last submitter on OEIS:

The On-Line Encyclopedia of Integer Sequences® (OEIS) is an online database containing integer sequences. These sequences are identified via an id starting with an A followed by 6 numbers. You can search for an id with the "id:" key on the search bar of OEIS.
id:A99744 will display sequence A099744 followed by all other sequences that mention it.

Your job is to write a program that, when given a number n, produces the nth number in sequence of the submitter above.

Rules

  • Each language may only be used once.
  • You may not post 2 answers in a row
  • Every next submision may only be max 10 bytes higher than the previous one
  • The champion is the last valid submission on june 14th

golfing is not a requirement but it is in your favour

\$\endgroup\$
5
  • \$\begingroup\$ Different OEIS sequences have vastly different complexity. I'm pretty sure my user id is solvable in 6 bytes of Jelly, which can break the whole game depending on the next user's id. \$\endgroup\$
    – Bubbler
    Jun 1 at 11:32
  • \$\begingroup\$ @Bubbler I like the idea of different complexities, but not sure how to prevent the colossal differences. Personally i like it, but if you have ny suggestions for how to improve, please let me know. \$\endgroup\$
    – Alex bries
    Jun 1 at 11:47
  • \$\begingroup\$ I don't think this works as a [answer-chaining] challenge, but it could work as just a regular code-golf challenge (i.e. write a program which takes an integer n and outputs the nth term of the sequence with your id). It's unlikely to be fair, but its better than [answer-chaining]. I've also done a bit of editing, feel free to change anything I did \$\endgroup\$ Jun 1 at 15:08
  • \$\begingroup\$ Yes, that's probably the better desicion, but after thinking about it more, its unlikely to be very fun, so ill leave it (for now). Thanks for the the constructive feedback guys. \$\endgroup\$
    – Alex bries
    Jun 1 at 20:04
  • \$\begingroup\$ Using user IDs is inherently unfair. \$\endgroup\$
    – qwr
    Jun 2 at 14:47
0
\$\begingroup\$

Write a program that mimics the output of the command env (with no arguments).

The program should print (to standard output, or closest equivalent) a list of all current environment variables, with each variable on it's own line. The name and content of a variable should be separated by an equal sign.

Here's a grammar:

line ::= name "=" contents
output ::= (line "\n")*

No using the env command, or any 1 command that completes the challenge on its own.

shortest code wins.

\$\endgroup\$
14
  • \$\begingroup\$ Can we use built-ins the get environment variables? \$\endgroup\$
    – Adám
    Nov 15 '20 at 15:50
  • \$\begingroup\$ @Adám If you mean "Can we use built-ins to get the environment variables", yes, I don't see a reason you couldn't, and otherwise it might be impossible to get them in some languages. \$\endgroup\$
    – binarycat
    Nov 15 '20 at 15:54
  • 1
    \$\begingroup\$ And I assume (ba|k|c|…)sh cannot participate? \$\endgroup\$
    – Adám
    Nov 15 '20 at 15:56
  • \$\begingroup\$ @Adám If they can find a way to get a list of environment variables without using env, I guess they could, unless I'm missing some other command that produces the same output. There's a lot of languages that can't complete the challenge (mostly esoteric ones), but they aren't technically banned. \$\endgroup\$
    – binarycat
    Nov 15 '20 at 23:28
  • \$\begingroup\$ How about set on Windows/DOS? \$\endgroup\$
    – Adám
    Nov 16 '20 at 8:07
  • \$\begingroup\$ @Adám I have no experience with windows, does it have similar functionality to env? if so then no. \$\endgroup\$
    – binarycat
    Jun 3 at 16:46
  • \$\begingroup\$ It is indeed. Note: As a beginner challenge writer (you've never posted a challenge before), you should avoid do X without Y challenges. \$\endgroup\$
    – Adám
    Jun 3 at 17:28
  • \$\begingroup\$ @Adám isn't "don't use a builtin that does exactly what you need" a standard loophole? \$\endgroup\$
    – binarycat
    Jun 3 at 19:32
  • \$\begingroup\$ No, not at all. \$\endgroup\$
    – Adám
    Jun 3 at 19:32
  • \$\begingroup\$ @Adám Huh, I guess you're right. I just don't want to have the challenge solved before it's even posted, with the 3 character bash program env. Does trying to prevent 1 cheeky answer really put you in the same category as forbidding something random? \$\endgroup\$
    – binarycat
    Jun 3 at 20:50
  • \$\begingroup\$ Does it really bother you that much that someone will post env or set as a solution? You're under no obligation to upvote or accept such an answer. \$\endgroup\$
    – Adám
    Jun 3 at 20:54
  • \$\begingroup\$ @Adám here's something you linked me: "A commonly used non-observable requirement is to avoid using a library function that solves the entire challenge. I believe these rules are OK. Like other non-observable requirements, one can find borderline cases of whether a built-in function solves all of the task or not, but the benefits of higher-quality answers outweigh the costs." this certainly seems to apply here. \$\endgroup\$
    – binarycat
    Jun 3 at 20:59
  • \$\begingroup\$ @Adám I've never posted anything because whenever I post a question to the sandbox all I get is reasons why my question is bad. And putting any additional rules whatsoever gets the same "no X without Y" response. Then people don't elaborate on anything. \$\endgroup\$
    – binarycat
    Jun 3 at 21:10
  • \$\begingroup\$ Don't be dismayed. We've all been there. Writing challenges is notoriously hard, especially for beginners. If you look at my account, I have lots of well-received challenges, but dig in, and you'll find that many of my early ones were flawed. I highly recommend answering a lot more existing challenges, before you attempt at writing your own. And when you do, decide on a simple unique task (this is hard, as a lot of obvious tasks have already been posted), with no special rules; just vanilla code golf. \$\endgroup\$
    – Adám
    Jun 3 at 21:14
0
\$\begingroup\$

Optimize imnotdeadfish

\$\endgroup\$
2
  • \$\begingroup\$ Deadfish (at least, the original one) used i and d intead of + and -. Is there a reason you chose to use them? \$\endgroup\$
    – pxeger
    Jun 3 at 10:45
  • \$\begingroup\$ @pxeger originally for the language I was going to have an input command so I swapped i and d for + and -, and I guess I never added them back. \$\endgroup\$
    – Underslash
    Jun 3 at 16:02
0
\$\begingroup\$

branch golfing: sort a list by number of prime factors

Specifically, first sorted by total number of prime factors, with any ties broken by number of unique prime factors (remove this?), then broken by size. The list will never contain 1.

Test cases:

[4,5,6,9] -> [5,4,9,6]
[10,11,12] -> [11,10,12]
[360 200 12] -> [12 200 360]
[63 64 65] -> [65 63 64]
\$\endgroup\$
13
  • \$\begingroup\$ Please avoid challenges involving the prime numbers. \$\endgroup\$
    – Adám
    Jun 3 at 20:42
  • \$\begingroup\$ Please avoid challenges where the scoring criteria relies on non-observable program requirements. \$\endgroup\$
    – Adám
    Jun 3 at 20:46
  • 1
    \$\begingroup\$ Please avoid making assumptions about language features. \$\endgroup\$
    – Adám
    Jun 3 at 20:47
  • 1
    \$\begingroup\$ Also, thank you for using the sandbox! :-) \$\endgroup\$
    – Adám
    Jun 3 at 20:47
  • \$\begingroup\$ @Adám Do you have any example of something where it isn't clear whether or not it is a conditional branch? Or any advice that isn't essentially just "this is bad"? \$\endgroup\$
    – binarycat
    Jun 3 at 20:56
  • \$\begingroup\$ Maybe. Are there any branches in this APL solution? The code means: the input ⊇⍨ permuted ∘⍋ according to a grade using prime factors for each , followed by ⍥≢ when counted, ∘∪ the unique ¨ for each, prime factors for each. Or in other words: Reorder according to a grading of prime factor count and then unique prime factor count. \$\endgroup\$
    – Adám
    Jun 3 at 21:10
  • \$\begingroup\$ From your description, sounds like a loop construct, which I intended to include, but I could clarify. \$\endgroup\$
    – binarycat
    Jun 3 at 21:21
  • \$\begingroup\$ If you count loop constructs, would you also count APL's + as a loop? It automatically loops over its arguments: Try it online! Besides, you state that "Builtin functions are presumed to be branchless." \$\endgroup\$
    – Adám
    Jun 3 at 21:24
  • \$\begingroup\$ No. It loops its own code, but can't be used to perform arbitrary code in a loop. \$\endgroup\$
    – binarycat
    Jun 3 at 21:28
  • \$\begingroup\$ My usage of was exactly parallel to any usage of +. They both auto-loop. However, ¨ is in fact an explicit loop. I could probably code around that too, though. An example would be extracting the odd numbers from a list. In many languages, you'd use a loop with a branch, but in APL you'd write List/⍨2|List which means L where 2 divides the list ['s elements; that's implicit]. Looping? Branching? Anyway, you get the idea. It'll be next to impossible to determine for every language (there are lots!) what exactly constitutes an explicit loop, or for that sake a branch. \$\endgroup\$
    – Adám
    Jun 3 at 21:32
  • \$\begingroup\$ @Adám so they are analogous to functions that take 2 arrays as input and provide one as output? that doesn't seem like a branch to me. "I could probably code around that too, though." Yeah that's kinda the point of the challenge. \$\endgroup\$
    – binarycat
    Jun 3 at 21:41
  • \$\begingroup\$ @Adám "but in APL you'd write List/⍨2|List which means L where 2 divides the list ['s elements; that's implicit]." this explanation isn't very clear. this seems like this construct (or pair of constructs, which you are confusingly explaining as one) is some kind of predicate filter/map? \$\endgroup\$
    – binarycat
    Jun 3 at 22:01
  • \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$
    – Adám
    Jun 3 at 22:01
0
\$\begingroup\$

Random Prisoner's Trilemma - Python 3 KOTH

\$\endgroup\$
0
\$\begingroup\$

Yet another digit insertion problem

\$\endgroup\$
0
\$\begingroup\$

How much faster than qsort can you achieve?

Task

Sort 1 million 32 bit integers as quickly as possible. Your code must create 1 million random non-negative integers in the range 0 to 999999 and sort them. Only the sorting should be timed.

Score

I will run your code and compare the timings to my default C code using qsort. That is:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdint.h>


int cmpfunc (const void * a, const void * b) {
   return ( *(int*)a - *(int*)b );
}

int main(void) {
    int sz;
    srand(time(NULL));
    printf("Enter the size of array::");
    scanf("%d",&sz);
    uint32_t *arr = malloc (sz * sizeof(uint32_t));
    int i;
    for(i=0;i<sz;i++)
        arr[i]=rand()%1000000; 
    clock_t begin = clock();
    qsort(arr, sz, sizeof(int), cmpfunc);
    clock_t end = clock();
    double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
    printf("%f seconds\n", time_spent);
    printf("%d\n", arr[10]);
    return 0;
}

Your score will be the timing for my C code divided by the timing for your code. I will run both on my PC. This means I will need clear instructions for how to compile and run your code on linux.

This means you will have to provide timing code in your solution so I am not timing the creation of the data.

Current timings

On my PC:

  • The sample C code takes 0.11 seconds.
  • Python sorted takes 0.24 seconds.

Notes

My code prints out one of the elements of the sorted array. This is to stop the opimizing compiler from removing the sorting code completely. You will have to do the same.

Builins are allowed. As ever this is a challenge per language so if your Python answer is faster than any other Python answer you have won that mini-competition.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ Obligatory question - builtins, yea or nay? \$\endgroup\$ Jun 7 at 14:31
  • \$\begingroup\$ That's probably the wisest choice - probably want to edit the post to say that. \$\endgroup\$ Jun 7 at 14:35
  • \$\begingroup\$ I strongly disagree with banning builtins. If any builtin is faster, either the builtin is interesting enough to be posted, or the challenge is boring. Banning builtins won't improve the latter, but it will hurt the former \$\endgroup\$ Jun 7 at 14:37
  • \$\begingroup\$ @cairdcoinheringaahing I can go with that. \$\endgroup\$
    – Anush
    Jun 7 at 14:37
  • \$\begingroup\$ @StackMeter I deleted my comment as bultins are going to be allowed. \$\endgroup\$
    – Anush
    Jun 7 at 14:39
  • \$\begingroup\$ I would argue that "only time sorting should be timed" is a bit unclear. Consider my code is: int counts[MAX],i,j,k,sort(*a,size){for(i=0;i<size;++i)++counts[a[i]];for(i=k=0;i<MAX;counts[i++]=0)for(j=counts[i];j--;)a[k++]=i;} (maybe some typos here, not tested) the initialize of counts array is required by sort. But C compiler will help me do so even begin main() entry and would probably not timed by my code. \$\endgroup\$
    – tsh
    Jun 8 at 6:12
  • \$\begingroup\$ @tsh what would you suggest? \$\endgroup\$
    – Anush
    Jun 8 at 7:08
  • \$\begingroup\$ Things to consider: 1) 32-bit signed or unsigned integers? Do I have a choice? 2) 32-bit (or any finite-sized) integers can be sorted using non-comparison sort algorithms, such as radix sort (which is asymptotically faster than any kind of comparison-based sort). Would you allow the answers to exploit this or not? \$\endgroup\$
    – Bubbler
    Jun 14 at 1:24
0
\$\begingroup\$

Does the regex match the string?

Despite having over 80 challenges tagged , we don't have one to simply verify if a regex matches a string.

Given a regular expression \$R\$ and a string \$S\$, output one of two distinct and consistent values to indicate whether the regex matches the string.

You may assume:

  • The input and output will be in any convenient methods
  • The regular expression may be in any regex flavour that existed before this question was posted
  • \$R\$ will always be well formed, and will not error, regardless of the string matched against it
  • \$R\$ may be either a regular expression object (such as Javascript's RegExp, Python's re.compile etc.) or a plain string object.
  • The output will either be:
    • 2 distinct, consistent values, such as 1/0, true/false, "Hello"/5
    • A truthy value and a falsey value, not necessarily consistent values

This is , so the shortest code in bytes wins.


Meta

\$\endgroup\$
2
  • \$\begingroup\$ Changed the formatting of the "distinct, consistent values" section because I kept interpreting 1/0 as something to do with division by zero \$\endgroup\$
    – pxeger
    Jun 8 at 18:52
  • \$\begingroup\$ I think the problem with a challenge like this is that there are only two types of solutions: generally low-effort calls to the built-in that does the task, and extremely tedious implementations of the built-in. For example, if I wanted to implement PCRE I would also need to handle the callout feature, which requires writing a whole API. You might be better off requiring a specific subset of behaviours to try to encourage answers that aren't just a built-in. \$\endgroup\$ Jun 9 at 17:28
0
\$\begingroup\$

Smallest number of actions to change reputation by [x] points

8: Upvote + downvote

75: Bounty + upvote + accepted answer

Draft

\$\endgroup\$
2
  • \$\begingroup\$ Potentially a dupe of this. Stoopid. \$\endgroup\$
    – lyxal
    Jun 9 at 4:55
  • \$\begingroup\$ @lyxal This one's about positive or negative rep gains though, so it's more general \$\endgroup\$ Jun 9 at 4:57
0
\$\begingroup\$

Finite Composition of Univariate Functions

Problem

Given $$\mathbb{F}:=\{f_i \mid f_i : \mathbb{R} \to \mathbb{R}\}$$ the set of all the real maps, and the n-ary function composition

\begin{gather} c_o(f_i) = f_1∘f_2∘f_3⋯∘f_n\\[8pt] ∀f_i ∈ \mathbb{F},~~~1≤i≤n∈\mathbb{N} \end{gather}

write a program which receives n functions of a real variable as the input and computes the in-order function composition, product of all the entered functions as a string.

As standard, x is the name of the parameter variable in each function. Any other literal is taken as a constant.

Examples

Example 1

input

number of functions: 3
f_1 = x + 1
f_2 = x - 10
f_3 = x^2 + 2

output

c_o(f_1,f_2,f_3) = ((x^2 + 2) - 10) + 1

Example 2

input

number of functions: 4
f_1 = 27x - sin(e)
f_2 = -7(x^2 + 1)^(1/2) 4y^3 + 21
f_3 = x^(3/2) + 4
f_4 = ln(z + 1)
(z, y, e are assumed as constants in the reals)

output

c_o(f_1,f_2,f_3,f_4) = 27(-7(((ln(z + 1))^(3/2) + 4)^2 + 1)^(1/2) 4y^3 + 21) - sin(e)
\$\endgroup\$
6
  • \$\begingroup\$ Any suggestion, improvement? please let me know. Thanks. \$\endgroup\$ Jun 8 at 20:08
  • 1
    \$\begingroup\$ Thanks for using the sandbox! This seems like an interesting idea, but currently it is too underspecified to be clear. For example, the test cases imply that the input to each function is represented by x, but you haven't stated anywhere that we can assume that. Consider also a slight change to one of your cases, where one function has -y(x^2 + 1). Is y a function or a constant? There are too many specifics, so hopefully the general idea gets across that you must specify how you are representing the functions very precisely for this to work. \$\endgroup\$ Jun 9 at 17:41
  • \$\begingroup\$ @FryAmTheEggman Thank you. I have edited it so that there's no ambiguity. \$\endgroup\$ Jun 9 at 18:19
  • \$\begingroup\$ That is a good change, but doesn't address the ambiguity in separating functions like sin from the product of constants. It also isn't clear to me whether x^2 - 7 is a valid solution for the first example. These have some overlap in that they (probably?) won't affect a solution that just substitutes the functions appropriately, but will affect any symbolic parser based approach. \$\endgroup\$ Jun 9 at 19:53
  • \$\begingroup\$ @FryAmTheEggman oh, yes, it's valid but it isn't required to go to such depths as to simplify symbolic expressions, that would be a problem on its own. I didn't specify so in the challenge and as for sin or those functions, since the problem to be addressed is the composition of functions any expression different from x should be "disregarded". I don't intend to make further computations with the output string. \$\endgroup\$ Jun 9 at 21:45
  • \$\begingroup\$ What I'm trying to communicate is that your "point" for writing the challenge doesn't really matter - in some language it probably would be better to use a parser. If you just want to say "no other assumptions about the form of the function can be made" that is fine - but you have to actually say it, otherwise your challenge is unclear because I won't be able to tell if a solution is valid or not. \$\endgroup\$ Jun 9 at 23:13
0
\$\begingroup\$

Interpret Unreadable


Introduction

Unreadable is a programming language designed to be – as the name states – unreadable (in most fonts, anyway). Instructions are ' followed by a run of "s. So while in a code block, '""'""'""" looks just fine, it looks like '""'""'""" outside of one - it is extremely difficult to tell what is going on.

The instructions are prefix, and are as so:

Instruction Arity Behavior
'" Unary Print; output the character with codepoint x, and return x.
'"" Unary Increment; return x+1.
'""" Nilary Unit; return 1.
'"""" Binary Both; evaluate and disregard x, and return the result of evaluating y.
'""""" Binary While; keep evaluating y until x is 0. Return the last result of evaluating y.
'"""""" Binary Set; set the xth variable to y, and return y.
'""""""" Unary Get; return the value of the xth value. Undefined is 0.
'"""""""" Unary Decrement; return x-1.
'""""""""" Ternary If-else; if x is 0, return z. Otherwise, return y.
'"""""""""" Nilary Input; return the codepoint of the next character of input. EOF is -1.

For example, a cat program would be:

'"""""'""'""""""'"""'""""""""""'"'"""""""'"""
while(++ setvar(1 = input())) {print(getvar(1))}

Or, in its unreadable glory: '"""""'""'""""""'"""'""""""""""'"'"""""""'"""

Challenge

Given a valid Unreadable program and its input separated by any non-' or " character, interpret the program as Unreadable code.

Test cases (uses ! as the separation character, I/O is represented in CP-437)

Input -> Output
'"'"""!this input does nothing lol -> ☺
'"""""'""'""""""'"""'""""""""""'"'"""""""'"""!This is a cat so I can output whatever I want. blah blah blah... -> This is a cat so I can output whatever I want. blah blah blah...
'""""'""""'""""""'"""'""'""'""'""'""'""'""'""'""'"""'"""""'"""""""'"""'""""'""""""'""'"""'""'""'""'""'""'""'""'"""""""'""'"""'""""'""""""'""'""'"""'""'""'""'""'""'""'""'""'""'""'"""""""'""'""'"""'""""'""""""'""'""'""'"""'""'""'""'""'""'""'""'""'""'""'""'"""""""'""'""'""'"""'""""'""""""'""'""'""'""'"""'""'""'""'""'"""""""'""'""'""'""'"""'""""'""""""'""'""'""'""'""'"""'""'""'""'"""""""'""'""'""'""'""'"""'""""'""""""'""'""'""'""'""'""'"""'""'""'""'""'""'""'""'""'""'""'""'""'"""""""'""'""'""'""'""'""'"""'""""'""""""'""'""'""'""'""'""'""'"""'""'"""""""'""'""'""'""'""'""'""'"""'""""""'"""'""""""""'"""""""'"""'""""'"'""'""'"""""""'""'"""'""""'"'""'"""""""'""'""'"""'""""'"'""""""""'""""""""'"""""""'""'""'""'"""'""""'"'""""""""'""""""""'"""""""'""'""'""'"""'""""'"'""'"""""""'""'""'""'"""'""""'"'""'""'""'""'"""""""'""'""'""'""'"""'""""'"'""'""'"""""""'""'""'""'""'""'"""'""""'"'""""""""'"""""""'""'""'""'""'""'""'"""'""""'"'""'"""""""'""'""'""'"""'""""'"'""'""'""'""'"""""""'""'""'""'"""'""""'"'""""""""'""""""""'"""""""'""'""'""'"""'""""'"'"""""""'""'""'"""'""""'"'""'""'""'"""""""'""'""'""'""'""'"""'"'"""""""'""'""'""'""'""'""'""'""" -> Hello, world!
'""""""'"""'""'""""""""""'""""""'""'"""'""""""""""'"'"""""'""""""'"""'""""""""'"""""""'"""'""""""'""'"""'""'"""""""'""'"""!A! -> b

Rules

  • Standard loopholes are forbidden.
  • A single trailing newline is allowed in the output, and no other trailing whitespace.
  • If possible, please link to an online interpreter (e.g. TIO) to run your program on.
  • Please explain your answer. This is not necessary, but it makes it easier for others to understand.
  • Languages newer than the question are allowed. This means you could create your own language where it would be trivial to do this, but don't expect any upvotes.
  • This is , so shortest code in bytes wins!
  • A +100 rep bounty will be given to the first Unreadable answer.
\$\endgroup\$
2
  • \$\begingroup\$ This doesn't seem like a particularly interesting challenge to me, to be honest. Decoding the program into commands is fairly trivial (split by ' and find lengths of each), in both golfing and practical languages, and the actual interpreting part of the challenge is basically the same as any other language. \$\endgroup\$ Jun 10 at 1:20
  • \$\begingroup\$ @RedwolfPrograms The interesting part is that commands are prefix, so it might take some thought to make an interpreter. \$\endgroup\$
    – Makonede
    Jun 10 at 1:55
0
\$\begingroup\$

Can we measure time?

You have 2 hourglasses with sand lying at bottom in both of hourglass, one that is \$1\$ sec hourglass(call it \$A\$) and other is \$\sqrt2\$ sec hourglass (call it \$B\$)

(A hourglass is said to be n second hour glass if time taken by all of the sand of hourglass to fall from top to bottom is n second)

Now we are given 2 integers \$a\$ and \$b\$ such that $$T=a+b\sqrt2 > 0$$ assume:$$\ 1000000\geq a \geq -1000000$$

$$\ 1000000\geq b \geq -1000000$$

we need to respond that can we measure this time \$T\$ with our hourglasses? ("YES" or "NO")

Some clarifications and definitions:

  • We say we can measure time \$t\$ if at that instance in at least one of hourglass sand have just stopped falling.

  • We can make a hourglass upside down(any number of time) if and only if at least one of the hour glass has empty top.

  • Assume time taken to invert a hourglass is 0 sec.(by invert means upside down,i.e the sand that was in bottom is now at top and the sand at top is now at bottom).

  • If at least one of hourglass sand have just stopped falling we can report this instant as the amount of time measured.

  • If sand on both the hour glass is at bottom and we decided to do no any operation, then it is assumed that we are reporting the time measured at this instance and the process stops.

Example 1:

\$a=0\$ and \$b=1\$

Our answer is true, because initially both the hourglass is given with sand at bottom and at the start we can invert B, so when the sand from B has fallen all to bottom at that instance a total of \$\sqrt2\$ time has passed and we can report it,hence we have measured \$\sqrt2\$ time.

Example 2:

\$ a=-1\$ and \$b=2\$

\$T = -1 +\sqrt2\$ Our answer is true, we can obtain it as follows: At time 0, turn both A and B upside down, At 1 sec A will be emptied to bottom, turn A upside down again (B remain falling as it was), now when B fall completely,turn A upside down, now when A empties the total duration is \$-1 +\sqrt2\$.

1(All the A falls, at this instance B is left with \$-1+\sqrt2\$ ) $$+$$ \$\sqrt2\$-1 (at this duration after the previous one B have fallen completely and A is left with \$1-(-1+\sqrt2)\$ at top, but we have inverted it so that means A is actually left with \$-1+\sqrt2\$ at top) $$+$$

\$-1+\sqrt2\$ (at this duration after the previous one A have fallen completely)

we can report this instant, the total time is:

\$(1)+(-1+\sqrt2)+(-1+\sqrt2)=-1 +2\sqrt2 \$

And for following input it is not possible to measure and you have to output "NO"

\$a=11\$ , \$b=-5\$

\$a=35\$ , \$b=-21\$

\$a=-4\$ , \$b=4\$

\$a=-8815\$ , \$b=6261\$

\$a=-1\$ , \$b=1\$

. . .

The idea of this problem is not my original, it appeared in a coding competition some time back.

\$\endgroup\$
3
0
\$\begingroup\$

Convert permutations to integers and back again

Convert a permutation of 0,...,n-1 to a number in the range 0,...,n!-1, and convert back again.

Task

Write a program containing two functions (or two programs).

The first function should accept a permutation (i.e. an ordering) of the numbers 0,1,2,...,n-1 (where n is any positive integer) and output an integer in the range 0,1,...,n!-1 (where n! is n factorial). Distinct permutations of the same length n must produce distinct outputs, but there are no further restrictions.

The second function should implement the inverse of the first function (except that it also needs to know n). It should accept an integer k in the range 0,1,...,n!-1 AND a positive integer n, and should output the permutation of 0,1,2,...,n-1 that yields k when sent to the first function.

The time and space complexity of both functions MUST be at most polynomial in n, i.e. O(n**c) for some fixed c. In particular, solutions that involving computing all n! permutations are NOT acceptable. (Unofficial bonus points for O(n)).

Shortest solution (including both functions and any additional code) in each language wins.

Examples

Assuming the two functions are f and g:

Input Output
f([0]) 0
g(0,1) [0]
f([0,1]), f([1,0]) 0 and 1 in either order
g(0,2), g(1,2) [0,1] and [1,0] in either order
f([3,4,1,0,2]) some integer in range 0,...,119
g(42,5) some permutation of 0,1,2,3,4
f(g(42,5)) 42
g(f([3,4,1,0,2]),5) [3,4,1,0,2]
f([1,0,1]) not valid input (not a permutation)
f([1,3,4]) not valid input (not a permutation of 0,1,2)
g(42,4) not valid input (42 >= 4!)

Notes

Permutations can be represented in any reasonable form.

You can assume that input(s) are valid (as described).

You can assume that n! fits in the standard integer type in your language, but your algorithm should theoretically work for any n.

Standard loopholes apply.

\$\endgroup\$
0
\$\begingroup\$

Boxes in boxes in boxes in boxes.....

ASCII boxes are fun, but the box drawing questions seem to be limited insofar as that they seem to take a specific set of boxes. Today, I hope to fix that. The challenge here is to write a program that takes a list of sides of boxes and characters to draw them with, and outputs the boxes.

To clarify some format issues:

Input

Input is flexible, and will look like 1) this

17

30 20 #$5

21 15 $%^

19 13 311

...

or 2) this

[17, [30, 20, "#$5], [21, 15, "$%^], [19, 13, "311"], ...]

You may support either or both of these types, but you must be consistent with this choice.

Input is given in this order:

The first number, a single number on one line, is the number of boxes to place.

Then, for as many times as said first number, you will receive 2 numbers and three characters - the two numbers represent length and width, in any order. The three characters represent, in this order:

  1. The character to use for the corners.
  2. The character to use for the edges.
  3. The character to fill the inside of the boxes.

The boxes should not overlap, but you have the freedom to place the boxes wherever you wish. The allowed symbols are !$%^&*()_-+=#~/?\@s, where the s represents space and in order to aid those who want to split on whitespace.

Input will be space separated within boxes and newline separated between boxes.

Output

Output should be a set of boxes, conforming to the regulations and conditions above - for example,

%###%
#***# *((*
#***# ())(
#***# ())(
%###% *((*

for the input

2

5 5 %#*

4 4 *()

or

[2, [5, 5, "%#*"], [4, 4, "*()"]

Scoring

This is , so shortest solution in bytes wins. Share your favourite drawings with your answer.

Additional tags:

Meta

Any issues?

Should the scoring be ?

Is the challenge specified enough?

\$\endgroup\$
4
  • \$\begingroup\$ Your scoring shouldn't be pop-con. Also, you realise people are just going to draw all the boxes newline-separated? Be clearer that the input format is flexible. \$\endgroup\$
    – emanresu A
    Jun 11 at 9:23
  • \$\begingroup\$ @Ausername let me go fix that \$\endgroup\$ Jun 11 at 10:29
  • \$\begingroup\$ @Ausername Should I add a bounding box to stop people just seperating the boxes by newlines \$\endgroup\$ Jun 11 at 10:33
  • \$\begingroup\$ I'm not saying anything's wrong with that, just that's how people are going to do it because it's the simplest way. \$\endgroup\$
    – emanresu A
    Jun 11 at 10:35
0
\$\begingroup\$

Given matrix \$A\$ and \$A^n\$, work out any possible positive \$n\$.

Examples:

  • \$\begin{pmatrix}1&2&3\\3&2&1\\1&0&1\end{pmatrix},\begin{pmatrix}36&32&44\\52&40&52\\12&8&12\end{pmatrix}\rightarrow 3\$
  • \$\begin{pmatrix}0&1&0\\0&0&1\\0&0&0\end{pmatrix},\begin{pmatrix}0&0&0\\0&0&0\\0&0&0\end{pmatrix}\rightarrow \text{any integer }\ge 3\$
  • \$\begin{pmatrix}0&1\\1&0\end{pmatrix},\begin{pmatrix}0&1\\1&0\end{pmatrix}\rightarrow \text{any odd positive integer }\$

Sandbox Notes

  • Since this question likely fall into pure matmul as , will this be ?
  • If so, what size and \$n\$ is reasonable?
  • Should it multiply in a modulo-\$p\$ ring?
  • If someone provide enough extra info, they have right to post this question(actually that's why I posted in sandbox)
\$\endgroup\$
4
  • \$\begingroup\$ Can you give some examples? \$\endgroup\$
    – math
    Jun 11 at 17:01
  • \$\begingroup\$ Sometimes lots of different n can work. What should we output then? \$\endgroup\$
    – xnor
    Jun 12 at 23:06
  • \$\begingroup\$ @xnor "Any possible positive n". But I agree that it should be specified better. \$\endgroup\$
    – user100690
    Jun 14 at 11:22
  • \$\begingroup\$ @ophact It's edited later than comment \$\endgroup\$
    – l4m2
    Jun 14 at 12:56
0
\$\begingroup\$

I am not a dad!

Task

Given a non-empty string. Check if it starts with "I am"/"I'm" (case-insensitive) and if it is, output the dad joke. Otherwise, terminate
P.S. There must be nothing in the STDERR.

Examples:

"I am an idiot" -> "Hi an idiot, I am Dad"
"I am rewuytheruty" -> "Hi rewuytheruty, I am Dad"
"i Am case insensitive" -> "Hi case insensitive, I am Dad"
"I'm A" -> "Hi A, I am Dad"
"i'M B" -> "Hi B, I am Dad"
"Iam together" -> terminated
"Nothing here!" -> terminated

Rules

  • This is , so the answer with shortest bytes wins.
  • These loopholes are, obviously, forbidden.
  • Standard code-golf rules apply.
  • Please specify the language you are using and the amount of bytes.
  • It would be great if you would put a link to a sandbox where your code can be ran in action, such as TIO.
  • Explaining your code is very welcomed.
\$\endgroup\$
3
  • \$\begingroup\$ I don't think the exceptions add anything to this challenge to be honest. And if you do keep them, they need to be better specified. \$\endgroup\$
    – pxeger
    Jun 13 at 19:38
  • \$\begingroup\$ Input validation is frowned upon (validation to check if any of the exceptions appear). As well as that, I observed that there are virtually no patterns or magic bitwise operations that can handle them, just hard-coding a few extra strings and some ternary operators. Doesn't really add anything to the other dad joke challenge to be honest. \$\endgroup\$
    – user100690
    Jun 14 at 12:19
  • \$\begingroup\$ And if I would remove the exceptions, will the challenge become better? Will it be worthy publishing? \$\endgroup\$ Jun 14 at 12:52
0
\$\begingroup\$

Write a shortest bijective program from String to Object.

You can specify two sets of chars \$C_1\$ and \$C_2\$, both of which consist of at least 4 different chars[1], and define:

  • String: string consisting of only chars in \$C_1\$ [C₁]*
  • Name: non-empty string consisting of only chars in \$C_2\$ [C₂]+
  • Object: a finite map from Name to Object, such that every way to go down finally go to empty Object(empty map)

Reasonable I/O allowed. Outputting in Object in languages like JavaScript, Array/String with proper encoding, folder, shuld be fine.

Notes

  • [1] unary or binary is too easy.
  • I meant to map to folder but folder charset is bad, then decided to give you choice.

Sandbox Notes

  • What does proper encoding mean? Or do I just remove the allowance?
\$\endgroup\$
0
\$\begingroup\$

Largest number with no repeating substrings of length \$l\$

Inspired by this question, in turn inspired by this one.

When I read the above questions, I thought: "Cool". And then I thought "What if we go further?"

Therefore, in this challenge, you must find the largest number that has no repeating substrings of length n. This is : fewest bytes wins.

Meta Stuff

This seems insanely hard - is it well specified enough?

Any changes that seem reasonable to add?

\$\endgroup\$
2
  • \$\begingroup\$ I would recommend adding testcases and instead of linking to posts for people to read, you could clarify in the description. \$\endgroup\$
    – user100690
    Jun 22 at 9:34
  • \$\begingroup\$ Is this the same as this? \$\endgroup\$
    – Shaggy
    Jul 2 at 14:22
0
\$\begingroup\$

Iterated ultimatum

Each round, players are paired. One player is the Proposer and the other is the Receiver.

The Proposer must choose a number x such that 0 < x < 100. The Receiver must then Accept or Reject this offer. If accepted, the Proposer gains x points and the Receiver gains 100 - x points. If rejected, neither player gains anything. This is repeated several times, then the Proposer and Receiver roles are reversed, then new pairings are made.

Repeat.

The idea is that the Proposer must try to maximise his own gain, while the Receiver can try to coerce the Proposer to give a larger share of the 100 points by rejecting unfair offers.

https://en.wikipedia.org/wiki/Ultimatum_game

Meta

  • Too similar to Iterated Prisoner's Dilemma?
  • Any other feedback?
\$\endgroup\$
0
\$\begingroup\$

Solve Encode a Lenguage with score 0. Shortest code wins. Quine rule applies. I'll unlikely post it.

\$\endgroup\$
3
  • \$\begingroup\$ @pxeger Qunie rule. \$\endgroup\$
    – l4m2
    Jun 20 at 11:03
  • \$\begingroup\$ Zsh, 120 bytes: Try it online!. Can probably be quite a lot shorter \$\endgroup\$
    – pxeger
    Jun 20 at 11:08
  • 1
    \$\begingroup\$ Undeleted as potential reference \$\endgroup\$
    – l4m2
    Jul 1 at 17:53
0
\$\begingroup\$

Smallest number of panels to represent \$1\$ through \$n\$ in base \$b\$

Inspired by this question. (I have taken a lot of inspiration from Puzzling recently).

Because not all of you spend all your (non-code-golf) time looking at puzzles, let me explain the relevant details.

The challenge involved figuring out how to express the numbers 1 through 8 in only 8 panels in bases 2, 3 and 4. Today, I want to do the converse.

Your task is to, given a number \$n\$ and a base, \$b\$, find the fewest number of panels to represent 1 - n in base b. By that, I mean taking a single continuous slice of the set of panels, we can represent a number, and we can do that for 1 through n.

To clarify, each panel can take a single base-\$b\$ number, and the goal is to find a way to represent each number from 1 through n as a base b number. A continuous slice is a set of panels such that all the panels are consecutive and in the same order as in the original number - for example, 221001120 - in which every two-digit and one-digit number is represented in reading order, left-to-right, as well as 100. Note that 101 and 111 are disallowed because they are not consecutive, with 0s in between, 110, 122 and 2110 are disallowed because they read from left to right, and 121 and 212 are disallowed because they reorder the panels.

For a bigger example, let us take the base as 3 and the number as 18: a valid solution is 122121110221010011200, as every number between 1 and 18 can be represented in base 3

1: 122121110221010011200

2: 122121110221010011200

3: 122121110221010011200

4: 122121110221010011200

5: 122121110221010011200

6: 122121110221010011200

7: 122121110221010011200

8: 122121110221010011200

9: 122121110221010011200

10: 122121110221010011200

11: 122121110221010011200

12: 122121110221010011200

13: 122121110221010011200

14: 122121110221010011200

15: 122121110221010011200

16: 122121110221010011200

17: 122121110221010011200

18: 122121110221010011200

In order to verify your solution does work, provide an optimal answer by the number such that it can be checked.

Input looks like this: n b, and output like this: number solution.

Sample inputs and outputs to aid you (output is represented as o - yes I did work all of these out, and yes, I do believe it is the shortest to just find a place to append the number in):

\$b = 2\$:

n <= 8; o = n (11101000)
n = 9, 10; o = 11 (10011101000)
n = 11; o = 13 (1001011101000)
n = 12, 13, 14; o = 14 (11001011101000)
n = 15, 16; o = n (110010111010000)

\$b = 3\$:

n <= 9; o = n (221001120)
n = 10; o = 11 (22101001120)
n = 11; o = 13 (1022101001120)
n = 12; o = 14 (11022101001120)
n = 13, 14, 15; o = 15 (111022101001120)
n = 16; o = 17 (12111022101001120)
n = 17; o = 19 (12212111022101001120)
n = 18; o = 20 (122121110221010011200)

\$b = 4\$:

n <= 10; o = n (1101220213)
n = 11; o = 12 (231101220213)
n = 12, 13; o = 13 (231101220213)
n = 14, 15; o = n (33231101220213)
n = 16, 17; o = 18 (10033231101220213)
n = 18; o = 20 (1003323110122010213)
n = 19, 20; o = 22 (100103323110122010213)

(i'm not touching 5+ this took me an hour)

\$\endgroup\$
0
\$\begingroup\$

Are these strings within N bit flips of each other?

Given two strings a and b, and a positive integer n, determine if b can be reached by performing exactly n bit-flips on a.

A bit-flip is defined as changing one of the bits in the character encoding of a string from a 0 to a 1 or from a 1 to a 0

The same bit may be flipped multiple times, so the 0110 can be reached in exactly 2 bit-flips of itself, as well as in 0 (e.g. 0110 -> 0100 -> 0110).

Test-cases

Truthy

n   a         b
=======================
1   hello     hullo
3   hello     hullo
5   hello     hullo
69  hello     hullo
4   hello     hello
1   x         h
1   x         p
1   x         y
2   x         q
2   x         l
2   x         x
4   x         l
4   x         x
4   x         w
4   x         e

Falsey

n   a         b
=======================
2   hello     hullo
5   hello     hello
1   x         a
1   x         n
1   x         f
1   x         x

Rules

  • You may assume/require:
    • n > 0
    • a and b are the same length
    • neither string is empty
    • both strings consist only of lowercase letters a to z (or uppercase A to Z instead, if you wish)
  • You should encode the strings in ASCII (or other ASCII-compatible encoding), but if your language cannot easily handle that, ask in the comments and I'll decide on special rules
  • Your code does not need to handle high n or long a or b, but it must work in theory
  • You may use any reasonable I/O method
  • Standard loopholes are forbidden
  • This is , so the shortest code in bytes wins

Meta

  • Better title suggestions?
  • I limited to ASCII to avoid people finding loopholes that trivialise the challenge. Do you have any other suggestions that would work better?
  • Test-case suggestions?
  • Is this a duplicate?
  • Is this clear enough?
  • Any other feedback?
\$\endgroup\$
2
  • \$\begingroup\$ This question is equals to: is n - (hamming distance of a and b) a non-negative even number? \$\endgroup\$
    – tsh
    Jun 30 at 10:08
  • \$\begingroup\$ @tsh yes, I've basically abandoned it \$\endgroup\$
    – pxeger
    Jun 30 at 12:18
0
\$\begingroup\$

Maximum unique characters

Write a program which maximises the amount of unique characters in its output while minimising the size of its source. The program must halt.

Functions for converting a character code to its character in any encoding are disallowed.

Your score is output unique chars / size in bytes, and higher is better.

Meta

  • Is this a duplicate?
  • Should character code functions be banned?
\$\endgroup\$
4
  • 2
    \$\begingroup\$ Do you mean "output" instead of "input" in the first line? Also, it sounds like "shortest code to print all chars having Unicode codepoint from 0 to 1114111", which is pretty boring. And you can't ban "character code functions" since it is simply not a thing in lots of languages. And you can't get most of the characters without it besides hardcoding the string itself anyway (or eval-ing), which makes it even more boring. \$\endgroup\$
    – Bubbler
    Jun 22 at 7:29
  • \$\begingroup\$ Maybe don't ban "character code functions" as they are pretty much the only way to produce an interesting solution to this challenge. \$\endgroup\$
    – user100690
    Jun 22 at 9:27
  • \$\begingroup\$ @RecursiveCo. for(let i=0;i<[insert 9's here];i++){console.log(String.fromCharCode(i)} (in JS) I'm just really bad at coming up with ideas. I've given up on this idea. \$\endgroup\$ Jun 22 at 9:49
  • \$\begingroup\$ What's to stop me making up a character encoding where every possible sequence of bytes in the range 0x48 to 0x57 represents one of infinite "characters" and then outputting all decimal numbers? Boom, infinite score. \$\endgroup\$
    – pxeger
    Jul 3 at 20:12
0
\$\begingroup\$

Time till Friday

\$\endgroup\$
2
  • \$\begingroup\$ What time in Friday? 12am? \$\endgroup\$
    – Razetime
    Jun 16 at 2:19
  • \$\begingroup\$ @Razetime Any time in Friday \$\endgroup\$
    – l4m2
    Jun 16 at 8:57
0
\$\begingroup\$

Extend the OEIS

On the OEIS, there are a significant amount of sequences which do not have proper continuations to them, in other words, the length of the sequence was cut short by the methods at that point.

An example of this is the sequence in this post before it was extended by this answer.

A sequence that wouldn't qualify for this post would be the fibonacci sequence because while it may have a limit on the OEIS, the end is not due to the method used, but instead due to the large amount of current entries.

Challenge:

Find a sequence on the OEIS that follows the above guidelines and extend it by any amount. Your answer should include the code, an explanation of it, as well as the new entries.

Example Answer

A1327807 
previous largest n=8 number = 100000001
new highest n=12 number = 37812879128

// code
// more code

// explanation of code and how you figured it out

Of course your answer doesn't need to follow that format exactly, it should just be close to it.

Notes:

You must write original code for this challenge. If there is already a program out there, and you're only contribution is running it on a better machine, that is a trivially extendable sequence.

This also goes for answers, as the only thing contributed cannot be simply better hardware.

This is for lack of a better tag, so good luck and have fun!

\$\endgroup\$
1
  • \$\begingroup\$ I think you should find one interesting sequence to extend (or some). Large part of this question is finding an extendable sequence that might be of interest (as popularity contest suggests). IMHO this part of research should be on asker's side. \$\endgroup\$
    – pajonk
    Jun 27 at 11:26
1
102 103
104
105 106
117

You must log in to answer this question.

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