Can I join the music box?

21

4

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

RGS

Posted 2020-02-08T08:21:30.513

Reputation: 5 047

8You must be European; apparently in the UK we changed the leading note to "ti" so that it didn't share a consonant. – Neil – 2020-02-08T10:57:39.233

Is the input guaranteed to be in lower case? – Arnauld – 2020-02-08T10:58:03.750

5@Neil Interesting, always thought it was because we love our 'ti'! :-) – Noodle9 – 2020-02-08T11:05:31.080

@Arnauld you can assume that, even though it was not in my original plans :p – RGS – 2020-02-08T11:23:44.900

5@Neil saying it like that makes it look like the UK is not in Europe :p – RGS – 2020-02-08T11:24:42.893

2Yeah, sadly we left over a week ago... – Neil – 2020-02-08T11:34:49.850

7Suggested test case: obsolete. (There's currently no real test case for sol, as solace also contains la.) – Arnauld – 2020-02-08T11:34:50.133

@Arnauld thanks for catching that – RGS – 2020-02-08T11:36:01.940

1I would have thought using so rather than sol would have been better for a golfing challenge as when all the matches are the same length there'd be more scope for different solutions. – Jonathan Allan – 2020-02-08T15:13:25.897

@JonathanAllan ahhh that would have been very clever... But I didn't come up with that and neither did anyone in the sandbox... So yeah :/ – RGS – 2020-02-08T16:39:14.207

Do you require a result for the empty string? I found a solution which works for all the test cases, but puts the empty string in the MMB. – GammaFunction – 2020-02-08T22:09:47.943

Suggested testcases: ols and los. – S.S. Anne – 2020-02-08T22:26:05.120

@GammaFunction a word is a non-empty string, so that would be fine. (Taking into account the motivation of the challenge.) Feel free to post it! – RGS – 2020-02-08T22:32:54.593

@S.S.Anne because they are a permutation of sol? Did you find any answer that would fail? – RGS – 2020-02-08T22:33:22.790

4Never mind those two. But lso would be a good test case to check if answers are cheating so instead of sol. This brings me back to when I would watch The Sound of Music all the time. – S.S. Anne – 2020-02-08T22:47:57.243

Can "Truthy" and "Falsy" be in any format? – S.S. Anne – 2020-02-08T23:18:37.293

1@S.S.Anne I don't think I understand. You can return any Truthy and Falsy values you like. – RGS – 2020-02-09T01:34:48.840

1You might reword it to say "any distinct Truthy or Falsy values". – S.S. Anne – 2020-02-09T14:26:39.367

1In Hungarian it's also ti instead of si. Also sol is just so – SztupY – 2020-02-10T11:29:36.613

Answers

12

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

Grimmy

Posted 2020-02-08T08:21:30.513

Reputation: 12 521

+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? – RGS – 2020-02-08T14:34:07.013

8

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.

xnor

Posted 2020-02-08T08:21:30.513

Reputation: 115 687

+1 good job on exploring multiple options! – RGS – 2020-02-08T10:07:38.783

1@RGS Thanks, I forgot to change that. – xnor – 2020-02-08T10:09:14.227

2In case someone tries it, using do|re|[ms]i|[fl]a|sol saves a total of 0 bytes, and just looks worse. – Ismael Miguel – 2020-02-10T10:49:27.377

8

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.

Jonathan Allan

Posted 2020-02-08T08:21:30.513

Reputation: 67 804

+1 nice solution, it is just a shame that you didn't manage to compress sol together with the other 6 musical notes – RGS – 2020-02-08T16:40:28.360

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. – RGS – 2020-02-08T16:42:47.000

I've added an 18 with it in now. – Jonathan Allan – 2020-02-08T17:05:35.140

“⁴ịṚn;ỊæṂ»œs7$fẆ 16 based on yours and @Grimmy’s. – Nick Kennedy – 2020-02-08T17:18:45.953

@NickKennedy ah yeah "sol" at the front allows œs – Jonathan Allan – 2020-02-08T17:30:54.400

2@NickKennedy make that 14 :) – Jonathan Allan – 2020-02-08T17:44:06.023

Very nice job, too bad I can't go for +2 :p – RGS – 2020-02-08T20:03:47.120

7

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'.

Arnauld

Posted 2020-02-08T08:21:30.513

Reputation: 111 334

2Nice. Haven't seen this language yet. – S.S. Anne – 2020-02-08T22:54:00.080

1What is this?! +1 for the effort – RGS – 2020-02-08T23:00:35.370

1@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.) – Arnauld – 2020-02-08T23:05:45.523

1This is either 51.25 bytes or 61.5 bytes, depending on how the opcodes are stored. – S.S. Anne – 2020-02-09T18:55:16.033

6

Perl 6, 26 bytes

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

Try it online!

Boring regex solution that checks for any of the strings.

Jo King

Posted 2020-02-08T08:21:30.513

Reputation: 38 234

1I 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. – RGS – 2020-02-08T08:48:17.660

6

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!

S.S. Anne

Posted 2020-02-08T08:21:30.513

Reputation: 1 161

+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? – RGS – 2020-02-08T23:02:17.477

@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. – S.S. Anne – 2020-02-08T23:12:00.323

@Arnauld I can best that and fix an idiotic bug that I made. -- or get the same thing, with your latest comment. – S.S. Anne – 2020-02-08T23:28:43.043

@Arnauld I didn't look but I think I got the same thing as you. Let me take a look. – S.S. Anne – 2020-02-08T23:37:05.210

79 bytes – Arnauld – 2020-02-09T00:12:58.800

Riffing on @Arnauld's comment: 72 bytes.

– gastropner – 2020-02-09T02:10:06.530

1@ceilingcat Where do you generate those weird UTF-8 strings? – S.S. Anne – 2020-02-09T15:30:25.460

2Google for something like "unicode 6f64" for "do\0\0" – ceilingcat – 2020-02-09T20:05:09.630

4

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).

Noodle9

Posted 2020-02-08T08:21:30.513

Reputation: 2 776

Good job! +1 Haven't seen much awk recently! – RGS – 2020-02-08T14:35:12.600

4

Retina, 21 bytes

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

Try it online!

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

79037662

Posted 2020-02-08T08:21:30.513

Reputation: 1 739

+1 for doing it anyway. if sol were so would you manage to do something shorter? – RGS – 2020-02-08T20:07:52.727

4@RGS They probably would be able to by one byte. – S.S. Anne – 2020-02-09T18:50:17.397

4

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

Kevin Cruijssen

Posted 2020-02-08T08:21:30.513

Reputation: 67 575

Why do you check for the "full match"? I'm assuming checking for a substring with the regex would be longer..? +1 for a Java submission. – RGS – 2020-02-10T08:47:38.550

1

@RGS Yeah, Java's regex-contains method is extremely verbose. It would be this instead: s->java.util.regex.Pattern.compile("do|re|mi|fa|sol|la|si").matcher(s).find() (77 bytes)

– Kevin Cruijssen – 2020-02-10T08:49:57.543

3

Python 3, 60 bytes

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

Try it online!

Mukundan

Posted 2020-02-08T08:21:30.513

Reputation: 1 188

Simple solution :) +1 – RGS – 2020-02-08T10:06:37.830

3

Red, 63 bytes

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

Try it online!

Galen Ivanov

Posted 2020-02-08T08:21:30.513

Reputation: 13 815

1Thanks for your submission! Red is a nice colour +1 – RGS – 2020-02-08T10:25:52.107

1@RGS Yes, it is! BTW, I think Red comes from reduce (the sofware complexity) – Galen Ivanov – 2020-02-08T12:15:09.413

1interesting! Thanks for sharing :D – RGS – 2020-02-08T13:10:21.267

3

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!

Lyxal

Posted 2020-02-08T08:21:30.513

Reputation: 5 253

Where do you define n? – Jo King – 2020-02-09T03:58:30.993

It's a predefined list. – Lyxal – 2020-02-09T03:59:52.757

1You need to include the definition in your code. I doubt it only costs 15 bytes to declare an array – Jo King – 2020-02-09T04:28:49.953

2Your scratch submissions inspire me +1 – RGS – 2020-02-09T10:48:10.630

2

Japt, 20 19 bytes

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

Try it

Shaggy

Posted 2020-02-08T08:21:30.513

