22
\$\begingroup\$

The magic music box (MMB)

This explains the motivation for the challenge, feel free to ignore.

The magic music box is a word game played by a group of people, where one is the owner of the magic music box and the other people are trying to put words inside the magic music box.

Rules for the game with humans: the game goes in turns, one person at a time. In your turn, you have to say a word you want to put in the MMB and the MMB owner says if your word can get in or not, depending on the game criterion. If you are the MMB owner, you have to say a word that can go in the MMB.

The task

You have to code a function/program that receives a word as input (in any sensible format) and outputs Truthy or Falsy. Truthy if the word can go in the MMB and Falsy otherwise.

For a word to be able to go in the MMB, it has to contain at least one of the following seven strings:

  • do
  • re
  • mi
  • fa
  • sol
  • la
  • si

Input

A lowercase "word" in any sensible format, for example:

  • a string
  • a list of characters
  • a list of ASCII values of the characters

Test cases

(Edited test cases to include obsolete, also, some answers may not have it yet)

far -> Truthy
solace -> Truthy
boat -> Falsy
shrimp -> Falsy
fire -> Truthy
summit -> Truthy
biscuit -> Falsy
bullet -> Falsy
doctor -> Truthy
blast -> Truthy
college -> Falsy
subsidiary -> Truthy
obsolete -> Truthy
also -> Falsy
\$\endgroup\$
2
  • \$\begingroup\$ Is the input guaranteed to be in lower case? \$\endgroup\$
    – Arnauld
    Commented Feb 8, 2020 at 10:58
  • \$\begingroup\$ @Arnauld you can assume that, even though it was not in my original plans :p \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 11:23

26 Answers 26

16
\$\begingroup\$

05AB1E, 15 14 bytes

’ïêo‡Åefa’7äåà

Try it online!

’ïêo‡Åefa’        # dictionary string "soldosimilarefa" (using the words sold and similar)
          7ä      # split in 7 parts of almost-equal length (excess length goes to the first parts)
            å     # for each part, check if it’s in the input
             à    # maximum
\$\endgroup\$
1
  • \$\begingroup\$ +1 for the nice fact that you golfed the musical notes! Do you have any idea if the string compression bit is similar to how string compression works in Jelly? \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 14:34
10
\$\begingroup\$

Jelly,  18  14 bytes

-4 thanks to Nick Kennedy & Grimmy's 05AB1E answer

7“Ẉ|nŻUḋ}»œsfẆ

A monadic Link accepting a list of characters which yields a, possibly empty, list of lists.

Try it online!

How?

Note that in Jelly an empty list is falsey, while a non-empty list is truthy (as employed by the if-else, ”T”FÇ?, in the footer of the Try it online link, above).

7“Ẉ|nŻUḋ}»œsfẆ - Link: list of characters, w
7              - seven
 “Ẉ|nŻUḋ}»     - "solfa"+"similar"+"edo"
          œs   - split into (seven) equal chunks
                  -> ["sol","fa","si","mi","la","re","do"]
             Ẇ - all sublists (w)
            f  - filter keep

Aside: solfa is a name of a solfège method, where tones are given single syllable names, and was when si first became ti.

\$\endgroup\$
7
  • \$\begingroup\$ +1 nice solution, it is just a shame that you didn't manage to compress sol together with the other 6 musical notes \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 16:40
  • \$\begingroup\$ let me rephrase that :) it is a shame that compressing sol didn't allow for a well-golfed solution :/ it may be interesting including your 19 byte in the answer and noting that it would've been longer. \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 16:42
  • \$\begingroup\$ I've added an 18 with it in now. \$\endgroup\$ Commented Feb 8, 2020 at 17:05
  • \$\begingroup\$ “⁴ịṚn;ỊæṂ»œs7$fẆ 16 based on yours and @Grimmy’s. \$\endgroup\$ Commented Feb 8, 2020 at 17:18
  • 2
    \$\begingroup\$ @NickKennedy make that 14 :) \$\endgroup\$ Commented Feb 8, 2020 at 17:44
9
\$\begingroup\$

Python, 52 bytes

import re
re.compile('do|re|mi|fa|sol|la|si').search

Try it online!

Yup, a regex. A match produces a Truthy match object, and a non-match produces a Falsey None. Using re.compile to make an compiled pattern as a function is a bit shorter than a direct lambda:

55 bytes

lambda w:re.search('do|re|mi|fa|sol|la|si',w)
import re

Try it online!

For comparison, without regex:

58 bytes

lambda w:any(map(w.count,'do re mi fa sol la si'.split()))

Try it online!

We can almost save a byte by writing 1in map(...), but this doesn't catch the string appearing two or more times.

\$\endgroup\$
3
  • \$\begingroup\$ +1 good job on exploring multiple options! \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 10:07
  • 1
    \$\begingroup\$ @RGS Thanks, I forgot to change that. \$\endgroup\$
    – xnor
    Commented Feb 8, 2020 at 10:09
  • 2
    \$\begingroup\$ In case someone tries it, using do|re|[ms]i|[fl]a|sol saves a total of 0 bytes, and just looks worse. \$\endgroup\$ Commented Feb 10, 2020 at 10:49
8
\$\begingroup\$

CP-1610 assembly (Intellivision), 41 DECLEs1 ≈ 52 bytes

A routine taking a pointer to a NUL-terminated string into R4 and setting the carry if the test is successful, or clearing it otherwise.

275         |         PSHR    R5
2A0         | @@read  MVI@    R4,     R0
338 061     |         SUBI    #'a',   R0
20B 01B     |         BMI     @@rtn
04C         |         SLL     R0,     2
04C         |         SLL     R0,     2
048         |         SLL     R0
3E0         |         XOR@    R4,     R0
2A1         |         MVI@    R4,     R1
33C 002     |         SUBI    #2,     R4
001         |         SDBD
2BD 0C6 048 |         MVII    #@@tbl, R5
368         | @@loop  CMP@    R5,     R0
204 00D     |         BEQ     @@rtn
001         | @@next  SDBD
37D 0CC 048 |         CMPI    #@@so,  R5
22C 008     |         BNEQ    @@loop
368         |         CMP@    R5,     R0
22C 01B     |         BNEQ    @@read
379 06C     |         CMPI    #'l',   R1
22C 01F     |         BNEQ    @@read
2B7         | @@rtn   PULR    R7
00F         | @@tbl   DECLE   $00F
245         |         DECLE   $245
1E9         |         DECLE   $1E9
0C1         |         DECLE   $0C1
101         |         DECLE   $101
229         |         DECLE   $229
22F         | @@so    DECLE   $22F

How?

Each note made of the ASCII codes \$(c_0,c_1)\$ is encoded as a single DECLE with the following formula:

$$((c_0-97)\times 32) \operatorname{xor} c_1$$

The edge case "sol" is encoded as "so" and put at the end of the lookup table. There's an additional test for the "l".

Full commented test code

        ROMW    10                ; use 10-bit ROM width
        ORG     $4800             ; map this program at $4800

        ;; ------------------------------------------------------------- ;;
        ;;  main code                                                    ;;
        ;; ------------------------------------------------------------- ;;
main    PROC

        SDBD                      ; set up an interrupt service routine
        MVII    #isr,   R0        ; to do some minimal STIC initialization
        MVO     R0,     $100
        SWAP    R0
        MVO     R0,     $101

        EIS                       ; enable interrupts

        SDBD                      ; R5 = pointer into the test case index
        MVII    #tc.tbl,R5
        MVII    #$200,  R3        ; R3 = backtab pointer
        MVII    #14,    R1        ; R1 = number of test cases

