572
\$\begingroup\$

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

Sandbox FAQ

Posting

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

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

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

Discussion

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

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

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

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

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

\$\endgroup\$
0

4642 Answers 4642

1
128 129
130
131 132
155
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, 2021 at 14:31
  • \$\begingroup\$ That's probably the wisest choice - probably want to edit the post to say that. \$\endgroup\$ Jun 7, 2021 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, 2021 at 14:37
  • \$\begingroup\$ @cairdcoinheringaahing I can go with that. \$\endgroup\$
    – user7467
    Jun 7, 2021 at 14:37
  • \$\begingroup\$ @StackMeter I deleted my comment as bultins are going to be allowed. \$\endgroup\$
    – user7467
    Jun 7, 2021 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, 2021 at 6:12
  • \$\begingroup\$ @tsh what would you suggest? \$\endgroup\$
    – user7467
    Jun 8, 2021 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, 2021 at 1:24
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, 2021 at 4:55
  • \$\begingroup\$ @lyxal This one's about positive or negative rep gains though, so it's more general \$\endgroup\$ Jun 9, 2021 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, 2021 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, 2021 at 17:41
  • \$\begingroup\$ @FryAmTheEggman Thank you. I have edited it so that there's no ambiguity. \$\endgroup\$ Jun 9, 2021 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, 2021 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, 2021 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, 2021 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, 2021 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, 2021 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
  • \$\begingroup\$ Thanks @pxeger for editing. \$\endgroup\$
    – cheems
    May 31, 2021 at 9:10
  • \$\begingroup\$ You should provide some impossible cases? \$\endgroup\$
    – l4m2
    Jun 3, 2021 at 14:09
  • \$\begingroup\$ Thanks, I have added. \$\endgroup\$
    – cheems
    Jun 3, 2021 at 14:53
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, 2021 at 9:23
  • \$\begingroup\$ @Ausername let me go fix that \$\endgroup\$ Jun 11, 2021 at 10:29
  • \$\begingroup\$ @Ausername Should I add a bounding box to stop people just seperating the boxes by newlines \$\endgroup\$ Jun 11, 2021 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, 2021 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 scat
    Jun 11, 2021 at 17:01
  • \$\begingroup\$ Sometimes lots of different n can work. What should we output then? \$\endgroup\$
    – xnor
    Jun 12, 2021 at 23:06
  • \$\begingroup\$ @xnor "Any possible positive n". But I agree that it should be specified better. \$\endgroup\$
    – user100690
    Jun 14, 2021 at 11:22
  • \$\begingroup\$ @ophact It's edited later than comment \$\endgroup\$
    – l4m2
    Jun 14, 2021 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, 2021 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, 2021 at 12:19
  • \$\begingroup\$ And if I would remove the exceptions, will the challenge become better? Will it be worthy publishing? \$\endgroup\$ Jun 14, 2021 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, 2021 at 9:34
  • \$\begingroup\$ Is this the same as this? \$\endgroup\$
    – Shaggy
    Jul 2, 2021 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, 2021 at 11:03
  • \$\begingroup\$ Zsh, 120 bytes: Try it online!. Can probably be quite a lot shorter \$\endgroup\$
    – pxeger
    Jun 20, 2021 at 11:08
  • 1
    \$\begingroup\$ Undeleted as potential reference \$\endgroup\$
    – l4m2
    Jul 1, 2021 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, 2021 at 10:08
  • \$\begingroup\$ @tsh yes, I've basically abandoned it \$\endgroup\$
    – pxeger
    Jun 30, 2021 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, 2021 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, 2021 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, 2021 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, 2021 at 20:12
0
\$\begingroup\$

Time till Friday

\$\endgroup\$
2
  • \$\begingroup\$ What time in Friday? 12am? \$\endgroup\$
    – Razetime
    Jun 16, 2021 at 2:19
  • \$\begingroup\$ @Razetime Any time in Friday \$\endgroup\$
    – l4m2
    Jun 16, 2021 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, 2021 at 11:26
0
\$\begingroup\$

Do I flip the side?

Introduction

When writing on a piece of paper folded \$n\$ times you have \$2^{n+1}\$ sides available to write on. When writing on those sides, you can imagine the following sequence of actions (for \$n=2\$):

  1. write on the first side and fill the whole side,
  2. flip the paper to the next empty side and write there until filled,
  3. now we have to unfold the paper once (at least) to get to the next empty side and "flip" the fold,
  4. flip the paper to the next empty side,
  5. unfold the paper twice to get to the empty side and "flip" the fold,
  6. etc.

