Valid Badminton Score?Relevant Part for a Badminton ServeConfused badminton players¿xu ti te gismytermorna? (Is it a valid gismu?)Life is a Maze: We take the wrong Path before we learnt to walkIt's a Bit of a Stretch․․․Best Yahtzee scoreLongest Repeating Subsequence of a Single DigitTernary-if ConverterMatrix Jigsaw PuzzlesThe Highest DiceCould you please stop shuffling the deck and play already?The Digit Triangles
Mistake in years of experience in resume?
'It addicted me, with one taste.' Can 'addict' be used transitively?
Retract an already submitted recommendation letter (written for an undergrad student)
Covering null sets by a finite number of intervals
Extension of 2-adic valuation to the real numbers
How can I get rid of an unhelpful parallel branch when unpivoting a single row?
Elements that can bond to themselves?
Can someone publish a story that happened to you?
Why did C use the -> operator instead of reusing the . operator?
On The Origin of Dissonant Chords
Can I criticise the more senior developers around me for not writing clean code?
How did Captain America use this in Avengers: Endgame?
How much cash can I safely carry into the USA and avoid civil forfeiture?
Relationship between AC, WO and Zorns Lemma in ZF-Powerset
Cyclomatic Complexity reduction JS
Does a large simulator bay have standard public address announcements?
Can't get 5V 3A DC constant
What is the term for a person whose job is to place products on shelves in stores?
Pre-plastic human skin alternative
Check if a string is entirely made of the same substring
Is there a grandfather paradox in Endgame?
Could moose/elk survive in the Amazon forest?
How can I practically buy stocks?
How does Captain America channel this power?
Valid Badminton Score?
Relevant Part for a Badminton ServeConfused badminton players¿xu ti te gismytermorna? (Is it a valid gismu?)Life is a Maze: We take the wrong Path before we learnt to walkIt's a Bit of a Stretch․․․Best Yahtzee scoreLongest Repeating Subsequence of a Single DigitTernary-if ConverterMatrix Jigsaw PuzzlesThe Highest DiceCould you please stop shuffling the deck and play already?The Digit Triangles
$begingroup$
Introduction:
I saw there was only one other badminton related challenge right now. Since I play badminton myself (for the past 13 years now), I figured I'd add some badminton-related challenges. Here the first one:
Challenge:
Input: Two integers
Output: One of three distinct and unique outputs of your own choice. One indicating that the input is a valid badminton score AND the set has ended with a winner; one indicating that the input is a valid badminton score AND the set is still in play; one indicating the input is not a valid badminton score.
With badminton, both (pairs of) players start with 0 points, and you stop when one of the two (pairs of) players has reached a score of 21, with at least 2 points difference, up to a maximum of 30-29.
So these are all possible input-pairs (in either order) indicating it's a valid badminton score AND the set has ended:
[[0,21],[1,21],[2,21],[3,21],[4,21],[5,21],[6,21],[7,21],[8,21],[9,21],[10,21],[11,21],[12,21],[13,21],[14,21],[15,21],[16,21],[17,21],[18,21],[19,21],[20,22],[21,23],[22,24],[23,25],[24,26],[25,27],[26,28],[27,29],[28,30],[29,30]]
And these are all possible input-pairs (in either order) indicating it's a valid badminton score BUT the set is still in play:
[[0,0],[0,1],[0,2],[0,3],[0,4],[0,5],[0,6],[0,7],[0,8],[0,9],[0,10],[0,11],[0,12],[0,13],[0,14],[0,15],[0,16],[0,17],[0,18],[0,19],[0,20],[1,1],[1,2],[1,3],[1,4],[1,5],[1,6],[1,7],[1,8],[1,9],[1,10],[1,11],[1,12],[1,13],[1,14],[1,15],[1,16],[1,17],[1,18],[1,19],[1,20],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[2,8],[2,9],[2,10],[2,11],[2,12],[2,13],[2,14],[2,15],[2,16],[2,17],[2,18],[2,19],[2,20],[3,3],[3,4],[3,5],[3,6],[3,7],[3,8],[3,9],[3,10],[3,11],[3,12],[3,13],[3,14],[3,15],[3,16],[3,17],[3,18],[3,19],[3,20],[4,4],[4,5],[4,6],[4,7],[4,8],[4,9],[4,10],[4,11],[4,12],[4,13],[4,14],[4,15],[4,16],[4,17],[4,18],[4,19],[4,20],[5,5],[5,6],[5,7],[5,8],[5,9],[5,10],[5,11],[5,12],[5,13],[5,14],[5,15],[5,16],[5,17],[5,18],[5,19],[5,20],[6,6],[6,7],[6,8],[6,9],[6,10],[6,11],[6,12],[6,13],[6,14],[6,15],[6,16],[6,17],[6,18],[6,19],[6,20],[7,7],[7,8],[7,9],[7,10],[7,11],[7,12],[7,13],[7,14],[7,15],[7,16],[7,17],[7,18],[7,19],[7,20],[8,8],[8,9],[8,10],[8,11],[8,12],[8,13],[8,14],[8,15],[8,16],[8,17],[8,18],[8,19],[8,20],[9,9],[9,10],[9,11],[9,12],[9,13],[9,14],[9,15],[9,16],[9,17],[9,18],[9,19],[9,20],[10,10],[10,11],[10,12],[10,13],[10,14],[10,15],[10,16],[10,17],[10,18],[10,19],[10,20],[11,11],[11,12],[11,13],[11,14],[11,15],[11,16],[11,17],[11,18],[11,19],[11,20],[12,12],[12,13],[12,14],[12,15],[12,16],[12,17],[12,18],[12,19],[12,20],[13,13],[13,14],[13,15],[13,16],[13,17],[13,18],[13,19],[13,20],[14,14],[14,15],[14,16],[14,17],[14,18],[14,19],[14,20],[15,15],[15,16],[15,17],[15,18],[15,19],[15,20],[16,16],[16,17],[16,18],[16,19],[16,20],[17,17],[17,18],[17,19],[17,20],[18,18],[18,19],[18,20],[19,19],[19,20],[20,20],[20,21],[21,21],[21,22],[22,22],[22,23],[23,23],[23,24],[24,24],[24,25],[25,25],[25,26],[26,26],[26,27],[27,27],[27,28],[28,28],[28,29],[29,29]]
Any other pair of integer would be an invalid badminton score.
Challenge rules:
- I/O is flexible, so:
- You can take the input as a list of two numbers; two separated numbers through STDIN or function parameters; two strings; etc.
- Output will be three distinct and unique values of your own choice. Can be integers (i.e.
[0,1,2]
,[1,2,3]
,[-1,0,1]
, etc.); can be Booleans (i.e.[true,false,undefined/null/empty]
); can be characters/strings (i.e.["valid & ended","valid","invalid"]
); etc. - Please specify the I/O you've used in your answer!
- You are allowed to take the input-integers pre-ordered from lowest to highest or vice-versa.
- The input integers can be negative, in which case they are of course invalid.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
These test cases are valid, and the set has ended:
0 21
12 21
21 23
28 30
29 30
These test cases are valid, but the set is still in play:
0 0
0 20
12 12
21 21
21 22
These test cases are invalid:
-21 19
-19 21
-1 1
12 22
29 31
30 30
42 43
1021 1021
code-golf number integer
$endgroup$
add a comment |
$begingroup$
Introduction:
I saw there was only one other badminton related challenge right now. Since I play badminton myself (for the past 13 years now), I figured I'd add some badminton-related challenges. Here the first one:
Challenge:
Input: Two integers
Output: One of three distinct and unique outputs of your own choice. One indicating that the input is a valid badminton score AND the set has ended with a winner; one indicating that the input is a valid badminton score AND the set is still in play; one indicating the input is not a valid badminton score.
With badminton, both (pairs of) players start with 0 points, and you stop when one of the two (pairs of) players has reached a score of 21, with at least 2 points difference, up to a maximum of 30-29.
So these are all possible input-pairs (in either order) indicating it's a valid badminton score AND the set has ended:
[[0,21],[1,21],[2,21],[3,21],[4,21],[5,21],[6,21],[7,21],[8,21],[9,21],[10,21],[11,21],[12,21],[13,21],[14,21],[15,21],[16,21],[17,21],[18,21],[19,21],[20,22],[21,23],[22,24],[23,25],[24,26],[25,27],[26,28],[27,29],[28,30],[29,30]]
And these are all possible input-pairs (in either order) indicating it's a valid badminton score BUT the set is still in play:
[[0,0],[0,1],[0,2],[0,3],[0,4],[0,5],[0,6],[0,7],[0,8],[0,9],[0,10],[0,11],[0,12],[0,13],[0,14],[0,15],[0,16],[0,17],[0,18],[0,19],[0,20],[1,1],[1,2],[1,3],[1,4],[1,5],[1,6],[1,7],[1,8],[1,9],[1,10],[1,11],[1,12],[1,13],[1,14],[1,15],[1,16],[1,17],[1,18],[1,19],[1,20],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[2,8],[2,9],[2,10],[2,11],[2,12],[2,13],[2,14],[2,15],[2,16],[2,17],[2,18],[2,19],[2,20],[3,3],[3,4],[3,5],[3,6],[3,7],[3,8],[3,9],[3,10],[3,11],[3,12],[3,13],[3,14],[3,15],[3,16],[3,17],[3,18],[3,19],[3,20],[4,4],[4,5],[4,6],[4,7],[4,8],[4,9],[4,10],[4,11],[4,12],[4,13],[4,14],[4,15],[4,16],[4,17],[4,18],[4,19],[4,20],[5,5],[5,6],[5,7],[5,8],[5,9],[5,10],[5,11],[5,12],[5,13],[5,14],[5,15],[5,16],[5,17],[5,18],[5,19],[5,20],[6,6],[6,7],[6,8],[6,9],[6,10],[6,11],[6,12],[6,13],[6,14],[6,15],[6,16],[6,17],[6,18],[6,19],[6,20],[7,7],[7,8],[7,9],[7,10],[7,11],[7,12],[7,13],[7,14],[7,15],[7,16],[7,17],[7,18],[7,19],[7,20],[8,8],[8,9],[8,10],[8,11],[8,12],[8,13],[8,14],[8,15],[8,16],[8,17],[8,18],[8,19],[8,20],[9,9],[9,10],[9,11],[9,12],[9,13],[9,14],[9,15],[9,16],[9,17],[9,18],[9,19],[9,20],[10,10],[10,11],[10,12],[10,13],[10,14],[10,15],[10,16],[10,17],[10,18],[10,19],[10,20],[11,11],[11,12],[11,13],[11,14],[11,15],[11,16],[11,17],[11,18],[11,19],[11,20],[12,12],[12,13],[12,14],[12,15],[12,16],[12,17],[12,18],[12,19],[12,20],[13,13],[13,14],[13,15],[13,16],[13,17],[13,18],[13,19],[13,20],[14,14],[14,15],[14,16],[14,17],[14,18],[14,19],[14,20],[15,15],[15,16],[15,17],[15,18],[15,19],[15,20],[16,16],[16,17],[16,18],[16,19],[16,20],[17,17],[17,18],[17,19],[17,20],[18,18],[18,19],[18,20],[19,19],[19,20],[20,20],[20,21],[21,21],[21,22],[22,22],[22,23],[23,23],[23,24],[24,24],[24,25],[25,25],[25,26],[26,26],[26,27],[27,27],[27,28],[28,28],[28,29],[29,29]]
Any other pair of integer would be an invalid badminton score.
Challenge rules:
- I/O is flexible, so:
- You can take the input as a list of two numbers; two separated numbers through STDIN or function parameters; two strings; etc.
- Output will be three distinct and unique values of your own choice. Can be integers (i.e.
[0,1,2]
,[1,2,3]
,[-1,0,1]
, etc.); can be Booleans (i.e.[true,false,undefined/null/empty]
); can be characters/strings (i.e.["valid & ended","valid","invalid"]
); etc. - Please specify the I/O you've used in your answer!
- You are allowed to take the input-integers pre-ordered from lowest to highest or vice-versa.
- The input integers can be negative, in which case they are of course invalid.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
These test cases are valid, and the set has ended:
0 21
12 21
21 23
28 30
29 30
These test cases are valid, but the set is still in play:
0 0
0 20
12 12
21 21
21 22
These test cases are invalid:
-21 19
-19 21
-1 1
12 22
29 31
30 30
42 43
1021 1021
code-golf number integer
$endgroup$
add a comment |
$begingroup$
Introduction:
I saw there was only one other badminton related challenge right now. Since I play badminton myself (for the past 13 years now), I figured I'd add some badminton-related challenges. Here the first one:
Challenge:
Input: Two integers
Output: One of three distinct and unique outputs of your own choice. One indicating that the input is a valid badminton score AND the set has ended with a winner; one indicating that the input is a valid badminton score AND the set is still in play; one indicating the input is not a valid badminton score.
With badminton, both (pairs of) players start with 0 points, and you stop when one of the two (pairs of) players has reached a score of 21, with at least 2 points difference, up to a maximum of 30-29.
So these are all possible input-pairs (in either order) indicating it's a valid badminton score AND the set has ended:
[[0,21],[1,21],[2,21],[3,21],[4,21],[5,21],[6,21],[7,21],[8,21],[9,21],[10,21],[11,21],[12,21],[13,21],[14,21],[15,21],[16,21],[17,21],[18,21],[19,21],[20,22],[21,23],[22,24],[23,25],[24,26],[25,27],[26,28],[27,29],[28,30],[29,30]]
And these are all possible input-pairs (in either order) indicating it's a valid badminton score BUT the set is still in play:
[[0,0],[0,1],[0,2],[0,3],[0,4],[0,5],[0,6],[0,7],[0,8],[0,9],[0,10],[0,11],[0,12],[0,13],[0,14],[0,15],[0,16],[0,17],[0,18],[0,19],[0,20],[1,1],[1,2],[1,3],[1,4],[1,5],[1,6],[1,7],[1,8],[1,9],[1,10],[1,11],[1,12],[1,13],[1,14],[1,15],[1,16],[1,17],[1,18],[1,19],[1,20],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[2,8],[2,9],[2,10],[2,11],[2,12],[2,13],[2,14],[2,15],[2,16],[2,17],[2,18],[2,19],[2,20],[3,3],[3,4],[3,5],[3,6],[3,7],[3,8],[3,9],[3,10],[3,11],[3,12],[3,13],[3,14],[3,15],[3,16],[3,17],[3,18],[3,19],[3,20],[4,4],[4,5],[4,6],[4,7],[4,8],[4,9],[4,10],[4,11],[4,12],[4,13],[4,14],[4,15],[4,16],[4,17],[4,18],[4,19],[4,20],[5,5],[5,6],[5,7],[5,8],[5,9],[5,10],[5,11],[5,12],[5,13],[5,14],[5,15],[5,16],[5,17],[5,18],[5,19],[5,20],[6,6],[6,7],[6,8],[6,9],[6,10],[6,11],[6,12],[6,13],[6,14],[6,15],[6,16],[6,17],[6,18],[6,19],[6,20],[7,7],[7,8],[7,9],[7,10],[7,11],[7,12],[7,13],[7,14],[7,15],[7,16],[7,17],[7,18],[7,19],[7,20],[8,8],[8,9],[8,10],[8,11],[8,12],[8,13],[8,14],[8,15],[8,16],[8,17],[8,18],[8,19],[8,20],[9,9],[9,10],[9,11],[9,12],[9,13],[9,14],[9,15],[9,16],[9,17],[9,18],[9,19],[9,20],[10,10],[10,11],[10,12],[10,13],[10,14],[10,15],[10,16],[10,17],[10,18],[10,19],[10,20],[11,11],[11,12],[11,13],[11,14],[11,15],[11,16],[11,17],[11,18],[11,19],[11,20],[12,12],[12,13],[12,14],[12,15],[12,16],[12,17],[12,18],[12,19],[12,20],[13,13],[13,14],[13,15],[13,16],[13,17],[13,18],[13,19],[13,20],[14,14],[14,15],[14,16],[14,17],[14,18],[14,19],[14,20],[15,15],[15,16],[15,17],[15,18],[15,19],[15,20],[16,16],[16,17],[16,18],[16,19],[16,20],[17,17],[17,18],[17,19],[17,20],[18,18],[18,19],[18,20],[19,19],[19,20],[20,20],[20,21],[21,21],[21,22],[22,22],[22,23],[23,23],[23,24],[24,24],[24,25],[25,25],[25,26],[26,26],[26,27],[27,27],[27,28],[28,28],[28,29],[29,29]]
Any other pair of integer would be an invalid badminton score.
Challenge rules:
- I/O is flexible, so:
- You can take the input as a list of two numbers; two separated numbers through STDIN or function parameters; two strings; etc.
- Output will be three distinct and unique values of your own choice. Can be integers (i.e.
[0,1,2]
,[1,2,3]
,[-1,0,1]
, etc.); can be Booleans (i.e.[true,false,undefined/null/empty]
); can be characters/strings (i.e.["valid & ended","valid","invalid"]
); etc. - Please specify the I/O you've used in your answer!
- You are allowed to take the input-integers pre-ordered from lowest to highest or vice-versa.
- The input integers can be negative, in which case they are of course invalid.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
These test cases are valid, and the set has ended:
0 21
12 21
21 23
28 30
29 30
These test cases are valid, but the set is still in play:
0 0
0 20
12 12
21 21
21 22
These test cases are invalid:
-21 19
-19 21
-1 1
12 22
29 31
30 30
42 43
1021 1021
code-golf number integer
$endgroup$
Introduction:
I saw there was only one other badminton related challenge right now. Since I play badminton myself (for the past 13 years now), I figured I'd add some badminton-related challenges. Here the first one:
Challenge:
Input: Two integers
Output: One of three distinct and unique outputs of your own choice. One indicating that the input is a valid badminton score AND the set has ended with a winner; one indicating that the input is a valid badminton score AND the set is still in play; one indicating the input is not a valid badminton score.
With badminton, both (pairs of) players start with 0 points, and you stop when one of the two (pairs of) players has reached a score of 21, with at least 2 points difference, up to a maximum of 30-29.
So these are all possible input-pairs (in either order) indicating it's a valid badminton score AND the set has ended:
[[0,21],[1,21],[2,21],[3,21],[4,21],[5,21],[6,21],[7,21],[8,21],[9,21],[10,21],[11,21],[12,21],[13,21],[14,21],[15,21],[16,21],[17,21],[18,21],[19,21],[20,22],[21,23],[22,24],[23,25],[24,26],[25,27],[26,28],[27,29],[28,30],[29,30]]
And these are all possible input-pairs (in either order) indicating it's a valid badminton score BUT the set is still in play:
[[0,0],[0,1],[0,2],[0,3],[0,4],[0,5],[0,6],[0,7],[0,8],[0,9],[0,10],[0,11],[0,12],[0,13],[0,14],[0,15],[0,16],[0,17],[0,18],[0,19],[0,20],[1,1],[1,2],[1,3],[1,4],[1,5],[1,6],[1,7],[1,8],[1,9],[1,10],[1,11],[1,12],[1,13],[1,14],[1,15],[1,16],[1,17],[1,18],[1,19],[1,20],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[2,8],[2,9],[2,10],[2,11],[2,12],[2,13],[2,14],[2,15],[2,16],[2,17],[2,18],[2,19],[2,20],[3,3],[3,4],[3,5],[3,6],[3,7],[3,8],[3,9],[3,10],[3,11],[3,12],[3,13],[3,14],[3,15],[3,16],[3,17],[3,18],[3,19],[3,20],[4,4],[4,5],[4,6],[4,7],[4,8],[4,9],[4,10],[4,11],[4,12],[4,13],[4,14],[4,15],[4,16],[4,17],[4,18],[4,19],[4,20],[5,5],[5,6],[5,7],[5,8],[5,9],[5,10],[5,11],[5,12],[5,13],[5,14],[5,15],[5,16],[5,17],[5,18],[5,19],[5,20],[6,6],[6,7],[6,8],[6,9],[6,10],[6,11],[6,12],[6,13],[6,14],[6,15],[6,16],[6,17],[6,18],[6,19],[6,20],[7,7],[7,8],[7,9],[7,10],[7,11],[7,12],[7,13],[7,14],[7,15],[7,16],[7,17],[7,18],[7,19],[7,20],[8,8],[8,9],[8,10],[8,11],[8,12],[8,13],[8,14],[8,15],[8,16],[8,17],[8,18],[8,19],[8,20],[9,9],[9,10],[9,11],[9,12],[9,13],[9,14],[9,15],[9,16],[9,17],[9,18],[9,19],[9,20],[10,10],[10,11],[10,12],[10,13],[10,14],[10,15],[10,16],[10,17],[10,18],[10,19],[10,20],[11,11],[11,12],[11,13],[11,14],[11,15],[11,16],[11,17],[11,18],[11,19],[11,20],[12,12],[12,13],[12,14],[12,15],[12,16],[12,17],[12,18],[12,19],[12,20],[13,13],[13,14],[13,15],[13,16],[13,17],[13,18],[13,19],[13,20],[14,14],[14,15],[14,16],[14,17],[14,18],[14,19],[14,20],[15,15],[15,16],[15,17],[15,18],[15,19],[15,20],[16,16],[16,17],[16,18],[16,19],[16,20],[17,17],[17,18],[17,19],[17,20],[18,18],[18,19],[18,20],[19,19],[19,20],[20,20],[20,21],[21,21],[21,22],[22,22],[22,23],[23,23],[23,24],[24,24],[24,25],[25,25],[25,26],[26,26],[26,27],[27,27],[27,28],[28,28],[28,29],[29,29]]
Any other pair of integer would be an invalid badminton score.
Challenge rules:
- I/O is flexible, so:
- You can take the input as a list of two numbers; two separated numbers through STDIN or function parameters; two strings; etc.
- Output will be three distinct and unique values of your own choice. Can be integers (i.e.
[0,1,2]
,[1,2,3]
,[-1,0,1]
, etc.); can be Booleans (i.e.[true,false,undefined/null/empty]
); can be characters/strings (i.e.["valid & ended","valid","invalid"]
); etc. - Please specify the I/O you've used in your answer!
- You are allowed to take the input-integers pre-ordered from lowest to highest or vice-versa.
- The input integers can be negative, in which case they are of course invalid.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
These test cases are valid, and the set has ended:
0 21
12 21
21 23
28 30
29 30
These test cases are valid, but the set is still in play:
0 0
0 20
12 12
21 21
21 22
These test cases are invalid:
-21 19
-19 21
-1 1
12 22
29 31
30 30
42 43
1021 1021
code-golf number integer
code-golf number integer
edited Mar 26 at 16:03
Kevin Cruijssen
asked Mar 26 at 14:59
Kevin CruijssenKevin Cruijssen
43.7k573222
43.7k573222
add a comment |
add a comment |
13 Answers
13
active
oldest
votes
$begingroup$
Stax, 20 bytes
ÇåπßéD╩¬7▼ß▌ΣU¬í╡S┤╘
Run and debug it
It takes input in the same format as the examples. 0
means there's a valid winner. 1
means the game is in progress. -1
means invalid score.
In pseudo-code, with ordered inputs x
and y
, the algorithm is
sign(clamp(x + 2, 21, 30) - y) | (x < 0 || x >= 30 ? 0 : -1)
sign
means numeric sign (-1
,0
, or1
)clamp
forces its first argument into the specified half-open interval
$endgroup$
add a comment |
$begingroup$
Python 2, 97 95 75 72 71 70 69 64 55 54 52 51 50 48 bytes
lambda a,b:(b-61<~a<a>b/22*b-3)*~(19<b-(b<30)>a)
Try it online!
Takes input as pre-ordered a,b
.
Returns -2
, -1
, 0
for ended
, in play
, invalid
.
-1 byte, thanks to Kevin Cruijssen
Left part (b-61<~a<a>b/22*b-3
) is a validity-check, and right part (19<b-(b<30)>a
) is a check for game ended.
$endgroup$
add a comment |
$begingroup$
Python 2, 47 bytes
lambda a,b:[61>60-a>b<3+max(19,a)for b in-~b,b]
Try it online!
Outputs a list of two Booleans. Thanks to TFeld for writing a test suite in their answer that made it easy to check my solution.
ended: [False, True]
going: [True, True]
invalid: [False, False]
The key insight is that a valid score ends the game exactly if increasing the higher value b
makes the score invalid. So, we just code up the validity condition, and check it for (a,b+1)
in addition to (a,b)
to see if the game has ended.
Validity is checked via three conditions that are chained together:
b<3+max(19,a)
: Checks that the higher scoreb
isn't past winning, with eitherb<=21
orb<=a+2
(win by two)60-a>b
: Equivalent toa+b<=59
, ensuring the score isn't above(29,30)
61>60-a
: Equivalent toa>=0
, ensures the lower score is non-negative
Python 2, 44 bytes
lambda a,b:[b-61<~a<a>b/22*b-3for b in-~b,b]
Try it online!
An improved validity check by TFeld saves 3 bytes. The main idea is to branch on "overtime" b>21
with b/22*b
which effectively sets below-21 scores to zero, whereas I'd branched on a>19
with the longer max(19,a)
.
Python 2, 43 bytes
lambda a,b:a>>99|cmp(2+max(19,a)%30-a/29,b)
Try it online!
Outputs:
ended: 0
going: -1
invalid: 1
Assumes that the inputs are not below $-2^99$.
$endgroup$
1
$begingroup$
Using my newest validity-check (b-61<~a<a>b/22*b-3
), you can save 3 bytes.
$endgroup$
– TFeld
Mar 27 at 11:17
1
$begingroup$
+1 byte to make your second solution work for all inputs:lambda a,b:-(a<0)|cmp(2+max(19,a)%30-a/29,b)
$endgroup$
– TFeld
Mar 27 at 12:51
add a comment |
$begingroup$
JavaScript (ES6), 55 53 48 bytes
Thanks to @KevinCruijssen for noticing that I was not fully assuming $ale b$ (saving 5 bytes)
Takes input as (a)(b)
with $ale b$. Returns $0$ (valid), $1$ (ended) or $2$ (invalid).
a=>b=>a<0|a>29|b>30|b>21&b-a>2?2:b>20&b-a>1|b>29
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 53 52 bytes
a=>b=>b<0|a-b>2&a>21|b>29|a>30?3:a>20&a-b>1|a>29?1:2
Called as f(max)(min)
. Returns 3 for invalid, 1 for finished, 2 for ongoing.
Saved 1 byte thanks to Kevin Cruijjsen
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 25 bytes
»19«28‘<‘×+2>ɗʋ⁹×,%Ƒ“œþ‘ɗ
Try it online!
Left argument: minimum. Right argument: maximum.
Invalid: 0
. Ongoing: 1
. Ended: 2
.
Mathematically, this works as below (the left argument is $x$, the right is $y$):
$$[a]=casesacolon1\lnot acolon0\otimes(a,b)=(abmod30,bbmod31)\x,yinmathbb Z\X:=min(max(x+1,20),29)\p:=(x,y)\([X<y]+1)[X+2>y][p=otimes p]$$
Explanation:
»19«28‘<‘×+2>ɗʋ⁹×,%Ƒ“œþ‘ɗ Left argument: x, Right argument: y
»19«28‘ X := Bound x + 1 in [20, 29]:
»19 X := max(x, 19).
«28 X := min(X, 28).
‘ X := X + 1.
<‘×+2>ɗʋ⁹ X := If X + 2 <= y, then 0, else if X < y, then 2, else 1:
< t := If X < y, then 1, else 0.
‘ t := t + 1.
+2>ɗ u := Check if X + 2 > y:
+2 u := X + 2.
> u := If u > y, then 1, else 0.
× X := t * u.
,%Ƒ“œþ‘ɗ z := If x mod 30 = x and y mod 31 = y, then 1, else 0:
, z := (x, y).
% “œþ‘ m := z mod (30, 31) = (x mod 30, y mod 31).
Ƒ z := If z = m, then 1, else 0.
× X * z.
$endgroup$
add a comment |
$begingroup$
VDM-SL, 80 bytes
f(i,j)==if(j-i>2and j>21)or(i<0or i=30or j>30)thenelse(j>20and j-i>1or j=30)
This function takes the scores ordered in ascending order and returns the empty set if the score is invalid or the set containing whether the set is complete (so true if the set is complete and valid and false if the set is incomplete and valid)
A full program to run might look like this:
functions
f:int*int+>set of bool
f(i,j)==if(j-i>2and j>21)or(i<0or i=30or j>30)thenelse(j>20and j-i>1or j=30)
Explanation:
if(j-i>2 and j>21) /*if scores are too far apart*/
or(i<0 or i=30 or j>30) /*or scores not in a valid range*/
then /*return the empty set*/
else /*else return the set containing...*/
(j>20 and j-i>1 or j=30) /*if the set is complete*/
$endgroup$
add a comment |
$begingroup$
Java (JDK), 59 48 bytes
a->b->b<0|b>29|a>b+2&a>21|a>30?0:a<21|a<30&a<b+2
Try it online!
Returns an Object
, which is the Integer
0
for invalid games and the Boolean
s true
and false
for valid ongoing games and for valid finished games respectively. Takes the score ordered (and curried), with the higher score first.
-2 bytes
by inverting the end-of-match check.-11 bytes
by currying, using bitwise operators, and some return type autoboxing trickery - thanks to @KevinCruijssen
Ungolfed
a-> // Curried: Target type IntFunction<IntFunction<Object>>
b-> // Target type IntFunction<Object>
// Invalid if:
b<0 // Any score is negative
| b > 29 // Both scores above 29
| a > b + 2 // Lead too big
& a > 21 // and leader has at least 21 points
| a > 30 // Anyone has 31 points
? 0 // If invalid, return 0 (autoboxed to Integer)
// If valid, return whether the game is ongoing (autoboxed to Boolean)
// Ongoing if:
: a < 21 // Nobody has 21 points
| a < 30 // Leader has fewer than 30 points
& a < b + 2 // and lead is small
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 35 bytesSBCS
Infix tacit function where ended is 2, ongoing is 1, invalid is 0, smaller and larger scores are left.
(,≡30 31|,)×(⊢<2+X)×1+⊢>X←29⌊20⌈1+⊣
Try it online!
Implements Erik the Outgolfer's mathematical formulas combined into
$$X:=min(max(x+1,20),29)\ ([X< y]+1)[X+2>y][(x,y)=(xbmod30,ybmod31)]$$
rearranged (as if traditional mathematical notation had vectorisation and inline assignments) to
$$[(x,y)=(x,y)bmod(30,31)]×[y<2+X]×(1+[y< (X:=min(29,max(20,1+x)))])$$
and translated directly to APL (which is strictly right-associative, so we avoid some parentheses):
$$((x,y)≡30 31|x,y)×(y<2+X)×1+y>X←29⌊20⌈1 +x$$
This can be converted into a tacit function simply by substituting $⊣$ for $x$ and $⊢$ for $y$, symbolising the left and right arguments rather than the two variables:
$$((⊣,⊢)≡30 31|⊣,⊢)×(⊣<2+X)×1+⊢>X←29⌊20⌈1+⊣$$
Now $⊣⎕⊢$ is equivalent to $⎕$ for any infix function $⎕$, so we can simplify to
$$(,≡30 31|,)×(⊣<2+X)×1+⊢>X←29⌊20⌈1+⊣$$
which is our solution; (,≡30 31|,)×(⊢<2+X)×1+⊢>X←29⌊20⌈1+⊣
:
⊣
the left argument; $x$1+
one plus that; $1+x$20⌈
maximum of 20 and that; $max(20,…)$29⌊
minimum of 29 and that; $min(29,…)$X←
assign that to X
; $X:=…$⊢>
is the right argument greater (0/1)?; $[y>…]$1+
add one; $1+…$(
…)×
multiply the following by that; $(…)×…$
2+X
two plus X
; $2+X$
⊢<
is the right argument less than that (0/1); $[y<…]$(
…)×
multiply the following by that; $(…)×…$
,
concatenate the arguments; $(x,y)$
30 31|
remainders when divided by these numbers; $…mod(30,31)$
,≡
are the concatenated arguments identical to that (0/1)?; $[(x,y)=…]$
$endgroup$
add a comment |
$begingroup$
x86 Assembly, 42 Bytes
Takes input in ECX
and EDX
registers. Note that ECX
must be greater than EDX
.
Outputs into EAX
, where 0
means the game's still on, 1
representing the game being over and -1
(aka FFFFFFFF
) representing an invalid score.
31 C0 83 F9 1E 77 1F 83 FA 1D 77 1A 83 F9 15 7C
18 83 F9 1E 74 12 89 CB 29 D3 83 FB 02 74 09 7C
08 83 F9 15 74 02 48 C3 40 C3
Or, more readable in Intel Syntax:
check:
XOR EAX, EAX
CMP ECX, 30 ; check i_1 against 30
JA .invalid ; if >, invalid.
CMP EDX, 29 ; check i_2 against 29
JA .invalid ; if >, invalid.
CMP ECX, 21 ; check i_1 against 21
JL .runi ; if <, running.
CMP ECX, 30 ; check i_1 against 30
JE .over ; if ==, over.
MOV EBX, ECX
SUB EBX, EDX ; EBX = i_1 - i_2
CMP EBX, 2 ; check EBX against 2
JE .over ; if ==, over.
JL .runi ; if <, running.
; if >, keep executing!
CMP ECX, 21 ; check i_1 against 21
JE .over ; if ==, over.
; otherwise, it's invalid.
; fallthrough!
.invalid:
DEC EAX ; EAX = -1
RETN
.over:
INC EAX ; EAX = 1
; fallthrough!
.runi:
RETN ; EAX = 0 or 1
Fun fact: this function almost follows the C Calling Convention's rules on which registers to preserve, except I had to clobber EBX
to save some bytes on stack usage.
Optional (not included in byte-count)
By adding the following 6 bytes directly before start of the code above, you can pass ECX
and EDX
unordered:
39 D1 7D 02 87 CA
Which is the following in readable Intel Syntax:
CMP ECX, EDX
JGE check
XCHG ECX, EDX
$endgroup$
add a comment |
$begingroup$
Retina 0.8.2, 92 bytes
d+
$*
^(10,19,121|(120,28),112|129,130)$|^(1*,10,20|(10,28),1?4)$|.+
$#1$#3
Try it online! Link includes test cases. Takes input in ascending order. Explanation: The first stage simply converts from decimal to unary so that the scores can be properly compared. The second stage contains six alternate patterns, grouped into three groups so that three distinct values can be output, which are 10
for win, 01
for ongoing and 00
for illegal. The patterns are:
- Against 0-19, a score of 21 is a win
- Against 20-28, a score of +2 is a win
- Against 29, a score of 30 is a win
- Against any (lower) score, a score of 0-20 is ongoing
- Against a score of up to 28, a score of +1 is ongoing
- Anything else (including negative scores) is illegal
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 33 32 bytesSBCS
h⍵+1 0+h←(⊢≡31 30|⊢)×21 2∨.≥-
Try it online!
in: a pair in descending order
out: 2=ongoing, 1=ended, 0=invalid
tests stolen from Adám's answer
$endgroup$
add a comment |
$begingroup$
Bash 4+, 97 89 91 88 bytes
Assume that inputs are ascending. Used concepts from VDM-SL answer. Try it Onlinez==0
- game in progress z==1
- game completed z==2
- invalid
-8 by bracket cleanup from (( & | ))
conditions
+2 fixing a bug, thanks to Kevin Cruijssen
-3 logic improvements by Kevin Cruijssen
i=$1 j=$2 z=0
((j-i>2&j>21|i<0|i>29|j>30?z=2:0))
((z<1&(j>20&j-i>1|j>29)?z=1:0))
echo $z
$endgroup$
1
$begingroup$
Your 89 bytes version seems to output1
instead of2
for0 30
. Your 97 bytes version was working correctly, so if you're unable to fix it, you can always rollback. Upvoted for that 97 version. :)
$endgroup$
– Kevin Cruijssen
Mar 28 at 13:59
1
$begingroup$
This should fix it, and golf a byte at the same time. :)
$endgroup$
– Kevin Cruijssen
Mar 28 at 14:05
1
$begingroup$
I fixed it, but yours was better! Hard to keep up :P
$endgroup$
– roblogic
Mar 28 at 14:14
$begingroup$
Bug at29 30
:( it should be "completed"
$endgroup$
– roblogic
Apr 3 at 8:39
1
$begingroup$
Ah oops.. thei>29
should bej>29
in the second ternary to fix it.
$endgroup$
– Kevin Cruijssen
Apr 3 at 8:42
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182245%2fvalid-badminton-score%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
13 Answers
13
active
oldest
votes
13 Answers
13
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Stax, 20 bytes
ÇåπßéD╩¬7▼ß▌ΣU¬í╡S┤╘
Run and debug it
It takes input in the same format as the examples. 0
means there's a valid winner. 1
means the game is in progress. -1
means invalid score.
In pseudo-code, with ordered inputs x
and y
, the algorithm is
sign(clamp(x + 2, 21, 30) - y) | (x < 0 || x >= 30 ? 0 : -1)
sign
means numeric sign (-1
,0
, or1
)clamp
forces its first argument into the specified half-open interval
$endgroup$
add a comment |
$begingroup$
Stax, 20 bytes
ÇåπßéD╩¬7▼ß▌ΣU¬í╡S┤╘
Run and debug it
It takes input in the same format as the examples. 0
means there's a valid winner. 1
means the game is in progress. -1
means invalid score.
In pseudo-code, with ordered inputs x
and y
, the algorithm is
sign(clamp(x + 2, 21, 30) - y) | (x < 0 || x >= 30 ? 0 : -1)
sign
means numeric sign (-1
,0
, or1
)clamp
forces its first argument into the specified half-open interval
$endgroup$
add a comment |
$begingroup$
Stax, 20 bytes
ÇåπßéD╩¬7▼ß▌ΣU¬í╡S┤╘
Run and debug it
It takes input in the same format as the examples. 0
means there's a valid winner. 1
means the game is in progress. -1
means invalid score.
In pseudo-code, with ordered inputs x
and y
, the algorithm is
sign(clamp(x + 2, 21, 30) - y) | (x < 0 || x >= 30 ? 0 : -1)
sign
means numeric sign (-1
,0
, or1
)clamp
forces its first argument into the specified half-open interval
$endgroup$
Stax, 20 bytes
ÇåπßéD╩¬7▼ß▌ΣU¬í╡S┤╘
Run and debug it
It takes input in the same format as the examples. 0
means there's a valid winner. 1
means the game is in progress. -1
means invalid score.
In pseudo-code, with ordered inputs x
and y
, the algorithm is
sign(clamp(x + 2, 21, 30) - y) | (x < 0 || x >= 30 ? 0 : -1)
sign
means numeric sign (-1
,0
, or1
)clamp
forces its first argument into the specified half-open interval
answered Apr 4 at 22:58
recursiverecursive
5,7441322
5,7441322
add a comment |
add a comment |
$begingroup$
Python 2, 97 95 75 72 71 70 69 64 55 54 52 51 50 48 bytes
lambda a,b:(b-61<~a<a>b/22*b-3)*~(19<b-(b<30)>a)
Try it online!
Takes input as pre-ordered a,b
.
Returns -2
, -1
, 0
for ended
, in play
, invalid
.
-1 byte, thanks to Kevin Cruijssen
Left part (b-61<~a<a>b/22*b-3
) is a validity-check, and right part (19<b-(b<30)>a
) is a check for game ended.
$endgroup$
add a comment |
$begingroup$
Python 2, 97 95 75 72 71 70 69 64 55 54 52 51 50 48 bytes
lambda a,b:(b-61<~a<a>b/22*b-3)*~(19<b-(b<30)>a)
Try it online!
Takes input as pre-ordered a,b
.
Returns -2
, -1
, 0
for ended
, in play
, invalid
.
-1 byte, thanks to Kevin Cruijssen
Left part (b-61<~a<a>b/22*b-3
) is a validity-check, and right part (19<b-(b<30)>a
) is a check for game ended.
$endgroup$
add a comment |
$begingroup$
Python 2, 97 95 75 72 71 70 69 64 55 54 52 51 50 48 bytes
lambda a,b:(b-61<~a<a>b/22*b-3)*~(19<b-(b<30)>a)
Try it online!
Takes input as pre-ordered a,b
.
Returns -2
, -1
, 0
for ended
, in play
, invalid
.
-1 byte, thanks to Kevin Cruijssen
Left part (b-61<~a<a>b/22*b-3
) is a validity-check, and right part (19<b-(b<30)>a
) is a check for game ended.
$endgroup$
Python 2, 97 95 75 72 71 70 69 64 55 54 52 51 50 48 bytes
lambda a,b:(b-61<~a<a>b/22*b-3)*~(19<b-(b<30)>a)
Try it online!
Takes input as pre-ordered a,b
.
Returns -2
, -1
, 0
for ended
, in play
, invalid
.
-1 byte, thanks to Kevin Cruijssen
Left part (b-61<~a<a>b/22*b-3
) is a validity-check, and right part (19<b-(b<30)>a
) is a check for game ended.
edited Mar 27 at 11:14
answered Mar 26 at 15:46
TFeldTFeld
16.6k21451
16.6k21451
add a comment |
add a comment |
$begingroup$
Python 2, 47 bytes
lambda a,b:[61>60-a>b<3+max(19,a)for b in-~b,b]
Try it online!
Outputs a list of two Booleans. Thanks to TFeld for writing a test suite in their answer that made it easy to check my solution.
ended: [False, True]
going: [True, True]
invalid: [False, False]
The key insight is that a valid score ends the game exactly if increasing the higher value b
makes the score invalid. So, we just code up the validity condition, and check it for (a,b+1)
in addition to (a,b)
to see if the game has ended.
Validity is checked via three conditions that are chained together:
b<3+max(19,a)
: Checks that the higher scoreb
isn't past winning, with eitherb<=21
orb<=a+2
(win by two)60-a>b
: Equivalent toa+b<=59
, ensuring the score isn't above(29,30)
61>60-a
: Equivalent toa>=0
, ensures the lower score is non-negative
Python 2, 44 bytes
lambda a,b:[b-61<~a<a>b/22*b-3for b in-~b,b]
Try it online!
An improved validity check by TFeld saves 3 bytes. The main idea is to branch on "overtime" b>21
with b/22*b
which effectively sets below-21 scores to zero, whereas I'd branched on a>19
with the longer max(19,a)
.
Python 2, 43 bytes
lambda a,b:a>>99|cmp(2+max(19,a)%30-a/29,b)
Try it online!
Outputs:
ended: 0
going: -1
invalid: 1
Assumes that the inputs are not below $-2^99$.
$endgroup$
1
$begingroup$
Using my newest validity-check (b-61<~a<a>b/22*b-3
), you can save 3 bytes.
$endgroup$
– TFeld
Mar 27 at 11:17
1
$begingroup$
+1 byte to make your second solution work for all inputs:lambda a,b:-(a<0)|cmp(2+max(19,a)%30-a/29,b)
$endgroup$
– TFeld
Mar 27 at 12:51
add a comment |
$begingroup$
Python 2, 47 bytes
lambda a,b:[61>60-a>b<3+max(19,a)for b in-~b,b]
Try it online!
Outputs a list of two Booleans. Thanks to TFeld for writing a test suite in their answer that made it easy to check my solution.
ended: [False, True]
going: [True, True]
invalid: [False, False]
The key insight is that a valid score ends the game exactly if increasing the higher value b
makes the score invalid. So, we just code up the validity condition, and check it for (a,b+1)
in addition to (a,b)
to see if the game has ended.
Validity is checked via three conditions that are chained together:
b<3+max(19,a)
: Checks that the higher scoreb
isn't past winning, with eitherb<=21
orb<=a+2
(win by two)60-a>b
: Equivalent toa+b<=59
, ensuring the score isn't above(29,30)
61>60-a
: Equivalent toa>=0
, ensures the lower score is non-negative
Python 2, 44 bytes
lambda a,b:[b-61<~a<a>b/22*b-3for b in-~b,b]
Try it online!
An improved validity check by TFeld saves 3 bytes. The main idea is to branch on "overtime" b>21
with b/22*b
which effectively sets below-21 scores to zero, whereas I'd branched on a>19
with the longer max(19,a)
.
Python 2, 43 bytes
lambda a,b:a>>99|cmp(2+max(19,a)%30-a/29,b)
Try it online!
Outputs:
ended: 0
going: -1
invalid: 1
Assumes that the inputs are not below $-2^99$.
$endgroup$
1
$begingroup$
Using my newest validity-check (b-61<~a<a>b/22*b-3
), you can save 3 bytes.
$endgroup$
– TFeld
Mar 27 at 11:17
1
$begingroup$
+1 byte to make your second solution work for all inputs:lambda a,b:-(a<0)|cmp(2+max(19,a)%30-a/29,b)
$endgroup$
– TFeld
Mar 27 at 12:51
add a comment |
$begingroup$
Python 2, 47 bytes
lambda a,b:[61>60-a>b<3+max(19,a)for b in-~b,b]
Try it online!
Outputs a list of two Booleans. Thanks to TFeld for writing a test suite in their answer that made it easy to check my solution.
ended: [False, True]
going: [True, True]
invalid: [False, False]
The key insight is that a valid score ends the game exactly if increasing the higher value b
makes the score invalid. So, we just code up the validity condition, and check it for (a,b+1)
in addition to (a,b)
to see if the game has ended.
Validity is checked via three conditions that are chained together:
b<3+max(19,a)
: Checks that the higher scoreb
isn't past winning, with eitherb<=21
orb<=a+2
(win by two)60-a>b
: Equivalent toa+b<=59
, ensuring the score isn't above(29,30)
61>60-a
: Equivalent toa>=0
, ensures the lower score is non-negative
Python 2, 44 bytes
lambda a,b:[b-61<~a<a>b/22*b-3for b in-~b,b]
Try it online!
An improved validity check by TFeld saves 3 bytes. The main idea is to branch on "overtime" b>21
with b/22*b
which effectively sets below-21 scores to zero, whereas I'd branched on a>19
with the longer max(19,a)
.
Python 2, 43 bytes
lambda a,b:a>>99|cmp(2+max(19,a)%30-a/29,b)
Try it online!
Outputs:
ended: 0
going: -1
invalid: 1
Assumes that the inputs are not below $-2^99$.
$endgroup$
Python 2, 47 bytes
lambda a,b:[61>60-a>b<3+max(19,a)for b in-~b,b]
Try it online!
Outputs a list of two Booleans. Thanks to TFeld for writing a test suite in their answer that made it easy to check my solution.
ended: [False, True]
going: [True, True]
invalid: [False, False]
The key insight is that a valid score ends the game exactly if increasing the higher value b
makes the score invalid. So, we just code up the validity condition, and check it for (a,b+1)
in addition to (a,b)
to see if the game has ended.
Validity is checked via three conditions that are chained together:
b<3+max(19,a)
: Checks that the higher scoreb
isn't past winning, with eitherb<=21
orb<=a+2
(win by two)60-a>b
: Equivalent toa+b<=59
, ensuring the score isn't above(29,30)
61>60-a
: Equivalent toa>=0
, ensures the lower score is non-negative
Python 2, 44 bytes
lambda a,b:[b-61<~a<a>b/22*b-3for b in-~b,b]
Try it online!
An improved validity check by TFeld saves 3 bytes. The main idea is to branch on "overtime" b>21
with b/22*b
which effectively sets below-21 scores to zero, whereas I'd branched on a>19
with the longer max(19,a)
.
Python 2, 43 bytes
lambda a,b:a>>99|cmp(2+max(19,a)%30-a/29,b)
Try it online!
Outputs:
ended: 0
going: -1
invalid: 1
Assumes that the inputs are not below $-2^99$.
edited Mar 28 at 0:22
answered Mar 27 at 0:18
xnorxnor
94.7k18194454
94.7k18194454
1
$begingroup$
Using my newest validity-check (b-61<~a<a>b/22*b-3
), you can save 3 bytes.
$endgroup$
– TFeld
Mar 27 at 11:17
1
$begingroup$
+1 byte to make your second solution work for all inputs:lambda a,b:-(a<0)|cmp(2+max(19,a)%30-a/29,b)
$endgroup$
– TFeld
Mar 27 at 12:51
add a comment |
1
$begingroup$
Using my newest validity-check (b-61<~a<a>b/22*b-3
), you can save 3 bytes.
$endgroup$
– TFeld
Mar 27 at 11:17
1
$begingroup$
+1 byte to make your second solution work for all inputs:lambda a,b:-(a<0)|cmp(2+max(19,a)%30-a/29,b)
$endgroup$
– TFeld
Mar 27 at 12:51
1
1
$begingroup$
Using my newest validity-check (
b-61<~a<a>b/22*b-3
), you can save 3 bytes.$endgroup$
– TFeld
Mar 27 at 11:17
$begingroup$
Using my newest validity-check (
b-61<~a<a>b/22*b-3
), you can save 3 bytes.$endgroup$
– TFeld
Mar 27 at 11:17
1
1
$begingroup$
+1 byte to make your second solution work for all inputs:
lambda a,b:-(a<0)|cmp(2+max(19,a)%30-a/29,b)
$endgroup$
– TFeld
Mar 27 at 12:51
$begingroup$
+1 byte to make your second solution work for all inputs:
lambda a,b:-(a<0)|cmp(2+max(19,a)%30-a/29,b)
$endgroup$
– TFeld
Mar 27 at 12:51
add a comment |
$begingroup$
JavaScript (ES6), 55 53 48 bytes
Thanks to @KevinCruijssen for noticing that I was not fully assuming $ale b$ (saving 5 bytes)
Takes input as (a)(b)
with $ale b$. Returns $0$ (valid), $1$ (ended) or $2$ (invalid).
a=>b=>a<0|a>29|b>30|b>21&b-a>2?2:b>20&b-a>1|b>29
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 55 53 48 bytes
Thanks to @KevinCruijssen for noticing that I was not fully assuming $ale b$ (saving 5 bytes)
Takes input as (a)(b)
with $ale b$. Returns $0$ (valid), $1$ (ended) or $2$ (invalid).
a=>b=>a<0|a>29|b>30|b>21&b-a>2?2:b>20&b-a>1|b>29
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 55 53 48 bytes
Thanks to @KevinCruijssen for noticing that I was not fully assuming $ale b$ (saving 5 bytes)
Takes input as (a)(b)
with $ale b$. Returns $0$ (valid), $1$ (ended) or $2$ (invalid).
a=>b=>a<0|a>29|b>30|b>21&b-a>2?2:b>20&b-a>1|b>29
Try it online!
$endgroup$
JavaScript (ES6), 55 53 48 bytes
Thanks to @KevinCruijssen for noticing that I was not fully assuming $ale b$ (saving 5 bytes)
Takes input as (a)(b)
with $ale b$. Returns $0$ (valid), $1$ (ended) or $2$ (invalid).
a=>b=>a<0|a>29|b>30|b>21&b-a>2?2:b>20&b-a>1|b>29
Try it online!
edited Mar 26 at 16:28
answered Mar 26 at 16:10
ArnauldArnauld
82.2k798339
82.2k798339
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 53 52 bytes
a=>b=>b<0|a-b>2&a>21|b>29|a>30?3:a>20&a-b>1|a>29?1:2
Called as f(max)(min)
. Returns 3 for invalid, 1 for finished, 2 for ongoing.
Saved 1 byte thanks to Kevin Cruijjsen
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 53 52 bytes
a=>b=>b<0|a-b>2&a>21|b>29|a>30?3:a>20&a-b>1|a>29?1:2
Called as f(max)(min)
. Returns 3 for invalid, 1 for finished, 2 for ongoing.
Saved 1 byte thanks to Kevin Cruijjsen
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 53 52 bytes
a=>b=>b<0|a-b>2&a>21|b>29|a>30?3:a>20&a-b>1|a>29?1:2
Called as f(max)(min)
. Returns 3 for invalid, 1 for finished, 2 for ongoing.
Saved 1 byte thanks to Kevin Cruijjsen
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 53 52 bytes
a=>b=>b<0|a-b>2&a>21|b>29|a>30?3:a>20&a-b>1|a>29?1:2
Called as f(max)(min)
. Returns 3 for invalid, 1 for finished, 2 for ongoing.
Saved 1 byte thanks to Kevin Cruijjsen
Try it online!
edited Mar 26 at 18:20
answered Mar 26 at 17:32
Embodiment of IgnoranceEmbodiment of Ignorance
3,194127
3,194127
add a comment |
add a comment |
$begingroup$
Jelly, 25 bytes
»19«28‘<‘×+2>ɗʋ⁹×,%Ƒ“œþ‘ɗ
Try it online!
Left argument: minimum. Right argument: maximum.
Invalid: 0
. Ongoing: 1
. Ended: 2
.
Mathematically, this works as below (the left argument is $x$, the right is $y$):
$$[a]=casesacolon1\lnot acolon0\otimes(a,b)=(abmod30,bbmod31)\x,yinmathbb Z\X:=min(max(x+1,20),29)\p:=(x,y)\([X<y]+1)[X+2>y][p=otimes p]$$
Explanation:
»19«28‘<‘×+2>ɗʋ⁹×,%Ƒ“œþ‘ɗ Left argument: x, Right argument: y
»19«28‘ X := Bound x + 1 in [20, 29]:
»19 X := max(x, 19).
«28 X := min(X, 28).
‘ X := X + 1.
<‘×+2>ɗʋ⁹ X := If X + 2 <= y, then 0, else if X < y, then 2, else 1:
< t := If X < y, then 1, else 0.
‘ t := t + 1.
+2>ɗ u := Check if X + 2 > y:
+2 u := X + 2.
> u := If u > y, then 1, else 0.
× X := t * u.
,%Ƒ“œþ‘ɗ z := If x mod 30 = x and y mod 31 = y, then 1, else 0:
, z := (x, y).
% “œþ‘ m := z mod (30, 31) = (x mod 30, y mod 31).
Ƒ z := If z = m, then 1, else 0.
× X * z.
$endgroup$
add a comment |
$begingroup$
Jelly, 25 bytes
»19«28‘<‘×+2>ɗʋ⁹×,%Ƒ“œþ‘ɗ
Try it online!
Left argument: minimum. Right argument: maximum.
Invalid: 0
. Ongoing: 1
. Ended: 2
.
Mathematically, this works as below (the left argument is $x$, the right is $y$):
$$[a]=casesacolon1\lnot acolon0\otimes(a,b)=(abmod30,bbmod31)\x,yinmathbb Z\X:=min(max(x+1,20),29)\p:=(x,y)\([X<y]+1)[X+2>y][p=otimes p]$$
Explanation:
»19«28‘<‘×+2>ɗʋ⁹×,%Ƒ“œþ‘ɗ Left argument: x, Right argument: y
»19«28‘ X := Bound x + 1 in [20, 29]:
»19 X := max(x, 19).
«28 X := min(X, 28).
‘ X := X + 1.
<‘×+2>ɗʋ⁹ X := If X + 2 <= y, then 0, else if X < y, then 2, else 1:
< t := If X < y, then 1, else 0.
‘ t := t + 1.
+2>ɗ u := Check if X + 2 > y:
+2 u := X + 2.
> u := If u > y, then 1, else 0.
× X := t * u.
,%Ƒ“œþ‘ɗ z := If x mod 30 = x and y mod 31 = y, then 1, else 0:
, z := (x, y).
% “œþ‘ m := z mod (30, 31) = (x mod 30, y mod 31).
Ƒ z := If z = m, then 1, else 0.
× X * z.
$endgroup$
add a comment |
$begingroup$
Jelly, 25 bytes
»19«28‘<‘×+2>ɗʋ⁹×,%Ƒ“œþ‘ɗ
Try it online!
Left argument: minimum. Right argument: maximum.
Invalid: 0
. Ongoing: 1
. Ended: 2
.
Mathematically, this works as below (the left argument is $x$, the right is $y$):
$$[a]=casesacolon1\lnot acolon0\otimes(a,b)=(abmod30,bbmod31)\x,yinmathbb Z\X:=min(max(x+1,20),29)\p:=(x,y)\([X<y]+1)[X+2>y][p=otimes p]$$
Explanation:
»19«28‘<‘×+2>ɗʋ⁹×,%Ƒ“œþ‘ɗ Left argument: x, Right argument: y
»19«28‘ X := Bound x + 1 in [20, 29]:
»19 X := max(x, 19).
«28 X := min(X, 28).
‘ X := X + 1.
<‘×+2>ɗʋ⁹ X := If X + 2 <= y, then 0, else if X < y, then 2, else 1:
< t := If X < y, then 1, else 0.
‘ t := t + 1.
+2>ɗ u := Check if X + 2 > y:
+2 u := X + 2.
> u := If u > y, then 1, else 0.
× X := t * u.
,%Ƒ“œþ‘ɗ z := If x mod 30 = x and y mod 31 = y, then 1, else 0:
, z := (x, y).
% “œþ‘ m := z mod (30, 31) = (x mod 30, y mod 31).
Ƒ z := If z = m, then 1, else 0.
× X * z.
$endgroup$
Jelly, 25 bytes
»19«28‘<‘×+2>ɗʋ⁹×,%Ƒ“œþ‘ɗ
Try it online!
Left argument: minimum. Right argument: maximum.
Invalid: 0
. Ongoing: 1
. Ended: 2
.
Mathematically, this works as below (the left argument is $x$, the right is $y$):
$$[a]=casesacolon1\lnot acolon0\otimes(a,b)=(abmod30,bbmod31)\x,yinmathbb Z\X:=min(max(x+1,20),29)\p:=(x,y)\([X<y]+1)[X+2>y][p=otimes p]$$
Explanation:
»19«28‘<‘×+2>ɗʋ⁹×,%Ƒ“œþ‘ɗ Left argument: x, Right argument: y
»19«28‘ X := Bound x + 1 in [20, 29]:
»19 X := max(x, 19).
«28 X := min(X, 28).
‘ X := X + 1.
<‘×+2>ɗʋ⁹ X := If X + 2 <= y, then 0, else if X < y, then 2, else 1:
< t := If X < y, then 1, else 0.
‘ t := t + 1.
+2>ɗ u := Check if X + 2 > y:
+2 u := X + 2.
> u := If u > y, then 1, else 0.
× X := t * u.
,%Ƒ“œþ‘ɗ z := If x mod 30 = x and y mod 31 = y, then 1, else 0:
, z := (x, y).
% “œþ‘ m := z mod (30, 31) = (x mod 30, y mod 31).
Ƒ z := If z = m, then 1, else 0.
× X * z.
edited Mar 27 at 13:43
answered Mar 26 at 17:15
Erik the OutgolferErik the Outgolfer
33.3k429106
33.3k429106
add a comment |
add a comment |
$begingroup$
VDM-SL, 80 bytes
f(i,j)==if(j-i>2and j>21)or(i<0or i=30or j>30)thenelse(j>20and j-i>1or j=30)
This function takes the scores ordered in ascending order and returns the empty set if the score is invalid or the set containing whether the set is complete (so true if the set is complete and valid and false if the set is incomplete and valid)
A full program to run might look like this:
functions
f:int*int+>set of bool
f(i,j)==if(j-i>2and j>21)or(i<0or i=30or j>30)thenelse(j>20and j-i>1or j=30)
Explanation:
if(j-i>2 and j>21) /*if scores are too far apart*/
or(i<0 or i=30 or j>30) /*or scores not in a valid range*/
then /*return the empty set*/
else /*else return the set containing...*/
(j>20 and j-i>1 or j=30) /*if the set is complete*/
$endgroup$
add a comment |
$begingroup$
VDM-SL, 80 bytes
f(i,j)==if(j-i>2and j>21)or(i<0or i=30or j>30)thenelse(j>20and j-i>1or j=30)
This function takes the scores ordered in ascending order and returns the empty set if the score is invalid or the set containing whether the set is complete (so true if the set is complete and valid and false if the set is incomplete and valid)
A full program to run might look like this:
functions
f:int*int+>set of bool
f(i,j)==if(j-i>2and j>21)or(i<0or i=30or j>30)thenelse(j>20and j-i>1or j=30)
Explanation:
if(j-i>2 and j>21) /*if scores are too far apart*/
or(i<0 or i=30 or j>30) /*or scores not in a valid range*/
then /*return the empty set*/
else /*else return the set containing...*/
(j>20 and j-i>1 or j=30) /*if the set is complete*/
$endgroup$
add a comment |
$begingroup$
VDM-SL, 80 bytes
f(i,j)==if(j-i>2and j>21)or(i<0or i=30or j>30)thenelse(j>20and j-i>1or j=30)
This function takes the scores ordered in ascending order and returns the empty set if the score is invalid or the set containing whether the set is complete (so true if the set is complete and valid and false if the set is incomplete and valid)
A full program to run might look like this:
functions
f:int*int+>set of bool
f(i,j)==if(j-i>2and j>21)or(i<0or i=30or j>30)thenelse(j>20and j-i>1or j=30)
Explanation:
if(j-i>2 and j>21) /*if scores are too far apart*/
or(i<0 or i=30 or j>30) /*or scores not in a valid range*/
then /*return the empty set*/
else /*else return the set containing...*/
(j>20 and j-i>1 or j=30) /*if the set is complete*/
$endgroup$
VDM-SL, 80 bytes
f(i,j)==if(j-i>2and j>21)or(i<0or i=30or j>30)thenelse(j>20and j-i>1or j=30)
This function takes the scores ordered in ascending order and returns the empty set if the score is invalid or the set containing whether the set is complete (so true if the set is complete and valid and false if the set is incomplete and valid)
A full program to run might look like this:
functions
f:int*int+>set of bool
f(i,j)==if(j-i>2and j>21)or(i<0or i=30or j>30)thenelse(j>20and j-i>1or j=30)
Explanation:
if(j-i>2 and j>21) /*if scores are too far apart*/
or(i<0 or i=30 or j>30) /*or scores not in a valid range*/
then /*return the empty set*/
else /*else return the set containing...*/
(j>20 and j-i>1 or j=30) /*if the set is complete*/
answered Mar 26 at 17:22
Expired DataExpired Data
1,058217
1,058217
add a comment |
add a comment |
$begingroup$
Java (JDK), 59 48 bytes
a->b->b<0|b>29|a>b+2&a>21|a>30?0:a<21|a<30&a<b+2
Try it online!
Returns an Object
, which is the Integer
0
for invalid games and the Boolean
s true
and false
for valid ongoing games and for valid finished games respectively. Takes the score ordered (and curried), with the higher score first.
-2 bytes
by inverting the end-of-match check.-11 bytes
by currying, using bitwise operators, and some return type autoboxing trickery - thanks to @KevinCruijssen
Ungolfed
a-> // Curried: Target type IntFunction<IntFunction<Object>>
b-> // Target type IntFunction<Object>
// Invalid if:
b<0 // Any score is negative
| b > 29 // Both scores above 29
| a > b + 2 // Lead too big
& a > 21 // and leader has at least 21 points
| a > 30 // Anyone has 31 points
? 0 // If invalid, return 0 (autoboxed to Integer)
// If valid, return whether the game is ongoing (autoboxed to Boolean)
// Ongoing if:
: a < 21 // Nobody has 21 points
| a < 30 // Leader has fewer than 30 points
& a < b + 2 // and lead is small
$endgroup$
add a comment |
$begingroup$
Java (JDK), 59 48 bytes
a->b->b<0|b>29|a>b+2&a>21|a>30?0:a<21|a<30&a<b+2
Try it online!
Returns an Object
, which is the Integer
0
for invalid games and the Boolean
s true
and false
for valid ongoing games and for valid finished games respectively. Takes the score ordered (and curried), with the higher score first.
-2 bytes
by inverting the end-of-match check.-11 bytes
by currying, using bitwise operators, and some return type autoboxing trickery - thanks to @KevinCruijssen
Ungolfed
a-> // Curried: Target type IntFunction<IntFunction<Object>>
b-> // Target type IntFunction<Object>
// Invalid if:
b<0 // Any score is negative
| b > 29 // Both scores above 29
| a > b + 2 // Lead too big
& a > 21 // and leader has at least 21 points
| a > 30 // Anyone has 31 points
? 0 // If invalid, return 0 (autoboxed to Integer)
// If valid, return whether the game is ongoing (autoboxed to Boolean)
// Ongoing if:
: a < 21 // Nobody has 21 points
| a < 30 // Leader has fewer than 30 points
& a < b + 2 // and lead is small
$endgroup$
add a comment |
$begingroup$
Java (JDK), 59 48 bytes
a->b->b<0|b>29|a>b+2&a>21|a>30?0:a<21|a<30&a<b+2
Try it online!
Returns an Object
, which is the Integer
0
for invalid games and the Boolean
s true
and false
for valid ongoing games and for valid finished games respectively. Takes the score ordered (and curried), with the higher score first.
-2 bytes
by inverting the end-of-match check.-11 bytes
by currying, using bitwise operators, and some return type autoboxing trickery - thanks to @KevinCruijssen
Ungolfed
a-> // Curried: Target type IntFunction<IntFunction<Object>>
b-> // Target type IntFunction<Object>
// Invalid if:
b<0 // Any score is negative
| b > 29 // Both scores above 29
| a > b + 2 // Lead too big
& a > 21 // and leader has at least 21 points
| a > 30 // Anyone has 31 points
? 0 // If invalid, return 0 (autoboxed to Integer)
// If valid, return whether the game is ongoing (autoboxed to Boolean)
// Ongoing if:
: a < 21 // Nobody has 21 points
| a < 30 // Leader has fewer than 30 points
& a < b + 2 // and lead is small
$endgroup$
Java (JDK), 59 48 bytes
a->b->b<0|b>29|a>b+2&a>21|a>30?0:a<21|a<30&a<b+2
Try it online!
Returns an Object
, which is the Integer
0
for invalid games and the Boolean
s true
and false
for valid ongoing games and for valid finished games respectively. Takes the score ordered (and curried), with the higher score first.
-2 bytes
by inverting the end-of-match check.-11 bytes
by currying, using bitwise operators, and some return type autoboxing trickery - thanks to @KevinCruijssen
Ungolfed
a-> // Curried: Target type IntFunction<IntFunction<Object>>
b-> // Target type IntFunction<Object>
// Invalid if:
b<0 // Any score is negative
| b > 29 // Both scores above 29
| a > b + 2 // Lead too big
& a > 21 // and leader has at least 21 points
| a > 30 // Anyone has 31 points
? 0 // If invalid, return 0 (autoboxed to Integer)
// If valid, return whether the game is ongoing (autoboxed to Boolean)
// Ongoing if:
: a < 21 // Nobody has 21 points
| a < 30 // Leader has fewer than 30 points
& a < b + 2 // and lead is small
edited Mar 26 at 21:57
answered Mar 26 at 20:08
Sara JSara J
690210
690210
add a comment |
add a comment |
$begingroup$
APL (Dyalog Unicode), 35 bytesSBCS
Infix tacit function where ended is 2, ongoing is 1, invalid is 0, smaller and larger scores are left.
(,≡30 31|,)×(⊢<2+X)×1+⊢>X←29⌊20⌈1+⊣
Try it online!
Implements Erik the Outgolfer's mathematical formulas combined into
$$X:=min(max(x+1,20),29)\ ([X< y]+1)[X+2>y][(x,y)=(xbmod30,ybmod31)]$$
rearranged (as if traditional mathematical notation had vectorisation and inline assignments) to
$$[(x,y)=(x,y)bmod(30,31)]×[y<2+X]×(1+[y< (X:=min(29,max(20,1+x)))])$$
and translated directly to APL (which is strictly right-associative, so we avoid some parentheses):
$$((x,y)≡30 31|x,y)×(y<2+X)×1+y>X←29⌊20⌈1 +x$$
This can be converted into a tacit function simply by substituting $⊣$ for $x$ and $⊢$ for $y$, symbolising the left and right arguments rather than the two variables:
$$((⊣,⊢)≡30 31|⊣,⊢)×(⊣<2+X)×1+⊢>X←29⌊20⌈1+⊣$$
Now $⊣⎕⊢$ is equivalent to $⎕$ for any infix function $⎕$, so we can simplify to
$$(,≡30 31|,)×(⊣<2+X)×1+⊢>X←29⌊20⌈1+⊣$$
which is our solution; (,≡30 31|,)×(⊢<2+X)×1+⊢>X←29⌊20⌈1+⊣
:
⊣
the left argument; $x$1+
one plus that; $1+x$20⌈
maximum of 20 and that; $max(20,…)$29⌊
minimum of 29 and that; $min(29,…)$X←
assign that to X
; $X:=…$⊢>
is the right argument greater (0/1)?; $[y>…]$1+
add one; $1+…$(
…)×
multiply the following by that; $(…)×…$
2+X
two plus X
; $2+X$
⊢<
is the right argument less than that (0/1); $[y<…]$(
…)×
multiply the following by that; $(…)×…$
,
concatenate the arguments; $(x,y)$
30 31|
remainders when divided by these numbers; $…mod(30,31)$
,≡
are the concatenated arguments identical to that (0/1)?; $[(x,y)=…]$
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 35 bytesSBCS
Infix tacit function where ended is 2, ongoing is 1, invalid is 0, smaller and larger scores are left.
(,≡30 31|,)×(⊢<2+X)×1+⊢>X←29⌊20⌈1+⊣
Try it online!
Implements Erik the Outgolfer's mathematical formulas combined into
$$X:=min(max(x+1,20),29)\ ([X< y]+1)[X+2>y][(x,y)=(xbmod30,ybmod31)]$$
rearranged (as if traditional mathematical notation had vectorisation and inline assignments) to
$$[(x,y)=(x,y)bmod(30,31)]×[y<2+X]×(1+[y< (X:=min(29,max(20,1+x)))])$$
and translated directly to APL (which is strictly right-associative, so we avoid some parentheses):
$$((x,y)≡30 31|x,y)×(y<2+X)×1+y>X←29⌊20⌈1 +x$$
This can be converted into a tacit function simply by substituting $⊣$ for $x$ and $⊢$ for $y$, symbolising the left and right arguments rather than the two variables:
$$((⊣,⊢)≡30 31|⊣,⊢)×(⊣<2+X)×1+⊢>X←29⌊20⌈1+⊣$$
Now $⊣⎕⊢$ is equivalent to $⎕$ for any infix function $⎕$, so we can simplify to
$$(,≡30 31|,)×(⊣<2+X)×1+⊢>X←29⌊20⌈1+⊣$$
which is our solution; (,≡30 31|,)×(⊢<2+X)×1+⊢>X←29⌊20⌈1+⊣
:
⊣
the left argument; $x$1+
one plus that; $1+x$20⌈
maximum of 20 and that; $max(20,…)$29⌊
minimum of 29 and that; $min(29,…)$X←
assign that to X
; $X:=…$⊢>
is the right argument greater (0/1)?; $[y>…]$1+
add one; $1+…$(
…)×
multiply the following by that; $(…)×…$
2+X
two plus X
; $2+X$
⊢<
is the right argument less than that (0/1); $[y<…]$(
…)×
multiply the following by that; $(…)×…$
,
concatenate the arguments; $(x,y)$
30 31|
remainders when divided by these numbers; $…mod(30,31)$
,≡
are the concatenated arguments identical to that (0/1)?; $[(x,y)=…]$
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 35 bytesSBCS
Infix tacit function where ended is 2, ongoing is 1, invalid is 0, smaller and larger scores are left.
(,≡30 31|,)×(⊢<2+X)×1+⊢>X←29⌊20⌈1+⊣
Try it online!
Implements Erik the Outgolfer's mathematical formulas combined into
$$X:=min(max(x+1,20),29)\ ([X< y]+1)[X+2>y][(x,y)=(xbmod30,ybmod31)]$$
rearranged (as if traditional mathematical notation had vectorisation and inline assignments) to
$$[(x,y)=(x,y)bmod(30,31)]×[y<2+X]×(1+[y< (X:=min(29,max(20,1+x)))])$$
and translated directly to APL (which is strictly right-associative, so we avoid some parentheses):
$$((x,y)≡30 31|x,y)×(y<2+X)×1+y>X←29⌊20⌈1 +x$$
This can be converted into a tacit function simply by substituting $⊣$ for $x$ and $⊢$ for $y$, symbolising the left and right arguments rather than the two variables:
$$((⊣,⊢)≡30 31|⊣,⊢)×(⊣<2+X)×1+⊢>X←29⌊20⌈1+⊣$$
Now $⊣⎕⊢$ is equivalent to $⎕$ for any infix function $⎕$, so we can simplify to
$$(,≡30 31|,)×(⊣<2+X)×1+⊢>X←29⌊20⌈1+⊣$$
which is our solution; (,≡30 31|,)×(⊢<2+X)×1+⊢>X←29⌊20⌈1+⊣
:
⊣
the left argument; $x$1+
one plus that; $1+x$20⌈
maximum of 20 and that; $max(20,…)$29⌊
minimum of 29 and that; $min(29,…)$X←
assign that to X
; $X:=…$⊢>
is the right argument greater (0/1)?; $[y>…]$1+
add one; $1+…$(
…)×
multiply the following by that; $(…)×…$
2+X
two plus X
; $2+X$
⊢<
is the right argument less than that (0/1); $[y<…]$(
…)×
multiply the following by that; $(…)×…$
,
concatenate the arguments; $(x,y)$
30 31|
remainders when divided by these numbers; $…mod(30,31)$
,≡
are the concatenated arguments identical to that (0/1)?; $[(x,y)=…]$
$endgroup$
APL (Dyalog Unicode), 35 bytesSBCS
Infix tacit function where ended is 2, ongoing is 1, invalid is 0, smaller and larger scores are left.
(,≡30 31|,)×(⊢<2+X)×1+⊢>X←29⌊20⌈1+⊣
Try it online!
Implements Erik the Outgolfer's mathematical formulas combined into
$$X:=min(max(x+1,20),29)\ ([X< y]+1)[X+2>y][(x,y)=(xbmod30,ybmod31)]$$
rearranged (as if traditional mathematical notation had vectorisation and inline assignments) to
$$[(x,y)=(x,y)bmod(30,31)]×[y<2+X]×(1+[y< (X:=min(29,max(20,1+x)))])$$
and translated directly to APL (which is strictly right-associative, so we avoid some parentheses):
$$((x,y)≡30 31|x,y)×(y<2+X)×1+y>X←29⌊20⌈1 +x$$
This can be converted into a tacit function simply by substituting $⊣$ for $x$ and $⊢$ for $y$, symbolising the left and right arguments rather than the two variables:
$$((⊣,⊢)≡30 31|⊣,⊢)×(⊣<2+X)×1+⊢>X←29⌊20⌈1+⊣$$
Now $⊣⎕⊢$ is equivalent to $⎕$ for any infix function $⎕$, so we can simplify to
$$(,≡30 31|,)×(⊣<2+X)×1+⊢>X←29⌊20⌈1+⊣$$
which is our solution; (,≡30 31|,)×(⊢<2+X)×1+⊢>X←29⌊20⌈1+⊣
:
⊣
the left argument; $x$1+
one plus that; $1+x$20⌈
maximum of 20 and that; $max(20,…)$29⌊
minimum of 29 and that; $min(29,…)$X←
assign that to X
; $X:=…$⊢>
is the right argument greater (0/1)?; $[y>…]$1+
add one; $1+…$(
…)×
multiply the following by that; $(…)×…$
2+X
two plus X
; $2+X$
⊢<
is the right argument less than that (0/1); $[y<…]$(
…)×
multiply the following by that; $(…)×…$
,
concatenate the arguments; $(x,y)$
30 31|
remainders when divided by these numbers; $…mod(30,31)$
,≡
are the concatenated arguments identical to that (0/1)?; $[(x,y)=…]$
edited Mar 28 at 11:01
answered Mar 28 at 10:52
AdámAdám
28.1k276207
28.1k276207
add a comment |
add a comment |
$begingroup$
x86 Assembly, 42 Bytes
Takes input in ECX
and EDX
registers. Note that ECX
must be greater than EDX
.
Outputs into EAX
, where 0
means the game's still on, 1
representing the game being over and -1
(aka FFFFFFFF
) representing an invalid score.
31 C0 83 F9 1E 77 1F 83 FA 1D 77 1A 83 F9 15 7C
18 83 F9 1E 74 12 89 CB 29 D3 83 FB 02 74 09 7C
08 83 F9 15 74 02 48 C3 40 C3
Or, more readable in Intel Syntax:
check:
XOR EAX, EAX
CMP ECX, 30 ; check i_1 against 30
JA .invalid ; if >, invalid.
CMP EDX, 29 ; check i_2 against 29
JA .invalid ; if >, invalid.
CMP ECX, 21 ; check i_1 against 21
JL .runi ; if <, running.
CMP ECX, 30 ; check i_1 against 30
JE .over ; if ==, over.
MOV EBX, ECX
SUB EBX, EDX ; EBX = i_1 - i_2
CMP EBX, 2 ; check EBX against 2
JE .over ; if ==, over.
JL .runi ; if <, running.
; if >, keep executing!
CMP ECX, 21 ; check i_1 against 21
JE .over ; if ==, over.
; otherwise, it's invalid.
; fallthrough!
.invalid:
DEC EAX ; EAX = -1
RETN
.over:
INC EAX ; EAX = 1
; fallthrough!
.runi:
RETN ; EAX = 0 or 1
Fun fact: this function almost follows the C Calling Convention's rules on which registers to preserve, except I had to clobber EBX
to save some bytes on stack usage.
Optional (not included in byte-count)
By adding the following 6 bytes directly before start of the code above, you can pass ECX
and EDX
unordered:
39 D1 7D 02 87 CA
Which is the following in readable Intel Syntax:
CMP ECX, EDX
JGE check
XCHG ECX, EDX
$endgroup$
add a comment |
$begingroup$
x86 Assembly, 42 Bytes
Takes input in ECX
and EDX
registers. Note that ECX
must be greater than EDX
.
Outputs into EAX
, where 0
means the game's still on, 1
representing the game being over and -1
(aka FFFFFFFF
) representing an invalid score.
31 C0 83 F9 1E 77 1F 83 FA 1D 77 1A 83 F9 15 7C
18 83 F9 1E 74 12 89 CB 29 D3 83 FB 02 74 09 7C
08 83 F9 15 74 02 48 C3 40 C3
Or, more readable in Intel Syntax:
check:
XOR EAX, EAX
CMP ECX, 30 ; check i_1 against 30
JA .invalid ; if >, invalid.
CMP EDX, 29 ; check i_2 against 29
JA .invalid ; if >, invalid.
CMP ECX, 21 ; check i_1 against 21
JL .runi ; if <, running.
CMP ECX, 30 ; check i_1 against 30
JE .over ; if ==, over.
MOV EBX, ECX
SUB EBX, EDX ; EBX = i_1 - i_2
CMP EBX, 2 ; check EBX against 2
JE .over ; if ==, over.
JL .runi ; if <, running.
; if >, keep executing!
CMP ECX, 21 ; check i_1 against 21
JE .over ; if ==, over.
; otherwise, it's invalid.
; fallthrough!
.invalid:
DEC EAX ; EAX = -1
RETN
.over:
INC EAX ; EAX = 1
; fallthrough!
.runi:
RETN ; EAX = 0 or 1
Fun fact: this function almost follows the C Calling Convention's rules on which registers to preserve, except I had to clobber EBX
to save some bytes on stack usage.
Optional (not included in byte-count)
By adding the following 6 bytes directly before start of the code above, you can pass ECX
and EDX
unordered:
39 D1 7D 02 87 CA
Which is the following in readable Intel Syntax:
CMP ECX, EDX
JGE check
XCHG ECX, EDX
$endgroup$
add a comment |
$begingroup$
x86 Assembly, 42 Bytes
Takes input in ECX
and EDX
registers. Note that ECX
must be greater than EDX
.
Outputs into EAX
, where 0
means the game's still on, 1
representing the game being over and -1
(aka FFFFFFFF
) representing an invalid score.
31 C0 83 F9 1E 77 1F 83 FA 1D 77 1A 83 F9 15 7C
18 83 F9 1E 74 12 89 CB 29 D3 83 FB 02 74 09 7C
08 83 F9 15 74 02 48 C3 40 C3
Or, more readable in Intel Syntax:
check:
XOR EAX, EAX
CMP ECX, 30 ; check i_1 against 30
JA .invalid ; if >, invalid.
CMP EDX, 29 ; check i_2 against 29
JA .invalid ; if >, invalid.
CMP ECX, 21 ; check i_1 against 21
JL .runi ; if <, running.
CMP ECX, 30 ; check i_1 against 30
JE .over ; if ==, over.
MOV EBX, ECX
SUB EBX, EDX ; EBX = i_1 - i_2
CMP EBX, 2 ; check EBX against 2
JE .over ; if ==, over.
JL .runi ; if <, running.
; if >, keep executing!
CMP ECX, 21 ; check i_1 against 21
JE .over ; if ==, over.
; otherwise, it's invalid.
; fallthrough!
.invalid:
DEC EAX ; EAX = -1
RETN
.over:
INC EAX ; EAX = 1
; fallthrough!
.runi:
RETN ; EAX = 0 or 1
Fun fact: this function almost follows the C Calling Convention's rules on which registers to preserve, except I had to clobber EBX
to save some bytes on stack usage.
Optional (not included in byte-count)
By adding the following 6 bytes directly before start of the code above, you can pass ECX
and EDX
unordered:
39 D1 7D 02 87 CA
Which is the following in readable Intel Syntax:
CMP ECX, EDX
JGE check
XCHG ECX, EDX
$endgroup$
x86 Assembly, 42 Bytes
Takes input in ECX
and EDX
registers. Note that ECX
must be greater than EDX
.
Outputs into EAX
, where 0
means the game's still on, 1
representing the game being over and -1
(aka FFFFFFFF
) representing an invalid score.
31 C0 83 F9 1E 77 1F 83 FA 1D 77 1A 83 F9 15 7C
18 83 F9 1E 74 12 89 CB 29 D3 83 FB 02 74 09 7C
08 83 F9 15 74 02 48 C3 40 C3
Or, more readable in Intel Syntax:
check:
XOR EAX, EAX
CMP ECX, 30 ; check i_1 against 30
JA .invalid ; if >, invalid.
CMP EDX, 29 ; check i_2 against 29
JA .invalid ; if >, invalid.
CMP ECX, 21 ; check i_1 against 21
JL .runi ; if <, running.
CMP ECX, 30 ; check i_1 against 30
JE .over ; if ==, over.
MOV EBX, ECX
SUB EBX, EDX ; EBX = i_1 - i_2
CMP EBX, 2 ; check EBX against 2
JE .over ; if ==, over.
JL .runi ; if <, running.
; if >, keep executing!
CMP ECX, 21 ; check i_1 against 21
JE .over ; if ==, over.
; otherwise, it's invalid.
; fallthrough!
.invalid:
DEC EAX ; EAX = -1
RETN
.over:
INC EAX ; EAX = 1
; fallthrough!
.runi:
RETN ; EAX = 0 or 1
Fun fact: this function almost follows the C Calling Convention's rules on which registers to preserve, except I had to clobber EBX
to save some bytes on stack usage.
Optional (not included in byte-count)
By adding the following 6 bytes directly before start of the code above, you can pass ECX
and EDX
unordered:
39 D1 7D 02 87 CA
Which is the following in readable Intel Syntax:
CMP ECX, EDX
JGE check
XCHG ECX, EDX
answered Mar 28 at 21:46
Fayti1703Fayti1703
613
613
add a comment |
add a comment |
$begingroup$
Retina 0.8.2, 92 bytes
d+
$*
^(10,19,121|(120,28),112|129,130)$|^(1*,10,20|(10,28),1?4)$|.+
$#1$#3
Try it online! Link includes test cases. Takes input in ascending order. Explanation: The first stage simply converts from decimal to unary so that the scores can be properly compared. The second stage contains six alternate patterns, grouped into three groups so that three distinct values can be output, which are 10
for win, 01
for ongoing and 00
for illegal. The patterns are:
- Against 0-19, a score of 21 is a win
- Against 20-28, a score of +2 is a win
- Against 29, a score of 30 is a win
- Against any (lower) score, a score of 0-20 is ongoing
- Against a score of up to 28, a score of +1 is ongoing
- Anything else (including negative scores) is illegal
$endgroup$
add a comment |
$begingroup$
Retina 0.8.2, 92 bytes
d+
$*
^(10,19,121|(120,28),112|129,130)$|^(1*,10,20|(10,28),1?4)$|.+
$#1$#3
Try it online! Link includes test cases. Takes input in ascending order. Explanation: The first stage simply converts from decimal to unary so that the scores can be properly compared. The second stage contains six alternate patterns, grouped into three groups so that three distinct values can be output, which are 10
for win, 01
for ongoing and 00
for illegal. The patterns are:
- Against 0-19, a score of 21 is a win
- Against 20-28, a score of +2 is a win
- Against 29, a score of 30 is a win
- Against any (lower) score, a score of 0-20 is ongoing
- Against a score of up to 28, a score of +1 is ongoing
- Anything else (including negative scores) is illegal
$endgroup$
add a comment |
$begingroup$
Retina 0.8.2, 92 bytes
d+
$*
^(10,19,121|(120,28),112|129,130)$|^(1*,10,20|(10,28),1?4)$|.+
$#1$#3
Try it online! Link includes test cases. Takes input in ascending order. Explanation: The first stage simply converts from decimal to unary so that the scores can be properly compared. The second stage contains six alternate patterns, grouped into three groups so that three distinct values can be output, which are 10
for win, 01
for ongoing and 00
for illegal. The patterns are:
- Against 0-19, a score of 21 is a win
- Against 20-28, a score of +2 is a win
- Against 29, a score of 30 is a win
- Against any (lower) score, a score of 0-20 is ongoing
- Against a score of up to 28, a score of +1 is ongoing
- Anything else (including negative scores) is illegal
$endgroup$
Retina 0.8.2, 92 bytes
d+
$*
^(10,19,121|(120,28),112|129,130)$|^(1*,10,20|(10,28),1?4)$|.+
$#1$#3
Try it online! Link includes test cases. Takes input in ascending order. Explanation: The first stage simply converts from decimal to unary so that the scores can be properly compared. The second stage contains six alternate patterns, grouped into three groups so that three distinct values can be output, which are 10
for win, 01
for ongoing and 00
for illegal. The patterns are:
- Against 0-19, a score of 21 is a win
- Against 20-28, a score of +2 is a win
- Against 29, a score of 30 is a win
- Against any (lower) score, a score of 0-20 is ongoing
- Against a score of up to 28, a score of +1 is ongoing
- Anything else (including negative scores) is illegal
answered Mar 26 at 20:09
NeilNeil
83.3k745179
83.3k745179
add a comment |
add a comment |
$begingroup$
APL (Dyalog Unicode), 33 32 bytesSBCS
h⍵+1 0+h←(⊢≡31 30|⊢)×21 2∨.≥-
Try it online!
in: a pair in descending order
out: 2=ongoing, 1=ended, 0=invalid
tests stolen from Adám's answer
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 33 32 bytesSBCS
h⍵+1 0+h←(⊢≡31 30|⊢)×21 2∨.≥-
Try it online!
in: a pair in descending order
out: 2=ongoing, 1=ended, 0=invalid
tests stolen from Adám's answer
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 33 32 bytesSBCS
h⍵+1 0+h←(⊢≡31 30|⊢)×21 2∨.≥-
Try it online!
in: a pair in descending order
out: 2=ongoing, 1=ended, 0=invalid
tests stolen from Adám's answer
$endgroup$
APL (Dyalog Unicode), 33 32 bytesSBCS
h⍵+1 0+h←(⊢≡31 30|⊢)×21 2∨.≥-
Try it online!
in: a pair in descending order
out: 2=ongoing, 1=ended, 0=invalid
tests stolen from Adám's answer
edited Apr 1 at 2:25
answered Apr 1 at 2:09
ngnngn
7,47612660
7,47612660
add a comment |
add a comment |
$begingroup$
Bash 4+, 97 89 91 88 bytes
Assume that inputs are ascending. Used concepts from VDM-SL answer. Try it Onlinez==0
- game in progress z==1
- game completed z==2
- invalid
-8 by bracket cleanup from (( & | ))
conditions
+2 fixing a bug, thanks to Kevin Cruijssen
-3 logic improvements by Kevin Cruijssen
i=$1 j=$2 z=0
((j-i>2&j>21|i<0|i>29|j>30?z=2:0))
((z<1&(j>20&j-i>1|j>29)?z=1:0))
echo $z
$endgroup$
1
$begingroup$
Your 89 bytes version seems to output1
instead of2
for0 30
. Your 97 bytes version was working correctly, so if you're unable to fix it, you can always rollback. Upvoted for that 97 version. :)
$endgroup$
– Kevin Cruijssen
Mar 28 at 13:59
1
$begingroup$
This should fix it, and golf a byte at the same time. :)
$endgroup$
– Kevin Cruijssen
Mar 28 at 14:05
1
$begingroup$
I fixed it, but yours was better! Hard to keep up :P
$endgroup$
– roblogic
Mar 28 at 14:14
$begingroup$
Bug at29 30
:( it should be "completed"
$endgroup$
– roblogic
Apr 3 at 8:39
1
$begingroup$
Ah oops.. thei>29
should bej>29
in the second ternary to fix it.
$endgroup$
– Kevin Cruijssen
Apr 3 at 8:42
add a comment |
$begingroup$
Bash 4+, 97 89 91 88 bytes
Assume that inputs are ascending. Used concepts from VDM-SL answer. Try it Onlinez==0
- game in progress z==1
- game completed z==2
- invalid
-8 by bracket cleanup from (( & | ))
conditions
+2 fixing a bug, thanks to Kevin Cruijssen
-3 logic improvements by Kevin Cruijssen
i=$1 j=$2 z=0
((j-i>2&j>21|i<0|i>29|j>30?z=2:0))
((z<1&(j>20&j-i>1|j>29)?z=1:0))
echo $z
$endgroup$
1
$begingroup$
Your 89 bytes version seems to output1
instead of2
for0 30
. Your 97 bytes version was working correctly, so if you're unable to fix it, you can always rollback. Upvoted for that 97 version. :)
$endgroup$
– Kevin Cruijssen
Mar 28 at 13:59
1
$begingroup$
This should fix it, and golf a byte at the same time. :)
$endgroup$
– Kevin Cruijssen
Mar 28 at 14:05
1
$begingroup$
I fixed it, but yours was better! Hard to keep up :P
$endgroup$
– roblogic
Mar 28 at 14:14
$begingroup$
Bug at29 30
:( it should be "completed"
$endgroup$
– roblogic
Apr 3 at 8:39
1
$begingroup$
Ah oops.. thei>29
should bej>29
in the second ternary to fix it.
$endgroup$
– Kevin Cruijssen
Apr 3 at 8:42
add a comment |
$begingroup$
Bash 4+, 97 89 91 88 bytes
Assume that inputs are ascending. Used concepts from VDM-SL answer. Try it Onlinez==0
- game in progress z==1
- game completed z==2
- invalid
-8 by bracket cleanup from (( & | ))
conditions
+2 fixing a bug, thanks to Kevin Cruijssen
-3 logic improvements by Kevin Cruijssen
i=$1 j=$2 z=0
((j-i>2&j>21|i<0|i>29|j>30?z=2:0))
((z<1&(j>20&j-i>1|j>29)?z=1:0))
echo $z
$endgroup$
Bash 4+, 97 89 91 88 bytes
Assume that inputs are ascending. Used concepts from VDM-SL answer. Try it Onlinez==0
- game in progress z==1
- game completed z==2
- invalid
-8 by bracket cleanup from (( & | ))
conditions
+2 fixing a bug, thanks to Kevin Cruijssen
-3 logic improvements by Kevin Cruijssen
i=$1 j=$2 z=0
((j-i>2&j>21|i<0|i>29|j>30?z=2:0))
((z<1&(j>20&j-i>1|j>29)?z=1:0))
echo $z
edited Apr 3 at 8:46
answered Mar 28 at 13:40
roblogicroblogic
1615
1615
1
$begingroup$
Your 89 bytes version seems to output1
instead of2
for0 30
. Your 97 bytes version was working correctly, so if you're unable to fix it, you can always rollback. Upvoted for that 97 version. :)
$endgroup$
– Kevin Cruijssen
Mar 28 at 13:59
1
$begingroup$
This should fix it, and golf a byte at the same time. :)
$endgroup$
– Kevin Cruijssen
Mar 28 at 14:05
1
$begingroup$
I fixed it, but yours was better! Hard to keep up :P
$endgroup$
– roblogic
Mar 28 at 14:14
$begingroup$
Bug at29 30
:( it should be "completed"
$endgroup$
– roblogic
Apr 3 at 8:39
1
$begingroup$
Ah oops.. thei>29
should bej>29
in the second ternary to fix it.
$endgroup$
– Kevin Cruijssen
Apr 3 at 8:42
add a comment |
1
$begingroup$
Your 89 bytes version seems to output1
instead of2
for0 30
. Your 97 bytes version was working correctly, so if you're unable to fix it, you can always rollback. Upvoted for that 97 version. :)
$endgroup$
– Kevin Cruijssen
Mar 28 at 13:59
1
$begingroup$
This should fix it, and golf a byte at the same time. :)
$endgroup$
– Kevin Cruijssen
Mar 28 at 14:05
1
$begingroup$
I fixed it, but yours was better! Hard to keep up :P
$endgroup$
– roblogic
Mar 28 at 14:14
$begingroup$
Bug at29 30
:( it should be "completed"
$endgroup$
– roblogic
Apr 3 at 8:39
1
$begingroup$
Ah oops.. thei>29
should bej>29
in the second ternary to fix it.
$endgroup$
– Kevin Cruijssen
Apr 3 at 8:42
1
1
$begingroup$
Your 89 bytes version seems to output
1
instead of 2
for 0 30
. Your 97 bytes version was working correctly, so if you're unable to fix it, you can always rollback. Upvoted for that 97 version. :)$endgroup$
– Kevin Cruijssen
Mar 28 at 13:59
$begingroup$
Your 89 bytes version seems to output
1
instead of 2
for 0 30
. Your 97 bytes version was working correctly, so if you're unable to fix it, you can always rollback. Upvoted for that 97 version. :)$endgroup$
– Kevin Cruijssen
Mar 28 at 13:59
1
1
$begingroup$
This should fix it, and golf a byte at the same time. :)
$endgroup$
– Kevin Cruijssen
Mar 28 at 14:05
$begingroup$
This should fix it, and golf a byte at the same time. :)
$endgroup$
– Kevin Cruijssen
Mar 28 at 14:05
1
1
$begingroup$
I fixed it, but yours was better! Hard to keep up :P
$endgroup$
– roblogic
Mar 28 at 14:14
$begingroup$
I fixed it, but yours was better! Hard to keep up :P
$endgroup$
– roblogic
Mar 28 at 14:14
$begingroup$
Bug at
29 30
:( it should be "completed"$endgroup$
– roblogic
Apr 3 at 8:39
$begingroup$
Bug at
29 30
:( it should be "completed"$endgroup$
– roblogic
Apr 3 at 8:39
1
1
$begingroup$
Ah oops.. the
i>29
should be j>29
in the second ternary to fix it.$endgroup$
– Kevin Cruijssen
Apr 3 at 8:42
$begingroup$
Ah oops.. the
i>29
should be j>29
in the second ternary to fix it.$endgroup$
– Kevin Cruijssen
Apr 3 at 8:42
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182245%2fvalid-badminton-score%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown