74
\$\begingroup\$

I recently created a new language called ;# (pronounced "Semicolon Hash") which only has two commands:

; add one to the accumulator

# modulo the accumulator by 127, convert to ASCII character and output without a newline. After this, reset the accumulator to 0. Yes, 127 is correct.

Any other character is ignored. It has no effect on the accumulator and should do nothing.

Your task is to create an interpreter for this powerful language!

It should be either a full program or a function that will take a ;# program as input and produce the correct output.

Examples

Output: Hello, World!
Program: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#

Output: ;#
Program: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#

Output: 2 d����{���
Program: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;hafh;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;f;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;###ffh#h#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ffea;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#au###h;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;h;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;o

Output: Fizz Buzz output
Program: link below

Output: !
Program: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#

Fizz Buzz up to 100

\$\endgroup\$
11
  • 1
    \$\begingroup\$ Is it acceptable if an interpreter doesn't terminate its execution at the end of the input but instead keeps looping indefinitely without producing extra output? \$\endgroup\$
    – Leo
    May 22, 2017 at 9:26
  • 6
    \$\begingroup\$ The second example makes me wonder about a program to encode a program to produce an output... recursive compilation! \$\endgroup\$
    – frarugi87
    May 22, 2017 at 9:29
  • 1
    \$\begingroup\$ @iamnotmaynard Semicolon Hash \$\endgroup\$ May 23, 2017 at 15:09
  • 5
    \$\begingroup\$ Maybe Wink Hash would be easier to say \$\endgroup\$ May 23, 2017 at 17:42
  • 1
    \$\begingroup\$ The Pastebin link appears to be dead. \$\endgroup\$
    – EasyasPi
    May 22, 2021 at 4:29

140 Answers 140

1
\$\begingroup\$

Gol><>, 20 18 bytes

Credit to Jo King.

iE;:`#=q$o`;=+`~P%

Try it online!

How it works

iE;:`#=q$o`;=+`~P%
                    Accumulator (m) is stored at the bottom
iE;                 Take input (n) as char; halt if EOF
   :`#=q            If n == '#'... (preserving n on the top)
        $o            Output m as char, discarding it
          `;=+      If n == ';', increment m
              `~P%  m = m % 127
                    Repeat indefinitely

Previous submission, 20 bytes

iE;:`#=Q$`~P%o|`;=?P

Try it online!

How it works

iE;:`#=Q$`~P%o|`;=?P

                      Accumulator (m) is always stored at the bottom
iE;                   Take input (n) as char, halt if EOF
   :`#=Q      |       If n == '#'... (preserving n on the top)
        $`~P%o        Swap m to the top, output m%127 as char
               `;=?   If n == ';'... (discarding n; m is exposed to the top)
                   P  Increment m
                      Repeat indefinitely
\$\endgroup\$
1
  • \$\begingroup\$ 18 bytes \$\endgroup\$
    – Jo King
    Sep 6, 2018 at 13:07
1
\$\begingroup\$

Backhand, 37 bytes

}>_oi!{:0v] @! |{^:v-"%";"#""-"|{]~.

Try it online!

As usual with Backhand programs, I'm pretty sure this could be golfed further, but to do so would require some restructuring.

Explanation

Note that by default the pointer moves three steps at a time

}>                 Start on the second character
    i  :  ]  ! |{  Get input and check if it is EOF
            @      Reflect and terminate if so
                  :  "  ;  "  - |{     Check if the character is a ;
                                   ~.  If so, pop the extra copy of the character
                      %  "    "  [    Increment by 1 and modulo by 127
                 ^ v    Decrement the pointer step value by one and then increment it again to skip the |{
 >_  !  0  And restart the loop
                                |      If it is not a ;, reflect
                    -  "  #  "         Check if it is a #
         v   !   ^   Increment pointer and decrement again
}>_o  !{    Output if the character was a # and restart the loop
\$\endgroup\$
1
\$\begingroup\$

C# (Visual C# Interactive Compiler), 66 bytes

s=>s.Split('#').Select(x=>(char)(x.Count(y=>y==59)%127)).ToArray()

Try it online!

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

PHP, 84 79 70 1 + 63 = 64 bytes

for(;$c=$argn[$i++];$a+=$c==";")$c^A^R||$a=~-print chr($a%127);

Run as pipe with -nR

Try it online!

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

CJam, 18 bytes

q'#/{';e=127%c}%);

Try it online!

Explanation

q                  "Take the whole input as a single string";
 '#/               "Split the input string with hashes";
                   "This counts the empty results";
                   "According to the challenge empty results can only be";
                   "generated from trailing #'s";
    {         }%   "Map every ; sequence in the string:";
     ';e=          "Count the semicolons"
         127%      "Find the remainder of the length w/ 127";
             c     "Convert to a character"
                ); "There is a trailing null string designed for this check";
                   "If there isn't a trailing null string (i.e.)";
                   "program doesn't end with #, this removes the last item of the list";
                   "Implicit flatten the list & print as string";
\$\endgroup\$
1
\$\begingroup\$

Packed Pyth, 14 bytes

Hex dump: AD 43 1F 7B 88 F8 43 4A BE 75 C7 6C 59 37

Try it online!

Pyth, 16 bytes

VPcw\#pC%/N\;127

Try it online!

Python equivalent:

for N in input().split('#')[:-1]:
    print(end=chr(N.count(';') % 127))

Token by token explanation:

VPcw\#pC%/N\;127
V                 # for N in                        :
   w              #          input()                      # take one line of input
  c \#            #                 .split('#')
 P                #                            [:-1]      # discard last element
          N       #                N
         / \;     #                 .count(';')
        %    127  #                             % 127
       C          #            chr(                  )
      p           #  print(end=                       )   # print without trailing newline

After doing this, I looked at the other Pyth answers and found that KarlKastor's also got 16 bytes. However, I believe my answer is more correct, as it does not print a trailing newline. Since every ;;;;;;;;;;# in the input results in outputting a newline, an extra one should not be added at the end.

Funnily enough, we also both made an imperative version. Mine comes in at 25 bytes:

VwIqN\;=%hZ127)IqN\#pC~Z0