@@loop  MVI@    R5,     R4        ; R4 = pointer to next string
        SDBD
        ADDI    #tc.00, R4

        PSHR    R5                ; save the test variables
        PSHR    R3
        PSHR    R1
        CALL    mmb               ; invoke our routine
        PULR    R1                ; restore the test variables
        PULR    R3
        PULR    R5

        MVII    #$88,   R0        ; R0 = '1'
        BC      @@draw

        MVII    #$80,   R0        ; or '0' if the carry is not set

@@draw  MVO@    R0,     R3        ; draw this character
        INCR    R3                ; increment the backtab pointer

        DECR    R1                ; next test case
        BNEQ    @@loop

        DECR    R7                ; done: loop forever

        ENDP

        ;; ------------------------------------------------------------- ;;
        ;;  test cases                                                   ;;
        ;; ------------------------------------------------------------- ;;
tc      PROC

@@tbl   DECLE   @@00 - @@00, @@01 - @@00, @@02 - @@00, @@03 - @@00
        DECLE   @@04 - @@00, @@05 - @@00, @@06 - @@00, @@07 - @@00
        DECLE   @@08 - @@00, @@09 - @@00, @@10 - @@00, @@11 - @@00
        DECLE   @@12 - @@00, @@13 - @@00

        ;; truthy
@@00    STRING  "far", 0
@@01    STRING  "solace", 0
@@02    STRING  "fire", 0
@@03    STRING  "summit", 0
@@04    STRING  "doctor", 0
@@05    STRING  "blast", 0
@@06    STRING  "subsidiary", 0
@@07    STRING  "obsolete", 0

        ;; falsy
@@08    STRING  "boat", 0
@@09    STRING  "shrimp", 0
@@10    STRING  "biscuit", 0
@@11    STRING  "bullet", 0
@@12    STRING  "college", 0
@@13    STRING  "also", 0

        ENDP

        ;; ------------------------------------------------------------- ;;
        ;;  ISR                                                          ;;
        ;; ------------------------------------------------------------- ;;
isr     PROC

        MVO     R0,     $0020     ; enable display

        CLRR    R0
        MVO     R0,     $0030     ; no horizontal delay
        MVO     R0,     $0031     ; no vertical delay
        MVO     R0,     $0032     ; no border extension
        MVII    #$D,    R0
        MVO     R0,     $0028     ; light-blue background
        MVO     R0,     $002C     ; light-blue border

        JR      R5                ; return from ISR

        ENDP

        ;; ------------------------------------------------------------- ;;
        ;;  our routine                                                  ;;
        ;; ------------------------------------------------------------- ;;
mmb     PROC

        PSHR    R5                ; save the return address on the stack

@@read  MVI@    R4,     R0        ; R0 = current character
        SUBI    #'a',   R0        ; turn it into an index in [0..25]
        BMI     @@rtn             ; if the result is negative, it means
                                  ; we've reached the end of the string:
                                  ; we return with the carry cleared by SUBI

        SLL     R0,     2         ; multiply R0 by 32
        SLL     R0,     2
        SLL     R0

        XOR@    R4,     R0        ; XOR it with the next character
        MVI@    R4,     R1        ; and load a 3rd character in R1
        SUBI    #2,     R4        ; rewind the pointer by 2 characters

        SDBD                      ; R5 = pointer into the lookup table
        MVII    #@@tbl, R5

@@loop  CMP@    R5,     R0        ; compare the lookup table entry with R0
        BEQ     @@rtn             ; match? (if yes, the carry is set)

@@next  SDBD                      ; if we haven't reached the end of the table,
        CMPI    #@@so,  R5
        BNEQ    @@loop            ; try again with the next entry

        CMP@    R5,     R0        ; last test with 'so'
        BNEQ    @@read            ; abort if it doesn't match

        CMPI    #'l',   R1        ; otherwise, make sure it's followed by a 'l'
        BNEQ    @@read            ; abort if it doesn't match
                                  ; otherwise, the carry is set

@@rtn   PULR    R7                ; return

        ;; lookup table: 'do', 're', 'mi', 'fa', 'la', 'si', 'so'