Challenge

Given number of folds \$n \geq 0 \$ output the number of unfolds needed to get to the next clear side.
Standard rules apply, so you can:

  • Take an index \$k \leq 2^{n+1}-1\$ and output the \$k^{th}\$ term, either 0 or 1 indexing.
  • Take a positive integer \$k \leq 2^{n+1}-1\$ and output the first \$k\$ terms.
  • Output whole sequence for given \$n\$.

Test cases

n | sequence
----------------------------------
0 | 0 (no unfolds, just a flip)
1 | 0 1 0
2 | 0 1 0 2 0 1 0
3 | 0 1 0 2 0 1 0 3 0 1 0 2 0 1 0
4 | 0 1 0 2 0 1 0 3 0 1 0 2 0 1 0 4 0 1 0 2 0 1 0 3 0 1 0 2 0 1 0

Meta

  • Too easy?
\$\endgroup\$
3
  • \$\begingroup\$ Is this first \$2^{n+1}-1\$ items of oeis.org/A007814? \$\endgroup\$
    – tsh
    Jun 28, 2021 at 8:41
  • \$\begingroup\$ @tsh Yes, it is. \$\endgroup\$
    – pajonk
    Jun 28, 2021 at 15:02
  • 1
    \$\begingroup\$ IMO this is a very near dupe of ABACABA sequence. \$\endgroup\$
    – Bubbler
    Jul 7, 2021 at 6:06
0
\$\begingroup\$

Is this a valid Temtem character name?

Given a string of between 0 and 15 (inclusive) printable ASCII characters, determine whether the string represents an acceptable character name for the game Temtem.

The following rules apply to character names:

  • Names must have at least 3 letters (a-z)
  • Names may have up to 2 total prefixes and/or suffixes of at least one letter
  • Prefixes and suffixes must be separated from the name by one of space, hyphen or apostrophe
  • The first letter of the name and each prefix may be capitalised but all other letters must be lower case.

Truthy examples:

Daddy's girl
de Morgan
Rip Van Winkle
Spider-Man
X-Men

Falsy examples:

McDonald's
-XX-
'falsy'

Note: Temtem may apply other checks to character names not included here.

As this is , Output must be a single consistent value for all valid names. Output for invalid names must be consistent for a given invalid name, but may vary between different invalid names, so for instance a count of errors is an acceptable output format.

This is , so the shortest program that breaks no standard loopholes wins!

\$\endgroup\$
2
  • \$\begingroup\$ Are Rip Van winkle and spider-Man valid? \$\endgroup\$
    – Adám
    Jun 27, 2021 at 12:59
  • \$\begingroup\$ @Adám They are for the purposes of this question, yes. \$\endgroup\$
    – Neil
    Jun 27, 2021 at 13:43
0
\$\begingroup\$

General Binary Counterman Jr

Related

General Binary Counterman Jr is the son of famed Mr. Binary Counterman. He’s continued in his father’s footsteps, counting strings of numbers in the family tradition. But binary has grown old; he’s not a computer. The General has waited for his father’s popularity to wane, and he has decided the time is nigh. The General is about to generalize!

As a reminder, his father would count the evens and odds like this: 1 1 0 0 1 0 would be read as 1st odd, 2nd odd, 1st even, 2nd even, 3rd odd, 3rd even and it becomes 1 3 0 2 5 4.

But not so the General. Evens and odds are just 0s and 1s mod 2, the General knows this. Instead of reducing mod 2, he likes to reduce strings down whatever mod he pleases. Once he does he counts the residues the same way as his father did, but in whatever mod he damn well wants.

The General has read the algorithms that fans have sent his father. But he believes that his new method will yield sufficiently different strategies as to deserve its own page on the internet.

Challenge

Given two inputs representing a mod m and a list L, the nth occurrence of a given congruence class in the list should be output as the nth integer of that class.

The I/O is very flexible and may take any reasonable format, so long as it doesn’t sidestep part of the problem. For instance, you may take the list backwards or as a string, but you can’t take it already reduced mod m.

This is , so least bytes wins!

Reference Implementation

Example

