569
\$\begingroup\$

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

Sandbox FAQ

Posting

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

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

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

Discussion

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

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

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

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

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

\$\endgroup\$
0

4562 Answers 4562

1
โ€ฆ
69 70
71
72 73
โ€ฆ
153
1
\$\begingroup\$

Follow the Path

Posted here.

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

Fermat's Last Theorem, mod n

It is a well known fact that for all integers \$p>2\$, there exist no integers \$x, y, z>0\$ such that \$x^p+y^p=z^p\$. However, this statement is not true in general if we consider the integers modulo \$n\$.

You will be given \$n\$ and \$p\$, which are two positive integers with \$n>1\$. Your task will be to write a function or program to compute all positive integers \$x, y, z<n\$ such that \$(x^p+y^p)\$ and \$z^p\$ give the same remainder when divided by \$n\$.

Input

Any reasonable method of input is allowed. E.g. two separate user inputs, ordered pair, two function parameters, etc.

Output

Any reasonable method of output is valid, it may be produced by a function or output to the screen. The order the triples are listed does not matter. Triples such as (1, 2, 3) and (2, 1, 3) are considered distinct, and all distinct triples should be listed exactly once. No invalid/trivial triples such as (0, 0, 0) should be output.

Examples

n p -> Possible Output
----------------------------------------------------------------
2 3 -> []
3 3 -> [(1,1,2),(2,2,1)]
3 4 -> []
4 3 -> [(1,2,1),(1,3,2),(2,1,1),(2,2,2),(2,3,3),(3,1,2),(3,2,3)]

Scoring

Shortest code in bytes with no standard loopholes wins.

\$\endgroup\$
3
  • \$\begingroup\$ I'd wager the average user of this site isn't particularly familiar with the mathematical notion of modulus, compared to the programming concept. I suspect some of them will find the last statement in the intro slightly confusing (my guess thinking that only the RHS is taken in modulus). Beyond clarifying that, I think you should specify in your test cases which parameter is which (i.e. n p -> result as the first line). \$\endgroup\$ Oct 31, 2019 at 19:40
  • \$\begingroup\$ @FryAmTheEggman I have fixed those issues, is there anything else? \$\endgroup\$
    – 79037662
    Oct 31, 2019 at 20:02
  • \$\begingroup\$ I don't see anything beyond adding some more test cases (particularly with larger n). Technically, this could be calculated for large p even if the intermediate results wouldn't work for a particular data type, but I assume you don't want to require that? Other than that it looks good to me, but of course I'm just one person, so I'd still wait a while. \$\endgroup\$ Oct 31, 2019 at 20:22
1
\$\begingroup\$

Sort and Table a Sentence by Word Lengths

In as few bytes as possible, sort the input, a delimited string OR list/vector/array of words containing printable ASCII except space into a table (or something resembling a table). I tried to make the table rules as code friendly as possible to allow golfing and non-golfing languages alike to compete. Table rules are as follows:

  • optional order, shortest to longest or vice versa, letter counts are required
  • formatting is not the challenge, but to repeat the above rule, letter count is required. So as long as the output is some form of numerically labelled rows of words, a numbered list, or a list of lists, or similar output, then it is a satisfactory answer.

  • including/excluding gaps (NA values, see below examples for both methods of output)

  • Word case is untouched. How the word appears in input should be shown in output.

Input 1:

Code Golf and Coding Challenges Meta

Output 1:

 1. NA
 2. NA
 3. and
 4. Code Golf Meta
 5. NA
 6. Coding
 7. NA
 8. NA
 9. NA
 10. Challenges

or

3. and
4. Code Golf Meta
6. Coding
10. Challenges

or

[[3, ['and']], [4, ['Code', 'Golf', 'Meta']], [6, ['Coding']], [10, ['Challenges']]]

Input 2:

My very excellent mother just served us nine pizzas. #JusticeForPluto

Output 2:

1. NA
2. My us
3. NA
4. very just nine (alphabetized version: just nine very)
5. NA
6. mother served pizzas (mother pizzas served)
7. NA
8. NA
9. excellent
10. NA
11. NA
12. NA
13. NA
14. NA
15. NA
16. #JusticeForPluto

or

2. My us
4. very just nine
6. mother served pizzas
9. excellent
16. #JusticeForPluto

or

[[2, ['My', 'us']], [4, ['very', 'just', 'nine']], [6, ['mother', 'served', 'pizzas']], [9, ['excellent']], [16, ['#JusticeForPluto']]]

More examples can be provided if necessary but I think this should suffice for now. Please give me pointers, this is my second attempt at a challenge. (the first failed dramatically)

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Are the letter counts a required part of the output? I would suggest removing the requirement of filtering punctuation and just allow input as a delimited string or array of words. \$\endgroup\$
    – Shaggy
    Nov 10, 2019 at 22:06
  • \$\begingroup\$ @Shaggy That is a very good suggestion. I think that that is a fantastic idea. I'll make the edit. \$\endgroup\$
    – Sumner18
    Nov 11, 2019 at 13:39
  • \$\begingroup\$ @Shaggy I don't see why it would be difficult for letter counts to be required in the output. The idea is to place them in rows of a table that denote the word lengths within its row. \$\endgroup\$
    – Sumner18
    Nov 11, 2019 at 14:04
  • 1
    \$\begingroup\$ I wasn't suggesting they shouldn't be included, but, if they must be included, that you make that clearer in the spec. \$\endgroup\$
    – Shaggy
    Nov 11, 2019 at 14:07
  • 1
    \$\begingroup\$ What constitutes a "table?" Is the formatting you've used required, or is something like this alright? If it isn't, it seems like around half the code in several golfing languages will be devoted to formatting. Is that the intent? \$\endgroup\$ Nov 11, 2019 at 20:34
  • \$\begingroup\$ @FryAmTheEggman Thank you for the suggestion. I don't want formatting to be the focus of the challenge, but rather than just placing words in a list/array/vector with some form of label. Essentially a list of lists as you've done. I'll make the change \$\endgroup\$
    – Sumner18
    Nov 11, 2019 at 22:26
  • 1
    \$\begingroup\$ Thanks for the edits, though I don't think you need to include the program I wrote (it may even be more confusing since not many people read Pyth). I'd also recommend including something saying what class of characters the words will be drawn from, like "printable ASCII except space" or something. \$\endgroup\$ Nov 12, 2019 at 20:54
1
\$\begingroup\$

Sand timer puzzler (code-golf)

I was googling for a sand timer and found this little item: set of joined sand timers, for 3, 4, and 5 minutes each.

That of course reminded me of multiple puzzles about measuring X minutes using only M- and N-minute timers or whatever.

The mission then, if you choose to accept, is:

write a program that takes 3 integer inputs 0<A<B<C<100
and outputs list of all possible times that can be measured
using 3 joined sand timers A, B, and C up to 2 hrs

Test cases:

[in progress]

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Isn't this basically any number that can be formed by some combination of multiples of A, B and C? Some test cases would be nice, and an objective winning criterion (such as code-golf) is mandatory \$\endgroup\$
    – Jo King Mod
    Nov 15, 2019 at 0:23
  • 2
    \$\begingroup\$ I'm not clear what can be done with the timers. Can you flip any timer only when a timer runs out? Can you tell when two timers are the same level? Are the timers joined together like in the picture? If the answer turns out to be any multiple of the GCD of the numbers, I think that would make for a pretty boring challenge. Minor thing: I'd suggest writing "120 minutes" rather than 2 hours. \$\endgroup\$
    – xnor
    Nov 15, 2019 at 8:48
1
\$\begingroup\$

Guessing the subset.

Preface

I've never done a challenge before, so I'd appreciate some help to get this right. In particular, I'm not sure how much I should specify a (language-neutral) API. I'm also not sure how to implement time limits on computation time. (I want to be able to run a trial in seconds, not weeks.)


This challenge is based on Math Stack Exchange question "Guessing a subset of {1,...,N}".

In this challenge, the robber's job is to choose a subset \$R \subseteq \{1,\dots,N\}\$, kind of. Then the cop's job is to deduce the robber's subset by asking questions.


Robber

When I was growing up, I would sometimes play Twenty Questions with my brother. I would pick some sort of animal, and answer his questions about it. However, when he guessed the answer I had in mind, I would try to come up with another animal that satisfied all of the same answers to his questionsโ€”and if I could do it, I would tell him he was wrong.

The robber's job is similar to my strategy in Twenty Questions. The cop will ask the robber questions about the robber's chosen subset, but the robber can keep changing the subset as long as the answers are consistent. The robber's job is trying to answer the questions in such a way as to maximize the number of questions the cop needs to ask, always ensuring that the answers do not contradict each other.

Cop

The cop's job is to successively pick subsets starting with \$C_1 \subseteq \{1, \dots, N\}\$ and ask the question, "Does \$C_1\ = R\$, and if not how many elements do \$C_1\$ and \$R\$ have in common?" (That is, \$|C_1 \cap R|\$.)

If \$C_k = R\$, then the cop has finished the interrogation, and her score is \$k\$. Otherwise, the cop then can use this information to choose a new set \$C_{k+1}\$, and ask the same question for \$C_{k+1}\$.

Rules

Both the cop and robber will be given a number \$N\$, then the cop will go first outputting a subset \$C_1 \subseteq \{1,...,N\}\$. The robber will then take this as an input and output \$|C_1 \cap R|\$. The cop will take this number as an input and output \$C_2\$ and so on.

For a given interrogation both the cop's and robber's score is \$k\$ where \$C_k = R\$ is the last, correct guess. Naturally, the cop is trying to minimize her score while the robber is trying to maximize his.

Each cop will be tested against each robber (perhaps multiple times) with varying values of \$N \leq 1000\$. The score for the cop and robbers will be the sum of the scores over all interrogations.