Reputation: 24 623

1+1 for not writing explicitly the musical notes. How did you encode them? String compression? – RGS – 2020-02-08T14:34:33.170

@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. – Shaggy – 2020-02-09T13:33:52.447

1Scratch that, now it checks if any of the substrings of the input are contained in the array. – Shaggy – 2020-02-09T14:31:52.483

Alright, thanks for the explanation! – RGS – 2020-02-09T20:04:35.143

2

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).

GammaFunction

Posted 2020-02-08T08:21:30.513

Reputation: 2 838

+1 thanks for your submission – RGS – 2020-02-08T23:02:37.737

I think any truthy-falsy value works. – S.S. Anne – 2020-02-08T23:14:07.617

Interesting choice. In Bash and Ksh the 1st solution could be 2 characters shorter due to unnecessary single quotes: Try it online!.

– manatwork – 2020-02-09T17:48:43.317

2

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?

user85052

Posted 2020-02-08T08:21:30.513

Reputation:

+1 for a solution in a different answer. Thanks for your submission! – RGS – 2020-02-09T01:35:26.013

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. – RGS – 2020-02-09T01:38:41.160

2

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

Lyxal

Posted 2020-02-08T08:21:30.513

Reputation: 5 253

Good work on that regex-less approach for a regex-less language +1 :D – RGS – 2020-02-09T10:47:51.780

2

Python 3, 59 bytes

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

Try it online!

ovs

Posted 2020-02-08T08:21:30.513

Reputation: 21 408

2

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.

John

Posted 2020-02-08T08:21:30.513

Reputation: 171

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(,'') ? – RGS – 2020-02-09T20:05:53.137

1

@RGS you could do it with magrittr or similar to create a functional sequence but that wouldn't be base R.

– Giuseppe – 2020-02-09T20:08:02.677

2

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!

famous1622

Posted 2020-02-08T08:21:30.513

Reputation: 451

Thanks for your submission! +1 for a Pyth answer. – RGS – 2020-02-10T17:13:37.973

2

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.

isaacg

Posted 2020-02-08T08:21:30.513

Reputation: 39 268

Cool submission, +1 for you. Somewhat similar to some of the other solutions in golfing languages, right? – RGS – 2020-02-10T20:11:28.187

1@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! – isaacg – 2020-02-10T20:19:19.697

1

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

Kevin Cruijssen

Posted 2020-02-08T08:21:30.513

Reputation: 67 575

That is one looooooong flag, maybe longer than the answer :p if you liked the challenge, consider upvoting it ;) – RGS – 2020-02-10T08:48:51.117

@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 – Kevin Cruijssen – 2020-02-10T08:51:38.050

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? – RGS – 2020-02-10T13:10:13.277

1

@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.

– Kevin Cruijssen – 2020-02-10T13:27:14.443

Too bad you already edited the flag out of the header :P Thanks for the link! – RGS – 2020-02-10T17:12:41.170

1

JavaScript (Node.js), 33 bytes

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

Try it online!

Craig Ayre

Posted 2020-02-08T08:21:30.513

Reputation: 217

Thanks for your submission, +1! Why did you go for "javascript (node.js)"? Is the node.js part relevant? – RGS – 2020-02-10T17:13:17.567

1Thanks! It's just the option I chose in this case, it's not specifically needed. Just relies on tagged templates, an ES6 feature. – Craig Ayre – 2020-02-11T14:30:22.127

1

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)

user85052

Posted 2020-02-08T08:21:30.513

Reputation:

+1 for you submission in W being a new language in the challenge! Good job. Can you add a TIO link? – RGS – 2020-02-11T14:21:07.263

Unfortunately I requested it just after Dennis began to feel sick. So, no TIO yet! – None – 2020-02-11T14:24:38.123

oh ok :/ I will have to trust you, then! – RGS – 2020-02-11T14:27:09.180

However, you can still run the interpreter online. Repl it! But repl.it doesn't have a permalink feature...

– None – 2020-02-11T14:36:21.157

1

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!

Finn Günther

Posted 2020-02-08T08:21:30.513

Reputation: 31

+1 for your nice J submission! Glad you liked it :) – RGS – 2020-02-11T21:38:05.683