Try it online!

Python equivalent:

Z=0
for N in input():
    if N==';': Z = (Z % 127) + 1
    if N=='#': print(end=chr(Z)); Z=0
\$\endgroup\$
0
1
\$\begingroup\$

Burlesque, 19 bytes

'#;;{';CN127.%L[}\m

Try it online!

'#;;     # Split strings at #s
{
 ';CN    # Count the number of ; in each
  127.%  # Mod 127
  L[     # Convert to char
}\m      # Map and concatenate
\$\endgroup\$
1
\$\begingroup\$

JavaScript (Node.js), 86 bytes

s=>[...s].map(e=>e==";"?++i:e=="#"?z+=String.fromCharCode(i%127,i=0)[0]:0,i=0,z="")&&z

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ This is not applying the modulo by 127. \$\endgroup\$
    – Deadcode
    Jan 23, 2020 at 9:26
1
\$\begingroup\$

Prolog (SWI), 104 bytes

It worked out to be shorter to write directly to stdout inside the predicate. The more idiomatic way of implementing something like this in Prolog would be to have third parameter for the predicate which would be the output from interpreting the program.

+A:-string_codes(A,B),0+B.
A+[E|T]:-E=35,!,C is A mod 127,put_code(C),0+T;E=59,!,B is A+1,B+T;A+T.
_+[].

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ You can remove the mod by matching against 127+X (my prolog terminology might be off) \$\endgroup\$
    – user41805
    Jan 24, 2020 at 17:20
1
\$\begingroup\$

PHP, 56 75 bytes

foreach(explode('#',$argn,-1)as$c)echo chr((count_chars($c,1)[59]??0)%127);

Try it online!

Thanks to @Umbrella for the nudge. Actually read the question and bug fixed.

\$\endgroup\$
1
  • \$\begingroup\$ This will echo a non-printable character at the end. Pass -1 to explode to fix. \$\endgroup\$
    – Umbrella
    Jan 24, 2020 at 21:45
1
\$\begingroup\$

Ral, 136 bytes

,:1-11:+:+:+:++:+:+:+?:11:+:+:+:+-:+:+1-+:0?10*+0=1+0?10*-0=111:+:+:+:++:++-:0?0-0?0*:1:+:+:+:+:+:+:+1-+:1+1111:+:++:+:++:+:++?1=.00=10?

Try it online!

Somewhat clarified

Code                         Stack after       Description
,:1-11:+:+:+:++:+:+:+?       n                 Input a character (n) and jump to the end if zero
:11:+:+:+:+-:+:+1-+:0?       n, n-59           Jump to the start if n>59
10*+0=                       n, n-59           Add 1 to the accumulator
1+0?                         n                 Jump to the start if n>58
10*-0=                       n                 Remove 1 from the accumulator
111:+:+:+:++:++-:0?          35-n              Jump to the start if n<35
0-0?                                           Jump to the start if n>35
0*                           acc               Load the accumulator from memory
:1:+:+:+:+:+:+:+1-+          acc, acc-127          Remove 127 from the accumulator
:1+1111:+:++:+:++:+:++?      acc, acc-127          Continue the loop (with acc=acc-127) if acc≥127
1=.                                            Print the accumulator
00=                                            Clear the accumulator
10?                                            Jump to the start
\$\endgroup\$
1
\$\begingroup\$

R, 79 76 bytes

Edit: -3 bytes thanks to Giuseppe

intToUtf8((attr(el(gregexpr(";*#",gsub("[^;#]","",scan(,"")))),"m")-1)%%127)

Try it online!

First deletes all non-;# characters from the input, then searches for the regex ;*#, which finds runs of ; characters followed by a # character. The match.length attribute of this (retrieved using 'm' for short) indicates the number of matched characters, of which the last one must be the #, and all the previous ones ;s. So we subtract one and convert to utf8 characters.

\$\endgroup\$
2
  • \$\begingroup\$ Why not just ;*# (instead of [^#]*#) in the gregexpr if you've removed all the non-;# characters? \$\endgroup\$
    – Giuseppe
    Oct 1, 2020 at 17:20
  • \$\begingroup\$ Yes! You're right! Thanks! I 'probably' left this in from an earlier attempt, but most-likely just didn't think of it... \$\endgroup\$ Oct 1, 2020 at 17:55
1
\$\begingroup\$

ThumbGolf, 24 bytes

Hexdump (little endian):

293b bf08 1c40 2923 d103 dec3 007f de10
2000 de19 d0f4 4770 

The program starts 16 bytes in at the 2000.

Commented assembly:

        // Include the ThumbGolf wrapper macros
        .include "thumbgolf.inc"
        // main starts below
.Lloop:
        // first check for semicolon
        cmp     r1, #';'
        // if equal, increment the accumulator
        it      eq
        addeq   r0, r0, #1
        // now check for hash
        cmp     r1, #'#'
        // skip if not equal (ThumbGolf doesn't work in IT blocks, unfortunately)
        bne     .Lnoprint
.Lprint:
        // modulo accumulator by 127
        umodi   r0, r0, 127
        // print accumulator
        putc    r0
        // -- fallthrough --
        // start here because why not (both print and entry need to reset the
        // accumulator, so it is convenient to do it here)
        .globl main
        .thumb_func
main:
        // reset accumulator to zero
        movs    r0, #0
.Lnoprint:
        // read next char into r1, sets zero flag on success
        getc    r1
        // if successful, continue interpreting
        beq     .Lloop
        // else return
        bx      lr

I actually found a bug in my recent refactor of ThumbGolf with this code.

When I executed getc, the illegal handler would trigger as normal, then trigger on the next instruction. After 2 hours fiddling with it, I realized that when switching the CPSR to use a nice bitfield struct, I forgot to account for some unused bits. This caused me to set the IT_D flag instead of the Z flag, putting the processor in a bad IT state, causing the crash. 😂

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

Pxem, 0 bytes (for content) + 50 bytes (for filename).

  • Filename (unprintables are escaped): M\177.w.i.c;.-\001.y.s\001.+;;;.a.c#.-\001.y.s\177.%.o###\177.a\001.+.a
  • Content is empty.

Usage

  • Full program.
  • I/O with stdin and stdout.
  • Accepts one program at once.

With comments

XX.z
# let counter is 127
.aM\177XX.z
# loop
.a.wXX.z
  # c = getchar()
  .a.iXX.z
  # increment here
  .a.c;.-\001.y.s\001.+;;;.aXX.z
  # output and reset here
  .a.c#.-\001.y.s\177.%.o###\177.aXX.z
# break if c is EOF
.a\001.+.a

Try it online!

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

Racket, 122 bytes

(let([n 0])(for([i s])(cond[(eq? i #\;)(set! n(+ 1 n))][(eq? i #\#)(display(integer->char(remainder n 127)))(set! n 0)])))

Try it online!

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

Assembly (MIPS, SPIM), 108 bytes

c:li$4 0
l:lb$2($5)
add$5 1
beqz$2 e
beq$2 35p
bne$2 59l
add$4 1
bge$4 127c
j l
p:li$2 11
syscall
j c
e:j$ra

TIO includes test cases.

Try it online!

This is a function which takes a null terminated string in $a1 and prints the result to stdout.

Ungolfed version with comments:

    # Input: Null terminated byte string in $a1
    # Output: Printed to stdout
semihash:
.Lclear:
    li      $a0, 0             # Clear accumulator
.Lloop:
    lb      $v0, ($a1)         # Load char from program string
    add     $a1, 1             # Advance pointer
    beqz    $v0, .Lreturn      # If char was '\0', return
    beq     $v0, '#', .Lprint  # If char was '#', print
    bne     $v0, ';', .Lloop   # If not ';', loop again
    add     $a0, 1             # Increment accumulator
    bge     $a0, 127, .Lclear  # Clear accumulator if it is >= 127
    j       .Lloop             # Otherwise loop
.Lprint:
    li      $v0, 11            # 11 = PRINT CHARACTER
    syscall                    # putchar($a0)
    j       .Lclear            # Clear accumulator and loop again
.Lreturn:
    j       $ra                # Return
\$\endgroup\$
1
\$\begingroup\$

jq -Rr, 46 bytes

Splitting and counting

[((./"#")[:-1][]/";")[:-1]|length%127]|implode

Try it online!

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

Ly, 33 bytes

0spir[';=[l+s!]p"#"=[l'~`%o!s]pp]

Try it online!

A different take using Ly

0sp                                - init backup cell to "0"
   ir                              - read input as codepoints and reverse stack
     [                           ] - loops once for each input char
      ';=                          - is it a ";"?
         [    ]p                   - then clause if true
          l                        - load the accumulate value
           +                       - increment by 1 ("if" result is on stack)
            s                      - update backup cell
             !                     - change top of stack to "0" to exit loop
               p                   - delete "if" result
                "#"=               - is is a "#"?
                    [        ]     - then clause if true
                     l             - load backup cell
                      '~`          - generate the number "127"
                         %         - calculate modulo w/ 127
                          o        - print top of stack as char
                           !       - convert to "0" (1)
                            s      - reset backup cell to "0"
                               p   - delete "if" result
                                p  - delete character we just processed

Note(1): If the input tries to print a null (meaning x'00') the code will fail. If that's a requirement I can tweak the code to harden it against that. I think it would just add one more character... Printing nulls sounds like a mistake though, so I'm not sure it's necessary?

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

batch, 293 bytes

@Echo off& Set f=For /f "UsebackQ Delims=" %%z in
Setlocal EnableDelayedExpansion&%f% ("%~1")Do (Set "l=%%~z"&Set "l=!l:;=-!"&%f:z=G% (`cmd/u/c ^"Echo(!l!^"^|find/v ""^|findstr "^^"`)Do (If %%G==- (Set/a i=i%%127+1)Else if %%G==# ((CMD /C Exit !i!)&<nul Set/p "=ESC7!=EXITCODEASCII!"&Set i=0)))

This interpreter contain an unprintable escape character (0x1b), marked by the presence of the string ESC To obtain a version containing the escape character, visit: https://pastebin.com/Y6vUi9A7

The use of the Escape sequence prevents syntax errors that occur when outputting strings with leading whitespace or = characters via set /p

Run from cmd.exe command line providing the filepath as arg 1, using doublequotes if the file path contains spaces, IE: Interpreter.bat path\to\filename.extension Each line of the program must be doubequoted, Example Helloworld.sch: ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;# "

Breakdown:

%= Supress command echoing =% @Echo off
%= Define command as macro with the FOR metavariable being replaced via substitution =% Set f=For /f "UsebackQ Delims=" %%z in
%= Enable 'runtime' expansion of vars within codeblocks =% Setlocal EnableDelayedExpansion
%= For each line in Arg 1 sourcefile =% %f% ("%~1")Do (
%= Assign line and replace semicolons with a non-standard delim =%    Set "l=%%~z"&Set "l=!l:;=-!"
%= Split string by character and for each character do =% %f:z=G% (`cmd/u/c ^"Echo(!l!^"^|find/v ""^|findstr "^^"`)Do (
%= Assess character =% If %%G==- (
%= increment accumulater =% Set/a i=i%%127+1
        )Else if %%G==# (
%= Convert Accumulator to Ascci character =% CMD /C Exit !i!
%= Output and reset Accumulator =% <nul Set/p "=ESC7!=EXITCODEASCII!"&Set i=0
)   )   )
\$\endgroup\$
1
\$\begingroup\$

(,), 305 Chars or \$305\log_{256}(3)\approx\$60.43 Bytes

(,,,,((())))(()()(),((()),()))(()(),()()()()())((),(()())()()())((),((),,,,(),,(())(()))(()()()))(,((()()),((,,,,,())))(,((()),((()))())((()),((()))(()()(),,,,(),,(())),,,,((())),(())),,,((()())),(()()())(()(),,,,(),,(()())(()())()()))((()),(,,,,,()),,((())),(()(),,,,(),,(()())()()),((()()))),,,((()())))

More readable version (I don't actually write in psuedo-code):

(,,,,((())))
(4,((()),()))
(3,()()()()())
(1,(3)()()())
(1,(1,,,,(),,(1)(1))(4))
(,
(5,((,,,,,())))
(,
(2,(2)())
(2,(2)(4,,,,(),,(1)),,,,(2),(1))
,,,
(5),
(4)(3,,,,(),,(3)(3)()())
)
(2,(,,,,,()),,(2),(3,,,,(),,(3)()()),(5))
,,,(5)
)

TIO

Quite Slow. Also doesn't work when input contains non-;# characters.

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

Morsecco:  206  203 bytes

writing an interpreter for a two-symbol language using a three-symbol language seems to be a fair challenge:

.   -- . -- . --.-  . . .--
. . . - .-.
-- - -.-. - -.- .- . .-...-- .- --..
 . .--... .- --.. --.
- .- --. - . . - .- . .------- .- - - --.. .-. . ------- .- - .-. - . --.
 - . -.- - . - .-- . . - . --.

The first line creates an error handler (code written to special address .) to quit the program without error if the input is used up. Everything else is pretty straight forward. Without having MOD or compare I always add -127, adding 127 again if the result was not zero. Maybe I can think of a shorter solution on another day.

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

Vyxal 3, 12 bytes

'#sṪᵛ';C₆v%O

Try it Online!

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

F#, 165 162 bytes

-3 bytes, thanks to Random User

let g a=
 let mutable b=0
 let mutable d=""
 for c in a do
  if c=';' then
  b<-b+1
  elif c='#' then
  d<-[|d;string(char(b%127))|]|>Array.fold(+)""
  b<-0
 d

It's basically a port of my C# answer.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ let golf a? golf?! Why? \$\endgroup\$ May 21, 2017 at 19:38
  • \$\begingroup\$ @RandomUser I don't know, but I shortened it. \$\endgroup\$ May 21, 2017 at 19:40
0
\$\begingroup\$

Python 3, 66 bytes

a=0
for c in input():a-=a*(c=='#'!=print(end=chr(a%127)))-(c==';')

Try it online!

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

Java 8, 112 bytes

This expression is a Consumer<String>, so it assumes s is a String.

(s)->{int i=0;for(char c:s.toCharArray()){if(c==';')i++;else if(c=='#'){System.out.print((char)(i%127));i=0;}}};
\$\endgroup\$
0
\$\begingroup\$

AHK, 83 bytes

Loop,Parse,1
{f:=A_LoopField
If(f=";")
i++
If(f="#"){
Send % Chr(Mod(i,127))
i=0
}}

By default, Loop,Parse will parse each character individually.


I had a 76 bytes version based on splitting the input on # but, as pointed out by manatwork as a comment, it'll print the very last section even without a # at the end.

Loop,Parse,1,#
Send % Chr(Mod(StrLen(RegExReplace(A_LoopField,"[^;]")),127))
\$\endgroup\$
2
  • \$\begingroup\$ Sure this prints only on #? I mean, sure ;;#;;; will result #2 and not #2#3? \$\endgroup\$
    – manatwork
    May 22, 2017 at 13:15
  • \$\begingroup\$ @manatwork Good point. I had to rewrite it at the expense of 7 bytes. Thanks. \$\endgroup\$ May 22, 2017 at 13:42
0
\$\begingroup\$

Ruby, 71 50 bytes

$*[0].split(?#).each{|p|$><<(p.count(?;)%127).chr}

Edit: Complete rewrite. manatwork's solution is still shorter, but this does it a slightly different way!

\$\endgroup\$
1
  • \$\begingroup\$ You can replace $><<(xxx).chr with putc xxx for -5 bytes. \$\endgroup\$
    – Jordan
    Dec 16, 2017 at 17:32
0
\$\begingroup\$

Fourier, 32 bytes

$(I~Q{59}{&A}Q{35}{A%127a0~A}&i)

Try it on FourIDE!

Enter the program between quotation marks.

Explanation Pseudocode

While i != Input length
    Q = Pop character off start of string and get char ASCII code
    If Q = 59 Then
        Increment A
    End If
    If Q = 35 Then
        Convert A mod 127 to character and Print
        A = 0
    End If
    Increment i
End While
\$\endgroup\$
0
\$\begingroup\$

Actually, 20 bytes

'#@s⌠';@c7╙D@%c⌡MdXΣ

Try it online!

Explanation:

'#@s⌠';@c7╙D@%c⌡MdXΣ
'#@s                  split on "#"
    ⌠';@c7╙D@%c⌡M     for each chunk:
     ';@c               count occurrences of ";"
         7╙D@%          mod by 127 (2**7-1)
              c         convert to ASCII char
                 dX   discard last item
                   Σ  concatenate
\$\endgroup\$
1
0
\$\begingroup\$

Add $p=";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#"; to actually enjoy this tasty script. ($p is the input variable)

PowerShell, 98 bytes

[char[]]$p|%{if($_-eq';'){$o++}elseif($_-eq'#'){Write-Host -NoNewLine ([char]($o%127));[int]$o=0}}

Try it online!

\$\endgroup\$

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.