\$\endgroup\$
1
  • \$\begingroup\$ I wish N was at most 24 so we can brute-force for 'giving the least information' answer as robber over 16M possible sets and then narrowing the set. Also consider this \$\endgroup\$ Nov 26, 2019 at 21:25
1
\$\begingroup\$

Name the hydrocarbon

A hydrocarbon is a chemical compound which consists of only hydrogen and carbon atoms. For this challenge, we will only consider the three simplest kinds of hydrocarbons: alkanes, alkenes, and alkynes with no branches.

An alkane with \$n\$ carbon atoms contains \$2n+2\$ hydrogen atoms. An alkene with \$n\$ carbon atoms contains \$2n\$ hydrogen atoms. An alkyne with \$n\$ carbon atoms contains \$2n-2\$ hydrogen atoms.

Each kind of hydrocarbon is named with a prefix indicating the number of carbon atoms it contains, followed by the suffix ane, ene, or yne if it is an alkane, alkene, or alkyne respectively. The numerical prefixes are as follows:

1  -> meth
2  -> eth
3  -> prop
4  -> but
5  -> pent
6  -> hex
7  -> hept
8  -> oct
9  -> non
10 -> dec

For example, we can see propane has 3 carbon and 8 hydrogen atoms, and heptyne has 7 carbon and 12 hydrogen atoms.

Challenge

Your task is to write a function or program that receives two integers, representing a number of carbon and hydrogen atoms, and produces or outputs the name of the corresponding hydrocarbon. Capitalization does not matter, and leading/trailing whitespace is allowed.

The input and output can be in any convenient format. You may assume the input will correspond to a valid hydrocarbon, and there are at most 10 carbon atoms.

Examples

Input -> Output
1 4   -> Methane
3 8   -> Propane
7 12  -> Heptyne
10 20 -> Decene

Rules

  • No standard loopholes.
  • Shortest code in bytes wins.

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

Numbers without 'E'

In this trial, I wish for us to think only of digits and digit compounds, from two to six trillion. If any in this group contains, in a plain Latin writing form, an indication of what our prompt prohibits, it is cast out of this group.

If a digit or digit compound contains 100, 1000, or similar, "1" is not a part of its plain Latin writing form. 1000 would simply boil down to "thousand", although 4000 is "four thousand".

What you must do:

Taking an input of N, in which N is not as high as 1000, nor as low as 0, (0 < N < 1000), and in which N is an ordinal, output what N points to in an array that follows our titular prompt.

Additionally, your solutions may contain only a solitary count of this cast out latin symbol (including diacritical marks and such, although this should not dismay you too much).

Your aim is to do this with a minimum bit count in your program.

This following portion is for clarification on what I am in pursuit of: 1 -> 2 (two) 3 -> 6 (six) 5 -> 32 (thirty two) 22 -> 1004 (thousand four) 100 -> 30 000 (thirty thousand)

Meta:

As you may have noticed, this is a little hard to read. I tried to spice it up by excluding any instance of the letter 'e' from the text description.

  • Should the challenge be changed to "evaluate if a number contains 'E'"? This is an alternative idea Id considered but Im not sure if it would make a better challenge
  • Does eliminating all instances of 'e' from the description make this challenge unreadable?
  • Does the additional challenge of only having 1 'e' in the solution add too much to the challenge?
  • Are the bounds too restrictive/not restrictive enough?
\$\endgroup\$
2
  • 3
    \$\begingroup\$ Hi there! These are called "Eban" numbers, and essentially has already been asked; the difference being you're asking for the nth number, while the linked question is asking for the first n. \$\endgroup\$ Dec 2, 2019 at 20:25
  • 1
    \$\begingroup\$ @AdmBorkBork I see, I had searched for similar questions but couldnt find anything. Thanks for letting me know. \$\endgroup\$
    – frank
    Dec 2, 2019 at 20:29
1
\$\begingroup\$

What's that frequency?

This is my first code-golf challenge, so apologies if it is a little unclear/already has been done. I gave the past challenges a good look over, but I may have missed something.

Create a function or a full program which accepts a frequency value, and then outputs the closest musical note, and the octave, this frequency corresponds to.

This function/program should support eight full octaves worth of notes, starting from C0 up to and including B8.

Test cases:

440.00 -> A4
466.16 -> A#4
466.20 -> A#4
261.63 -> C4
16.35 -> C0
0.00 -> C0
7902.13 -> B8
10000.00 -> B8

A full list of frequencies and notes they correspond to can be found here: https://pages.mtu.edu/~suits/notefreqs.html

