10
\$\begingroup\$

Objective

Given the distance between two keys in an octave, identify its name.

But there's a caveat. In this challenge, there are 22 keys in an octave, not usual 12.

Here, a porcupine[7] scale will be assumed.

Mapping

White keys are marked bold.

Distance Name
0 Unison
1 Augmented Unison or Diminished Second
2 Minor Second
3 Major Second
4 Augmented Second
5 Diminished Third
6 Minor Third
7 Major Third
8 Augmented Third or Diminished Fourth
9 Perfect Fourth
10 Major Fourth
11 Augmented Fourth or Diminished Fifth
12 Minor Fifth
13 Perfect Fifth
14 Augmented Fifth or Diminished Sixth
15 Minor Sixth
16 Major Sixth
17 Augmented Sixth
18 Diminished Seventh
19 Minor Seventh
20 Major Seventh
21 Augmented Seventh or Diminished Octave
(others) (don't care)

Rule

You can freely mix cases in output. Trailing whitespaces are permitted.

\$\endgroup\$
4
  • \$\begingroup\$ Please provide some test cases. \$\endgroup\$ Commented Apr 18, 2023 at 11:38
  • 4
    \$\begingroup\$ @JeffZeitlin The "Mapping" presents all test cases. \$\endgroup\$ Commented Apr 18, 2023 at 11:42
  • \$\begingroup\$ Do you confirm it's OK to use either the augmented or diminished form in an inconsistent way when both are allowed? (Sorry, I should have asked before answering.) \$\endgroup\$ Commented Apr 18, 2023 at 12:49
  • 3
    \$\begingroup\$ @Arnauld It's a free choice. \$\endgroup\$ Commented Apr 18, 2023 at 12:56

4 Answers 4

10
\$\begingroup\$

JavaScript (ES6), 153 bytes

n=>n?(a="AugmentedDiminishedMinorMajorPerfectSecondThirdFourthFifthSixthSeventh".match(/.[a-z]+/g))["51324"[n-9]^n%13%4]+' '+a[n+3*(n>11)+19>>2]:'Unison'

Try it online!

How?

The case \$n=0\$ is processed separately.

We use the repeating sequence Diminished / Minor / Major / Augmented for \$1\le n\le 8\$ and for \$14\le n\le 21\$. The corresponding indices in the lookup array are \$[1,2,3,0]\$. This is done by reducing \$n\$ modulo \$13\$ and then modulo \$4\$.

We actually use the same calculation for \$9\le n\le 13\$, but we apply a bitwise XOR to get the correct indices \$[4,3,0,2,4]\$, corresponding to Perfect (Fourth) / Major (Fourth) / Augmented (Fourth) / Minor (Fifth) / Perfect (Fifth).

This gives:

"51324"[n - 9] ^ n % 13 % 4

We then need to append Second to Seventh with indices \$5\$ to \$10\$ in the lookup array. The expected sequence is:

     n | 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21
-------+---------------------------------------------------------------
 index | 5  5  5  5  6  6  6  6  7  7  7  8  8  9  9  9  9 10 10 10 10

Basically, each index is repeated 4 times but 3 indices are omitted between \$n=11\$ and \$n=12\$.

This can be obtained with:

n + 3 * (n > 11) + 19 >> 2
\$\endgroup\$
6
\$\begingroup\$

Vyxal, 54 bytes

6ɾ›∆o`diø¤Ṁ§ ↑ṙ €ǐ ÷¨ «ø⟑ƒ₄ḭ`⌈vMƒJRvṄ»9Tr⌈»bTİ`Ẏ↲½Ŀ`pi

Try it Online!

How?

Get the list ["second", "third", ... , "seventh"]:

6ɾ›∆o

Get the list ["diminished", "minor", "perfect", "major", "augumented"]:

`diø¤Ṁ§ ↑ṙ €ǐ ÷¨ «ø⟑ƒ₄ḭ`⌈

Get all pairs in the correct order and join them by space:

vMƒJRvṄ

Only keep the some of the pairs:

»9Tr⌈»bTİ

Prepend "unison" and index into the list:

`Ẏ↲½Ŀ`pi
\$\endgroup\$
2
\$\begingroup\$

Charcoal, 95 94 bytes

⪫E§⪪”$&⊞ςq×P5μ·⸿§▷"↑W4⪪9Qλς”²⊖N§⪪”↶⌈∨S⎚χ]¹↶E´üêB⭆↓HηW◧⁻◨~,⦄Zi≦r⊗Þπ↖Z):⊕À´Aeδ∨8:≧#$/VMχ)A” ⌕αι 

Try it online! Link is to verbose version of code. Explanation:

    ”...”                   Compressed lookup table
   ⪪     ²                  Split into substrings of length `2`
  §                         Index by
           N                Input integer
          ⊖                 Decremented
 E                          Map over letters
             ⪪”...”         List of words
            §               Indexed by
                    ⌕αι     Uppercase letter index
⪫                           Join with spaces
                            Implicitly print

Note that the lookup table is 43 letters long so that the last entry only has one letter; this is the one that is then selected for an input of 0.

Previous 95-byte solution:

Nθ∧θ§⪪”↶↧*y³↨Cⅈ~➙…⟧⊖⁺¡κY⁸⁴Σ1|R6;” §”)⊞⮌i›‽”θM→§⪪”↶⌈∨l⟲Eχ⁼⁰θ℅BNμ↨%),ρ℅«◨ THY¬O⬤ε” §”)➙:⌊B/M⁷ê\`”θ

Try it online! Link is to verbose version of code. Explanation:

Nθ

Input the distance.

∧θ§⪪”...” §”...”θ

If it's not zero, cyclically index into the compressed table 4012301234231 to find the index into the compressed list of words diminished minor major augmented perfect.

M→

Leave a space between the two words.

§⪪”...” §”...”θ

Index into the compressed table 0111122223334455556666 to find the index into the compressed list of words unison second third fourth fifth sixth seventh.

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

05AB1E, 71 70 bytes

.•10°ÝΣËðw¶\ƵUʒ•…‡®¢ÑíÀ«#•”Öζт'µ���5вè“…Þ‰ª¦ƒ³äÇïÖµ“#•γ¤æ•ÅΓø.•I¢#€•šÅв»

Outputs in lowercase.

Try it online or verify all test cases.

Explanation:

.•10°ÝΣËðw¶\ƵUʒ• # Push compressed string "augmented diminished "
 …‡®¢ÑíÀ         # Push dictionary string "major minor perfect"
        «        # Append them together
         #       # Split this string on spaces:
                 #  ["augmented","diminished","major","minor","perfect"]
•”Öζт'µ•        '# Push compressed integer 160475945053335
        5в       # Convert it to base-5 as list:
                 #  [1,3,2,0,1,3,2,1,4,2,1,3,4,1,3,2,0,1,3,2,0]
          è      # 0-based index each into the previous list of strings
“…Þ‰ª¦ƒ³äÇïÖµ“   # Push dictionary string "second third fourth fifth sixth seventh"
              #  # Split it by spaces as well
•γ¤æ•            # Push compressed integer 4333444
     ÅΓ          # Run-length decode the list of strings and digits of this integer
ø                # Create pairs of the two list of strings
 .•I¢#€•         # Push compressed string "unison"
        š        # Prepend it to the list of pairs
Åв               # Convert the (implicit) input-integer to this custom base as list
  »              # Join each inner pair by spaces, and then the strings by newlines,
                 # which simply pushes the only string in the list in this case
                 # (after which it is output implicitly as result)

See this 05AB1E tip of mine (all four sections) to understand why .•10°ÝΣËðw¶\ƵUʒ• is "augmented diminished "; …‡®¢ÑíÀ is "major minor perfect"; •”Öζт'µ• is 160475945053335; •”Öζт'µ•5в is [1,3,2,0,1,3,2,1,4,2,1,3,4,1,3,2,0,1,3,2,0]; “…Þ‰ª¦ƒ³äÇïÖµ“ is "second third fourth fifth sixth seventh"; •γ¤æ• is 4333444; and .•I¢#€• is "unison".

\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.