In my examples, I will represent the I/O as 3: 5 3 2 8 4 5 9 -> 1 3 2 4 5 6 to represent the reminder. This means m = 2 and L = 1 1 0 0 1 0. But again, you are not required to do it this way. In fact, you’re encouraged to find the I/O scheme that works best for your language and algorithm!

Input: 3: 5 3 2 8 4 5 9

This gets counted mod 3 by its congruence class of [0], [1] or [2]:

L  m       Count       
5 %3  ->  1st [2]  ->  2
3 %3  ->  1st [0]  ->  0
2 %3  ->  2nd [2]  ->  5
8 %3  ->  3rd [2]  ->  8
4 %3  ->  1st [1]  ->  1
5 %3  ->  4th [2]  ->  11
9 %3  ->  2nd [0]  ->  3

Output: 2 0 5 8 1 11 3

Test Cases

The most fun part! How do you like the test cases?

2: 1 3 0 2 5 4 
   1 3 0 2 5 4 
2: 1 1 0 0 1 0
   1 3 0 2 5 4 
5: 1 1 0 0 1 0
   1 6 0 5 11 10 
1: 9 8 7 6 5 4 3 2 1 0
   0 1 2 3 4 5 6 7 8 9 
100: 101 102 103 104 105
     1 2 3 4 5
10: 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3
    3 1 4 11 5 9 2 6 15 13 25 8 19 7 29 23 12 33 18 14 16 22 26 24 43 53 
7: 10 20 30 40 50 60 70 80 90 100
   3 6 2 5 1 4 0 10 13 9
8: 09 18 27 36 45 54 63 72 81 90
   1 2 3 4 5 6 7 0 9 10
12: 11 22 33 44 55 66 77 88 99 110 121 132
    11 10 9 8 7 6 5 4 3 2 1 0
11: 1 1 2 3 5 8 13 21 34 55 89 144
    1 12 2 3 5 8 13 10 23 0 34 45 
4: 2 4 8 16 32 64 128 256 512 1024 2048
   2 0 4 8 12 16 20 24 28 32 36 

Other Cheats

In the interest of making this as flexible as possible for all the masochistic and impossible fun languages, here are other things you may skimp on:

  • You may assume list L will only contain single digit numbers.
  • You may assume mod m will be a single digit number.
  • You may do anything when m = 0, including throwing an error.
  • You may assume no leading 0s in the numbers.
  • It is less consistent with the pattern, but you may eliminate 0s from your output by starting the count for [0], and only the [0] class, at m instead. Then, in the example program, 1st [0] → 3 and 2nd [0] → 6. It would output 2 *3* 5 8 1 11 *6* instead of 2 *0* 5 8 1 11 *3*
  • Feel free to comment any other ideas and I will add them in if they don’t detract from the spirit of the challenge, and primarily serve to give the turing tarpits a hand. If the cheat would be used by mainstream and golfing langs, it’s probably not a good idea.

Please mention what cheats you’re taking advantage of, if any!

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

Project Euler 001 in constant time

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

Will the hydra finally die? Part II

Background

This is a follow up question to the question: Will the Hydra finally die?

As before a dangerous A Medusa have released a dangerous Hydra which is revived unless the exact number of heads it have is removed. The knights can remove a certain number of heads with each type of attack, and each attack causes a specific amount of heads to regrow. This time the knights are more impatient and having seen your previous abilities want you to** write a program or function that returns a list of hits which will leave the hydra 1 hit from death

Note that this is fundamentally different from Become the Hydra Slayer. in 2 aspects. 1: We are not asking for the optimal solution 2: each attack causes a different number of heads to grow back. this radically changes the approach needed.

For example:

input: heads = 2, 
       attacks = [1, 25, 62, 67], 
       growths = [15, 15, 34, 25], 

output: [5, 1, 0, 0]

Explanation: The Hydra has 10 heads to start with, we have 4 different attacks and for each attack, growth gives us the number of heads that grows back. hits gives us the number of times each attack is applied. So the number of heads the Hydra has after each attack is

2 -> 16 -> 30 -> 44 -> 58 -> 72 -> 62

Since 62 is a valid attack value (It lies in the attack list), we return True since the Hydra will die on the next attack (be left with 0 heads). Note that the order for when the attacks are done is irrelevant.

2 -> 16 -> 6 -> 20 -> 34 -> 48 -> 62

Input

Input should contain heads (an integer), attacks (a list of how many heads can be removed), regrowths (how many heads grow back per attack)