This is a code golf, so shortest code wins!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Thanks for using the sandbox! :) I found the inverse challenge. I feel as though I've reviewed this version as well, but perhaps it never left the sandbox. In any case, you should include a method by which to classify the frequencies, and what precisely you mean by closeness in the body of your challenge. External links are nice but not enough! \$\endgroup\$ Dec 5, 2019 at 14:58
  • \$\begingroup\$ Great idea! Just make sure to flesh out the rules: perhaps specify that A=440Hz and that each note is 2 ^ (1/12) times the note below it (if I'm remembering my music theory correctly). \$\endgroup\$
    – FlipTack
    Dec 27, 2019 at 14:18
  • \$\begingroup\$ You may also want to consider adding some tags: music, code-golf \$\endgroup\$
    – FlipTack
    Dec 27, 2019 at 14:19
1
\$\begingroup\$

plan an efficient finnish bus stop on a sphere

Apparently respecting personal space is very important at finnish bus stops. Now given some "minimum-personal-space-angle" \$\vartheta\$, your job is designing a bus stop on a sphere for as many people as possible respecting the "minimum-personal-space-angle".

Let us rephrase this a little bit more clearly: Let \$S^2 = \{x \in \mathbb R^3 \mid \Vert x \Vert_2 =1 \}\$ be the unit sphere in \$\mathbb R^3\$. Given the angle \$\vartheta \in (0,\pi)\$ you should find a set \$U \subset S^2\$ such that all pairs of vectors \$x,y \in U\$ (\$x \neq y\$) are at least an angle of \$\vartheta\$ apart, that is \$x \cdot y \leqslant \cos \vartheta\$.

And this set \$U\$ should be as large as possible - but this does not mean that your program needs to find the largest possible \$U\$ (this is a hard unsolved problem), but it should try to make it as large as possible as this will be part of the score.

Let us define \$a_\vartheta = \vert U \vert\$ as the number of vectors your program found for \$\vartheta\$.

The score \$s\$ of your submission will be

$$ s=\frac{1}{N}\sum_{n=1}^N a_{\vartheta_n} w_n$$

where \$\vartheta_n = 1/n\$, \$w_n = 1/n^2\$. And you can choose \$N \in \mathbb N\$ as large as you want.

Inspired by this reddit thread.

META:

I think the choice of \$\vartheta_n\$ and \$w_n\$ needs some fine tuning to make the challenge interesting. My thoughts so far: The idea is that \$a_{\vartheta} \leqslant c \frac{1}{\vartheta^2}\$ since every vector on the sphere needs a circle of a radius that is at least \$\vartheta/2\$, so the area of such a circle is about \$\pi (\vartheta/2)^2\$ which means we can fit at most \$\frac{4\pi}{\pi (\vartheta/2)^2} = \frac{1}{\vartheta^2}\$ (just as a rough estimate).

So I think with current choice of \$\vartheta_n\$ and \$w_n\$ the score should be bounded. But I fear that with the current choice of these sequences the greatest score will be achieved by a relatively simple solution where someone just chooses \$N=1,2\$ or so.

Can we alleviate this by adding a factor of \$\log n\$ to \$w_n\$? Unfortunately I think this would incentivise using very large \$N\$.


EDIT: Instead of using \$\log n\$ I think using a bounded increasing sequence would work. E.g. \$(1-1/n)\$ so \$w_n = \frac{1}{n^2}(1- \frac{1}{n})\$.


If you have any thoughts or ideas, please share!

\$\endgroup\$
4
  • \$\begingroup\$ I didn't have time to actually think about this challenge, but my first reaction is that it seems weird to let the solver choose N. Might balancing the scoring be easier if you pick some value high enough to be interesting and specify it in the challenge? \$\endgroup\$
    – xnor
    Nov 30, 2019 at 10:02
  • \$\begingroup\$ @xnor thanks for the feedback! I thought maybe some answers would include very inefficient algorithms. While I cannot directly prevent those, I thought it would be a nice idea to try to discourage them via the scoring method. So ideally you'd get the best solution every time, and if not, get solutions that are as good as possible for the most possible n. I know it looks quite convoluted:) \$\endgroup\$
    – flawr
    Nov 30, 2019 at 23:47
  • \$\begingroup\$ This seems neat, but I did stumble at one point in understanding. You say \$ a_{\vartheta} \$ is what the program found, which led me to believe this value was going to be fixed in the scoring. I think if you change it to "finds" it will be pretty immediately clear that what I thought isn't correct. Also, assuming I'm reading correctly we never consider angles greater than 1 radian, which is a tad surprising following the definition (not really a problem, just something I noticed). \$\endgroup\$ Dec 5, 2019 at 18:54
  • \$\begingroup\$ @FryAmTheEggman Yes this is correct. For \$\vartheta=\pi/2\$ the optimal \$a_\vartheta\$ is 6 (octahedron). For \$\vartheta \approx 0.9680399...\$ the optimal number is \$a_\vartheta=12\$ (icosahedron), so \$\vartheta=1\$ must be somewhere in between, and my thinking was that for angles this large, optimal solutions can easily be found. But it would easily be possible to define a totally different sequence for \$\vartheta_n\$ - if you have a suggestion let me know! \$\endgroup\$
    – flawr
    Dec 5, 2019 at 20:06
1
\$\begingroup\$

Roll for Initiative!

Tags:

Introduction

In tabletop games like Dungeons and Dragons, when you begin a battle, all involved parties roll for initiative. In DnD 5e, this is 1d20 + DEX + Other bonuses, where DEX is the bonus given by your Dexterity stat. The characters that roll higher numbers go first. We'll use a similar, deterministic system in this challenge.

The Challenge

Write a program or function that, when given a list of characters, will output a list of characters in order of initiative.

A character is defined as this:

character = {
    name: "name" // a string
    statblock: [SPD, DEX, WHT] // a list of numbers
                               // DEX = dexterity, SPD = speed, WHT = weight
}

The formula for initiative is the following: $$\text{Initiative} = \left\lfloor{ \frac{\text{SPD}^2}{\sqrt{\lvert\text{DEX}\rvert}} }\right\rfloor - \text{WHT}$$

Input

A list of characters, unsorted. This can be a JSON object, a list of lists, a list of dictionaries, a series of strings etc.

It is guaranteed that all names will be unique.

Output

A list of characters, or character names, sorted by initiative order from highest to lowest, based on the above formula.

Rules

Sample IO

Input --> Output
[[Name, SPD, DEX, WHT], ...]
    --> [[Name, SPD, DEX, WHT], ...] (or [Name, Name, ...])
---------
[[Alice,1,2,3],[Bob,10,5,0],[Charlie,3,2,1]]
    --> [Bob, Charlie, Alice]
// Alice = -3, Bob = 44, Charlie = 5

[[Z,1,1,1],[B,1,1,1],[XY,5,1,1]]
    --> [XY, Z, B]
// Retain the order of characters from the input if they have the same initiative.
// Z = 0, B = 0, XY = 24

[[Neg,-3,-3,-1],[SomeNeg,5,-2,-4],[NoNeg,4,6,8]]
    --> [SomeNeg, Neg, NoNeg]
// Negative values are valid.
// Neg = 6, SomeNeg = 13, NoNeg = -2

[[Flo,1.5,2.5,3.5],[MoreFlo,2,2.5,3.5]]
    --> [[MoreFlo,2,2.5,3.5], [Flo,1.5,2.5,3.5]]
// Floats are also valid.
// Flo = -2.5, MoreFlo = -1.5

[[Lonely,1,2,3]]
    --> [[Lonely,1,2,3]]
// Input with 1 item.

[]
    --> []
// Empty input leads to empty output.
\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can use \left and \right in mathjax to make your brackets the right size. I also think that the output format is a little pointlessly strict - why not also allow just the list of names (same with requiring stable sorts)? \$\endgroup\$ Dec 4, 2019 at 23:11
1
\$\begingroup\$

Count the length of head movement

Moved here

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

Sort By the New Alphabet

The order of the alphabet is really quite arbitrary. I propose a new ordering of the alphabet, ordered so that adjacent letters (in capital form) are similar in shape. Here is the order:

JUOQGCDPRBEFTILVYXKHAMWNZS

Of course, this makes a lot of previously written code redundant. To fix this problem we will start re-implementing that code, in its updated form.

Your task is to create a program or function that takes a string or list of characters as input, and outputs that string/list sorted according to this new ordering.

You can assume that all input will contain only uppercase alphabetic characters.


I know it's similar to this and this, but this challenge has a fixed ordering, so I hope this allows for some more ingenuity as well as the requirement to store the ordering efficiently.

\$\endgroup\$
2
  • \$\begingroup\$ Is uppercase mandatory, or are we allowed to take both input and store the compressed alphabet as lowercase? \$\endgroup\$ Dec 16, 2019 at 9:36
  • \$\begingroup\$ You can store the alphabet however you want. You can accept input as upper or lowercase. \$\endgroup\$ Dec 16, 2019 at 20:42
1
\$\begingroup\$

edit: check it out live here!

Play Big 2 by yourself, as fast as you can

\$\endgroup\$
9
  • \$\begingroup\$ Seems a good first go. There is one major ambiguity I can find: You don't explain if aces are high or low. From your straight explanation, I guess they can be both, but you can't 'wrap' around. Please add an explanation about that. Also, the straight flush, while a Poker hand, isn't required algorithmically: It's a subset of both straights and flushes, so any algorithm detecting them will also catch the straight flush. \$\endgroup\$ Nov 18, 2019 at 8:01
  • \$\begingroup\$ Consider 3352 ['8C', '7C', '4C', '0C', 'AC'] 3966 ['4H', '6D', '3S', '5H', '2S'] 8063 ['AS', 'AH'] 8191 ['8D'] for the first test \$\endgroup\$ Nov 18, 2019 at 14:00
  • \$\begingroup\$ tinyurl.com/cgm-a18285-1 -- tio (may run more than \$1\$ min for \$hands\ge7\$) \$\endgroup\$ Nov 18, 2019 at 14:17
  • \$\begingroup\$ @AlienAtSystem you're right - aces can be used as a high or a low, but they can't appear in the 'middle' of a straight, so to say. I'll update the straight description. Re: the straight flush - yeah I figured this too, mostly adding it for the sake of completion. I'll also make a note about that. Thanks for reading through it! \$\endgroup\$
    – aphrid
    Nov 18, 2019 at 15:08
  • \$\begingroup\$ @AlexeyBurdin ack, you're right! I came up with the suiting on a whim and didn't really sit down to consider if it was possible to dump the hand faster. Oops. I meant to use the first test case as a general explanatory case, so I'll update my tests to reflect that. (Also, it seems like your tinyurl link is broken...) \$\endgroup\$
    – aphrid
    Nov 18, 2019 at 15:10
  • \$\begingroup\$ tinyurl.com/cgm-a18285-2 -- I use bfs with early exit if goal reached, so it can't be done faster(in words of move numbers, not computation time). ) \$\endgroup\$ Nov 18, 2019 at 16:22
  • \$\begingroup\$ @AlexeyBurdin Hmm, I still can't seem to use that link, but I appreciate your attempts nonetheless \$\endgroup\$
    – aphrid
    Nov 18, 2019 at 17:34
  • 1
    \$\begingroup\$ One more )) tiny.cc/cgm_a18285_2 \$\endgroup\$ Nov 18, 2019 at 18:33
  • \$\begingroup\$ That link works like a charm, great work! \$\endgroup\$
    – aphrid
    Nov 18, 2019 at 18:56
1
\$\begingroup\$

Challenge posted to Main here

\$\endgroup\$
12
  • \$\begingroup\$ I'd say this is very close to being a dupe of the Fibonacci challenge. Often one could pretty directly replace the (inc/dec)rement with a divisibility check. The specific nature of the Fibonacci challenge allows a lot of tricks that wouldn't work as well here, though. \$\endgroup\$ Dec 9, 2019 at 20:48
  • \$\begingroup\$ Could you link to that challenge? \$\endgroup\$ Dec 9, 2019 at 20:50
  • \$\begingroup\$ Here you go. \$\endgroup\$ Dec 9, 2019 at 20:51
  • \$\begingroup\$ Hmm, I see. Is there a way to modify this to invalidate more answers from that question? Maybe a new winning criterion? \$\endgroup\$ Dec 9, 2019 at 20:54
  • \$\begingroup\$ You could try something like scoring each submission by the sum of each byte's smallest Fibonacci multiple? That's kind of a lazy fix (and you need to deal with null bytes, lenguage, etc.) but it could work. You can try asking in chat for more ideas, and of course if I think of anything I'll let you know :) \$\endgroup\$ Dec 9, 2019 at 20:56
  • \$\begingroup\$ @FryAmTheEggman How do you like the update? \$\endgroup\$ Dec 9, 2019 at 23:46
  • \$\begingroup\$ I don't think your precise method of scoring is ideal, it seems like it could be abused to get a score of zero too easily. I recommend scoring actual bytes, not the unicode characters they turn into. \$\endgroup\$ Dec 10, 2019 at 5:55
  • \$\begingroup\$ @FryAmTheEggman Hmm, sorry for bugging you, but how would you suggest doing that? I'm not sure I see the picture. \$\endgroup\$ Dec 10, 2019 at 6:23
  • \$\begingroup\$ I guesss something like Lenguage could come in and have a program full of spaces, henceforth getting a score of 0. \$\endgroup\$
    – lyxal
    Dec 10, 2019 at 10:30
  • \$\begingroup\$ @Jono2906 I don't know how to modify this to make this work, frankly. \$\endgroup\$ Dec 10, 2019 at 18:45
  • \$\begingroup\$ No worries, and I recommend not worrying too much about Lenguage and the like, they are often kind of impossible to fix. What I mean is, the characters used in code are ambiguous and not particularly meaningful. Instead, score based on the bytes of the program, which are clear and fixed. Then keep the part with the fib multiples, but add one to the bytes beforehand to avoid zero. \$\endgroup\$ Dec 10, 2019 at 20:24
  • \$\begingroup\$ @FryAmTheEggman Makes sense! I'm pretty happy now with where this challenge is at. \$\endgroup\$ Dec 10, 2019 at 22:38
1
\$\begingroup\$

Expand a road network


You've been employed as a city planner (obligatory seinfeld clip) and you have been tasked with expanding the road system of Codegolfville. Here's a diagram of what Codegolfville could look like:

        | |
        | |
--------+ +-------
--------+ +-------
        | |
        | +-------
        | +-------
        | |
        | |

Your job is to expand the existing infrastructure \$n\$ blocks in a specific direction.

The Challenge

  1. Take two inputs - a direction to expand in, and the number of blocks to expand - through any reasonable input format.

  2. Expand the existing roadways in the ASCII map, in the direction specified.

    a. You must take into account the existing roadways - you can only expand on roads that are already there, and if there are no roads to expand, you won't expand anything.

    b. Your program must work for any example map, not just the one provided above.

  3. Show the output on STDOUT, if your language supports it.

Test Cases

        will be done soon

Other Rules