@@tbl   DECLE   ('d' - 'a') * 32 XOR 'o'
        DECLE   ('r' - 'a') * 32 XOR 'e'
        DECLE   ('m' - 'a') * 32 XOR 'i'
        DECLE   ('f' - 'a') * 32 XOR 'a'
        DECLE   ('l' - 'a') * 32 XOR 'a'
        DECLE   ('s' - 'a') * 32 XOR 'i'
@@so    DECLE   ('s' - 'a') * 32 XOR 'o'

        ENDP

Output

output

screenshot from jzIntv


1. A CP-1610 opcode is encoded with a 10-bit value (0x000 to 0x3FF), known as a 'DECLE'.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Nice. Haven't seen this language yet. \$\endgroup\$
    – S.S. Anne
    Commented Feb 8, 2020 at 22:54
  • 1
    \$\begingroup\$ What is this?! +1 for the effort \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 23:00
  • 1
    \$\begingroup\$ @S.S.Anne In your defence, the Intellivision is a bit outdated. It's a 40-year old console. :-p (And the CP-1600 CPU family was not used in many other systems.) \$\endgroup\$
    – Arnauld
    Commented Feb 8, 2020 at 23:05
  • 1
    \$\begingroup\$ This is either 51.25 bytes or 61.5 bytes, depending on how the opcodes are stored. \$\endgroup\$
    – S.S. Anne
    Commented Feb 9, 2020 at 18:55
7
\$\begingroup\$

Perl 6, 26 bytes

{?/do|re|mi|fa|sol|la|si/}

Try it online!

Boring regex solution that checks for any of the strings.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I am aware that regex is a straightforward, and rather boring (as you put it) solution. I am hoping someone does something neat without regex! I edited the challenge to explicitly allow for lists of ascii values as input. Maybe someone can work with that. \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 8:48
6
\$\begingroup\$

C (gcc), 58 characters, 70 bytes

c;f(int*s){for(c=7;c&&!strstr(s,L"潤敲業慦慬楳\x6c6f73"+--c););}

Creative method required to save bytes/characters.

-17 thanks to Arnauld!
-8 bytes thanks to gastropner!
-2 bytes and -12 characters thanks to ceilingcat!

Try it online!

\$\endgroup\$
8
  • \$\begingroup\$ +1 for a C answer. I think it would be neater to return 1 for a Truthy and it doesn't change the byte count. If the method doesn't return explicitly, doesn't it count as returning null? Isn't that an acceptable Falsy? \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 23:02
  • \$\begingroup\$ @RGS The return; returns true for a Truthy because of the way the return register works. It saves two bytes from return 1;. The return 0; is the Falsy value. That's outside of the loop, when all of the possible strings have been checked. \$\endgroup\$
    – S.S. Anne
    Commented Feb 8, 2020 at 23:12
  • \$\begingroup\$ @Arnauld I can best that and fix an idiotic bug that I made. -- or get the same thing, with your latest comment. \$\endgroup\$
    – S.S. Anne
    Commented Feb 8, 2020 at 23:28
  • 1
    \$\begingroup\$ @ceilingcat Where do you generate those weird UTF-8 strings? \$\endgroup\$
    – S.S. Anne
    Commented Feb 9, 2020 at 15:30
  • 2
    \$\begingroup\$ Google for something like "unicode 6f64" for "do\0\0" \$\endgroup\$
    – ceilingcat
    Commented Feb 9, 2020 at 20:05
4
\$\begingroup\$

AWK, 47 \$\cdots\$ 31 30 bytes

{print/do|re|mi|fa|sol|la|si/}

Try it online!

awk automatically compares any regex with $0 (current line).

\$\endgroup\$
1
  • \$\begingroup\$ Good job! +1 Haven't seen much awk recently! \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 14:35
4
\$\begingroup\$

Retina, 21 bytes

do|re|mi|fa|sol|la|si