You may take input in any convenient method. This includes, but is not limited to

  • A list of tuples (1, 15, 5), (25, 15, 1), (62, 34, 0), (67, 25, 0)
  • Lists 2, [1, 25, 62, 67], [15, 15, 34, 25], [5, 1, 0, 0]
  • Reading values from STDIN 1 15 1 15 1 15 1 15 1 15 25 15
  • A file of values

Output

  • An array, or some way to easily indicate which hits the knights are to take. Example: 5 1 0 0

Note 1 Say that your input is attacks = [1, 25, 62, 67] and the hydra has 25 heads left, then you cannot output the answer as [1,0,0,0], [0,0,0,1] etc. Your output and input must be sorted similarly. Otherwise it will be very confusing for the Knights.

Note 2: Your program can never leave the Hydra with a negative number of heads. Meaning if the Hydra has 15 heads, an attack removes 17 heads and regrows 38. You may not perform this attack.


Scoring

  • This is a you will be scored as follows: the total sum of hits your code produces from the test data + length of answer in bytes
  • Note that how you input and parse the test data is not part of your code length. Your code should, as stated above simply take in some a headcount, attacks, regrowth's and return a list/representation of how many hits each attack has to be performed to leave the hydra exactly 1 hit from death.

Lowest score wins!


Test data

       attacks = [1, 25, 62, 67], 
       growths = [15, 15, 34, 25],

use every integer from 1 to 200 as the number of heads. An sample from the first 100 can be found below. Again your program does not have to return these values, it is merely an example of how the scoring would work. As seen below the total sum for each of these hits are 535 meaning my score would be 535+length of code in bytes

   1 [0, 0, 0, 0]
   2 [5, 1, 0, 0]
   3 [3, 2, 0, 0]
   4 [7, 4, 0, 0]
   5 [5, 5, 0, 0]
   6 [4, 0, 0, 0]
   7 [2, 1, 0, 0]
   8 [6, 3, 0, 0]
   9 [4, 4, 0, 0]
  10 [8, 6, 0, 0]
  11 [1, 0, 0, 0]
  12 [5, 2, 0, 0]
  13 [3, 3, 0, 0]
  14 [7, 5, 0, 0]
  15 [5, 6, 0, 0]
  16 [4, 1, 0, 0]
  17 [2, 2, 0, 0]
  18 [6, 4, 0, 0]
  19 [4, 5, 0, 0]
  20 [3, 0, 0, 0]
  21 [1, 1, 0, 0]
  22 [5, 3, 0, 0]
  23 [3, 4, 0, 0]
  24 [7, 6, 0, 0]
  25 [0, 0, 0, 0]
  26 [4, 2, 0, 0]
  27 [2, 3, 0, 0]
  28 [6, 5, 0, 0]
  29 [4, 6, 0, 0]
  30 [3, 1, 0, 0]
  31 [1, 2, 0, 0]
  32 [5, 4, 0, 0]
  33 [3, 5, 0, 0]
  34 [2, 0, 0, 0]
  35 [0, 1, 0, 0]
  36 [4, 3, 0, 0]
  37 [2, 4, 0, 0]
  38 [6, 6, 0, 0]
  39 [2, 0, 0, 0]
  40 [3, 2, 0, 0]
  41 [1, 3, 0, 0]
  42 [5, 5, 0, 0]
  43 [3, 6, 0, 0]
  44 [2, 1, 0, 0]
  45 [0, 2, 0, 0]
  46 [4, 4, 0, 0]
  47 [2, 5, 0, 0]
  48 [1, 0, 0, 0]
  49 [2, 1, 0, 0]
  50 [3, 3, 0, 0]
  51 [1, 4, 0, 0]
  52 [5, 6, 0, 0]
  53 [1, 0, 0, 0]
  54 [2, 2, 0, 0]
  55 [0, 3, 0, 0]
  56 [4, 5, 0, 0]
  57 [2, 6, 0, 0]
  58 [1, 1, 0, 0]
  59 [2, 2, 0, 0]
  60 [3, 4, 0, 0]
  61 [1, 5, 0, 0]
  62 [0, 0, 0, 0]
  63 [1, 1, 0, 0]
  64 [2, 3, 0, 0]
  65 [0, 4, 0, 0]
  66 [4, 6, 0, 0]
  67 [0, 0, 0, 0]
  68 [1, 2, 0, 0]
  69 [2, 3, 0, 0]
  70 [3, 5, 0, 0]
  71 [1, 6, 0, 0]
  72 [0, 1, 0, 0]
  73 [1, 2, 0, 0]
  74 [2, 4, 0, 0]
  75 [0, 5, 0, 0]
  76 [1, 0, 1, 0]
  77 [0, 1, 0, 0]
  78 [1, 3, 0, 0]
  79 [2, 4, 0, 0]
  80 [3, 6, 0, 0]
  81 [1, 0, 1, 0]
  82 [0, 2, 0, 0]
  83 [1, 3, 0, 0]
  84 [2, 5, 0, 0]
  85 [0, 6, 0, 0]
  86 [1, 1, 1, 0]
  87 [0, 2, 0, 0]
  88 [1, 4, 0, 0]
  89 [2, 5, 0, 0]
  90 [0, 0, 1, 0]
  91 [1, 1, 1, 0]
  92 [0, 3, 0, 0]
  93 [1, 4, 0, 0]
  94 [2, 6, 0, 0]
  95 [0, 0, 1, 0]
  96 [1, 2, 1, 0]
  97 [0, 3, 0, 0]
  98 [1, 5, 0, 0]
  99 [2, 6, 0, 0]
 100 [0, 1, 1, 0]
