-3
\$\begingroup\$

Is it a good chord?

Definition of a chord:

We define a chord as three notes together.

Definition of a note:

We define a note as a number between 1 and 7, inclusive. As in music, we define 1 as do, 2 as re, 3 as fa, etc. However, the note names are not important. They will not be included in the question and likely not in a golfed solution. 1 is a note. 0 and 8 are not a note. As we will mention later, the input is a list of three notes, and invalid notes will not appear as an input. So even if you print the entire Never Gonna Give You Up lyrics when you encounter invalid inputs, I don't care. (However, I don't see how that's more golf-y.)

Definition of a good chord:

We define a good chord as follows:

  • If there are any two notes that are the same, disregard one of them.

  • Sort the notes.

  • Space the result on a piano. For instance, 135 will look like X X X and so will 246, 357, for instance.

  • If any of the notes are adjacent, it is considered a bad chord and thus not a good chord. That is, a chord containing 1 and 2 is bad, so is a chord containing 1 and 7.

  • The only possibilities that are left are:

With three digits,

  • 135

  • 136

  • 137

  • 146

  • 147

  • 157

  • 246

  • 247

  • 257

  • 357

And with two digits,

  • 13 which could have been 113 or 133

  • 14 which could have been 114 or 144

  • 15 which could have been 115 or 155

  • 16 which could have been 116 or 166

  • 24 which could have been 224 or 244

  • 25 which could have been 225 or 255

  • 26 which could have been 226 or 266

  • 27 which could have been 227 or 277

  • 35 which could have been 335 or 355

  • 36 which could have been 336 or 366

  • 37 which could have been 337 or 377

  • 46 which could have been 446 or 466

  • 47 which could have been 447 or 477

  • 57 which could have been 557 or 577

And with one digit,

  • 1 which means 111

  • 2 which means 222

  • 3 which means 333

  • 4 which means 444

  • 5 which means 555

  • 6 which means 666

  • 7 which means 777

Note that the above possibilities are already sorted, while you should not expect your input to be sorted. Also, the above possibilities are represented as a three digit number, while your input will be a list of three numbers from 1 to 7 inclusive.

I would not expect an answer that hard-codes the values above, but if you intend to, or for some reason it is more golf-y, you are permitted to do it.

Your challenge:

Given an input, decide whether it is good or not. Return a true-y or false-y value, a true-y value such as 1 means that it is good, while a false-y value such as 0 means that it is not good. Do not use ambiguous values like or \n (indicating a newline) or [[]] et cetera.

Scoring:

This is code-golf.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I see you've had a number of poorly received questions lately. You should try using the Sandbox for feedback before posting your questions (and by "using", I mean leaving them for more than a few hours and posting them after they are voted on). \$\endgroup\$
    – Jo King
    May 12, 2022 at 4:30
  • \$\begingroup\$ Not to be picky, but aren't there 12 notes (in occidental music)? Your challenge doesn't seem to take in account that there is only a half-tone between B and C and between E and F, making your definition a bit weird to me \$\endgroup\$
    – Kaddath
    May 18, 2022 at 10:57
  • 1
    \$\begingroup\$ I'm not taking that into account because that messes up the input format and makes it harder to explain. \$\endgroup\$ May 18, 2022 at 11:34

2 Answers 2

1
\$\begingroup\$

x86-64 machine code, 19 bytes

31 D2 AD 0F AB C2 FF CF 75 F8 8D 04 12 85 D0 0F 94 C0 C3

Try it online!

Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes the length and address of an array of 32-bit integers in EDI and RSI, respectively, and returns a value in AL.

In assembly:

.global f
f:  xor edx, edx    # Set EDX to 0.
r:  lodsd           # Load a number from the array into EAX, advancing the pointer.
    bts edx, eax    # Set the bit in that position in EDX to 1.
    dec edi         # Subtract 1 from EDI, counting down from the length.
    jnz r           # Jump back if that is not zero.
    lea eax, [rdx+rdx]  # Set EAX to 2 times EDX -- the bits move up by 1.
    test eax, edx   # Set flags based on the bitwise AND of EAX and EDX.
                    # This checks for adjacent bits being 1.
    setz al         # Set AL based on whether the result was zero.
    ret             # Return.
\$\endgroup\$
1
\$\begingroup\$

Python 3, 32 bytes

lambda l:not{*l}&{x+1for x in l}

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.