578
\$\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\$
3
  • 1
    \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$ Commented May 15, 2024 at 14:05
  • 2
    \$\begingroup\$ @None1 If you don't get feedback for a while you can ask in the nineteenth byte \$\endgroup\$ Commented May 29, 2024 at 13:27
  • \$\begingroup\$ I have been once submitted a question to sandbox and downvoted to -1, but after submitting it anyway it has 8-9 score right now. \$\endgroup\$ Commented Dec 5, 2025 at 18:13

5038 Answers 5038

1
150 151
152
153 154
168
0
\$\begingroup\$

The Gather Operation

Overview

Output: You may take in input and output in any reasonable format.

Definication

The gather operation extracts values from a string based on a pattern-matching syntax.

Syntax

gather <x, y, z, ...> from <string> using <gather_syntax> [check <varname>]
  • Characters can be escaped with \

  • <varname> in check sets to 0 if gather fails or 1 if successful

Pattern Syntax

The syntax string uses special markers to define patterns:

  • * - Matches 0 or more characters (like regex .*)

  • ? - Matches 0 or 1 character (like regex .?)

  • ! - Matches a space-delimited word

  • %:<chr> - Matches a string quoted with character

  • Escape these special characters with \

Value Extraction Syntax

Values are extracted using:

((&varname[:modifiers] [options]))

Modifiers:

  • :d - Only decimal numbers allowed

  • :a - Only ASCII characters allowed

  • :f - Only decimal numbers or floats allowed

  • :b:<charset> - Only characters in allowed (escape spaces with )

Options:

  • fss - Force space at start of value

  • fes - Force space at end of value

  • rc:<charset> - Remove these characters before processing

Examples

Basic Example

gather x from 'Money: $17276' using 'Money: ((&x:d rc:$))'
  • Matches "Money: " prefix

  • Extracts numeric value into x

Complex Example

gather num, str, balance from 'Hello! Good Moring. I have a number: 400,90190,189 . A string is "Hello World!"? Yes. I have 81,38173,327 in my bank.' using 'Hello\! !! I have a number:((&num:d fss rc:,)). A string is ((&str:a rc:".)) I have ((&balance:d fes rc:,)) in my bank.' check success

Result:

num = 40090190189
str = 'Hello World!'
balance = 8138173327
success = true

