66
\$\begingroup\$

Write the shortest program that prints the sound my alarm clock makes, and stops after an inputted number of beeps.

For reference, here is the sound my alarm makes:

beep beep beep beep beep beepbeep beepbeep beepbeep beepbeep beepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeep

Basically beep, beepbeep, beepbeepbeep, and beepbeepbeepbeep repeated 5 times each with spaces in between, followed by a beepbeep...beep which is 25 beeps long with no spaces in between (does beep still sound like a word to you?).

Your program should take a number as input (assume it's between 0 and 75), and stop printing after that many beeps.

Note: Your program should stop after that many beeps, not after that many groups of beeps. For example, 7 will return beep beep beep beep beep beepbeep.

Whitespace in between beeps must follow the exact pattern above, although any trailing whitespace or unsuppressable output from your compiler or interpreter is allowed.

Test cases:

3   beep beep beep
0   
1   beep
7   beep beep beep beep beep beepbeep
8   beep beep beep beep beep beepbeep beep
55  beep beep beep beep beep beepbeep beepbeep beepbeep beepbeep beepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeepbeep
67  beep beep beep beep beep beepbeep beepbeep beepbeep beepbeep beepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeep

This is code golf, so the shortest answer in bytes, per language, wins.

\$\endgroup\$
16
  • 7
    \$\begingroup\$ This challenge is evil - will upvote if I didn't reach my daily vote limit. Care to continue showcasing dotcomma? \$\endgroup\$ Aug 21, 2020 at 13:34
  • \$\begingroup\$ @HighlyRadioactive Thanks! This challenge might actually be doable in dotcomma, I think. \$\endgroup\$ Aug 21, 2020 at 13:41
  • \$\begingroup\$ Obviously, but it won't be short in any way. (BTW You don't have to provide a full program, so , or . is acceptable for length 1.) Where's the full spec for it and why isn't it TC? \$\endgroup\$ Aug 21, 2020 at 13:43
  • 2
    \$\begingroup\$ @Kraay89 after the 5 groups of 4 beeps, it's 25 beeps in a row. The input is guaranteed to not exceed that many beeps. \$\endgroup\$ Aug 21, 2020 at 14:01
  • 1
    \$\begingroup\$ HNQ #1! Hooray! \$\endgroup\$ Aug 22, 2020 at 9:31

33 Answers 33

1
2
1
\$\begingroup\$

Wolfram Language (Mathematica), 68 bytes

If[Accumulate@⌈Range@20/5⌉~FreeQ~#,"beep","beep "]&~Array~#<>""&

Try it online!

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

Haskell, 99 bytes

f n=foldr(\i a->take i a++" "++(drop i a))(take(n*4)$cycle"beep")$scanl(+)4[(x`div`5)*4|x<-[6..19]]

Try it online!

foldr(\i a->take i a++" "++(drop i a)) - we fold accumulator inserting spaces at index from list.

(take(n*4)$cycle"beep") - accumulator = string of n "beep"s

$scanl(+)4[(xdiv5)*4|x<-[6..19]] - generates list of indexes where spaces should be inserted

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

Pip, 33 bytes

(1Xa^@:{i+:a}M_X5MJ\,4)R1"beep"Js

Attempt This Online!

\$\endgroup\$
1
2

Your Answer

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

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