| Bytes | Lang | Time | Link |
|---|---|---|---|
| 429 | Bespoke | 250827T091115Z | Josiah W |
| 025 | Pip | 220222T233811Z | DLosc |
| 068 | PowerShell | 200821T232249Z | mazzy |
| 019 | vemf | 240610T161116Z | taswelll |
| 068 | Python 3 | 240610T141440Z | None1 |
| 058 | Haskell | 220222T220608Z | lynn |
| 569 | dotcomma | 201001T123047Z | Dorian |
| 064 | Zsh | 210530T150557Z | pxeger |
| 020 | Vyxal | 210530T165218Z | wasif |
| 110 | Python 3 | 200821T135050Z | pxeger |
| 853 | Poetic | 201002T063836Z | JosiahRy |
| 019 | 05AB1E | 200821T145121Z | Kevin Cr |
| 123 | Setanta | 200826T122016Z | bb94 |
| 099 | Haskell | 200825T193239Z | AZTECCO |
| 068 | Wolfram Language Mathematica | 200825T054730Z | att |
| 054 | JavaScript ES7 | 200821T144245Z | Arnauld |
| nan | x8616 machine code | 200821T191054Z | 640KB |
| nan | dotcomma old | 200821T143159Z | rydwolf |
| 054 | Perl 5 | 200823T155833Z | Kjetil S |
| 105 | Lua | 200821T145515Z | Riptide |
| 015 | Husk | 200822T180220Z | Zgarb |
| 060 | C gcc | 200821T172820Z | Noodle9 |
| 118 | Python 3 | 200821T140720Z | Manish K |
| 5046 | J | 200821T171635Z | Jonah |
| 032 | APL Dyalog Unicode | 200821T211522Z | Tessella |
| 059 | Python 2 | 200821T221004Z | xnor |
| 227 | PowerShell 5.1 | 200821T213633Z | PowerShe |
| 016 | Jelly | 200821T212234Z | Jonathan |
| 164 | Python 3 | 200821T195938Z | christia |
| 023 | Charcoal | 200821T192441Z | Neil |
| 050 | APL+WIN | 200821T192332Z | Graham |
| 075 | Io | 200821T142859Z | user9649 |
| 069 | R | 200821T152549Z | Dominic |
| 188 | Wolfram Language Mathematica | 200821T144902Z | ZaMoC |
| 095 | R | 200821T141158Z | Giuseppe |
| 076 | Rust | 200821T144943Z | madlaina |
Bespoke, 429 bytes
pre-midnight
silent reflection
relaxation till morning
beeebeeep!beeebeeep!beeebeeep!beeebeeep
ALRIGHT!I am up now
waking this goddamn early?I am very awfully tired
but if something pleasant awaits me,why sit?I persevered
I go have scoops of cereal at six-ten A.M
it really is so serene at home,isnt it
sometime,listen closely to how it all is
softly,as birdies all sing
in mornings,everything is rather peaceful
although it ends
The locations of the spaces are encoded in the bits of the number 600479991223647.
Pip, 33 25 bytes
"beep"Xa^@4*\$+J(\,4)X5Js
Explanation
"beep"Xa^@4*\$+J(\,4)X5Js
\,4 Range from 1 to 4 inclusive
( )X5 Repeat each digit 5 times
J Join into a single string
\$+ Scan on addition
4* Multiply each by 4
^@ Split at those indices the following string:
"beep"Xa "beep" repeated (cmdline arg) times
Js Join on spaces
PowerShell, 68 bytes
(0.."$args"|%{' '*((0x444444924AABE-shr$_)%2)*($_-lt52)})-join'beep'
The script:
- generates an array of whitespaces and empty strings
- joins array elements with 'beep'
The script can add a trailing whitespace that is allowed by the author. See the test cases in the TIO link.
The PowerShell works with 64 bitmasks only, so I had to add a condition ($_-lt52)
vemf, 19 bytes
┴‼♪¨beep₧╟4↨‼5╤+æn,
Function that takes a number and returns a string. Try it online
┴‼♪¨beep₧╟4↨‼5╤+æn,
♪¨beep ' ["beep"]
┴‼ ' repeat α times
₧╟4↨‼5╤+ ' partition at...
4↨‼5 ' 1111122223333344444
╤+ ' prefix sum
æn ' join
Python 3, 68 bytes
lambda x:''.join('beep'+' '*(600479991223647>>i&1)for i in range(x))
Explanation
600479991223647 equals to 0b10001000100010001000100100100100100101010101011111, for every i that satisfies the i-th beep (0-indexed) has a space after it, the bit representing 2i is 1, thus we can take out these bits and print the beeps according to the bits.
dotcomma, 617 569 bytes
[,].[[[,.][[[[[.][.][.][.].,][,.].,][,.].,][[,][[[,][,.].,][,][,].,].,][,][[[,.][.][.].,][.][.][.].,][,][[[,.][[[,.][[,]].,][],].,],].[,][.,][[.][.][.][.][.].,].[.[.[[[,.][[].[],].,][[,][[,][[[[,][[[,],]].,],]].,][],][.[.[,].][,][,]].][,][[,][[,][,][,]].,][.[.[,].]][[,.][[].[],].,],.[[[,][[,.]].,][.[.[,].][,]]],.[.[.[,].][,[.][.][.][.][.].,][,]][,],.][.[.[,].][,]][[[,.][[].[],].,][,.].,].[.[,].][,][,],.][,][.[.[,].]][,[,[,[,[,[,[,[,.]]]]]]]]].,].[[.[.[,].]][[,.][[].[],].,][.[[,],]][.[.[,].][,][,]][.[,]][,.][.[.[,].][,][,.]][.[[,][,.],.]].][.[.[,.].]][,.]],.[[,.]]
-48 bytes by rearranging the last counter loop and thereby avoiding duplicate code.
Phew, I need to rearrange my brain again... Bracket chaos ^^
This is first try with this language. It's quite fun. The changes made to the old version seem to be very effective when I can shrink the program size to less than 1% of the old version. Are there plans to put this language on tio.run? What about plumber? I think that's interesing, too.
Use the following snippet on your own risk (especially when changing the dotcomma code. I had several freezes because I unintetionally created endless loops)
<script src="https://combinatronics.com/Radvylf/dotcomma/master/interpreter.js"></script><script src="https://code.jquery.com/jquery-3.5.1.min.js"></script><script>$(document).ready(function () {$("#btnInterpret").click(function () {$("#txtResult").text(interpret($("#txtCode").val(), parseInt($("#txtInput").val()), $("#lstOutputAs").children("option:selected").val()));});});</script><style>.textBox {background-color: white;border: 1px solid black;font-family: Courier New, Courier, monospace;width: 100%;}</style>Code: <textarea id="txtCode" type="text" class="textBox" style="height: 200px">[,].[[[,.][[[[[.][.][.][.].,][,.].,][,.].,][[,][[[,][,.].,][,][,].,].,][,][[[,.][.][.].,][.][.][.].,][,][[[,.][[[,.][[,]].,][],].,],].[,][.,][[.][.][.][.][.].,].[.[.[[[,.][[].[],].,][[,][[,][[[[,][[[,],]].,],]].,][],][.[.[,].][,][,]].][,][[,][[,][,][,]].,][.[.[,].]][[,.][[].[],].,],.[[[,][[,.]].,][.[.[,].][,]]],.[.[.[,].][,[.][.][.][.][.].,][,]][,],.][.[.[,].][,]][[[,.][[].[],].,][,.].,].[.[,].][,][,],.][,][.[.[,].]][,[,[,[,[,[,[,[,.]]]]]]]]].,].[[.[.[,].]][[,.][[].[],].,][.[[,],]][.[.[,].][,][,]][.[,]][,.][.[.[,].][,][,.]][.[[,][,.],.]].][.[.[,.].]][,.]],.[[,.]]</textarea><br />Input: <textarea id="txtInput" type="text" class="textBox">25</textarea><br /><input id="btnInterpret" type="button" value="Run" />Output as: <select id="lstOutputAs"><option value="true">String</option><option value="">Number array</option></select><br />Result:<br /><div id="txtResult" class="textBox" style="overflow-wrap: break-word"></div>
Code:
(sorry for the missing interpunctuation. This way I was able to run the commented code directly in the interpreter)
[,].[ if input > 0
[[,.][ save input on recursion stack
[
[ ### Build ASCII values for "b" "e" "p" and space " "
[[.][.][.][.].,] 4
[,.].,] 8
[,.].,] 16
[[,] put 16 on recursion stack and save copy in queue
[
[[,][,.].,] 32
[,][,].,] 96
.,] 112 ("p")
in queue: 32 96 112
[,] roll left (queue: "@p ")
[[[,.][.][.].,][.][.][.].,] "b" "e"
[,] roll left (queue: " bep")
[[[,.][ save " " on recursion stack
[[,.][[,]].,] reverse letters ("peb")
[], insert 0 (start of queue)
].,],] save two copies of 32 (one for space character and one for counting beeps)
### Build list of "beep"s in reverse - each separated by a null char
Since the maximum input is 75 the 25 consecutive beeps at the end
will be limited by the input - so I can safely put a few more
beeps into the list because I just have a 32 handy
sc: spaces counter
pc: pattern counter
bc: beep counter
target queue: 0 0 sc pc bc " peb"
current queue: "peb" 0 bc(32) " "
I will refer to the two consecutive 0s at the start of the variable
section as "start of queue" or just "start"
pc: | 1 | 2 |
sc: | 1 | 2 | 3 | 4 | 5 | 1 | 2 | 3 | 4 | 5 |
bc: | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 1 | 2 | 1 | 2 | 1 | 2 | 1 | 2 |
beep beep beep beep beep beepbeep beepbeep beepbeep beepbeep beepbeep
.[,] roll to start
[.,] insert 1 for spaces counter (since I append new beeps to the start of the
queue we are only one space away from the next pattern)
[[.][.][.][.][.].,] insert 5 for pattern counter
queue: pc(5) bc(32) " bep" 0 sc(1)
.[ while pattern counter > 0 ### Attention: current position is beep counter!
.[ while spaces counter > 0 ### Attention: current position is beep counter!
.[ while beep counter > 0
[[,.][[].[],].,] save beep counter -1 on queue (also hold it in recursion stack)
[ # put a copy of "beep" on the queue
[,] roll over " "
[[,][[ put "p" on recursion stack
[[,][[ put "e" on recursion stack
[,] put "b" on recursion stack
,]] put "b" on queue
.,],]] put "ee" on queue
.,] put "p" on queue
[], put 0 on queue
]
[
.[.[,].] roll to start (roll until two consecutive 0s are found)
[,][,] go to beep counter
]
.] return value for loop (end of beep counter loop)
# insert space
[,] roll over beep counter
[[,][[,][,][,]].,] copy and insert space
# if spaces counter - 1 > 0: copy pattern counter to beep count
(the pattern counter contains the number of consecutive beeps
that should be separated by a space)
[.[.[,].]] roll to spaces counter
[[,.][[].[],].,] decrement spaces counter
,.[ if spaces counter > 0
[[,][[,.]].,] replace beep counter with copy of pattern counter
[.[.[,].][,]] roll to pattern counter (if the spaces loop repeats we need to be at
the beep counter; I will read the next value to determine if the loop
should repeat; Thats's why I stop one value before beep counter)
],.[ else
.[.[,].] roll to spaces count
[,[.][.][.][.][.].,] set it 5 for next round
[,] roll to beep count
]
[,],. get return value for loop (pattern counter for repeating
or beep counter(0) for stopping)
] end of spaces loop
[.[.[,].][,]] roll to pattern counter
[
[[,.][[].[],].,] decrement pattern counter
[,.]., set new beep counter = pattern counter
]
.[.[,].][,] roll to pattern counter
[,],. repeat if > 0
] end of pattern loop
[,][.[.[,].]] roll to start
[,[,[,[,[,[,[,[,.]]]]]]]] delete variables constants and excess space in front of first beep
].,] put input back into queue
### Count beeps
The idea is to delete all 0s between the beeps until we match the input
then deleting everything behind it
I thought it would be easy to delete single 0s - What I didn't consider was
that I can end a loop only after a 0 has been processed so I needed a trick
What I do is: duplicate every character until I reach a 0 (which will also
be duplicated)
Then find the first 0 (reassigning it to the end of the queue) and delete
the second 0
After that I can delete the duplicated characters including the 0
.[ while input counter > 0
[.[.[,].]] roll to start
[[,.][[].[],].,] decrement input counter
[.[[,],]] duplicate until first 0
[.[.[,].][,][,]] roll to start + 2
[.[,]] roll to first 0
[,.] delete second 0
[.[.[,].][,][,.]] roll to start + 2 (deleting the second character)
[.[[,][,.],.]] delete every 2nd character until 0 found
.] end of loop end of loop
[.[.[,.].]] delete everything up to start
[,.] delete input counter
],.[ else (if input is 0)
[,.] delete input and output nothing
]
Zsh, 64 bytes
repeat $1 z+=beep.
repeat 4 repeat x+=5,5 z[t+=x]=\
<<<${z//./}
Because of a bug that's not fixed in the Zsh version available on TIO, the x+=5,5 needs to be single-quoted for +2 bytes.
Works by constructing a string of beep., replacing some .s with spaces, and then removing the .s. The differences in the indeces at which to remove the .s are 5, 5, 5, 5, 5, 10, 10, ... 15, 15, 20, 20, 20, 20, 20, so we cumulatively sum these as we go.
repeat $1: do this {input} times:z+=beep.: appendbeep.to the variable$z(which implicitly starts empty)
repeat 4:repeat x+=5,5: do this 5 times, but also increment$xby5(it starts at0implicitly) before the loop starts:t+=x: increment$t(the cumulative sum) by$x(again,$tstarts at0implicitly)z[]=\: set the$tth character (1-indexed) of$zto a space
${z//./}: take$z, with dots.replaced by {empty string}<<<: print
Python 3, 108 120 118 110 bytes
+12 because I forgot to include the import statement which I had to put in the TIO header, not body
-2 by replacing \x00 with \0 - thanks to @ovs
-8 by filtering instead of replacing, and switching from . to !
import zlib;lambda x:filter(33 .__ne__,zlib.decompress(b'x\x9cKJM-PH\xc2A(\x92\xc7\xa26\x97nb4!\0hm{7')[:x*5])
How It Works
Sorry. I couldn't be bothered to come up with a clever algorithm.
zlib compressed string: beep beep beep beep beep beep!beep beep!beep beep!beep beep!beep beep!beep beep!beep!beep beep!beep!beep beep!beep!beep beep!beep!beep beep!beep!beep beep!beep!beep!beep beep!beep!beep!beep beep!beep!beep!beep beep!beep!beep!beep beep!beep!beep!beep beep!beep!beep!beep!beep!beep!beep!beep!beep!beep!beep!beep!beep!beep!beep!beep!beep!beep!beep!beep!beep
which is indexed into upto n*5th character, and then we filter for the bytes which don't equal 33 (exclamation mark). I chose ! using a brute-force to find the the shortest compressed output from zlib.
Poetic, 853 bytes
anything i did was futile
o,a clock i set definitely failed
i know i,at one A.M,crave a rest
i notice,o!the alarm!it beeps
it provides no break to get a dream
its six A.M
aaggh,i got up
should i get sleep at six A.M while in bed?nope,never
i need to snooze now,but couldnt
im tired
ill get cereal:a bowl,milk,flakes
o no,the milk spills
dammit,i shout,getting kleenex and old unclean napkins
next,the pouch of frosted flakes
finally,i make a toast
i look,o no!eight A.M
must i hustle,so i begin at ten?i needed to rush,i am tardy
so i change:i get a jacket,i get a shirt
aw hell,o no,found no pair o pants
ill clearly suffer in a pair o boxers
i see,o no!eleven A.M
its a shame,o,too late
really,ill wear a blouse
so now i hurry
o,here now
i sit
time flies
i see,o my!three P.M
now i earned a rest
i badly ne-ee-ee-ee-eeeded a nap
i topple,and then i do
This was a tough program to write. I wrote the poem about an alarm that wakes me up way too early.
05AB1E, 22 21 20 19 bytes
F’¼®b’4L5и{¦.¥NåúRJ
-1 byte by porting the approach used in multiple other answers.
Try it online or verify all test cases.
Original approach:
05AB1E (legacy), 22 21 bytes
'¬ž4L₂¸«×5иé»Z¡I£'p«J
Output is joined by newlines. If this has to be spaces instead, 1 byte has to be added by replacing the » with ðý.
Try it online or verify all test cases.
I wanted to use the legacy version of 05AB1E, since the maximum builtin Z works on strings (getting the character with the largest codepoint), which isn't the case in the new version of 05AB1E. This would have saved a byte over 'r. Unfortunately, the legacy version lacks the append_to_list builtin ª, so we'll have to use ¸« instead.
So here is a regular 05AB1E version as well with the same 22 21 bytes:
'¬ž4L₂ª×5иé»'r¡I£'p«J
Try it online or verify all test cases.
Explanation:
F # Loop `N` in the range [0, (implicit) input-integer):
’¼®b’ # Push dictionary string "peeb"
4L # Push list [1,2,3,4]
5и # Repeat it 5 times: [1,2,3,4,1,2,3,4,...]
{ # Sort it: [1,1,1,1,1,2,2,2,2,2,...]
¦ # Remove the first value
.¥ # Undelta this list (with implicit leading 0):
# [0,1,2,3,4,6,8,10,12,14,17,20,23,26,29,33,37,41,45,49]
Nå # Check if `N` is in this list (1 if truthy; 0 if falsey)
ú # Pad "peeb" with that many leading spaces
R # Reverse it to "beep" or "beep "
J # Join all strings on the stack together
# (after the loop, the result is output implicitly)
'¬ž '# Push dictionary string "beer"
4L # Push a list [1,2,3,4]
₂ # Push 26
ª # New version: Append it as trailing item to the list
¸« # Legacy version: Wrap into a list; merge the lists together
# [1,2,3,4,26]
× # Repeat each string that many times:
# ["beer","beerbeer","beerbeerbeer","beerbeerbeerbeer",...]
5и # Repeat this list five times
é # Sort it based on length
» # Join all strings in the list by newlines
'r '# New version: Push "r"
Z # Legacy version: Push the maximum character (without popping),
# which is "r"
¡ # Split the string on "r"
I£ # Leave the first input amount of substrings
'p« '# Append a "p" to each string in the list
J # And join it all together again
# (after which the result is output implicitly)
See this 05AB1E tip of mine (section How to use the dictionary?) to understand why ’¼®b’ is "peeb" and '¬ž is "beer".
Setanta, 146 144 140 124 123 bytes
-16 bytes by using a cheaper check for the first beep.
-1 byte by discovering that braces could be left out in one place.
gniomh(n){s:=""le i idir(0,n){a:=(i&freamh@mata((i-1)//5*8+1)+1)//2d:=(i-5*(a*a-a)/2)%a ma!d&i<51 s+=" "s+="beep"}toradh s}
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]]
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
Wolfram Language (Mathematica), 68 bytes
If[Accumulate@⌈Range@20/5⌉~FreeQ~#,"beep","beep "]&~Array~#<>""&
JavaScript (ES7), 55 54 bytes
f=n=>n?f(n-1)+'beep'+[" "[n>50|n%~~(n**=.4)^52%~n]]:''
How?
Given \$1\le n< 50\$, we want to know the number of consecutive beeps that are expected in this part of the sequence. The exact value is given by:
$$\left\lfloor\sqrt{\frac{2n}{5}}+\frac{1}{2}\right\rfloor$$
which is a slightly modified version of A002024.
But in practice, we only need an exact value on the boundaries of the runs of beeps and we can deal with a few off-by-one errors. That's why we instead compute the following approximation:
$$k=\left\lfloor n^{2/5}\right\rfloor$$
We need to insert a space whenever one of the following conditions is satisfied:
- \$k=1\$ and \$n\bmod 1=0\$ (the 2nd part being always true)
- \$k=2\$ and \$n\bmod 2=1\$
- \$k=3\$ and \$n\bmod 3=0\$
- \$k=4\$ and \$n\bmod 4=2\$
All the above conditions can be merged into:
$$(n \bmod k) = (52 \bmod (k+1))$$
\$52\$ being the smallest integer \$x>0\$ such that \$x\bmod 3=1\$, \$x\bmod 4=0\$ and \$x\bmod 5=2\$.
We need an additional test for \$n\ge50\$, where all remaining beeps are concatenated together. Otherwise, unwanted spaces would be inserted, starting at \$n=54\$.
Hence the final JS expression:
n > 50 | n % ~~(n **= 0.4) ^ 52 % ~n
which evaluates to 0 when a space must be inserted.
JavaScript (ES7), 55 bytes
A simpler approach using a lookup bit mask.
f=n=>n?f(--n)+'beep'+(0x222222492555F/2**n&1?' ':''):''
x86-16 machine code, IBM PC DOS, 58 54 53 bytes
Binary:
00000000: a182 0086 e02d 3030 d50a 7423 95b8 2009 .....-00..t#.. .
00000010: b305 b101 8bf1 ba30 01cd 2183 fe05 740c .......0..!...t.
00000020: e20a 4b75 03b3 0546 8bce cd29 4d75 eac3 ..Ku...F...)Mu..
00000030: 6265 6570 24 beep$
Listing:
A1 0082 MOV AX, WORD PTR [82H] ; command line AL = first char, AH = second char
86 E0 XCHG AH, AL ; endian convert
2D 3030 SUB AX, '00' ; ASCII convert
D5 0A AAD ; BCD to binary convert
74 23 JZ EXIT ; handle 0 input case
95 XCHG AX, BP ; Beeps Counter (BP) = user input
B8 0920 MOV AX, 0920H ; AH = 9, AL = ' '
B3 05 MOV BL, 5 ; Space Counter (SC) = 5
B1 01 MOV CL, 1 ; Beeps per Space Counter (BpSC) = 1
8B F1 MOV SI, CX ; Beeps per Space (BpS) = 1
BA 0130 MOV DX, OFFSET BEEP ; DX pointer to 'beep' string
BEEP_LOOP:
CD 21 INT 21H ; display beep
83 FE 05 CMP SI, 5 ; exceeded 50 beeps?
74 0C JZ NO_SPACE ; if so, don't display space
E2 0A LOOP NO_SPACE ; if BpSC not zero, don't display space
4B DEC BX ; decrement Space Counter (SC)
75 03 JNZ DO_SPACE ; if SC is zero, restart it and increment BpS
B3 05 MOV BL, 5 ; reset SC to 5
46 INC SI ; increment BpS
DO_SPACE:
8B CE MOV CX, SI ; reset Beeps per Space Counter (BpSC)
CD 29 INT 29H ; display space
NO_SPACE:
4D DEC BP ; decrement Beeps Counter (BP)
75 EA JNZ BEEP_LOOP
EXIT:
C3 RET ; return to DOS
BEEP DB 'beep$'
Someone in the comments described this challenge as "evil". I wouldn't go that far... but definitely lacking empathy.
Arbitrary modulos can be pesky in x86 when registers are tight. This is the inelegant counter/countdown approach (seemed only appropriate for an alarm clock challenge), basically just jockeying these three counters:
SI= Beeps per Space (BpS): Start at1. Increment every5spaces displayed. Once5is reached, no more spaces are displayed.BX= Space counter (SC): Start at5. Decrement every space displayed. At0, incrementBpSand reset to5.CX= Beeps per Space Counter (BpSC): Start at1. Decrement every'beep'displayed. At0, display a space and reset to currentBpS.
A standalone PC DOS executable, input is via command line.
Props: -1 byte thx to @gastropner!
dotcomma (old), 96577 bytes
Dotcomma is a language I created. I don't think I have any documentation or interpreter to link to yet, so it's not really competing at the moment. Takes input based on the number of inputs. Because it's so long, and very repetitive, here's the two blocks it's made up of:
For every beep without a space:
[[,.],[[[.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.].,][[.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.].,][[.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.].,][[.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.].,]]]
For every beep with a space:
[[,.],[[[.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.].,][[.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.].,][[.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.].,][[.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.].,][[.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.][.].,]]]
There's probably a way to golf down those constants. Anyway, I'll post an explanation when I have time.
Update: Dotcomma now has documentation and an interpreter. Because I added so many important new features since I posted this, it's practically a different language. If anyone else wants to post a different dotcomma answer that uses the full extent of the language's features, go ahead!
Perl 5, 54 bytes
$_=" beep"x$_;s/ /0x444444924aabe>>$x&$x++<51?$&:""/ge
Ungolfed a bit:
$_=" beep"x$_; # create string of space+beep the input number of times
s/ / # remove spaces unless it's space number
0x444444924aabe # 1 2 3 4 5 7 9 11 13 15 18 21 24 27 30
# 34 38 42 46 or 50 (counting from zero)
# 0x444444924aabe in binary have 1's on
# those positions
>>$x # keep space if 1-bit and space number <= 50
&$x++<51?$&:""/ge # remove space if not
Lua, 105 bytes
function b(n)t={}for i=5,24 do t[(i-1)*(i-2)//10]=' 'end for i=1,n do io.write('beep'..(t[i]or''))end end
Ungolfed code and test program:
function b(n)
t={}
for i=5, 24 do
t[(i-1)*(i-2)//10] = ' '
end
for i=1, n do
io.write('beep' .. (t[i] or ''))
end
end
for k, v in ipairs({ 3, 0, 1, 7, 8, 55, 67, 75 }) do
io.write(v .. '\t') b(v) print()
end
Output:
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
75 beep beep beep beep beep beepbeep beepbeep beepbeep beepbeep beepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeep beepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeepbeep
Edit 1: Thank you for your suggestions :) It greatly helped to compress the sequence that was used.
Edit 2: 99 Bytes solution provided by Arnault, getting rid of the (-1) and using a partial and clever one's complement to decrease a number:
function b(n)t={}for i=4,23 do t[i*~-i//10]=' 'end for i=1,n do io.write('beep'..(t[i]or''))end end
Husk, 16 15 bytes
wmΣC:Ṙ5ḣ4¹R¨⁸ep
Explanation
¨⁸ep Compressed string literal "beep"
R Repeat n times, n is input:
["beep","beep",..,"beep"]
C:Ṙ5ḣ4¹ Cut the above into pieces.
ḣ4 Range to 4: [1,2,3,4]
Ṙ5 Replicate 5 times:
[1,1,1,1,1,2,2,2,2,2,..,4]
: ¹ Append n:
[1,1,1,1,1,2,2,2,2,2,..,4,n]
C Cut the beep list to these lengths:
[["beep"],["beep"],..,[..,"beep","beep"]]
C stops when it runs out of elements, possibly cutting the last list short.
In this case it has to, since the beep list has length n.
mΣ Concatenate each:
["beep","beep",..,"beepbeep...beep"]
w Join by spaces, implicitly print.
C (gcc), 72 \$\cdots\$ 66 60 bytes
Saved 10 bytes thanks to the man himself Arnauld!!!
f(n){n&&printf(" beep"-~-(0x888889249557c>>n&n<55),f(n-1));}
Recursively calls itself \$n\$ times evaluating a bitwise expression (where the \$1\$ bits of a hard coded integer indicate if a space is needed) to determine whether or not to prefix the current beep with a space. This is done by adding \$0\$ or \$1\$ to a string literal (char* pointer) to offset it by one or not.
Python 3, 134 124 118 bytes
def f(n):
b=[*'beep']*n
for i in b'\4\t\16\23\30!*3<ER_ly\x86\x97\xa8\xb9\xca\xdb':b.insert(i,' ')
return''.join(b)
Explanation: Simply works by inserting a blank space at the required indices of the string.
Thanks to pxeger for -6 bytes
J, 50 46 bytes
;@({.<@,&' '@;/.[$<@'beep')&((##\)25,~1+5#i.4)
how
25,~1+5#i.4 produces:
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 25
(##\) pairs that with an integer list of the same length:
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
and duplicates the bottom list according to the corresponding element of the top list:
1 2 3 4 5 6 6 7 7 8 8 9 9 10 10 11 11 11 12 12 12 13 13 13 14 14 14 15 15 15 16 16 16 16 17 17 17 17 18 18 18 18 19 19 19 19 20 20 20 20 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21
Call this our "key". We're going to use it to group our "beep"s together.
Our key becomes the right argument to ;@({.<@,&' '@;/.[$<@'beep').
[$<@'beep' first duplicates "beep" according to the input. Say, for an input of 8 we get:
┌────┬────┬────┬────┬────┬────┬────┬────┐
│beep│beep│beep│beep│beep│beep│beep│beep│
└────┴────┴────┴────┴────┴────┴────┴────┘
{. takes the first 8 elements of our key, creating a new key:
1 2 3 4 5 6 6 7
The key adverb /. applies the verb <@,&' '@; to each group defined by the new key. It unboxes, appends a space, and reboxes:
┌─────┬─────┬─────┬─────┬─────┬─────────┬─────┐
│beep │beep │beep │beep │beep │beepbeep │beep │
└─────┴─────┴─────┴─────┴─────┴─────────┴─────┘
;@ unboxes again, giving the result:
beep beep beep beep beep beepbeep beep
APL (Dyalog Unicode), 32 bytes
∊' ',⍨¨(⎕↑×∊↑⍨¨25,⍨5/⍳4)⊂⊂'beep'
With significant golfing input from ngn.
Explanation
The code inside the parens builds a boolean array describing the grouping pattern, which we'll come back to below; quad (⎕) prompts for the quantity of beeps and the pattern is cut to that number. To the right of the parens the word 'beep' is enclosed (monadic ⊂) to make it a single thing (instead of an array of 4 characters), and that is partition-enclosed (dyadic ⊂) by the pattern which groups the beep and implicitly repeats it to match the cut pattern length. To the left of the parens, the beeps get one space (' ') appended (,⍨) to each (¨) group of them, then get flattened (∊) into the result string.
Building the group pattern follows this progression:
5/⍳4 ⍝ five-replicate the first four numbers
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4
25,⍨5/⍳4 ⍝ append 25 for the long run
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 25
↑⍨¨25,⍨5/⍳4 ⍝ turn each (¨) of the numbers into
⍝ a group that long, padded with zeros.
⍝ using take selfie (↑⍨).
⍝ e.g. Take first 3 items out of "3", get 3 0 0.
┌→┐ ┌→┐ ┌→┐ ┌→┐ ┌→┐ ┌→──┐ ┌→──┐ ┌→──┐ ┌→──┐ ┌→──┐ ┌→────┐ ┌→────┐ ┌→────┐ ┌→────┐ ┌→────┐ ┌→──────┐ ┌→──────┐ ┌→──────┐ ┌→──────┐ ┌→──────┐ ┌→─────────────────────────────────────────────────┐
│1│ │1│ │1│ │1│ │1│ │2 0│ │2 0│ │2 0│ │2 0│ │2 0│ │3 0 0│ │3 0 0│ │3 0 0│ │3 0 0│ │3 0 0│ │4 0 0 0│ │4 0 0 0│ │4 0 0 0│ │4 0 0 0│ │4 0 0 0│ │25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0│
└~┘ └~┘ └~┘ └~┘ └~┘ └~──┘ └~──┘ └~──┘ └~──┘ └~──┘ └~────┘ └~────┘ └~────┘ └~────┘ └~────┘ └~──────┘ └~──────┘ └~──────┘ └~──────┘ └~──────┘ └~─────────────────────────────────────────────────┘
∊↑⍨¨25,⍨5/⍳4 ⍝ flatten (∊) the nesting
1 1 1 1 1 2 0 2 0 2 0 2 0 2 0 3 0 0 3 0 0 3 0 0 3 0 0 3 0 0 4 0 0 0 4 0 0 0 4 0 0 0 4 0 0 0 4 0 0 0 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
×∊↑⍨¨25,⍨5/⍳4 ⍝ use direction (×) to turn all non-zero into 1
⍝ 1 marks the start of each group, 0 pads their length.
⍝ A boolean group-array for the full beep pattern
1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
20↑×∊↑⍨¨25,⍨5/⍳4 ⍝ take (↑) 20 beeps. (⎕ number beeps)
⍝ This is how it cuts in the middle of a
⍝ run of beepbeepbeep, by cutting the pattern.
1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0
(20↑×∊↑⍨¨25,⍨5/⍳4)⊂⊂'beep' ⍝ p-enclose of 'beep' shows the grouping,
⍝ and the cutoff group at the end.
┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→──────────────┐ ┌→──────────────┐ ┌→──────────────┐ ┌→──────────────┐ ┌→──────────────┐ ┌→─────────────────────┐ ┌→──────────────┐
│ ┌→───┐ │ │ ┌→───┐ │ │ ┌→───┐ │ │ ┌→───┐ │ │ ┌→───┐ │ │ ┌→───┐ ┌→───┐ │ │ ┌→───┐ ┌→───┐ │ │ ┌→───┐ ┌→───┐ │ │ ┌→───┐ ┌→───┐ │ │ ┌→───┐ ┌→───┐ │ │ ┌→───┐ ┌→───┐ ┌→───┐ │ │ ┌→───┐ ┌→───┐ │
│ │beep│ │ │ │beep│ │ │ │beep│ │ │ │beep│ │ │ │beep│ │ │ │beep│ │beep│ │ │ │beep│ │beep│ │ │ │beep│ │beep│ │ │ │beep│ │beep│ │ │ │beep│ │beep│ │ │ │beep│ │beep│ │beep│ │ │ │beep│ │beep│ │
│ └────┘ │ │ └────┘ │ │ └────┘ │ │ └────┘ │ │ └────┘ │ │ └────┘ └────┘ │ │ └────┘ └────┘ │ │ └────┘ └────┘ │ │ └────┘ └────┘ │ │ └────┘ └────┘ │ │ └────┘ └────┘ └────┘ │ │ └────┘ └────┘ │
└∊───────┘ └∊───────┘ └∊───────┘ └∊───────┘ └∊───────┘ └∊──────────────┘ └∊──────────────┘ └∊──────────────┘ └∊──────────────┘ └∊──────────────┘ └∊─────────────────────┘ └∊──────────────┘
∊' ',⍨¨(20↑×∊↑⍨¨25,⍨5/⍳4)⊂⊂'beep' ⍝ append one space in each group
⍝ and flatten.
beep beep beep beep beep beepbeep beepbeep beepbeep beepbeep beepbeep beepbeepbeep beepbeep
Python 2, 59 bytes
f=lambda n:n*"?"and f(n-1)+"beep "[:4|0x444444924aabe>>n&1]
Uses a hardcoded lookup table to decide whether to put a space after each beep. I attempted to make formulas instead but didn't find something shorter.
PowerShell 5.1, 227 bytes
$n=10;function f($x){$r.Length-in$x};$c=0;$r="";$t=0;while($c-lt$n){$s=-1;switch($true){{f(0..24)}{$s=1}{f(25..69)}{$s=2}{f(70..134)}{$s=3}{f(135..219)}{$s=4}};$r+="beep";$t++;if($t-ne$s){$c++;continue};$r+=" ";$t=0;$c++};$r
Explanation: $n is the input number. I tried to write this without doing it via arrays because I felt like it would be cheating, as I had already read this answer. I used the length of the string to determine how many "beeps" were needed before I placed a space. If the length of the string is between 0 and 24, 1 space. If the length of the string is between 25 and 69, 2 spaces. etc.
Here's the "cleaner" version
$n = 9
function bl ($x) {$beepString.Length -in $x}
$count = 0
$beepString = ""
$beepsThisTime = 0
while($count -lt $n)
{
$neededBeepsBeforeSpace = -1
switch($true)
{
{bl(0..24)}{$neededBeepsBeforeSpace = 1}
{bl(25..69)}{$neededBeepsBeforeSpace = 2}
{bl(70..134)}{$neededBeepsBeforeSpace = 3}
{bl(135..219)}{$neededBeepsBeforeSpace = 4}
}
$beepString += "beep"
$beepsThisTime++
if($beepsThisTime -ne $neededBeepsBeforeSpace){$count++;continue}
$beepString+=" "
$beepsThisTime = 0
$count++
}
$beepString
Jelly, 17 16 bytes
4Rx5Ä‘œṖȧ€“&?»$K
A monadic Link accepting an integer which yields a list of characters.
How?
4Rx5Ä‘œṖȧ€“&?»$K - Link: integer, n e.g. 8
4 - four 4
R - range [1,2,3,4]
5 - five 5
x - times [1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4]
Ä - accumulate [1,2,3,4,5,7,9,11,13,15,18,21,24,27,30,34,38,42,46,50]
‘ - increment [2,3,4,5,6,8,10,12,14,16,19,22,25,28,31,35,39,43,47,51]
$ - last two links as a monad - i.e. f(n):
“&?» - compressed string "beep"
ȧ€ - (n) AND each ("beep") ["beep","beep","beep","beep","beep","beep","beep","beep"]
œṖ - split before indices [["beep"],["beep"],["beep"],["beep"],["beep"],["beep","beep"],["beep"]]
K - join with spaces "beep beep beep beep beep beepbeep beep"
Python 3 , 164 Bytes
This is my recursive approach. Somehow it's worse than I imagined it in my head.
Explanation: n is the input number
The g function generates the beep sequence, where x controls the numbers of "beep"s . Every 4th call x is incremented by 1, and with the 16th call it's set to 25. In the next call it's reset to 1 . g generates n groups of "beep"s the string is stored in v
f cuts v to the corrext number by searching for the next "b" in v until n is reached.
g=lambda s,x,m:s if m>n else g(s+"beep"*x+" ",([25,1]+[x+(m%4<1)]*14)[(m+1)%16],m+1)
v=g("",1,1)
f=lambda m,i:v[:i] if m>n else f(m+1,v.find("b",i+1))
print(f(1,1))
Charcoal, 23 bytes
FN«beep¿&⍘(XsB!,zOγX²ι→
Try it online! Link is to verbose version of code. Uses the popular bitmask approach. Explanation:
FN«
Loop the given number of times.
beep
Print a beep.
¿&⍘(XsB!,zOγX²ι→
If the appropriate bit in the constant is set, then move right one character. The constant is probably the same as everyone else's but here I'm effectively encoding it using base 95.
APL+WIN, 50 bytes
Prompts for input of n:
(4×(p/m),¯1↑-(p←n≤0)/n←(+\m←(5/⍳4),25)-⎕)⍴¨⊂'beep'
Io, 81 78 75 bytes
Shamelessly ported from Arnauld's answer.
f :=method(i,if(i>0,f(i-1).."beep".." "repeated(1200959982447294>>i&1),""))
Io, 152 113 bytes
Port of Manish Kundu's answer.
method(x,O :=("beep"repeated(x)asList);" !*3<ER_ly¨¹ÊÛ"foreach(i,if(i<x*4,O atInsert(i," ")));O join)
Explanation
method(x, // Input x
O :=("beep"repeated(x)asList) // "beep" repeated x times
" !*3<ER_ly"foreach(i, // For every codepoint in this string:
if(i<x*4, // If doing this doesn't cause an error:
O atInsert(i," "))); // Insert at this position
O join) // Join O without a separator
R, 89 87 73 69 bytes
Edit: -20 (yes, 20) bytes thanks to Giuseppe
x=scan();cat(strrep("beep",c(b<-(a=5:24%/%5)[cumsum(a)<x],x-sum(b))))
The guts of this are stolen from Giuseppe's R answer, so please upvote that one... Edit: especially after he's now massively golfed-down this one!
However, I wanted to see whether a simpler, non-regex approach of constructing the correct number of 'beep'-repetitions (instead of making a very long one and then cutting it down) could be shorter.
So far it is...
Wolfram Language (Mathematica), 188 bytes
If[#==0,"",c=#;T@v_:=v~Table~5;w=Accumulate[z=Flatten@{T/@Range@4,25}];StringRiffle[""<>#&/@Join[1~Table~#&/@z[[;;Max@Position[w,m=Max@Select[w,#<=c&]]]],{Table[1,c~Mod~m]}]/. 1->"beep"]]&
R, 95 bytes
substr(s<-Reduce(paste,strrep("beep",c(rep(1:4,e=5),25))),1,c(el(gregexpr("b",s))[scan()]+3,0))
Thanks to @Dingus for pointing out a bug which made my code longer (and also wrong). Thanks to madlaina for suggesting a better regex.
Outgolfed handily by Dominic van Essen.
nreps <- c(rep(1:4,e=5), # repeat the beeps 1,2,3,4 each 5 times
25) # and 25 times
beep <- strrep("beep",nreps) # build a list of the repeated "beep"s
s <- Reduce(paste,beep) # combine into one string, separated by spaces
i <- el(gregexpr("b",s)) # find the start index of each occurrence of a "beep"
e <- i[scan()]+3 # find the end index: the starting point of the n'th beep + 3
substr(s,1,c(e,0)) # and substring into s from 1 to e (or 0 if e is empty)
Rust, 76 127 bytes
|n|(0..n).fold("".into(),|a,i|a+"beep"+&" "[..0x222222492555F>>i.min(63)&1])
Shamelessly ported from Arnauld's JS solution
The binary constant has a bit set wherever the "beep" should be followed by a space.
Old solution
|n|[1,2,3,4,25].iter().fold(format!(""),|a,&i|a+&("beep".repeat(i)+" ").repeat(5)).rsplitn(176-n,'b').last().map(str::to_owned)
Explanation:
We first construct the string beep beep beep beep beep beepbeep beepbeep beepbeep beepbeep beepbeep beepbeepbeep... with the last 25 successive beeps also being repeated 5 times. This string contains 175 beeps, so we trim from the right to and including the 176-nth b and take the sub string left of there.