Try it online!

Very obvious and boring solution. 0 for false, nonzero for true.

\$\endgroup\$
2
  • \$\begingroup\$ +1 for doing it anyway. if sol were so would you manage to do something shorter? \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 20:07
  • 4
    \$\begingroup\$ @RGS They probably would be able to by one byte. \$\endgroup\$
    – S.S. Anne
    Commented Feb 9, 2020 at 18:50
4
\$\begingroup\$

Java 8, 43 bytes

s->s.matches(".*(do|re|mi|fa|sol|la|si).*")

Try it online.

Explanation:

s->           // Method with String parameter and boolean return-type
  s.matches(  //  Check if the String matches this regex fully:
    ".*       //   Any amount of optional leading characters
       (do|re|mi|fa|sol|la|si)
              //   Followed by one of our music sounds
     .*")    "//   Followed by any amount of optional trailing characters
\$\endgroup\$
2
3
\$\begingroup\$

Python 3, 60 bytes

lambda w:any(i in w for i in'do re mi fa sol la si'.split())

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Simple solution :) +1 \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 10:06
3
\$\begingroup\$

Red, 63 bytes

func[s][parse s[to["do"|"re"|"mi"|"fa"|"sol"|"la"|"si"]to end]]

Try it online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Thanks for your submission! Red is a nice colour +1 \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 10:25
  • 1
    \$\begingroup\$ @RGS Yes, it is! BTW, I think Red comes from reduce (the sofware complexity) \$\endgroup\$ Commented Feb 8, 2020 at 12:15
  • 1
    \$\begingroup\$ interesting! Thanks for sharing :D \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 13:10
3
\$\begingroup\$

Scratch 3.0, 13 blocks/135 + 21 = 156 bytes

+21 for having a predefined list n. Y'all do that by creating a new list within Scratch and entering each item manually. It took 21 keystrokes to manually create the list.

Scratch Blocks!

As SB Syntax:

when gf clicked
ask()and wait
set[o v]to(0
set[i v]to(1
repeat(7
change[o v]by<(answer)contains(item(i)of[n v
change[i v]by(1
end
say(o

This was a rather simple approach, as thankfully, there were appropriate built-ins. Zero is falsey and anything else is truthy.

I still don't have access to my old account, but y'all can still Try it online Scratch!

\$\endgroup\$
4
  • \$\begingroup\$ Where do you define n? \$\endgroup\$
    – Jo King
    Commented Feb 9, 2020 at 3:58
  • \$\begingroup\$ It's a predefined list. \$\endgroup\$
    – lyxal
    Commented Feb 9, 2020 at 3:59
  • 1
    \$\begingroup\$ You need to include the definition in your code. I doubt it only costs 15 bytes to declare an array \$\endgroup\$
    – Jo King
    Commented Feb 9, 2020 at 4:28
  • 2
    \$\begingroup\$ Your scratch submissions inspire me +1 \$\endgroup\$
    – RGS
    Commented Feb 9, 2020 at 10:48
3
\$\begingroup\$

R, 44 40 bytes

Another simple regex implementation. Fixed stupid mistake, thanks @Giuseppe.

grepl("do|re|mi|fa|sol|la|si",scan(,''))

Try it online!

One could also save a character by using grep instead of grepl, where integer(0) is falsey and everything else truthy... but that's not a big change and can't process a whole list at once.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for your R submission! Isn't there a shorter way to write an arrow function or something like that, so save the characters from scan(,'') ? \$\endgroup\$
    – RGS
    Commented Feb 9, 2020 at 20:05
  • 2
    \$\begingroup\$ @RGS you could do it with magrittr or similar to create a functional sequence but that wouldn't be base R. \$\endgroup\$
    – Giuseppe
    Commented Feb 9, 2020 at 20:08
2
\$\begingroup\$

Zsh, 36 35 bytes

[[ $1 =~ 'do|re|mi|fa|sol|la|si' ]]

Try it online! Try it online!

The =~ operator enables regex matching with the zsh/regex module, which is one byte shorter than glob matching using = (see previous answer).


If truthy-falsy convetions can be swapped, then 35 bytes:

[ ${1:#*(do|re|mi|fa|sol|la|si)*} ]

Try it online!

In any case, writing all syllables out is just as short as any combination, such as (do|re|[ms]i|[fl]a|sol).

\$\endgroup\$
3
  • \$\begingroup\$ +1 thanks for your submission \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 23:02
  • \$\begingroup\$ I think any truthy-falsy value works. \$\endgroup\$
    – S.S. Anne
    Commented Feb 8, 2020 at 23:14
  • \$\begingroup\$ Interesting choice. In Bash and Ksh the 1st solution could be 2 characters shorter due to unnecessary single quotes: Try it online!. \$\endgroup\$
    – manatwork
    Commented Feb 9, 2020 at 17:48
2
\$\begingroup\$

Keg, -rR 53 bytes

@h2|/÷!1≠:[⑹]øƒ0&᠀®s`do,re,mi,fa,sol,la,si`\,/÷(©s@hƒ

Try it online!

A rather regex-less approach for a rather regex-less language. :P

Zero is falsey, any other value is truthy.

Explained

This program has two parts: the helper function (h) and the main part. Here is the extracted function:

@h2|/÷!1≠:[⑹]øƒ

This function h takes 2 parameters from the stack, both of which are going to be strings.

@h2|            # Function definition
    /÷          # Split the first string (input) on the second string (note) and push individual items
      !1≠       # Push the length of the item splitted stack and see if it doesn't equal 1
         [⑹]    # If the above comparison results in true, increment the register
            øƒ  # Clear the stack of all remaining items and end the function

Now that the function is out of the way, we can get on to the real fun stuff: the body of the program.

0&᠀®s`do,re,mi,fa,sol,la,si`\,/÷(©s@hƒ
0&                                      # Store 0 in the register
  ᠀®s                                   # Take the input as a string and store it in var "s"
     `do,re,mi,fa,sol,la,si`\,/÷        # Push the string "do,re,mi,fa,sol,la,si", split on ","s and item split 
                                (©s@hƒ  # Apply function "h" to each and every item in that list.
# -rR automatically prints the value stored in the register at End Of Execution
\$\endgroup\$
1
  • \$\begingroup\$ Good work on that regex-less approach for a regex-less language +1 :D \$\endgroup\$
    – RGS
    Commented Feb 9, 2020 at 10:47
2
\$\begingroup\$

Python 3, 59 bytes

lambda w:any('sdrmflsooeiaail'[i::7]in w for i in range(7))

Try it online!

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

Japt, 20 19 bytes

`ÎolÌ·nè^`qÍøUã

Try it

\$\endgroup\$
4
  • 1
    \$\begingroup\$ +1 for not writing explicitly the musical notes. How did you encode them? String compression? \$\endgroup\$
    – RGS
    Commented Feb 8, 2020 at 14:34
  • \$\begingroup\$ @RGS, the backticks contain a compressed string, you can see what it decompresses to in the "transpiled" field. From there, I'm just splitting it to an array on ns and checking whether any of its elements appear in the input. \$\endgroup\$
    – Shaggy
    Commented Feb 9, 2020 at 13:33
  • 1
    \$\begingroup\$ Scratch that, now it checks if any of the substrings of the input are contained in the array. \$\endgroup\$
    – Shaggy
    Commented Feb 9, 2020 at 14:31
  • \$\begingroup\$ Alright, thanks for the explanation! \$\endgroup\$
    – RGS
    Commented Feb 9, 2020 at 20:04
2
\$\begingroup\$

GolfScript, 34 bytes

:a;7,{a"sdrmflsooeiaail"@>7%/,2=},

Try it online!

Explanation

:a;                                # Assign the input to the "accumulator"
   7,                              # Yields [0 1 2 3 4 5 6]
     {                          }, # Keep all that full fill this condition
                                   # Item = current item
                                   # ac = accumulator
      a"sdrmflsooeiaail"           # Stack: <item> <ac> "sdrmflsooeiaail"
                        @          # Stack: <ac> "sdrmflsooeiaail" <item>
                         >         # The slice begins at the current item
                          7%       # With a step of 7
                            /      # Try to split the input by the sliced item
                             ,2=   # Is the slice was successful?
\$\endgroup\$
2
  • \$\begingroup\$ +1 for a solution in a different answer. Thanks for your submission! \$\endgroup\$
    – RGS
    Commented Feb 9, 2020 at 1:35
  • \$\begingroup\$ I like to acknowledge people's work :) in my opinion, from the OPs standpoint, any answer that solves the challenge and is an honest attempt at golfing deserves an upvote from the OP. Further upvotes are given by the community to the answers they like the most and are better golfed, etc :) I hope this makes sense. \$\endgroup\$
    – RGS
    Commented Feb 9, 2020 at 1:38
2
\$\begingroup\$

Pyth, 20 bytes

At least it's as long as the regex...

See TIO for the two unprintables in the packed string.

:z."a|ê)H·>ÔMv´#°"

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for your submission! +1 for a Pyth answer. \$\endgroup\$
    – RGS
    Commented Feb 10, 2020 at 17:13
2
\$\begingroup\$

Pyth, 17 bytes

}#zc7."asÐ@»„¸Ï

Try it online!

Makes use of Pyth's string compression feature, .", to compress the string soldosimilarefa, then chops that string into 7 pieces, extra length in the first one, then filters which of those strings are contained in the input. If there is at least one, the result is truthy.

\$\endgroup\$
2
  • \$\begingroup\$ Cool submission, +1 for you. Somewhat similar to some of the other solutions in golfing languages, right? \$\endgroup\$
    – RGS
    Commented Feb 10, 2020 at 20:11
  • 1
    \$\begingroup\$ @RGS Yes, the "chop into 7 pieces and check" part is the same. All the rest is really just the language's built-in compression techniques. Pyth's are OK, but not the best. Thanks! \$\endgroup\$
    – isaacg
    Commented Feb 10, 2020 at 20:19
2
\$\begingroup\$

J, 42 bytes

[:>./^:_(;:'do re mi fa sol la si')&=@<\\.

There's probably a way to golf the string, but I had a hard enough time coming up with this as is. Fun challenge!

Explanation:

[:              NB. Capped fork
  >./^:_        NB. Get the largest value in the resulting array, i.e. 1 or 0
        (;:'do re mi fa sol la si') NB. Array of boxed words
        &       NB. Bind words to
         =@<    NB. Box and compare
            \   NB. With the prefixes
             \. NB. Of the suffixes

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ +1 for your nice J submission! Glad you liked it :) \$\endgroup\$
    – RGS
    Commented Feb 11, 2020 at 21:38
  • \$\begingroup\$ 35 bytes. \$\endgroup\$
    – Bubbler
    Commented Mar 4, 2020 at 4:29
1
\$\begingroup\$

C# (Visual C# Interactive Compiler) with /u:System.Text.RegularExpressions.Regex-flag, 37 bytes

s=>IsMatch(s,"do|re|mi|fa|sol|la|si")

Try it online.

Explanation:

s=>                           // Method with string parameter and bool return-type
  IsMatch(s,                  //  Check if the string contains the following regex-match:
    "do|re|mi|fa|sol|la|si")  //   One of the music sounds
\$\endgroup\$
5
  • \$\begingroup\$ That is one looooooong flag, maybe longer than the answer :p if you liked the challenge, consider upvoting it ;) \$\endgroup\$
    – RGS
    Commented Feb 10, 2020 at 8:48
  • \$\begingroup\$ @RGS Yeah. Luckily you don't have a leader-board, otherwise the flag in my answer would make it unreadable, haha. Happened once before. ;p \$\endgroup\$ Commented Feb 10, 2020 at 8:51
  • \$\begingroup\$ and you didn't learn the lesson! Also, is the leaderboard good practice? Or is it just for challenges with a lot of upvotes already? \$\endgroup\$
    – RGS
    Commented Feb 10, 2020 at 13:10
  • 1
    \$\begingroup\$ @RGS I personally never use it, but if you want to add a leader-board to your challenge feel free to copy it from another challenge and edit it in. Here is my previous answer where I used it and someone mentioned I broke the leader-board. \$\endgroup\$ Commented Feb 10, 2020 at 13:27
  • \$\begingroup\$ Too bad you already edited the flag out of the header :P Thanks for the link! \$\endgroup\$
    – RGS
    Commented Feb 10, 2020 at 17:12
1
\$\begingroup\$

JavaScript (Node.js), 33 bytes

s=>s.match`do|re|mi|fa|sol|la|si`

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for your submission, +1! Why did you go for "javascript (node.js)"? Is the node.js part relevant? \$\endgroup\$
    – RGS
    Commented Feb 10, 2020 at 17:13
  • 1
    \$\begingroup\$ Thanks! It's just the option I chose in this case, it's not specifically needed. Just relies on tagged templates, an ES6 feature. \$\endgroup\$
    – Craig Ayre
    Commented Feb 11, 2020 at 14:30
1
\$\begingroup\$

W d, 24 22 bytes

I finally managed to compress the string!

Take your input in the form "['your string']". Languages without grouping are having a terrible time here.

☺¶4∙)╘┐►↔₧uVÿñ☼╠◙╤Γ()¿

Uncompressed:

1y56WX0y`2,"Wb,R`3,+,ak2=W

Explanation

1y56WX0y`2,                # Split "farmiesila" into chunks of 2
           "Wb,R`3,+       # Add "sol" and "do" wrapped into a list into the list
                    ,      # Try to split the input by all these strings
                     ak2=W # Choose all lengths that are equal to 2 (i.e. split successful)
\$\endgroup\$
4
  • \$\begingroup\$ +1 for you submission in W being a new language in the challenge! Good job. Can you add a TIO link? \$\endgroup\$
    – RGS
    Commented Feb 11, 2020 at 14:21
  • \$\begingroup\$ Unfortunately I requested it just after Dennis began to feel sick. So, no TIO yet! \$\endgroup\$
    – user85052
    Commented Feb 11, 2020 at 14:24
  • \$\begingroup\$ oh ok :/ I will have to trust you, then! \$\endgroup\$
    – RGS
    Commented Feb 11, 2020 at 14:27
  • \$\begingroup\$ However, you can still run the interpreter online. Repl it! But repl.it doesn't have a permalink feature... \$\endgroup\$
    – user85052
    Commented Feb 11, 2020 at 14:36
1
\$\begingroup\$

J, 33 bytes

[:OR@,do`re`mi`fa`sol`la`si E.&><

Try it online!

How it works

[:OR@,do`re`mi`fa`sol`la`si E.&><
      do`re`mi`fa`sol`la`si        NB. 7 enclosed strings to search for
                                <  NB. Enclose the input
                            E.&>   NB. Find matches for each of the 7 strings
[:OR@,                             NB. Flatten and take OR
\$\endgroup\$
1
\$\begingroup\$

Excel, 155 bytes

=ISNUMBER(FIND(0,SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"si",0),"la",0),"sol",0),"fa",0),"mi",0),"re",0),"do",0)))

A sequence of SUBSTITUTE, and then a check to see if any of them found a match.

FIND returns error #VALUE! if no match is found, so would have to wrap each usage in error handling.

Test samples

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for the screenshot! Interesting work done with EXCEL here :) \$\endgroup\$
    – RGS
    Commented Mar 4, 2020 at 9:46

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.