Explanation

  • Matches the initial Hello! Good Morning pattern

  • Extracts number, removing commas (rc:,)

  • Extracts quoted string, removing quotes (rc:")

  • Extracts balance, removing commas

  • Sets success to 1 (true) since all extractions succeeded

\$\endgroup\$
2
  • \$\begingroup\$ i'd expect the first test case to fail because of the $ char that breaks the pattern matching. is this on purpose? "escape spaces with" > i assume a backslash got eaten? typo in "definication". otherwise LGTM \$\endgroup\$ Commented Jul 11, 2025 at 8:46
  • \$\begingroup\$ WTF........................ \$\endgroup\$ Commented Dec 16, 2025 at 18:01
0
\$\begingroup\$

Outer automorphism of S₆

Input: x is a permutation of 6 elements

Output: y is a permutation of 6 elements

Implement a function/program that takes an input permutation on a set of 6 and outputs/returns a permutation on a set of 6.

Conditions:

  • The function/program must map each of the 720 possible input permutations to a different output.
  • The mapping must be an automorphism that is not an inner one. For example, the identitymapping would not be valid as it is an inner automorphism.
  • The function/program must always give the same output for each of the 720 possible inputs. It may do anything (crash, error, or have non-deterministic behaviour) on inputs other than these 720.
  • The input format and output format must be consistent, but your input format can be different from the output format.
  • Your program should run for at most 1 minute on each input.

You may take input and output in any reasonable format.

Allowed formats (example for permutation 0->2->3->0, 1->4->1, 5->5) include but are not limited to:

  • [2,4,3,0,1,5] (list)
  • {0:2,1:4,2:3,3:0,4:1,5:5} (dict)
  • 243015 or (decimal integer, might be only 5 digits if 0 maps to 0 in the permutation)

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

Implement shellscript variable expansion

Task

Given a shellscript-like language program as input, output what every OutputLine would output.

Language specifications

As in POSIX Shell Script Language specification.

It's a line-oriented, line-oriented-output-only total language. It works on string-value variables. For simplicity, you have to implement single-letter variables only. At least two variables have to be supported. The variable is unset until assigned.

The syntax and semantics is as follows:

Program := /* Empty */ {
  1. End program
} | Line Program {
  1. Do Line
  2. Do Program
}
Line := AssignmentLine {
  1. Do AssignmentLine
} | UnsetLine {
  1. Do UnsetLine
} | OutputLine {
  1. Do OutputLine
}
AssignmentLine := Assignment Newline {
  1. Do Assignment
} | Assignment Space AssignmentLine {
  1. Do Assignment
  2. Do AssignmentLine
}
Assignment := VariableName "=" StringValue {
  1. Evaluate StringValue
  2. Assign step 1 result to variable named VariableName
}
UnsetLine := UnsetCommand Newline {
  1. Do UnsetCommand
}
UnsetCommand := "unset" Space VariableName {
  1. Unset variable named VariableName
} | UnsetCommand Space VariableName {
  1. Unset variable named VariableName
}
OutputLine := StringValue Newline {
  1. Evaluate StringValue
  2. Output step 1 result as a line
}
StringValue := /* Empty */ {
  1. Evaluate to an empty string
} | StringChar StringValue {
  1. Evaluate to the concatenation of StringChar and StringValue
} | VariableExpansion and StringValue {
  1. Evaluate to the concatenation of VariableExpansion and StringValue
}
VariableExpansion := "$" VariableName {
  1. If variable named VariableName is unset, evaluate to an empty string
  2. Otherwise, evaluate to content of the variable
} | "${" VariableName "}" {
  1. Same as semantics of the following syntax: "$" VariableName
} | 
VariableName := "a" | "b" | ... | "y" | "z"
StringChar := "a" | ... | "z" | "0" | ... | "9" | "_" | "-" | ":"
NewLine := "\n"
Space := " "

line is either variable definition or bare string when latter case output the result

support at least two distinct characters for string value to assign

One test case

$a
${a}
${a-Empty}
${a:-Empty}
${#a}
a=codegolf
${a#*o}
${a##*o}
${a#q}
unset a
${a:=zxcv}
$a
b=hi_world
${a}_$b
a=${a:=foo}_$a
${a+vcxz}_${#b}
a=
${a+vcxz}_${#b}
${a:+vcxz}_${#b}

outputs:



Empty
Empty
0
degolf
lf
zxcv
zxcv
zxcv_hi_world
zxcv_zxcv_8
_8
zxcv_8

Meta

I am bored to write actual specs and tests.

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

Reset my scrollbar

My scrollbar has three properties: min, pos, and max; and these must be in ascending order at all times.

The problem arises when you want to reset the min, pos and max to three new values, but the scrollbar API only allows you to set one at a time, and your update will fail if the values do not remain in ascending order.

For example, if the scrollbar has min 0, pos 5 and max 10, and you want to set it to min 20, pos 25 and max 30, you need to set the max first, then the pos second, then the min last.

Given the current and desired min, pos and max values, please output the order in which the values need to be changed so that the values remain in ascending order after each change.

You can encode the output using any three consistent byte-sized values to represent min, pos and max.

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

\$\endgroup\$
5
  • \$\begingroup\$ pseudo-code: if (max_new > max_old) then {set max, set pos, set min} else {set min, set pos, set max} That's it, right? \$\endgroup\$ Commented Oct 20, 2025 at 1:10
  • 1
    \$\begingroup\$ @M-- No, that will fail for old=(3; 4; 5) new=(1; 2; 6) \$\endgroup\$ Commented Oct 20, 2025 at 7:42
  • \$\begingroup\$ I see. So the window can be "resized" as well. \$\endgroup\$ Commented Oct 20, 2025 at 14:58
  • \$\begingroup\$ Is it possible for pos to be equal to either extreme? You do say they must be ascending, which implies not, but as-is I'm not sure that is your intention. \$\endgroup\$ Commented Oct 22, 2025 at 19:19
  • 1
    \$\begingroup\$ @FryAmTheEggman I think probably the easiest thing to do would be to say that all six values will be different, as this will avoid needless complications. \$\endgroup\$ Commented Oct 23, 2025 at 7:38
0
\$\begingroup\$

Given a wall maze of 50x50, write two functions:

  • One takes the maze as input and returns a positive integer;
  • The other takes the integer and walk through the maze from left-top to right-bottom. At any time, it can only see if it's wall the nearest 4 positions.

A testing lib in js is provided here. Using other languages is fine but you may need to write your testlib.

Minimize sqrt(the passed number) + walked steps.

Your program would get executed on multiple tests and average score is used.

Notes

  • I first want to make a block maze but it's hard to implement
  • Was log2(the passed number) + walked steps but that likely result telling every branch
  • scoring need suggestions
\$\endgroup\$
0
\$\begingroup\$

Say there are three multisets A, B, C. An infix condition has form

<ON|NEXTTO|NEAR> <a multiset>

where

  • ON requires the multiset is a subset of A
  • NEXTTO requires the multiset is a subset of B
  • NEAR requires the multiset is a subset of A⨆B⨆C, where mean multiset sum, producing a multiset whose count for each element is the sum of its counts in the input multisets.

Given some conditions, decide if any element of any input multiset is redundant, aka. is it possible to remove any element from any input multiset, such that the condition suggests same multisets A, B, C.

IO

  • Input not sorted. Yet if you take input as multiset and your language automatically sort it, then it's fine.
  • You can decide all uppercase or all lowercase
  • You can assume no empty condition in input, but not that conditions remain not empty after removal(test case 2 = on(baba) on(), but you won't get direct input like this)
  • Inverting output is fine.

Test cases:

on(baba) on(keke) => false
on(baba) on(baba) => true
on(baba keke) nextto(baba keke) => false
on(baba keke) near(baba) => true
on(baba baba) => false
on(baba) on(baba baba) => true
on(baba keke) on(baba baba) => true
on(baba) nextto(baba) near(baba baba) => true
on(baba) nextto(baba) near(baba baba baba) => false

Shortest code in each language wins.

Notes

  • C seems useless. Should it get removed?
\$\endgroup\$
0
\$\begingroup\$

posted

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

Pick and Flip

Challenge

Given an array of integers, perform the Pick and Flip algorithm, which is defined like this:

  1. Set n to 1 (if 1-indexed) or 0 (if 0-indexed).
  2. Set i to the n-th element of the array. If it doesn't exist, stop and return the array.
  3. Reverse the i-th element of the array, if it exists. For example, 15 reverses to 51, and 20 reverses to 2.
  4. Increase n by 1 and return to step 2.

Test Cases

1-indexed:

  3   5  19   6 720  50    Input
 [3]  5  19   6 720  50    Pick
  3   5 (91)  6 720  50    Flip
  3  [5] 91   6 720  50    Pick
  3   5  91   6 (27) 50    Flip
  3   5 [91]  6  27  50    Pick
  3   5  91   6  27  50    Flip
  3   5  91  [6] 27  50    Pick
  3   5  91   6  27  (5)   Flip
  3   5  91   6 [27]  5    Pick
  3   5  91   6  27   5    Flip
  3   5  91   6  27  [5]   Pick
  3   5  91   6 (72)  5    Flip
  3   5  91   6  72   5    Output

0-indexed:

  2   4  19   5 720  40    Input
 [2]  4  19   5 720  40    Pick
  2   4 (91)  5 720  40    Flip
  2  [4] 91   5 720  40    Pick
  2   4  91   5 (27) 40    Flip
  2   4 [91]  5  27  40    Pick
  2   4  91   5  27  40    Flip
  2   4  91  [5] 27  40    Pick
  2   4  91   5  27  (4)   Flip
  2   4  91   5 [27]  4    Pick
  2   4  91   5  27   4    Flip
  2   4  91   5  27  [4]   Pick
  2   4  91   5 (72)  4    Flip
  2   4  91   5  72   4    Output

Restrictions

  • Every integer in the array will be at least 1 (if 1-indexed) or 0 (if 0-indexed).
  • The array will not be empty.

Scoring

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

Get BB(k-1) from BB(k)

Here BB(k) is the longest running step of k-state, 2-symbol deterministic Turing machine. A movement of tape head is required per step, as data source does.

Test cases:

47176870 => 107 # BB(5)=>BB(4)
107 => 21 # BB(4)=>BB(3)

Explain your code as there's technical difficulty to test answers.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ You need to explain your definition of Turing machine a little more. For one I assume you probably mean deterministic Turing machine, but this is worth specifying. Some definitions require that a Turning machine move the tape head on every transition, some definitions allow the tape head to remain fixed. Some definitions require a specific halt state, some halt when there is no transition available. etc. These differences are usually trivial but BB(k) is highly sensitive to them. \$\endgroup\$ Commented Jan 9 at 13:38
  • \$\begingroup\$ Isn't this impossible? The BB(n) sequence is not computable. But if there was a program that solved your problem then wouldn't there be a simple modification of it that computed BB(n)? \$\endgroup\$ Commented Feb 3 at 12:04
  • \$\begingroup\$ @aeh5040 BB(n-1) is uncomputable because we don't have a value promised large enough, but here BB(n) is provided \$\endgroup\$ Commented Feb 4 at 15:16
  • \$\begingroup\$ @l4m2 I am not convinced. I don't know what you mean by "a value promised large enough". Every individual integer is trivially computable. It is sequences that may not be. The sequence mapping n to BB(n) is not because it would require determining which of the n-state TMs halt for each n, which requires solving the halting problem. The (n-1)-state machines are in effect a subset of the n-state ones, but just knowing the max 1s produced by a halting n-state does not help knowing which n-1 state ones halt. \$\endgroup\$ Commented Feb 5 at 15:06
0
\$\begingroup\$

List directories needed to exist to reach a path ("mkdir -p --dry-run")

(The challenge has been posted.)

\$\endgroup\$
7
  • \$\begingroup\$ Hmm. A similar challenge exists but it was closed... \$\endgroup\$ Commented Jan 28 at 5:06
  • 1
    \$\begingroup\$ you can safely ignore the old challenge, it needed a winning criterion which you have with code-golf. this seems relatively trivial, but maybe there's some odd cases in which it's not? \$\endgroup\$ Commented Jan 28 at 11:09
  • 1
    \$\begingroup\$ @Themoonisacheese The main catch of this proposed challenge is how to handle . and .. in paths. And I want to make it usable in the real world, as if one day someone implements the actual --dry-run in mkdir(1). \$\endgroup\$ Commented Jan 28 at 11:27
  • \$\begingroup\$ i see. nothing wrong with easy real-world use cases (As in, i'm not gonna tell you not to post it) but some people do downvote challenges that they find too easy, FYI. \$\endgroup\$ Commented Jan 28 at 11:29
  • \$\begingroup\$ Given that .. should never appear in the output, is it guaranteed that no input would perform a directory traversal attack as specified in the previous challenge? \$\endgroup\$ Commented Jan 28 at 16:35
  • \$\begingroup\$ @UnrelatedString If you do mkdir -p a/../b, you would see mkdir creates two directories. So you are to resolve .. to match the behavior. In other words, this challenge allows directory traversal. \$\endgroup\$ Commented Jan 28 at 20:58
  • \$\begingroup\$ It would be helpful to spell out the significance of . and .. for this challenge. I know what they mean, but it still took me a second to realize why a/d was in the output. \$\endgroup\$ Commented Jan 28 at 22:20
0
\$\begingroup\$

Return the minimum Conjunctive Normal Formula equivalent to the one given in input.

Translated by Google + some my changes

A conjunctive normal formula (abbreviated here CNF) is a conjunction of clauses, which are disjunctions of variables. It is represented by writings such as

(A∨B∨∼C∨∼D)∧(Q∨R∨∼P∨∼K)∧...∧(∼M)

where (A∨B∨∼C∨∼D), (Q∨R∨∼P∨∼K), ..., (∼M) are each the clauses of the CNF above, where A B C D ... M are "variables" of the respective clauses. Each of these variables can take on any value in the set TF={1,0}. Once a value in the set TF has been assigned to each variable, the value of the CNF can be calculated by performing the functions ∨ ∧ ∼ with the binary values ​​0 1 of each variable.

The operation ∨ is defined by

1∨0=1; 0∨1=1; 1∨1=1; 0∨0=0

The operation ∧ is defined by

1∧0=0; 0∧1=0; 1∧1=1; 0∧0=0

The function ∼ is defined by

∼1=0; ∼0=1

Two CNFs A(x1,x2,...xn) and B(y1,y2,...yn), with variables {x1,x2,...xn} and {y1,y2,...yn}, are said to be equivalent if any assignment {x1,x2,...xn} ∪ {y1,y2,...yn} with values ​​in the set TF={1,0} yields the same final Boolean value (performing all calculations with the functions ∨ ∧ ∼) in CNF A and CNF B.

If A and B are two conjunctive normal formulas, we say that A is less than B if the sum of all occurence of ∧ and or ∨ of A is less than the sum of all occurence of the and ∧ and or ∨ of B

Examples: Let's say two CNFs A and B with

A=(a1∨a2)∧(a3∨a4) and B=(a1∨a2)∧a3

then B<A because numbers of ∧ and ∨ of B is 2 that is less than the number of ∧ and ∨ of A that is 3.

Here we require a program that, given a CNF A, returns a CNF B that is as small as possible and equivalent to A. The winner is the one who finds the minimum number of the sum of all the or[∨] and and[∧] that appear in all the CNF results of below exercises.

If two answers are tied, then the winner is the one with the smallest program in terms of number of bytes in the source code.

Exercises (the formulas are the same as those in Prove me wrong!)

(P∨∼Q∨∼R)∧(Q∨R∨∼P)∧(Q∨∼P∨-R)
(∼P)∧(S)∧(R∨∼P)∧(U∨∼Q)∧(X∨∼R)∧(Q∨∼S)∧(∼P∨∼U)∧(W∨∼Q∨∼U)
(∼P∨∼Q)∧(Q∨P)∧(P∨∼Q)∧(Q∨∼P)
(P)∧(∼P∨∼S)∧(P∨T)∧(Q∨∼R)∧(∼R∨∼S)∧(∼P∨∼Q∨∼R)∧(∼P)
(T∨∼S)∧(∼S)∧(Q∨∼R)∧(∼R∨∼S)∧(∼P∨∼Q∨∼R)∧(∼P)

These formulas can be represented in the code with maximum freedom, for example,

(P∨∼Q∨∼R)∧(Q∨R∨∼P)∧(Q∨∼P∨-R)

could be represented as an array of 3 strings:

('P-Q-R')('QR-P')('Q-P-R')

Examples:

In finding a smaller equivalent CNF for (P∨∼Q∨∼R)∧(Q∨∼R∨∼P)∧(Q∨∼P∨-R) I would have found (Q∨∼P)∧(P∨∼Q∨∼R). It has 1 and ∧, and 3 or ∨ in total so 4 is the length of this result formula that is more little of the one of input that has length 6 or and 2 and that would be 8.

Could be useful these equivalences

A∨B∨..∨D is equivalent to each permutations of variables A B..D 
A∧B∧..∧D is equivalent to each permutations of variables A B..D 
A∨B∨..∨∼A∨..∨D is equivalent to 1 or always true, 1 is the name of that proposition 
A∧B∧..∧∼A∧..∧D is equivalent to ∼1 or always false or 0 zero
A∨∼1 is equivalent to  A
A∨ 1 is equivalent to  1
A∧∼1 is equivalent to ∼1 (that is 0 too)
A∧ 1 is equivalent to  A
A∧(A∨∼A) is equivalent to A
A∧(B∨∼A) is equivalent to A∧B
(P∨Q)∧(P∨R) is equivalent to P∨(Q∧R) useful when R is ∼Q
(A∨B∨C∨D)∧(Q∨R∨P∨K)∧(A∨B) is equivalent to (Q∨R∨P∨K)∧(A∨B)

tag logic codegolf

\$\endgroup\$
3
  • \$\begingroup\$ I thought this problem is NP-complete, is it not? \$\endgroup\$ Commented Feb 9 at 12:49
  • \$\begingroup\$ @Explorer09 I don't know, I didn't see in books the definition of equivalent cnf, and minimal equivalent cnf... one would ask that to one expert academic... I search 'minimal cnf' and this problem exist and Google says it is np-hard I don't know the meaning \$\endgroup\$ Commented Feb 9 at 13:30
  • \$\begingroup\$ It means there is unlikely a solution that can solve the problem in polynomial time (N² or N³). The time complexity would be (2^n) or more. It's a difficult computer science problem. \$\endgroup\$ Commented Feb 9 at 15:13
0
\$\begingroup\$

SCR max speed calculator

SCR is a train driving game on Roblox. Distances are measured in miles, and speeds in miles per hour. The driving guide dictates specific speeds for specific scenarios:

  • The speed should never be higher than either the maximum speed of the train or the imposed speed limit.
  • If the train is less than or equal to 0.35 miles from the station, the train should go no more than 35mph.
  • If it is a terminating station, it should be no more than 15mph.
  • If the signal is a single yellow aspect, it should be no more than 45mph.
  • If the signal is a red aspect and the distance to the signal is less than the distance to the station, the train should be at a complete stop (0mph). If the station is closer, normal station approach rules apply.
  • Double yellow and green aspects do not carry speed restrictions by themselves.

Given the train’s maximum speed, the current speed limit, the distance to the next station, the distance to the next signal, and the current signal aspect, output the maximum speed the train is allowed to move at in mph. If the next signal aspect is red and the station is closer than the next signal, you may assume that the train is at most 0.35mi away from the next station. Shortest code wins, standard loopholes apply.


Too complex?

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

Inference a transformer

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

Can you Shut The Box?

Shut The Box is a simple dice game, where a player attempts to "shut" all of the numbered tiles (traditionally, 1 through 9) by rolling dice. The way the game works:

  • The box has 9 numbered and hinged tiles, numbered 1, 2, 3, etc. up to 9. Initially, all 9 begin "open".
  • A player rolls two 6-sided dice and total the two dice.
  • They then "shut" any combination of tiles that sum to the dice total.
  • Repeat until all tiles are shut, or no more open tiles can sum to the dice total.
  • The player's final score is the total of all remaining open tiles, with a lower score being better.

Note that there are multiple ways that one dice roll can shut different tiles. For example, rolling a total of 5 can close either the 5 tile, the 4 and 1 tiles, or the 3 and 2 tiles. Importantly, there is only one of each numbered tile, so once a tile has been used, it cannot be used again. Thus, for a roll of 6, the combination of 3 and 3 isn't valid, but the 3, 2 and 1 tiles are.


Given a non-empty list of positive integers ranging from 2 to 12 inclusive, output the lowest possible score for that series of dice rolls, in that order. You may take input in any acceptable and reasonable format and method, but please note that, as order matters, the manner in which you take input must distinguish different orders of the same integers.

This is a challenge, so the shortest code in bytes in each language wins.

Test cases

Input -> Output
[10, 10, 10, 10, 5] -> 0
\$\endgroup\$
0
\$\begingroup\$

posted

\$\endgroup\$
2
  • \$\begingroup\$ I tried this a long time back with a lot of prettifying, and the result, though ungolfed, looks nice: scratch.mit.edu/projects/1194935769 \$\endgroup\$ Commented Mar 5 at 16:21
  • \$\begingroup\$ @Rhaixer nice! I've used a gravity sim as a way to learn a new language a number of times, it's a great problem that's easy to add stuff to \$\endgroup\$ Commented Mar 6 at 6:55
0
\$\begingroup\$

Golf my scratchblocks code

For my bigger Scratch programs, I use an external tool which inputs a project file and outputs the scratchblocks code for the sprites within it. However, this workaround merely replaces one problem (writing the golfed code) with another (golfing some code), and on top of that I have to account for some of the weird quirks of this tool. For example, here's a golfed function that draws a fast quadratic Bézier curve in Scratch, as generated by this tool:

define d (s\) (a\) (b\) (c\) (d\) (e\) (f\)
set [g v] to (((a::custom) + (e::custom)) - ((2) * (c::custom)))
set [h v] to ((2) * ((c::custom) - (a::custom)))
set [i v] to (((b::custom) + (f::custom)) - ((2) * (d::custom)))
set [j v] to ((2) * ((d::custom) - (b::custom)))
set [k v] to (((2) * (g)) / ((s::custom) * (s::custom)))
set [l v] to (((g) / ((s::custom) * (s::custom))) + ((h) / (s::custom)))
set [o v] to (((2) * (i)) / ((s::custom) * (s::custom)))
set [p v] to (((i) / ((s::custom) * (s::custom))) + ((j) / (s::custom)))
pen up
go to x\: (a::custom) y\: (b::custom)
pen down
repeat (s::custom)
    go to x\: ((x position) + (l)) y\: ((y position) + (p))
    change [p v] by (o)
    change [l v] by (k)
end

See it rendered here. It will be massively oversized if I paste it here.

Immediately we can see some issues with what we get. The parameters have collapsed due to the \s, messing up the rendering of everything else.

After receiving this, I run it through a script to automatically remove the backslashes and the ::customs, and then sit down, look through the code, and golf it.

However, I'm tired of having to manually golf it myself. That's your task: given a scratchblocks program that is an output from this tool, golf it, keeping in mind the following rules:

Input

A multiline scratchblocks program representing a valid Scratch program, consisting only of printable ASCII characters (0x20-0x7E), taken via our default I/O methods. Comments (//s outside of a string input) will not be present in the program.

Output

Following these rules, output another syntactically valid golfed scratchblocks program:

  1. The [] part indicates a string input in scratchblocks. Since (thankfully) strings are preserved as-is from this tool, don't interfere with anything that has a [ a few characters back and an unescaped ] a few characters forward (on the same line). The sequence \] after a [ does not terminate the string.

  2. Some lines are just the text when @greenFlag clicked. These, and only these, are to be replaced with when gf clicked

  3. Leading whitespace on all lines is to be removed.

    So the second last line becomes just change [l v] by (k)

  4. Remove whitespace between characters where at least one side is non-alphanumeric, unless the whitespace occurs inside a [...] string input.

    Non-alphanumeric is defined as not contained in the string 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

    So the 4th-last line becomes go to x:((x position)+(l))y:((y position)+(p)). Note that all the spaces, except x p and y p, have been removed. Additionally, the 3rd line becomes set[h v]to((2)*((c)-(a))). Even if h was actually a variable $, you must not collapse the space in $ v since the space is contained within square brackets ([])

  5. At the end of each line, all trailing characters in the string >]) are to be removed.

    For example, line 1 becomes define d(s)(a)(b)(c)(d)(e)(f without the last ).

    However, if the line ends with a string input, only the closing unescaped square bracket may be removed. If we have a line set[t v]to[test>)], only the last ] can be removed, since the >) is part of a string, and removing that would affect the string's contents itself.

  6. ends present as the very last lines in the program are to be removed.

    Thus for this (meaningless) program, the last two ends can be removed.

when gf clicked
repeat(5
repeat(5
change[i v]by(1
end
end
  1. ends preceding a when gf clicked or a define line are also to be removed. So if I define a function after the above program, the ends still can be removed.

  2. On top of this, you should also handle escapes. To represent ] in a string input, you must type \].

    This means that \] do not terminate a string input, and under no circumstances can a \] be removed.

These transformations can be done in any order as long as the final output satisfies all the rules.

Test cases

Input -> Output
"set [x v] to [Hello, World!]" -> "set[x v]to[Hello, World!" (rules 1, 4, 5)

"say [Don't remove these! <([\])>]" -> "say[Don't remove these! <([\])>" (rules 4, 5)

"when @greenFlag clicked
move (10) steps" 
-> "when gf clicked
move(10)steps" (rules 2 and 4)

"repeat(10)
    move (10) steps
    turn cw (5) degrees
end"
-> "repeat(10
move(10)steps
turn cw(5)degrees
" (rules 3, 4, 5, 6)

"go to x: ( (x position) + (1) ) y: ( (y position) - (1) )" 
-> "go to x:((x position)+(1))y:((y position)-(1" (rules 4 and 5)

"define g
repeat(5
move(10)steps
end
define f(x
repeat(6
turn cw(x)degrees
end
when gf clicked
say[Hi!
" -> "define g
repeat(5
move(10)steps
define f(x
repeat(6
turn cw(x)degrees
when gf clicked
say[Hi!" (rule 7)

"say[Special character:\]blah blah]" -> "say[Special character:\]blah blah" (rule 8)

"when @greenFlag clicked
repeat (10)
    go to x: ( (x position) + (1) ) y: ( (y position) + (1) )
    say [(Count > 0)]
end
end
define g (x)
say[x\]]
repeat(5)
change[i v]by(1)
end" ->
"when gf clicked
repeat(10
go to x:((x position)+(1))y:((y position)+(1
say[(Count > 0)
define g(x
say[x\]
repeat(5
change[i v]by(1" (general test case)

The initial program becomes
"define d(s)(a)(b)(c)(d)(e)(f
set[g v]to(((a)+(e))-((2)*(c
set[h v]to((2)*((c)-(a
set[i v]to(((b)+(f))-((2)*(d
set[j v]to((2)*((d)-(b
set[k v]to(((2)*(g))/((s)*(s
set[l v]to(((g)/((s)*(s)))+((h)/(s
set[o v]to(((2)*(i))/((s)*(s
set[p v]to(((i)/((s)*(s)))+((j)/(s
pen up
go to x:(a)y:(b
pen down
repeat(s
go to x:((x position)+(l))y:((y position)+(p
change[p v]by(o
change[l v]by(k"

This is , so shortest answer (in bytes) wins!

META: probably a lot of ambiguities as phrased, please let me know if you find any and vote to let me know when I can post this.

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

Implement Vyxal 3's extract-truthy-head

\$\endgroup\$
2
  • \$\begingroup\$ I’ve just learnt about Vyxal from this post. There’s seems to be more cool things to find browsing through in the Sandbox than on the questions asked \$\endgroup\$ Commented Mar 11 at 12:13
  • \$\begingroup\$ @Mika Vyxal is a very cool language, you can check it out by taking (the tour)[github.com/Vyxal/Vyxal/blob/version-3/documentation/Tour.md] \$\endgroup\$ Commented Mar 11 at 14:28
0
\$\begingroup\$

Oneliner: Atom/RSS piped in, “N days ago” out

Specifically, “Nd ago”.

Oneliner receiving content of Atom/RSS xml (can assume xml syntax correctness) via pipe and printing out how many days ago was last post published (not updated) from system time (can be wrong by one day).

(Challenging is that both date formats have to be handled in the two formats)

POSIX (invoked from sh or bash) or GNU bash/coreutils/awk or perl or jq or python (no non-ubiquitous dependencies) (I’d wish to encourage plan9port rc or Drew DeVault’s xc but that’s too broad and unubiquitous for accepted answer scope), additional tools use is on-topic but not an answer to be checkmarked.

Can assume things but reasonably common (abundant human error, implementations used by dozens of people on the internet independently) non-malicious feed specifics in the wild can prove a solution non-checkmark-eligible


It has some real life conditions rather than all provided possible inputs

Moved from Oneliner: Atom/RSS piped in, “N days ago” out

\$\endgroup\$
1
  • 1
    \$\begingroup\$ copying the comment I made from original post: it would be good to add a test-cases section to allow for easier verification of solutions, and since code golf is a competition per language it usually isn't interesting to restrict answers to specific languages \$\endgroup\$ Commented Mar 11 at 12:11
0
\$\begingroup\$

Output the following text:

⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠈⠘⠀
⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠌⠜⠄
⠥⠧⠭⠽⠵⠯⠿⠷⠮⠾⠬⠼⠤
⠡⠣⠩⠹⠱⠫⠻⠳⠪⠺⠨⠸⠠
⠂⠆⠒⠲⠢⠖⠶⠦⠔⠴⠐⠰

The first row are all symbols that don't take two bottom dots and cannot move up. 2-4 rows are 1st row add some dots and 5th row shifts down.

Note there are 13 characters on 1st line but only 12 on 5th. Empty cell does have meaning(typically mean space in letter-based languages) but there's no shifted space.

\$\endgroup\$
2
  • \$\begingroup\$ You seemed to have made other challenges related to Unicode braille (1 2), didn't you? How are these challenges related to each other? \$\endgroup\$ Commented Mar 16 at 12:00
  • \$\begingroup\$ @Explorer09 Not much related it seems \$\endgroup\$ Commented Mar 16 at 12:09
0
\$\begingroup\$

In Manufactoria(swf version), entry and exit are fixed, and conveyor cost. Therefore we can treat some sequential operations "free".

Yes this is also optimal though I do unnecessary stuff

$$\text{Yes this is also optimal though I do unnecessary stuff}$$

Now given an infinite grid, do everything with lowest extra cost. Or a finite definition can be:

  • Claim a score M such that, for every (Turing-computable) function {R,B}^n -> {R,B,G,Y}^n, there is a size N where you can complete the question with M+N components.

You can assume no green and yellow input but they may be required in output. Also here we assume an infinite tape rather than just 50.

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

Help me "prove" π = 4

\$\endgroup\$
7
  • \$\begingroup\$ Request stacked image of n=k and n=k+1 with aux line if it helps \$\endgroup\$ Commented Mar 19 at 21:50
  • \$\begingroup\$ i.sstatic.net/JpVM7nC2.png maybe \$\endgroup\$ Commented Mar 19 at 21:53
  • \$\begingroup\$ @l4m2 it probably would, thanks! \$\endgroup\$ Commented Mar 20 at 1:45
  • \$\begingroup\$ It is mandatory to draw the circle beneath the staircase graph? I think for the \$n=15\$ example, it can look nicer if the red circle is hidden. \$\endgroup\$ Commented Mar 20 at 5:51
  • \$\begingroup\$ It is mandatory, just to provide a comparison and show how accurate the staircase graph gets as \$ n \$ increases \$\endgroup\$ Commented Mar 20 at 9:22
  • \$\begingroup\$ suggest "Test case" <-> "Example". whhat a test case is is generally accepted to be a collection of input/output for testing, while an example is a specifically explained, well, example. otherwise LGTM \$\endgroup\$ Commented Mar 23 at 9:31
  • \$\begingroup\$ Yeah I was actually on my way to change that when I noticed your comment... fixed \$\endgroup\$ Commented Mar 23 at 11:57
0
\$\begingroup\$

Got closed, and was referred here

Despite being an incredibly popular graphical output demo video (similar to "It runs DOOM!), there is no code golf for Bad Apple yet!

The Challenge:

Output the attached 20 consecutive frames (or more if you want!) (I used this tool and set the frame rate to 1fps) of the video, in ascii, or any other method of graphical output (such as pygame, turtle, LED lights, GCODE that 3d prints a frame, anything goes).

The Rules:

Standard rules on loopholes apply

Resolution of the frame must be (at minimum) 40*30. Any downsampling can be used

Scoring is done based on standard Code Golf rules

An example ascii output is available at this link (Note that it is animated, but you do not need to clear the terminal between frames, only output 20)

The Frames:

enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

Ascii Output:

Hosted here: https://github.com/SiffrinSuffrin/BadAppleTXT/blob/main/badapple.txt

Good luck!

\$\endgroup\$
2
  • \$\begingroup\$ I believe that simply adding an ascii output to reproduce to the question should fix the original close reason? \$\endgroup\$ Commented Mar 24 at 9:33
  • \$\begingroup\$ Update: I am unable to do this due to breaking the character limit, will probably just host an output on github \$\endgroup\$ Commented Mar 24 at 9:40
0
\$\begingroup\$

Input: a crafting recipe, each ingredients containing its crafting recipe or "not obtainable from crafting table". No item is shown.

Output: an ID. Same item has same ID and different item has different ID. You can assume such an item exist.

Example Input:

OOO OOO OOO
OOO OOO OOO
OOO OOO OOO

OOO     OOO
OOO  X  OOO
OOO     OOO

OOO     ...
OOO  X  ..O
OOO     ...

Example Output:

Your ID representing iron leggings or golden leggings.


Scoring

  • Shortest code wins. Is only a choice if this doesn't make question trivial. (Likely chosen, x=>x+'' is invalid e.g. there're 128 leggings recipe but only 4 types)
  • Minimize len(code)+introduced item count.

To decide

  • Shapeless crafting handle (maybe would force on left-top)
\$\endgroup\$
7
  • \$\begingroup\$ I'm a bit confused: what is there to signify which materials are being used? Functionally, by this input, iron nuggets and oak planks would have the same crafting recipe (unless I'm misunderstanding something) \$\endgroup\$ Commented Mar 28 at 20:42
  • \$\begingroup\$ @MijiGamin1 Yes they look same, so this input can also result golden leggings. An answer can make use of this returning two values for similar recipe, claiming one is iron and one is gold \$\endgroup\$ Commented Mar 28 at 21:19
  • \$\begingroup\$ this just feels like the code would consist of importing every single crafting recipe into a program, that doesn't seem very fun \$\endgroup\$ Commented Mar 28 at 21:34
  • \$\begingroup\$ @MijiGamin1 For e.g. items with unique recipe, such a recipe can just return an unique ID, it doesn't need to know what it is. That's why I don't require the ID meaning anything \$\endgroup\$ Commented Mar 28 at 21:54
  • 2
    \$\begingroup\$ i just feel like this problem needs to be more properly defined, i'm quite confused \$\endgroup\$ Commented Mar 29 at 1:04
  • \$\begingroup\$ @MijiGamin1 Idea from xiaoce.fun/mcitem though it's interactive and require the chosen item(besides some equivalents on color) while I just allow anything that works \$\endgroup\$ Commented Mar 29 at 1:40
  • \$\begingroup\$ i just feel like too much of the code would go towards hardcoding in the individual crafting recipes, so much so that golfing wouldn't really affect much \$\endgroup\$ Commented Mar 29 at 4:26
0
\$\begingroup\$

My vinyls have all caught colds!

\$\endgroup\$
11
  • 3
    \$\begingroup\$ Suggestion: simply the output to just say whether the title is truly "ill" (i.e. positive or negative). Also add tag decision-problem \$\endgroup\$ Commented Mar 26 at 18:20
  • 2
    \$\begingroup\$ Suggested examples: "Chill", "Villa" are false positives. "Illegitimate" is truly sick. \$\endgroup\$ Commented Mar 26 at 18:28
  • \$\begingroup\$ @Explorer09 i feel that the existing output requirements add more of a challenge to the problem \$\endgroup\$ Commented Mar 26 at 19:40
  • \$\begingroup\$ Challenges about parsing specific form of outputs are not interesting challenges. See this \$\endgroup\$ Commented Mar 26 at 23:20
  • \$\begingroup\$ @Explorer09 the array type of output isn't required, all that is required is the sick albums be outputted \$\endgroup\$ Commented Mar 27 at 0:23
  • 1
    \$\begingroup\$ Yes, and so your challenge can work equally well by checking individual titles rather than a list of titles input all at once. \$\endgroup\$ Commented Mar 27 at 0:47
  • \$\begingroup\$ @Explorer09 I suppose you have a good point, the bulk of the challenge is the identification, rather than the output. I'll edit it now \$\endgroup\$ Commented Mar 27 at 12:57
  • \$\begingroup\$ No need to quarantine them when you have some cleaning fluid… \$\endgroup\$ Commented Mar 28 at 23:04
  • \$\begingroup\$ @TheEmptyStringPhotographer i mean yea i get that but i just needed a story behind the challenge \$\endgroup\$ Commented Mar 29 at 1:05
  • \$\begingroup\$ Does upper/lower case of letters matter here and if so, in what way? \$\endgroup\$ Commented Mar 29 at 22:36
  • \$\begingroup\$ @TheEmptyStringPhotographer no, this challenge is case-insensitive \$\endgroup\$ Commented Mar 29 at 23:05
0
\$\begingroup\$

How big are the stripes?

Challenge

An \$n\$-stripey integer is an integer whose binary representation is a subsequence of \$n\$ ones, then \$n\$ zeroes, repeating infinitely. For instance, 57,825 is 4-stripey because its binary representation is 1110000111100001; each “stripe” is 4 bits long.

Given a positive integer, return any \$n\$ for which it is \$n\$-stripey. At least one \$n\$ is guaranteed to exist.

Test Cases

 Input: 57825
Binary: 1110000111100001
Output: 4

 Input: 2
Binary: 10
Output: 1 (or any number greater than 1)

 Input: 9
Binary: 1001
Output: 2

 Input: 255
Binary: 11111111
Output: 8 (or any number greater than 8)

 Input: 7937
Binary: 1111100000001
Output: 7 

Scoring

\$\endgroup\$
1
  • \$\begingroup\$ 26 is not an \$n\$-stripey number for any \$n\$, so it is not a valid input. \$\endgroup\$ Commented Apr 5 at 12:43
0
\$\begingroup\$

ed(1) addresses

Given adresses for the ed(1) command, complement what are missing. That's it.

Input format

A line.

Test cases

Inputs

1,2
1;3
,
7,
,9
;
3;
;6
.,
3;7
2;
,.
,$
;$
;$
3,
2,
6,
2;
$;$
3,.
,4
;4
4;
1,
;
,
5;.

Outputs

1,2
1;3
1,$
7,$
1,9
.;$
3;3
.;6
.,$
3;7
2;2
1,.
1,$
.;$
.;$
3,$
2,$
6,$
2;2
$;$
3,.$
1,4
.;4
4;4
1,$
1;$
1,$
5;.

Meta

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

Writing the rounding and truncating functions for float point numbers

A float point number could be expressed like this:

FloatPointNumber = BaseFloatPoint x 2^ExponentFloatPoint

By "bits of the float point type," I mean the bits that BaseFloatPoint has in the float type under consideration. These bits are used to store the digits of the float number. Both BaseFloatPoint and ExponentFloatPoint should be binary numbers type in the end.

The question here requires that the float point type be 64 bits, that is BaseFloatPoint is 64 bits, and here when I say "float point number" or "float point type" or "float," I mean a 64-bit float point type, a 64-bit float, that has a 64-bit BaseFloatPoint.

Let's define a function that returns decimal digits must have a float point number w.

lenfld(w)= floor((63-floor(log(2,max(w,1))))/3.322)

which in APL would be written

lenfld←{⌊(63-⌊2⍟⍵⌈1)÷3.322}

Or better, considering the external ⎕fpc, or external precision:

lenfld←{⌊3.322÷⍨⎕fpc-1+⌊2⍟1⌈⍵}

The question requires writing two functions:

  1. One called "truncdgt," with inputs of a non-negative integer dg (for the number of digits) and a float w, and output of a float res. The output of this function is such that if it is constructed in a string with the float w truncated at the digit dg—let's call it Str—then the conversion of that string to a float always satisfies this formula:

    abs(res-(conversion to float)(Str))< 10^-lenfld(w)

  2. One called "roundgt," with inputs a nonnegative integer dg (for the digit number) and a float w, and output a float res. The output of this function is such that if it is constructed in a string with the float w rounded to the digit dg, let's call it Str, then the conversion of that string to a float always satisfies this formula:

    abs(res-(conversion to float)(Str))< 10^-lenfld(w)

The function (conversion to float)(String_trunc dg w) it seems be ok as the function truncdgt, the same for roundgt. But should be many functions of them.

If the digit number for the float number to be truncated or rounded is outside the 64 bits that can be reached for that number, both functions must return NaN or it is not a number, or something that is clearly not a float number.

Here on my PC, in the APL language, there is an implementation of these two functions, the float point numbers, it is possible, them have a "v" suffix; that's how they are written in the exercises.

This question has the codegolf tag, so answers that solve all the exercises will be ranked by the number of bytes of code in the answer, and the answer with the fewest bytes of code implementing the two functions "truncdgt" and "roundgt" will win.

The exercises are as follows:

  1. First line is the input, then the name of the function that prints the result and other info; "tds" mean it call truncdgt, "rds" mean it call roundgt. Then the input digit dg, input float w
  2. Next line: the float that returns as the result "res" the function "truncdgt" or "roundgt" (I think converted by the system to digits), the truncated or rounded string of the number w from digit dg, which we will call "Str", delta=abs(res-(conversion to float)(Str))
  3. Next line: lenfld(w), and delta<10^-lenfdl(w), 1 means true, 0 means false.

Exercises:

  tds 1 1234567890123456785v
∅
  rds 1 1234567890123456785v
∅
  tds 0 123456789012345678.5v
res= 123456789012345678.00v Str= 123456789012345678.v d=∣res-⍎Str= 0v
Lenfld= 2v  (d<1e¯ 2v )= 1
  rds 0 123456789012345678.5v
res= 123456789012345679.00v Str= 123456789012345679.v d=∣res-⍎Str= 0v
Lenfld= 2v  (d<1e¯ 2v )= 1
  tds 0 123456789012345678.5v
res= 123456789012345678.00v Str= 123456789012345678.v d=∣res-⍎Str= 0v
Lenfld= 2v  (d<1e¯ 2v )= 1
  rds 0 123456789012345678.5v
res= 123456789012345679.00v Str= 123456789012345679.v d=∣res-⍎Str= 0v
Lenfld= 2v  (d<1e�� 2v )= 1
  rds 4 0.7390851332v
res= 0.739100000000000000v Str= 0.7391v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1
  tds 4 0.7390851332v
res= 0.739000000000000000v Str= 0.7390v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1
  rds 2 2.8078v
res= 2.810000000000000000v Str= 2.81v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1
  tds 2 2.8078v
res= 2.800000000000000000v Str= 2.80v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1
  rds 6 2.8078v
res= 2.807800000000000000v Str= 2.807800v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1
  tds 6 2.8078v
res= 2.807800000000000000v Str= 2.807800v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1
  tds 2  4.349999999999999999v
res= 4.340000000000000000v Str= 4.34v d=∣res-⍎Str= 4.33680869E¯19v
Lenfld= 18v  (d<1e¯ 18v )= 1
  rds 2  4.349999999999999999v
res= 4.350000000000000000v Str= 4.35v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1
  tds 2 ¯4.349999999999999999v
res= ¯4.340000000000000000v Str= ¯4.34v d=∣res-⍎Str= 4.33680869E¯19v
Lenfld= 18v  (d<1e¯ 18v )= 1
  rds 2 ¯4.349999999999999999v
res= ¯4.350000000000000000v Str= ¯4.35v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1
  tds 19  4.349999999999999999v
∅
  tds 18  4.349999999999999999v
res= 4.349999999999999999v Str= 4.349999999999999999v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1
  tds 17  4.349999999999999999v
res= 4.349999999999999990v Str= 4.34999999999999999v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1
  tds 16  4.349999999999999999v
res= 4.349999999999999900v Str= 4.3499999999999999v d=∣res-⍎Str= 4.33680869E¯19v
Lenfld= 18v  (d<1e¯ 18v )= 1
  rds 19  4.349999999999999999v
∅
  rds 18  4.349999999999999999v
res= 4.349999999999999999v Str= 4.349999999999999999v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1
  rds 17  4.349999999999999999v
res= 4.350000000000000000v Str= 4.35000000000000000v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1
  rds 16  4.349999999999999999v
res= 4.350000000000000000v Str= 4.3500000000000000v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1

These two results below have undefined behavior because the input float has more digits than the float can store in its space, so they should be rejected.

  tds 2  4.3499999999999999999v
res= 4.350000000000000000v Str= 4.35v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1
  rds 2  4.3499999999999999999v
res= 4.350000000000000000v Str= 4.35v d=∣res-⍎Str= 0v
Lenfld= 18v  (d<1e¯ 18v )= 1

For these last two results, there is an undefined behavior because all the digits of 4.3499999999999999999v are 20, while the float type can only render significant numbers with a total number of digits less than or equal to 19.

4.3499999999999999999v
4.3499999999999999999v
1 2345678901234567890
 is 20 digits 

when better result to me that number can hold only lenfld(4.349999999999999999v)=18 decimal digits.

Here for that number I have:

30⍕4.349999999999999999v
4.3499999999999999991v
1 2345678901234567890 is 20 digits. 

This prints digits that can't be printed because they don't exist. So I think that number has enough bits in memory to be >= 4.35.

Translate to English by Google and some my changes.

\$\endgroup\$
10
  • \$\begingroup\$ (1.) Should the floating point be stored internally in binary or in decimal? This affects rounding precision in the output. (2.) If the digit position of the round or trunc function exceeds the precision supported by the floating point type, then the number should return as is. NaN is not designed for this purpose. \$\endgroup\$ Commented Apr 6 at 1:11
  • \$\begingroup\$ @Explorer09 all in binary, base and exponent \$\endgroup\$ Commented Apr 7 at 2:22
  • \$\begingroup\$ For me for 2, it can not return one float if error condition is found. NaN will be perfect because it is a float different of other float. This can not be ok if sys rise one exception \$\endgroup\$ Commented Apr 7 at 10:28
  • \$\begingroup\$ For (2.) it's not an error for overprecision. It's as if you have the input truncdgt 10 123.0 and it returns the same floating point value because there are no fraction digits to round. If you want to warn the client (or user or whoever) about too much precision, I suggest make it an Undefined Behavior for the purpose of this challenge. In short, either allow it and return the same value, or make it UB. \$\endgroup\$ Commented Apr 7 at 11:48
  • \$\begingroup\$ @Explorer09 trunc 10 123.0 is ok , what is not ok is trunc 17 123.0 ; 17+3=20 this suppose a 20 digit number, but a float can have only 19 digits, so there is one error \$\endgroup\$ Commented Apr 7 at 14:19
  • \$\begingroup\$ I asked Google, it seems they call it float 80, that has 64 bits for store digits that result to them as 18 19 decimal digits... google.com/… \$\endgroup\$ Commented Apr 7 at 14:40
  • \$\begingroup\$ With multiprecision float library (such as GNU MPFR), the 19-digit limit can be bypassed, and the explicit guard would make no sense. In short you shouldn't care about the limit. \$\endgroup\$ Commented Apr 7 at 17:15
  • \$\begingroup\$ By the way, you didn't seem to realize there is a standard called IEEE 754 that most floating point hardware comply to. Better learn it. IEEE 754 float64 has 11 bits of exponents and 53 bits of significand precision. \$\endgroup\$ Commented Apr 7 at 17:21
  • \$\begingroup\$ @Explorer09 I mean only float that have 64 bits for store the digits as float 80 ieee754 \$\endgroup\$ Commented Apr 8 at 8:25
  • \$\begingroup\$ There is no float80 format in ieee754. You might be referring to x86 extended-precision format instead. \$\endgroup\$ Commented Apr 8 at 9:41
0
\$\begingroup\$

Word problem for \$A_\infty\$

Objective

Given an element in the infinitieth alternating group \$A_\infty\$, decide whether it's equal to the identity element.

The group \$A_\infty\$

For consider the collection of bijections between \$\mathbb N\$ (including zero) and \$\mathbb N\$, endowed with function composition as a binary operator. This results in a group, and this group is denoted \$S_\omega\$. Its identity element is the identity function over \$\mathbb N\$.

The infinitieth symmetric group, denoted by \$S_\infty\$, is a subgroup of \$S_\omega\$ consisting of bijections that fixes all elements of \$\mathbb N\$ except some finitely many elements. The infinitieth alternating group \$A_\infty\$ is a subgroup of \$S_\infty\$ consisting of bijections represent-able by composition of an even number of transpositions (that is, a bijection that sends one element to another element and vice versa).

I/O format

It is known that \$A_\infty\$ is generated by elements in the form of \$(n \enspace n+1 \enspace n+2)\$ (that is, the bijection that sends \$n\$ to \$n+1\$, \$n+1\$ to \$n+2\$, and \$n+2\$ to \$n\$) for some \$n \in \mathbb N\$. As such, the input shall be given as a list of the \$n\$s involved, interpreted as the composition of the bijections they represent, from the right to the left.

The output format is flexible. Standard loopholes apply.

Examples

Truthy

[]
[0,0,0]
[1,1,1]
[0,0,0,3,3,3]
[3,3,3,2,2,2]
[0,1,0,1]
[0,0,2,2,2,0]
[2,0,2,0,4,4,4]

Falsy

[0]
[1]
[0,0]
[0,1]
[0,2]
[2,1,0]
[0,0,1,1]
\$\endgroup\$
1
  • \$\begingroup\$ This seems to be written in a needlessly intimidating and verbose way that asks for more math knowledge than is needed. I'd replace the whole text with something like the following and add a worked example. "Imagine the numbers 0, 1, 2, ... are written in order. You're given a list of instructions, where 'i' means to rotate the three numbers in positions i, i+1, and i+2. After following the instructions, are all numbers back to where they started?" \$\endgroup\$ Commented Mar 31 at 4:41
0
\$\begingroup\$

Big Numbers with =+× and def


Write a program in this atomic language, with the symbols =, ==, +, ×, def (define a function), return, variables with any name, parentheses, curly brackets, if, and min() Scoring is heavily punished using \$\frac{\text{num}}{\text{biggest operator defined in code}(\text{bytes}, 2)}\$, so be careful! The biggest number in your program is the result!
The variable x0 is automatically set to 1.
Example program (10^10):

t=x0+x0+x0+x0+x0+x0+x0+x0+x0+x0
y=t*t
t=y*y
k=y*t*t
\$\endgroup\$
8
  • \$\begingroup\$ Should we optimize for maximum or minimum score? \$\endgroup\$ Commented Apr 8 at 18:55
  • \$\begingroup\$ So would this work as a functional 10^10? \$\endgroup\$ Commented Apr 8 at 19:40
  • \$\begingroup\$ @Rhaixer Maximum score. \$\endgroup\$ Commented Apr 8 at 23:19
  • \$\begingroup\$ @MijiGamin1 I calculated by hand and it's 100,000,000 or 10⁸ if not retroactive, or if retroactive 10²⁰. It's not retroactive though. \$\endgroup\$ Commented Apr 8 at 23:22
  • \$\begingroup\$ What do you mean by "retroactive"? And my apologies, this is the one I meant to send \$\endgroup\$ Commented Apr 9 at 14:52
  • \$\begingroup\$ @MijiGamin like, retroactive is definitions change with what they are defined with. Like a retroactive prog x=(((x0+x0)*(x0+x0))+x0)*(x0) y=xx, x=yy, y would update... also yup! 10⁴*10⁴*10²=10¹⁰!. Also my retroactive estimate is wrong, the program would be infinity because it causes an infinite loop. But no retroactivity here! \$\endgroup\$ Commented Apr 9 at 20:12
  • \$\begingroup\$ What is the syntax? Is it like Python? \$\endgroup\$ Commented Apr 27 at 21:20
  • \$\begingroup\$ This can easily be cheesed by returning 1 if the second argument is 2, and some big number otherwise \$\endgroup\$ Commented Apr 27 at 21:22
0
\$\begingroup\$

Select and Delete Fields: Unicage Edition

\$\endgroup\$
1
150 151
152
153 154
168

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.