This is , so lowest score in bytes wins. Standard loopholes are forbidden. Have fun!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Are blocks a fixed dimension or is it based on the size of the input? Does it expand in only one direction or can it be multiple? Finally, what does expansion mean? Are we replicating the block n times? Merely extending the roads on the expanding edge (i.e. appending n*width - or |s)? \$\endgroup\$
    – Veskah
    Dec 11, 2019 at 14:21
1
\$\begingroup\$

Union of Two Polygons

Given two intersecting polygons as input, output a third polygon that is the union of the two input polygons, that is to say, the perimeter that encloses all points present in at least one of the two input polygons.

Example polygon unions

Example inputs/outputs

2 Squares

  [(0, 0), (0, 2), (2, 2), (2, 0)]
| [(1, 1), (1, 3), (3, 3), (3, 1)]
==> [(0, 0), (0, 2), (1, 2), (1, 3), (3, 3), (3, 1), (2, 1), (2, 0)]

... more to come

Notes and Rules

  • Input will be two lists of at least 3 2d points each, taken in any convenient format.
  • Output should be a list of 2d points, in any convenient format.
  • It does not matter which point you list first.
  • It does not matter whether you output in clockwise or counterclockwise order.
  • Polygons may be concave
  • You may assume that both polygons are not self-intersecting
  • You may assume that the polygons overlap in at least two places exclusively via edge-edge crossings rather than vertex-edge intersections, vertex-vertex intersections, or flush edge-edge overlaps.
  • You may assume that the polygons do not overlap in such a way that the union would have at least one hole in it.
  • You must be accurate to at least 0.01 for all polygons between -100 and 100 units along each axis.
  • Standard rules apply. Shortest code wins.

\$\endgroup\$
1
  • \$\begingroup\$ Can you add some examples? \$\endgroup\$ Dec 13, 2019 at 16:01
1
\$\begingroup\$

Make an "implicit" parser

