[,].[[[,.][[[[[.][.][.][.].,][,.].,][,.].,][[,][[[,][,.].,][,][,].,].,][,][[[,.][.][.].,][.][.][.].,][,][[[,.][[[,.][[,]].,][],].,],].[,][.,][[.][.][.][.][.].,].[.[.[[[,.][[].[],].,][[,][[,][[[[,][[[,],]].,],]].,][],][.[.[,].][,][,]].][,][[,][[,][,][,]].,][.[.[,].]][[,.][[].[],].,],.[[[,][[,.]].,][.[.[,].][,]]],.[.[.[,].][,[.][.][.][.][.].,][,]][,],.][.[.[,].][,]][[[,.][[].[],].,][,.].,].[.[,].][,][,],.][,][.[.[,].]][,[,[,[,[,[,[,[,.]]]]]]]]].,].[[.[.[,].]][[,.][[].[],].,][.[[,],]][.[.[,].][,][,]][.[,]][,.][.[.[,].][,][,.]][.[[,][,.],.]].][.[.[,.].]][,.]],.[[,.]]
-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
]
,
or.
is acceptable for length 1.) Where's the full spec for it and why isn't it TC? \$\endgroup\$