535

Meta

  • What would a good scoring method for this type of question be?
  • My method outputs 2873 for the total count from 1 to 200, is this too high, too low?
  • Feel free to suggest other improvements to my testing data
\$\endgroup\$
0
\$\begingroup\$

Transdeletion

Transdeletion is the process of removing a letter from a word and forming another word by creating an anagram from the remaining letters.

If you can do this repeatedly, all the way down to a single letter ("A" or "I", usually, in English), you have formed a "Transdeletion Pyramid".

The Challenge

Given a word list (containing any number of words, up to the max your language can handle) and a starting word, find and output the Transdeletion pyramid.

The word list will include the starting word, and is guaranteed to contain all of the words required to make the pyramid (Sandbox: should it? Or is it a better challenge if it won't always be possible to succeed?). A change of case for any letters of the word is allowed at any time - i.e. dealing with casing isn't part of the challenge. So you can assume all inputs are in lowercase, or uppercase, or whatever suits.

This is , so shortest answer in bytes wins, usual rules apply.

Examples

In the form [[wordList],"startWord"] -> [ordered output list]

[["a", "an", "ant"], "ant"] -> ["ant","an","a"]
[["I", "in", "tin", "sink", "ink"], "sink"] -> ["sink","ink","in", "I"]
[["I", "in", "tin", "sink", "ink"], "in"] -> ["in", "I"]
[["a", "I", "tin", "ant", "sink", "an" "ink"], "ant"] -> ["ant","an","a"]
[["FAT", "TALIERA", "INTERLAMINATES", "ULCER", "ALTER", "TALE", "A", "RATE", "I", "ANTICEREMONIALIST", "MATERIAL", "INCOMPETENT", "TRILAMINATE", "TEA", "TEA", "TRIFLE", "NONMATERIALITIES", "FRATERNISATION", "AT", "AT", "ORNAMENTALITIES", "RETAIL", "TAIL", "MATERNALITIES", "TERMINALIA", "LATIMERIA", "FATIMA", "OBSCURE", "LENS", "MATRILINEATE"],"ANTICEREMONIALIST"] -> ["ANTICEREMONIALIST", "NONMATERIALITIES", "ORNAMENTALITIES", "INTERLAMINATES", "MATERNALITIES", "MATRILINEATE", "TRILAMINATE", "TERMINALIA", "LATIMERIA", "MATERIAL", "TALIERA", "RETAIL", "ALTER", "RATE", "TEA", "AT", "A"]

Sandbox Questions

  1. Should it be possible that the input contains no valid chains?
  2. Should the challenge instead be to find the longest chain, even if it doesn't go down to 1 letter?
  3. Should the starting word be provided or would it be a better challenge without it?
\$\endgroup\$
0
\$\begingroup\$

Decide Magma's Identity

Objective

Given a magma with 256 elements, decide whether it has the identity element.

Definition

A magma is a set endowed with a binary operation. Let's denote the set by \$S\$ and the binary operation by \$\circ\$.

An element \$e \in S\$ is the identity element if for every \$a \in S\$, \$e \circ a = a \circ e = a\$ holds.

If \$e\$ exists, its existence is unique, for if \$f \in S\$ also is an identity element, \$e = e \circ f = f\$.

Input Format

The binary operation \$\circ\$ itself, as a black-box function, will be inputted.

The type of \$\circ\$ doesn't matter. Possible choices include (type names in C):

  • Accepting two chars, returning one char

  • Accepting two int8_ts, returning one int8_t

  • Accepting two uint8_ts, returning one uint8_t

  • Accepting one int16_t (to break bytewise), returning one unsigned char

Ungolfed Solution

Haskell

This implementation is much generalized version of the challenge. It can test an arbitrary finite magma, and will explicitly find the identity element if it exists.

It might seem to have time complexity of \$O(n^2)\$, but it's actually \$O(n)\$.

import Control.Monad
import Data.Maybe

findIdentity :: (Eq a, Enum a, Bounded a) => (a -> a -> a) -> Maybe a
findIdentity op = listToMaybe $ do
    let elements = [minBound .. maxBound]
    e <- elements
    guard (all (\f -> op e f == f) elements)
    guard (all (\f -> op f e == f) elements)
    pure e
\$\endgroup\$
0
\$\begingroup\$

Packing Boxes into a Truck

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

Compile Esolang to Esolang

Based on Convert FRACTRAN to Brainfuck.

  • Compile Brainfuck to FRACTRAN
  • Compile /// to Brainfuck
  • Compile Brainfuck to ///

If you have other ideas, please add them. Be sure it's reasonably doable with simple tarpits, eg Jelly to Vyxal to APL isn't all that fun. If you can make a variation of that fun, that should be posted separately.

If you'd like me to make this into a CW to make it easier to contribute, please comment and let me know!

\$\endgroup\$
4
  • \$\begingroup\$ FRACTRAN to Retina 0.8.2 would prove that the latter is Turing-complete (Regex on its own isn't, but Retina has loops. On the other hand, Retina 1 has eval, so you can probably do some nasty things like a payload-capable quine attempting to evaluate itself, thus implementing Fibonacci recursively.) \$\endgroup\$
    – Neil
    Jul 11, 2021 at 11:07
  • \$\begingroup\$ @Neil I'm thinking that one of them should be a simple, well-known and pretty vanilla lang. Eg Brainfuck <-> Retina, or, since it's based on string subs, /// <-> Retina might be fun. How do those sound? Or would you prefer from FRACTRAN/another Minsky machine? I also am slightly worried about Retina's complexity, but maybe just a subset of Retina would be required? \$\endgroup\$
    – AviFS
    Jul 11, 2021 at 19:45
  • \$\begingroup\$ I can't comment on the other languages because I don't know them, but Retina 0.8.2 isn't that complex; its only loop is the convergence loop and the only conditional code is basically whether a regex matches or not. \$\endgroup\$
    – Neil
    Jul 11, 2021 at 22:42
  • \$\begingroup\$ is this structured as an answer chaining problem? \$\endgroup\$
    – Razetime
    Jul 14, 2021 at 7:35
0
\$\begingroup\$

Make me some puzzles

So, a while ago on Puzzling, I posted this. It basically had a whole bunch of equations that were wrong, and when you figured out how much they were wrong by, and transformed 1-26 into A-z, it yielded the phrase ALLWRONG.

Your challenge is to take a string of letters as input, and output a series of wrong, randomly generated equations that are wrong by the correct amount to yield said string.

Equations must be of the form number operation number = number, where each number is a positive integer less than 100, and the operators are +-*/, although × and ÷ are acceptable instead of */.

I'm going to be quite lenient on the definition of 'random' in this one - all possible equations must have a nonzero chance of appearing for any given letter.

Valid equations should have the result of the left hand side's difference from the right hand side being the correct number to, when 1-26 is transformed into A-Z, yield the corresponding character.

Output can be as an array, newline separated, whatever. Equations don't need to be spaced, that's just for readability. You can even output as a list of [1,+,1,=,3] or something.

Testcases

These are possible outputs, not proper testcases.

A => 1 + 1 = 3
HI => 3 * 4 = 4, 9 * 2 = 9
LOL => 20 / 5 = 16, 7 * 5 = 20, 50 - 23 = 15
\$\endgroup\$
1
128 129
130
131 132
155

You must log in to answer this question.

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