In this task, given an infix expression, fill in all of the implicit inputs and evaluate this expression with the other given input. (You only need to deal with (+, -, and ().)

Expressions are only allowed to be dyadic and not monadic. If an operator is monadic, prepend an input.

What do I do?

The rule is simple: if something is preceded with a nilad or a parenthesized expression, it is a dyad.

+ is a dyad here:

2 + 1
(5 + 2)
3 + ((2) + 4)

Otherwise, the operator is a monad.

+ is a monad here:

 +(2 - 2)
(+ 2)

If you find a monad in your code, immediately prepend it with the a character.

a +(2 - 2)
(a+ 2)

That's about it.

Examples

The input expression is guaranteed to not produce errors, such as the format 2- which is impossible to prepend an input.

"+++a",2 -> a+a+a+a = 2+2+2+2 = 8
"(+1)+(-1)",5 -> (a+1)+(a-1) = (5+1)+(5-1) = 10
"+(2-a)", 3 -> a+(2-a) = 3+(2-3) = 2
"(5+2)+2+1", 7 -> (5+2)+2+1 = 10
"--2", 2 -> a-a-2 = 0-2 = -2

Rules

  • This is , so the shortest code wins.
  • Standard loopholes are disallowed.
\$\endgroup\$
4
  • \$\begingroup\$ I've been thinking of making a challenge to parse a simple subset of APL e.g. numbers and + and - and /, but what does your challenge have to do with APL? APL doesn't have implicit arguments for nilads, and a+(2-) is a syntax error in most dialects. \$\endgroup\$
    – Adám
    Dec 15, 2019 at 9:16
  • \$\begingroup\$ @Adám (You said nilad, I assume you meant monad.) 1. I assume scanning for nilads was how APL was parsed. Correct me if I am wrong. 2. Although APL doesn't provide arguments, the only less trivial way I can think of compared to outputting how many arguments an operator has is to provide the arguments. Do you have a better way to do this? 3. To simplify the challenge, preventing syntax errors is unneccecary. \$\endgroup\$
    – user85052
    Dec 15, 2019 at 9:43
  • \$\begingroup\$ Yeah, sorry about the "nilad" instead of "monad". 1. That's wouldn't work. 2. How about simply evaluating a given expression consisting of `[-+/ 0-9]? That's easy to verify against a real interpreter. 3. Just guarantee that the input expression has no errors. \$\endgroup\$
    – Adám
    Dec 15, 2019 at 9:48
  • \$\begingroup\$ What is the correct answer for "--2",2? \$\endgroup\$
    – Adám
    Dec 15, 2019 at 10:48
1
\$\begingroup\$

Asyncronous Breakfast

I haven't seen any asyncronous challenges here, even tho it's an important part of coding, so here's my idea, based on an example (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/) that explains asyncronous coding:

You are making breakfast. The things you want to serve are:
Cooked eggs, Bacon, Coffee, Orange Juice and Toast.

You start boiling the eggs, cooking the bacon, making coffee, and toasting toast. 
When everything is finished, you're serving the orange juice.

After every finished food, the console outputs "[Food] is ready."
\$\endgroup\$
2
  • 1
    \$\begingroup\$ I think you should generally only specify things about the input and the output, and not the program's internal behaviour ("do addition without the + operator"-like questions are now discredited). Can you define a required output in a way that the only way to produce it is for the program to run asynchronously? \$\endgroup\$
    – KeizerHarm
    Dec 16, 2019 at 14:29
  • 1
    \$\begingroup\$ How about checking the multi-threading tag? \$\endgroup\$
    – Adám
    Dec 16, 2019 at 22:03
1
\$\begingroup\$

Blackjack

This is kept fairly simple, compared to a real Blackjack-Game:

Write a program that creates a blackjack game, where the input "h" means "hit" and "s" means "stand". Everything else outputs nothing, it just waits for the right input.

Rules:
- You can draw as many cards as you want, also to make it easier, there is no card limit.
  This means you could draw more than 4 Asses.
- The cards you can get are
  standard-cards (2-10, J, Q, K, A) where the Values are the default ones:

2-9 = 2-9,
10, J, Q, K = 10

- A is a special card. So to make it easy, the default value is 11.
  If a player gets over 21, the value gets reduced to 1.
  In the case that a player has two or more A-Cards, all but one A
  reduces to 1, giving a total value of 14 for 4 Asses. (11+1+1+1)

- The dealer needs to get in between 18-21. If the bank has reached a value in 
this radius,
it can't draw another card (For example: Bank reached 18.
                          It can't get another card to get closer to 21)

- The game runs forever
- hit means โ€ždraw another cardโ€œ, stand means โ€žstop with cards and wait for 
the dealer to reach his limitโ€œ

Procedure:

- The player gets 2 cards at the beginning, shown by "Player:" in the console 
  (Example: Player gets 2 and 5 at the beginning. 
  Console output: "Player: 2, 5").

- The cards can be shown in the console by their values
  (For example: 2, 10, 1 | No need for: 2, K, A), but you can also use 
  the card-names instead. Your choice. But you need to show the maximum
  value you have
  (for example:
  first draw console output "Player: 2, 4, 5 = 11",
  second draw console output "Player: 2, 4, 5, 7 = 18")

- The input by the player is "h" for "hit" and "s" for "stand". Also allowed 
  is 1 and 0

- In the console, the player is displayed by "Player:"
- In the console, the dealer is displayed by "Dealer:"

- After the player got two cards, the dealer gets one card.
  Then the player can hit or stand.
  After every card drawn from the player,
  the dealer gets another card until he reaches his limit. (18-21)

  If the dealer reaches 21 before the player does, the dealer wins.
  If the Player reaches 21 first, the player wins.
  If the dealer reached his limit, and the player stands on the same value, it's a draw.
  If the dealer is over 21 first, the player wins.
  If the player is over 21 first, the dealer wins.

- At the end you get the output "Win", "Lose", "Draw",
  or "Blackjack", depending on the game

This game is a challenge, even the smallest result won'tbe under 150 bytes at least

\$\endgroup\$
7
  • \$\begingroup\$ @Noodle9 1. If you want to write 'h' and mistype, then you basically ruined your win 2. Blackjack rules: win = more points than dealer or Blackjack | lose = less points than Dealer | draw = same points as dealer | Blackjack = 21 points straight | 3. As it's the easy version there is only one hand, will add that \$\endgroup\$ Dec 16, 2019 at 18:14
  • \$\begingroup\$ Do you know blackjack? You draw cards and try to get as close to 21 as possible. If you get 21 you already have won the game. if you get 20 you could still draw a card, maybe it's an Ass. But you still need to get higher points than the dealer, but not more than 21 \$\endgroup\$ Dec 16, 2019 at 18:37
  • \$\begingroup\$ if you play with 52 cards you could draw up to 7 cards (4*Ass+ 3*2 = 20) \$\endgroup\$ Dec 16, 2019 at 18:38
  • \$\begingroup\$ Yes I've played the game T_T But questions/challenges need to be self-contained with a full explanation for anyone who's doesn't know the game. Also you should edit your sandbox to include the things above. \$\endgroup\$
    – Noodle9
    Dec 16, 2019 at 19:59
  • \$\begingroup\$ If a player gets over 21, the value gets reduced to 1. this contradicts the bit below of all but one A reduces to 1, giving a total value of 14 for 4 Asses. (11+1+1+1) \$\endgroup\$
    – Corsaka
    Dec 20, 2019 at 22:36
  • \$\begingroup\$ @Corsaka It doesn't. First ace you have 11, second ace makes that 22 so it gets reduced to 12, third ace makes that 23 so it gets reduced to 13, forth ace makes that 24 so it gets reduced to 14. \$\endgroup\$
    – Noodle9
    Jan 3, 2020 at 21:48
  • \$\begingroup\$ Ah, I misread that. Apologies. \$\endgroup\$
    – Corsaka
    Jan 5, 2020 at 13:20
1
\$\begingroup\$

Decorate the Christmas Tree

Tags:

Intro

It's a week before Christmas and the your family just bought a Christmas tree. Your little sister has a box of ornaments which she wants you to decorate the tree with.

Challenge

Write a function or program to randomly decorate the tree with all the ornaments from the box. All possible arrangements of ornaments on the tree must have a non-zero probability of occurrence.

Input

  1. height of the tree n
  2. 'box' of ornaments (a string of printable ascii characters where each character represents an ornament) in which order doesn't matter. Also, you can assume that '#' will not show up as an ornament since it is used to draw bare branches.

Given the number of branches on a tree of size n is (n-1)^2 you can assume that the number of ornaments in the box will be less than or equal to the number of branches on the tree.

Example of a box of ornaments: o = '**@@***@@$$**OOOO....'. Since this string is 21 characters long it can only be valid input for n > 5.

Output

Print out the tree with its decorations

The tree is the following structure of ascii characters where n specifies the height of the tree:

//Tree where n=9                         //Tree where n=6
        #                                        #
       ###                                      ###
      #####                                    #####
     #######                                  #######
    #########                                #########
   ###########                                  |||
  #############
 ###############
       |||

Bare branches will always be represented with '#' and the bottom trunk is always ||| while centered with center character of each row.

Examples of output with ornaments:

//n=9, o='X@@X%%%**&&'                   //n=6, o='OO*X*X'
        #                                        O
       ##%                                      O##
      #X###                                    #X#*#
     ###@##%                                  *######
    #&#######                                #####X###
   #@######X##                                  |||
  #####%##*####
 ##*######&#####
       |||

Rules

Meta

  • Is this too close to a duplicate?
  • Are there any improvements or clarifications required?
\$\endgroup\$
8
  • 2
    \$\begingroup\$ By random, do you mean that every possible distribution of decorations should be equally likely? Or just that the distribution changes with each run? \$\endgroup\$
    – frank
    Dec 17, 2019 at 20:10
  • 1
    \$\begingroup\$ What does the tree look like if n is even? That is, how does the trunk center? \$\endgroup\$ Dec 17, 2019 at 20:14
  • \$\begingroup\$ Every level of the tree will have an odd number of characters, no matter what the value of n is, so the trunk should remain centered with the top level of the tree. \$\endgroup\$
    – Grumpy_Boy
    Dec 17, 2019 at 21:09
  • \$\begingroup\$ What can you put in the box of ornaments? Printable ascii characters? Unicode? Also, what if there's more ornaments than there is area of tree to put them on? \$\endgroup\$
    – KeizerHarm
    Dec 17, 2019 at 22:41
  • 1
    \$\begingroup\$ To add to frank's comment: codegolf.meta.stackexchange.com/a/10909/36398 \$\endgroup\$
    – Luis Mendo
    Dec 17, 2019 at 23:14
  • 1
    \$\begingroup\$ Regarding "a string of printable ascii and/or unicode characters" You should know that handling unicode (millions of possible characters, from Urdu ุงูุฑุฏููˆโ€Ž to cuneiform ๐’€ฃ) is a lot harder in many golfing languages than printable ascii (which is mostly just the Latin alphabet and some punctuation marks) - to the point where using the tag unicode is advisable if you want the solution to handle unicode characters. If you want the possibility to handle every conceivable tree decoration, you should be more explicit about it than use an and/or construction. \$\endgroup\$
    – KeizerHarm
    Dec 18, 2019 at 9:20
  • 1
    \$\begingroup\$ Fair enough. Sticking to printable ascii should be fine then. \$\endgroup\$
    – Grumpy_Boy
    Dec 18, 2019 at 22:44
  • \$\begingroup\$ This feels very familiar; I think we may have had it before but, maybe, without the inputs. \$\endgroup\$
    – Shaggy
    Dec 18, 2019 at 23:54
1
\$\begingroup\$

For any integer a and any positive odd integer n the Jacobi symbol is defined as follows: $$ \left(\frac{a}{n}\right) = \left(\frac{a}{p_1}\right)^{\alpha_1} \left(\frac{a}{p_2}\right)^{\alpha_2} \cdots \left(\frac{a}{p_k}\right)^{\alpha_k} $$ where $$n = p_1^{\alpha_1}p_2^{\alpha_2}\cdots{p_k^{\alpha_k}}$$ is the prime factorization of n. The Legendere symbol is defined for all integers a and odd primes p as $$\left(\frac{a}{p}\right) = \begin{cases} 0 & \text{if $a \equiv 0 \pmod{p}$},\\ 1 & \text{if $a \not\equiv 0 \pmod{p}$ and for some integer $x$: $a \equiv x^2 \pmod{p}$},\\ -1 & \text{if $a \not\equiv 0 \pmod{p}$ and there is no such $x$}. \end{cases} $$

Your task is to write a function that will take two parameters: a and v, where a is a positive integer, and v is a list of n values. The function should return the index of the first value in v for which the Jacobi symbol is -1. For this challenge, you may assume that all values in the v array are odd primes, and are greater than or equal to a. The length of v will be between 4 and 100 values. If no value in v produces a -1 result for the Jacobi symbol, simply return the length of v.

Because each invocation of the function will execute very quickly, your function will be tested against a wide variety of inputs and the execution time will be summed. This process will be repeated 50 times and the best execution time will serve as your score. My machine is a 2018 Macbook Pro, with the following specs:

CPU: Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
machdep.cpu.features: FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 CLFSH DS ACPI MMX FXSR SSE SSE2 SS HTT TM PBE SSE3 PCLMULQDQ DTES64 MON DSCPL VMX EST TM2 SSSE3 FMA CX16 TPR PDCM SSE4.1 SSE4.2 x2APIC MOVBE POPCNT AES PCID XSAVE OSXSAVE SEGLIM64 TSCTMR AVX1.0 RDRAND F16C
machdep.cpu.leaf7_features: SMEP ERMS RDWRFSGS TSC_THREAD_OFFSET BMI1 HLE AVX2 BMI2 INVPCID RTM SMAP RDSEED ADX IPT SGX FPU_CSDS MPX CLFSOPT
GPU: Intel UHD Graphics 630 1536MB
RAM: 32GB 2400MHz DDR4

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

Even-Odd chunks

(Inspired by the Keg utility of this challenge)

Given an input string, e.g. s c 1= e(a"E"), split the input into even-odd chunks.

Example

This input string, when mapped to its code points, yields the list [115, 32, 99, 32, 49, 61, 32, 101, 40, 97, 34, 69, 34, 41]. When applied modulo-2 for every item, this returns [1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1].

In this list let's find the longest possible chunk that is consistent with even and odd code points:

[1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1]

For the first chunk, this yields [1, 0, 1, 0, 1] because this is the longest chunk that follows the pattern

Odd Even Odd Even Odd Even ...

or

Even Odd Even Odd Even Odd ...

. Adding another codepoint into [1, 0, 1, 0, 1, 1] breaks the pattern, therefore it is the longest possible even-odd chunk that starts from the beginning of the string.

Using this method, we should split the input into chunks so that this rule applies. Therefore the input becomes (the ; here is simply a separator; this can be any separator that is not an empty string):

s c 1;= e(a"E")

Rules

  • This is so the shortest solution wins. Let it be known that flags don't count towards being in the pattern. They also don't count towards byte count in this challenge.
\$\endgroup\$
2
  • \$\begingroup\$ Right now, the output specified in the introduction (Longest even-odd chunk) doesn't agree with the example, where you have instead the string split into even-odd chunks. Both would work as challenge, but you have to choose which. \$\endgroup\$ Dec 21, 2019 at 12:24
  • \$\begingroup\$ I chose the latter because it is easier to specify. \$\endgroup\$
    – user85052
    Dec 21, 2019 at 12:30
1
\$\begingroup\$

Convert Character Substrings to Numeric

I often have to take character data and categorize it numerically. A common thing I do is to take character type variables and convert them to numeric type characters, keeping same categories according to the level of work I'm doing. (The longer the substring, the more in depth, shorter substrings for broad level). Enough backstory...

The challenge: In as few bytes as possible, convert the input part A, a vector/list of unique strings, into the output, a vector/list of numbers, keeping unique categories within the length of substrings the same length, which is input part B.

Input:

  1. w, Vector/list of unique strings of equal character length. n <= 10

    • These strings may be any combination of uppercase letters and numbers. Sorry if it seems my examples follow a pattern, I just created them after a similar pattern I see in the data I work with.
  2. s, where 1 <= s <= n

Output: May take input and output in the same order, or you can convert alphabetically, but output in the same order. See example 2. (I've included comments in my output to clarify, this is not required)

Example Input 1:

#Already alphabetized, but this input is not always guaranteed

s = 3, w = 
[ABC01, 
 ABC11,
 ABC21,
 ABD01,
 ABE01,
 ABE02,
 ACA10,
 ACA11,
 ACB20,
 ACB21]

Example Output 1:

[1, #ABC
 1, 
 1, 
 2, #ABD
 3, #ABE
 3, 
 4, #ACA
 4, 
 5, #ACB
 5]

Example Input 2: s = 4, w =

[X1Z123,
 X1Z134,
 X1Y123,
 X1Y134,
 X1Y145,
 X1Y156,
 X1X123,
 X1X124,
 X1X234,
 X2Z123,
 X2Z134,
 X2Z222,
 X2Z223,
 X2Z224]

Example 2 Output:

#Categorize by order
[1, #X1Z1
 1,
 2, #X1Y1
 2,
 2,
 2,
 3, #X1X1
 3,
 4, #X1X2
 5, #X2Z1
 5,
 6, #X2Z2
 6,
 6] 

OR if conversion follows alphabetical formatting,

#Categorize alphabetically, but output in same order as input.
[6, #X1Z1
 6,
 5, #X1Y1
 5,
 5,
 5,
 3, #X1X1
 3,
 4, #X1X2
 1, #X2Z1
 1,
 2, #X2Z2
 2,
 2] 
\$\endgroup\$
2
  • \$\begingroup\$ I'm a little confused; the input matches the regex [A-Z]+[0-9]+ and the task is to replace the inputs with unique integer identifiers based on the first s letters? Something like as.integer(as.factor(substring(w,1,s)))? I think it's a good challenge but needs a little more clarification. \$\endgroup\$
    – Giuseppe
    Dec 23, 2019 at 19:58
  • \$\begingroup\$ Sorry, I suppose I didn't specify how the input will appear. The input is not supposed to follow any specific regex pattern, but some inputs will be similar enough. It could be all uppercase letters or all numbers. \$\endgroup\$
    – Sumner18
    Dec 23, 2019 at 20:24
1
\$\begingroup\$

Partial tq interpreter

In this task you are expected to provide a list output given an input tq program. The tq programs will not contain whitespace inside them. (I find tq extremely difficult to implement within a short time, therefore I consider it to be a nice challenge.)

What is tq, in the first place?

tq is a lazy-evaluated language that is designed with the idea that array items should be accessable during the definition of them. In tq, there is no explicit separator of an array, only special arrangements of monadic/dyadic functions and nilads.

The following program is a program printing [123] (Pretend that tq doesn't support strings because we aren't dealing with them in this case):

123

This defines a list with the first item being the number 123, after which all items in the list will be outputted inside a list.

In tq, numbers are supported to allow multiple-digits. So this defines a list with 2 items:

12+12,5

In this test case, you are expected to output the list [24,5]. Let's explain it step by step.

12+12   # This evaluates 12 + 12 in the current item in the list, returning 24
     ,  # A separator. This separates two items when they could be potentially
        # ambiguous when they are applied without a separator.
      5 # This evaluates 5 in the current item in the list, returning 5
        # The comma is simply a no-op that doesn't require parsing.

So you think that tq is not hard at all to implement? Well, remember that tq also has a special feature of accessing the items in an array before the array is defined!

555th123

We introduce two new atoms:

  • t (tail) means access the last item in the list
  • h (head) means access the first item in the list

Therefore our list is going to yield:

[555,123,555,123]

Now take a look at this program:

555ps123

We introduce 2 more atoms:

  • p Yield the next item before (previous) the current position
  • s Yield the next item after (succeeding)the current position

This yields the list:

[555,555,123,123]

A quick reference of the tq language

Just assume that you only have two operands for the operators.

  • [0-9] starts a number. Numbers will only be positive integers, i.e. no decimals and negative numbers.
  • , This is a separator of different items when it is given that two consecutive indexes will be ambiguous with each other without a separator. In tq all of the remaining characters can act as a separator, but in this case it is a good idea to implement only , for the ease of your implementation.
  • + and * These are arithmetic operators. Usually in tq, they may be applied multiple times, e.g. 1+2+3, but in your implementation, input will be provided so that this will not happen and only 1+2 will happen (there will not be applications multiple times).
  • t return the last item in the list. If the code is t1,2,3 it shall return [3,1,2,3].
  • h return the first item in the list. If the code is 1,2,3h it shall return [1,2,3,1].
  • p returns the item before the current item. If the code is 0,1,p,3,4 the code shall return [0,1,1,3,4].
  • s returns the item after the current item. If the code is 0,1,s,3,4 the code shall return [0,1,3,3,4].

More test cases

  • 4p*p will yield [4,16]
  • 1p+s2 will yield [1,3,2]
  • 1,2,3h+t4,5,6 will yield [1,2,3,7,4,5,6]
  • 3ppss6 will yield [3,3,3,6,6,6]
  • You also have to implement multiple hops. E.g. 1th should yield [1,1,1]
  • If you know that something is going to form a loop, e.g. 1sp2, the cells that form the loop should be removed. Therefore the previous example will yield [1,2].
  • Out of bounds indexing will yield the closest index of the indexed item that is a number. E.g. 1,2s should yield [1,2,2]
\$\endgroup\$
1
\$\begingroup\$

Internal Truth Machine

It's a normal truth machine but instead of taking input, it uses the first character of the program. Thus, internal.

Example: 0abcd prints 0 and halts, and 1abcd prints 1 infinitely.

\$\endgroup\$
2
1
\$\begingroup\$

Balanced interval tree

You will write a balanced, online interval tree.

  • A function, method, or procedure that performs insertion into a query of intervals that overlap with an interval over a, b in O(log n) time, given that a is less than b, including:
    • intervals that fully enclose a, b
    • intervals fully within a, b
    • intervals that start to the left of a but end before b
    • intervals that start to the right of a but end after b
  • A function, method, or procedure that performs insertion ov an arbitrary interval a,b into a data structure in O(log n) time
  • Both O-bounds must hold after arbitrary series of insertions and queries

Requirements

If you write non-method functions, your submission may take the data structure as a global variable or receive the data structure as the first parameter.

You must informally prove your submission falls within the required O-bounds or name the data structure your program implements. If the name of the data structure you are implementing is obscure, you may name the paper of the data structure.

This is , so the submission with the shortest length in bytes wins.

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

Posted: Find the Inverse Neighbor Pairs

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

floating-point error matters

Write a expression of floating-point numbers in any languages. When calculating the expression without floating-point errors (as what a human do), it should be 0. But with floating-point errors (as what happened in your language), it yield 1 instead.

  • Floating-point numbers are some numbers which store a finite number digits (binary or decimal or in any other bases) of fraction, plus an exponent in computer. It may be IEEE 754, but not must be.
  • Loss of precision due to integer types (which do not has a exponent) are not allowed in the expression. You are still allowed to include integers (or even other types) in your expression as long as operations such as rounding into an integer are not the root of errors.

Shortest codes win as code-golf.


Sandbox:

  • Is there any duplicates here?
  • Is asking for an expression instead of full program allowed?
\$\endgroup\$
1
  • \$\begingroup\$ Yes, you can allow expressions. Good fit for this one, imho. \$\endgroup\$
    – Adám
    Feb 6, 2020 at 11:33
1
\$\begingroup\$

No title yet.

By Zekendorf's theorem every non-negative integer has a unique representation as the sum of Fibonacci numbers where no two numbers coincide or are adjacent.

In The minimum fibonacci challenge! the challenge was to output the list of Fibonacci numbers. However, you can instead consider the list of coefficients of the sum \$ \small x_0F(2) + x_1F(3) + x_2F(4) + \ldots \$ (since \$ \small F(0) = 0 \$ and \$ \small F(1) = F(2) \$ never appear in the Zekendorf representation) and represent that as a binary number \$ \ldots x_2 x_1 x_0 \$, e.g. \$ \small 67 = \small 1F(2) + 0F(3) + 1F(4) + 0F(5) + 1F(6) + 0F(7) + 0F(8) + 0F(9) + 1F(10) \$ which we can represent using the binary number \$ \small 100010101 \$ or \$ \small 277 \$ in decimal.

We can readily convert the binary representation back into the original integer by calculating the sum of the relevant Fibonacci numbers. However, I would like you to, given an input integer \$ \small n \$, output the decimal integer whose binary representation encodes the Zekendorf representation of \$ \small n \$ in this way.

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

\$\endgroup\$
5
  • 1
    \$\begingroup\$ I would clarify that your binary representation is "flipped", i.e. 0-extends infinitely to the left. \$\endgroup\$ Feb 8, 2020 at 18:32
  • \$\begingroup\$ @JonathanFrech flipped in comparison to what? \$\endgroup\$
    – RGS
    Feb 10, 2020 at 20:18
  • \$\begingroup\$ @RGS I wrote the Fibonacci coefficients from left to right but the bits in the binary number from right to left and it wasn't so clear before. \$\endgroup\$
    – Neil
    Feb 10, 2020 at 21:15
  • \$\begingroup\$ Oh ok, but that still matches what we don in binary. I can also write 11 = 1 + 2 + 8 and \$11 = 1011_2\$ :) but sure, going for perfect clarity is better than trusting other people's common sense \$\endgroup\$
    – RGS
    Feb 10, 2020 at 21:54
  • 2
    \$\begingroup\$ @RGS Having to guess the specifications from a single example is not really common sense as it is annoying. \$\endgroup\$ Feb 11, 2020 at 21:41
1
\$\begingroup\$

Calculate Mahjong points

Introduction to Mahjong tiles

Mahjong (้บป้›€) is a board game that originates from China. Mahjong tiles used in this challenge are in Unicode points U+1F000 โ€“ U+1F021:

๐Ÿ€€๐Ÿ€๐Ÿ€‚๐Ÿ€ƒ๐Ÿ€„๐Ÿ€…๐Ÿ€†๐Ÿ€‡๐Ÿ€ˆ๐Ÿ€‰๐Ÿ€Š๐Ÿ€‹๐Ÿ€Œ๐Ÿ€๐Ÿ€Ž๐Ÿ€๐Ÿ€๐Ÿ€‘๐Ÿ€’๐Ÿ€“๐Ÿ€”๐Ÿ€•๐Ÿ€–๐Ÿ€—๐Ÿ€˜๐Ÿ€™๐Ÿ€š๐Ÿ€›๐Ÿ€œ๐Ÿ€๐Ÿ€ž๐Ÿ€Ÿ๐Ÿ€ ๐Ÿ€ก

They are categorized as:

  • Winds (้ขจ็‰Œ): ๐Ÿ€€(East Wind), ๐Ÿ€(South Wind), ๐Ÿ€‚(West Wind), ๐Ÿ€ƒ(North Wind)

  • Dragons (ไธ‰ๅ…ƒ็‰Œ): ๐Ÿ€„(Red Dragon), ๐Ÿ€…(Green Dragon), ๐Ÿ€†(White Dragon)

  • Ten Thousands (่ฌๅญ): ๐Ÿ€‡(One of the Ten Thousands) through ๐Ÿ€(Nine of the Ten Thousands)

  • Bamboos (็ดขๅญ): ๐Ÿ€(One of the Bamboos; note that it depicts a bird) through ๐Ÿ€˜(Nine of the Bamboos)

  • Circles (็ญ’ๅญ): ๐Ÿ€™(One of the Circles) through ๐Ÿ€ก(Nine of the Circles)

  • Winds and Dragons are together called Honors (ๅญ—็‰Œ).

  • Ten Thousands, Bamboos and Circles are each called a suit and together called Numbers (ๆ•ฐ็‰Œ). They have ranks from 1 to 9.

  • Among Numbers, the Ones and the Nines are called Terminals (่€้ ญ็‰Œ). The Twos through the Eights are called Simples (ไธญๅผต็‰Œ).

  • Honors and Terminals are together called Orphans (ๅนบไน็‰Œ).

Every Mahjong tiles have 4 copies of themselves.

Mahjong Hand

A legal Hand will be given as the input. It consists of:

  • A Head, which is 2 identical tiles.

  • 4 Bodies, each which is either:

    • A Sequence, which is 3 consecutive Numbers of the same suit.

    • A Triplet, which is 3 identical tiles.

Hence, a Hand consists of 14 tiles.

There are exceptions. See "Seven Heads" and "Thirteen Orphans" below.

Points

The objective is to calculate how many points a Hand has. Points are gained by having Yakus (ๅฝน), which are cumulative.

Also I apologize that I named these Yakus to be more intuitive for the code golf, making them differ from the 'usual' names. Sorry!

1 Point Yakus

  • Menzen Tsumo (้–€ๅ‰ๆธ…่‡ชๆ‘ธๅ’Œ), which is worth 1 point, will always be assumed.

  • Pinfu (ๅนณๅ’Œ): Get a non-Dragon Head and 4 Sequences.

    • Example: ๐Ÿ€ƒ๐Ÿ€ƒ๐Ÿ€‡๐Ÿ€ˆ๐Ÿ€‰๐Ÿ€‘๐Ÿ€’๐Ÿ€“๐Ÿ€”๐Ÿ€•๐Ÿ€–๐Ÿ€Ÿ๐Ÿ€ ๐Ÿ€ก
  • One Pair (ไธ€็›ƒๅฃ): Get 2 identical Bodies.

    • Example: ๐Ÿ€‚๐Ÿ€‚๐Ÿ€‚๐Ÿ€‡๐Ÿ€‡๐Ÿ€‡๐Ÿ€ˆ๐Ÿ€‰๐Ÿ€“๐Ÿ€“๐Ÿ€”๐Ÿ€”๐Ÿ€•๐Ÿ€•
  • Dragon Triplet (ๅฝน็‰Œ): Get a Triplet of Dragons. Multiple Dragon Triplets are cumulative.

    • Example: ๐Ÿ€†๐Ÿ€†๐Ÿ€†๐Ÿ€‡๐Ÿ€ˆ๐Ÿ€‰๐Ÿ€Š๐Ÿ€Š๐Ÿ€’๐Ÿ€“๐Ÿ€”๐Ÿ€›๐Ÿ€œ๐Ÿ€
  • All Simples (ๆ–ญๅนบไน): Let the Hand consist only of Simples.

    • Example: ๐Ÿ€ˆ๐Ÿ€‰๐Ÿ€Š๐Ÿ€“๐Ÿ€“๐Ÿ€“๐Ÿ€š๐Ÿ€›๐Ÿ€›๐Ÿ€œ๐Ÿ€œ๐Ÿ€๐Ÿ€ ๐Ÿ€ 

2 Points Yakus

  • Seven Heads (ไธƒๅฏพๅญ): Get 7 Heads. It cannot contain 2 identical Heads.

    • Example: ๐Ÿ€€๐Ÿ€€๐Ÿ€‚๐Ÿ€‚๐Ÿ€†๐Ÿ€†๐Ÿ€ˆ๐Ÿ€ˆ๐Ÿ€Š๐Ÿ€Š๐Ÿ€๐Ÿ€๐Ÿ€›๐Ÿ€›
  • Colorful Sequences (ไธ‰่‰ฒๅŒ้ †): Get a sequence for each suit, consisting of the same set of ranks.

    • Example: ๐Ÿ€€๐Ÿ€€๐Ÿ€๐Ÿ€๐Ÿ€๐Ÿ€‰๐Ÿ€Š๐Ÿ€‹๐Ÿ€’๐Ÿ€“๐Ÿ€”๐Ÿ€›๐Ÿ€œ๐Ÿ€
  • Full Sequence (ไธ€ๆฐ—้€š่ฒซ): Get 3 sequences of the same suit, consisting of ranks of 123, 456, and 789.

    • Example: ๐Ÿ€€๐Ÿ€€๐Ÿ€๐Ÿ€๐Ÿ€๐Ÿ€‡๐Ÿ€ˆ๐Ÿ€‰๐Ÿ€Š๐Ÿ€‹๐Ÿ€Œ๐Ÿ€๐Ÿ€Ž๐Ÿ€
  • Semi-Orphans (ใƒใƒฃใƒณใ‚ฟ): Let all Heads and Bodies have at least 1 Orphan.

    • Example: ๐Ÿ€€๐Ÿ€€๐Ÿ€๐Ÿ€๐Ÿ€๐Ÿ€‡๐Ÿ€ˆ๐Ÿ€‰๐Ÿ€๐Ÿ€‘๐Ÿ€’๐Ÿ€ก๐Ÿ€ก๐Ÿ€ก
  • Concealed Three (ไธ‰ๆš—ๅˆป): Get 3 Triplets.

    • Example: ๐Ÿ€€๐Ÿ€€๐Ÿ€๐Ÿ€๐Ÿ€๐Ÿ€Š๐Ÿ€Š๐Ÿ€Š๐Ÿ€‹๐Ÿ€‹๐Ÿ€‹๐Ÿ€‘๐Ÿ€’๐Ÿ€“
  • Colorful Triplets (ไธ‰่‰ฒๅŒๅˆป): Get a Triplet for each suit, consisting of the same rank.

    • Example: ๐Ÿ€€๐Ÿ€€๐Ÿ€‰๐Ÿ€Š๐Ÿ€Š๐Ÿ€Š๐Ÿ€Š๐Ÿ€‹๐Ÿ€“๐Ÿ€“๐Ÿ€“๐Ÿ€œ๐Ÿ€œ๐Ÿ€œ
  • Dragons Minor (ๅฐไธ‰ๅ…ƒ): Let the Head and 2 Bodies consist of Dragons. Cumulative with the 2 Dragon Triplets.

    • Example: ๐Ÿ€„๐Ÿ€„๐Ÿ€…๐Ÿ€…๐Ÿ€…๐Ÿ€†๐Ÿ€†๐Ÿ€†๐Ÿ€Š๐Ÿ€‹๐Ÿ€Œ๐Ÿ€’๐Ÿ€“๐Ÿ€”
  • All Orphans (ๆทท่€้ ญ): Let the Hand consist only of Orphans. Supersedes Semi-Orphans. Cumulative with Seven Heads.

    • Example: ๐Ÿ€๐Ÿ€๐Ÿ€‚๐Ÿ€‚๐Ÿ€ƒ๐Ÿ€ƒ๐Ÿ€†๐Ÿ€†๐Ÿ€‡๐Ÿ€‡๐Ÿ€๐Ÿ€๐Ÿ€˜๐Ÿ€˜
  • Three of a Kind (ไธ€่‰ฒไธ‰้ †): Get 3 identical Bodies. Supersedes One Pair.

    • Example: ๐Ÿ€…๐Ÿ€…๐Ÿ€‡๐Ÿ€‡๐Ÿ€‡๐Ÿ€ˆ๐Ÿ€ˆ๐Ÿ€ˆ๐Ÿ€‰๐Ÿ€‰๐Ÿ€‰๐Ÿ€™๐Ÿ€š๐Ÿ€› (Note that this example also presents Semi-Orphans, which makes it supersede Concealed Three.)

3 Points Yakus

  • Two Pairs (ๅ…ฉ็›ƒๅฃ): Get 2 pairs of identical Bodies. Supersedes One Pair and Seven Heads.

    • Example: ๐Ÿ€ƒ๐Ÿ€ƒ๐Ÿ€‡๐Ÿ€‡๐Ÿ€ˆ๐Ÿ€ˆ๐Ÿ€‰๐Ÿ€‰๐Ÿ€‘๐Ÿ€‘๐Ÿ€’๐Ÿ€’๐Ÿ€“๐Ÿ€“
  • Semi-Terminals (็ด”ใƒใƒฃใƒณใ‚ฟ): Let all Heads and Bodies have at least 1 Terminal. Supersedes Semi-Orphans.

    • Example: ๐Ÿ€‡๐Ÿ€‡๐Ÿ€‡๐Ÿ€ˆ๐Ÿ€‰๐Ÿ€๐Ÿ€Ž๐Ÿ€๐Ÿ€๐Ÿ€๐Ÿ€๐Ÿ€™๐Ÿ€™๐Ÿ€™
  • Semi-Flush (ๆททไธ€่‰ฒ): Let the Numbers consist of a single suit.

    • Example: ๐Ÿ€‚๐Ÿ€‚๐Ÿ€‡๐Ÿ€ˆ๐Ÿ€‰๐Ÿ€‰๐Ÿ€‰๐Ÿ€‰๐Ÿ€Š๐Ÿ€‹๐Ÿ€Œ๐Ÿ€Œ๐Ÿ€๐Ÿ€Ž

6 Points Yaku

  • Flush (ๆธ…ไธ€่‰ฒ): Let the Hand consist of a single suit of Numbers. Supersudes Semi-Flush.

    • Example: ๐Ÿ€‡๐Ÿ€‡๐Ÿ€‡๐Ÿ€ˆ๐Ÿ€‰๐Ÿ€‰๐Ÿ€‰๐Ÿ€‰๐Ÿ€Š๐Ÿ€‹๐Ÿ€Œ๐Ÿ€Œ๐Ÿ€๐Ÿ€Ž

Yakumans

Yakumans (ๅฝนๆบ€) worth 13 points, and supersede all Yakus above. Multiple Yakumans are cumulative.

Without Yakumans, the points are capped at 13.

  • Concealed Four (ๅ››ๆš—ๅˆป): Get 4 Triplets.

    • Example: ๐Ÿ€€๐Ÿ€€๐Ÿ€‰๐Ÿ€‰๐Ÿ€‰๐Ÿ€Œ๐Ÿ€Œ๐Ÿ€Œ๐Ÿ€’๐Ÿ€’๐Ÿ€’๐Ÿ€ž๐Ÿ€ž๐Ÿ€ž
  • Thirteen Orphans (ๅ›ฝๅฃซ็„กๅŒ): Collect all 13 Orphans, plus an additional Orphan.

    • Example: ๐Ÿ€€๐Ÿ€๐Ÿ€‚๐Ÿ€ƒ๐Ÿ€„๐Ÿ€…๐Ÿ€†๐Ÿ€‡๐Ÿ€‡๐Ÿ€๐Ÿ€๐Ÿ€˜๐Ÿ€™๐Ÿ€ก
  • Nine Gates (ไน่“ฎๅฎ็‡ˆ): Get Flush of ranks of 1112345678999, plus an additional Number of the same suit.

    • Example: ๐Ÿ€‡๐Ÿ€‡๐Ÿ€‡๐Ÿ€ˆ๐Ÿ€‰๐Ÿ€Š๐Ÿ€‹๐Ÿ€‹๐Ÿ€Œ๐Ÿ€๐Ÿ€Ž๐Ÿ€๐Ÿ€๐Ÿ€
  • All Greens (็ท‘ไธ€่‰ฒ): Let the Hand consist only of Green Dragons and the Twos, Threes, Fours, Sixes, and Eights of the Bamboos.

    • Example: ๐Ÿ€…๐Ÿ€…๐Ÿ€…๐Ÿ€‘๐Ÿ€‘๐Ÿ€’๐Ÿ€’๐Ÿ€“๐Ÿ€“๐Ÿ€•๐Ÿ€•๐Ÿ€•๐Ÿ€—๐Ÿ€—
  • All Honors (ๅญ—ไธ€่‰ฒ): Let the Hand consist only of Honors. Cumulative with Concealed Four.

    • Example: ๐Ÿ€€๐Ÿ€€๐Ÿ€€๐Ÿ€๐Ÿ€๐Ÿ€‚๐Ÿ€‚๐Ÿ€‚๐Ÿ€…๐Ÿ€…๐Ÿ€…๐Ÿ€†๐Ÿ€†๐Ÿ€†
  • All Terminals (ๆธ…่€้ ญ): Let the Hand consist only of Terminals. Cumulative with Concealed Four.

    • Example: ๐Ÿ€‡๐Ÿ€‡๐Ÿ€‡๐Ÿ€๐Ÿ€๐Ÿ€๐Ÿ€๐Ÿ€๐Ÿ€๐Ÿ€˜๐Ÿ€˜๐Ÿ€™๐Ÿ€™๐Ÿ€™
  • Dragons Major (ๅคงไธ‰ๅ…ƒ): Get a Triplet for each of Dragons.

    • Example: ๐Ÿ€„๐Ÿ€„๐Ÿ€„๐Ÿ€…๐Ÿ€…๐Ÿ€…๐Ÿ€†๐Ÿ€†๐Ÿ€†๐Ÿ€‡๐Ÿ€ˆ๐Ÿ€‰๐Ÿ€‘๐Ÿ€‘
  • Winds Minor (ๅฐๅ››ๅ–œ): Let the Head and 3 Bodies consist of Winds.

    • Example: ๐Ÿ€€๐Ÿ€€๐Ÿ€๐Ÿ€๐Ÿ€๐Ÿ€‚๐Ÿ€‚๐Ÿ€‚๐Ÿ€ƒ๐Ÿ€ƒ๐Ÿ€ƒ๐Ÿ€–๐Ÿ€—๐Ÿ€˜
  • Straight Flush (้€ฃไธƒๅฏพ): Get Seven Heads with Numbers with consecutive ranks of the same suit.

    • Example: ๐Ÿ€š๐Ÿ€š๐Ÿ€›๐Ÿ€›๐Ÿ€œ๐Ÿ€œ๐Ÿ€๐Ÿ€๐Ÿ€ž๐Ÿ€ž๐Ÿ€Ÿ๐Ÿ€Ÿ๐Ÿ€ ๐Ÿ€ 
  • Four of a Kind (ไธ€่‰ฒๅ››้ †): Get 4 identical Bodies.

    • Example: ๐Ÿ€ƒ๐Ÿ€ƒ๐Ÿ€“๐Ÿ€“๐Ÿ€“๐Ÿ€“๐Ÿ€”๐Ÿ€”๐Ÿ€”๐Ÿ€”๐Ÿ€•๐Ÿ€•๐Ÿ€•๐Ÿ€•
  • Winds Major (ๅคงๅ››ๅ–œ): Worths 2 Yakumans. Get a Triplet for each of Winds. Cumulative with Concealed Four.

    • Example: ๐Ÿ€€๐Ÿ€€๐Ÿ€€๐Ÿ€๐Ÿ€๐Ÿ€๐Ÿ€‚๐Ÿ€‚๐Ÿ€‚๐Ÿ€ƒ๐Ÿ€ƒ๐Ÿ€ƒ๐Ÿ€–๐Ÿ€–
  • The Septentrions (ๅคงไธƒๆ˜Ÿ): Worths 2 Yakumans. Get a Head with each of Honors. Supersedes All Honors.

    • The only example: ๐Ÿ€€๐Ÿ€€๐Ÿ€๐Ÿ€๐Ÿ€‚๐Ÿ€‚๐Ÿ€ƒ๐Ÿ€ƒ๐Ÿ€„๐Ÿ€„๐Ÿ€…๐Ÿ€…๐Ÿ€†๐Ÿ€†

Other rules about Mahjong

When a Hand can be interpreted as different combinations of Heads and Bodies, the combination with the most points will be chosen. (See Three of a Kind and Two Pairs above)

Examples

๐Ÿ€…๐Ÿ€…๐Ÿ€‹๐Ÿ€‹๐Ÿ€Œ๐Ÿ€Œ๐Ÿ€๐Ÿ€๐Ÿ€‘๐Ÿ€’๐Ÿ€“๐Ÿ€Ÿ๐Ÿ€ ๐Ÿ€ก : Menzen Tsumo + One Pair = 2 points.

๐Ÿ€‰๐Ÿ€Š๐Ÿ€‹๐Ÿ€Œ๐Ÿ€๐Ÿ€Ž๐Ÿ€‘๐Ÿ€’๐Ÿ€“๐Ÿ€”๐Ÿ€”๐Ÿ€ž๐Ÿ€Ÿ๐Ÿ€  : Menzen Tsumo + Pinfu + All Simples = 3 points.

๐Ÿ€€๐Ÿ€€๐Ÿ€€๐Ÿ€๐Ÿ€๐Ÿ€๐Ÿ€‚๐Ÿ€‚๐Ÿ€‚๐Ÿ€ƒ๐Ÿ€ƒ๐Ÿ€ƒ๐Ÿ€†๐Ÿ€† : Winds Major + Concealed Four + All Honors = 52 points. (Most points possible)

Rules about code golf

  • Input type and format doesn't matter, but it must consist of the Unicode characters above. In C++, valid examples include std::u8string (sorted or not) and std::multiset<u32char_t>.

  • Output type and format doesn't matter either.

  • Invalid Hands (not exactly 14 tiles, contains 5 copies of the same tile, etc) fall into don't care situation.

  • If and only if your language doesn't support Unicode, use the following table to parse Mahjong tiles:

           |x0|x1|x2|x3|x4|x5|x6|x7|x8|x9|xA|xB|xC|xD|xE|xF  
    -------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--
    U+1F00x|We|Ws|Ww|Wn|Dr|Dg|Dw|T1|T2|T3|T4|T5|T6|T7|T8|T9
    -------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--
    U+1F01x|B1|B2|B3|B4|B5|B6|B7|B8|B9|C1|C2|C3|C4|C5|C6|C7
    -------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--
    U+1F02x|C8|C9|
    
\$\endgroup\$
6
  • \$\begingroup\$ A related, more golfable challenge posted here: codegolf.stackexchange.com/q/199202/89459 \$\endgroup\$ Feb 10, 2020 at 6:30
  • \$\begingroup\$ Maybe you need more testcase. At least one per yaku. \$\endgroup\$
    – tsh
    Feb 10, 2020 at 14:40
  • \$\begingroup\$ Should output for 11112233778899m be 13 or 14? \$\endgroup\$
    – tsh
    Feb 16, 2020 at 7:02
  • \$\begingroup\$ @tsh Since it has no Yakuman, its point is capped at 13. \$\endgroup\$ Feb 16, 2020 at 7:06
  • \$\begingroup\$ Is Straight Flush (้€ฃไธƒๅฏพ) required to be All Simples (ๆ–ญๅนบไน)? \$\endgroup\$
    – tsh
    Feb 16, 2020 at 7:15
  • \$\begingroup\$ @tsh No. ๅฐ่ปŠ่ผช, ๅคง่ปŠ่ผช, and their correspondent to other suits are all Straight Flush. \$\endgroup\$ Feb 16, 2020 at 7:17
1
โ€ฆ
69 70
71
72 73
โ€ฆ
153

You must log in to answer this question.

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