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: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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\$ Commented 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\$ Commented May 22, 2017 at 9:29
  • 1
    \$\begingroup\$ @iamnotmaynard Semicolon Hash \$\endgroup\$ Commented May 23, 2017 at 15:09
  • 5
    \$\begingroup\$ Maybe Wink Hash would be easier to say \$\endgroup\$ Commented May 23, 2017 at 17:42
  • 2
    \$\begingroup\$ The Pastebin link appears to be dead. \$\endgroup\$ Commented May 22, 2021 at 4:29

141 Answers 141

1 2 3 4
5
0
\$\begingroup\$

Add $p=";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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group\$
0
\$\begingroup\$

JavaScript (ES6), 71 Bytes

p=>([...p].map(v=>v==";"?i++:b+=String.fromCharCode(i,i=0),i=0,b=""),b) 

This can probably be golfed, but I think the concept passing extra arguments to functions is one of the reasons why JavaScript is one of the more interesting languages to golf in.

\$\endgroup\$
1
  • \$\begingroup\$ This seems to insert spaces between each character of the output nor does it look like it ignores invalid characters. \$\endgroup\$ Commented May 29, 2017 at 12:05
0
\$\begingroup\$

java, 86 95 bytes

this is a lambda expression assignable to a Consumer<String>

s->{for(String t:s.split("#|[^#]*\\Z"))System.out.print((char)(t.split(";",-1).length-1%127));} 

Explanation:

  • split the input using # as the delimiter and ignore everything after the last match
  • for each substring, count the number of ;'s and output the count as a char
\$\endgroup\$
0
\$\begingroup\$

Ly, 44 bytes

0<i[[";"=[pp>1+<2$]p"#"=[pp>(127)%o0<2$]]i]; 

Try it online!

This submission does not work with the latest version of the Ly interpreter.
A version that does work, for 43 bytes:

ir[[";"=[pp>1+<2$]p"#"=[pp>(127)%o<2$]pp]]; 

Try it online!

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

MaybeLater, 99 bytes

s=read()wheni is*{if((S=s[i])!=u){if(S==";")a++if(S=="#"){writechra%127a=0}when0secondpass i++}}i=0 

Ungolfed & Commented

input_string=read() // Read the input from STDIN when index is *{ // When index updates... if((this_char=input_string[index])!=undefined){ // If it's not undefined (So we've iterated onto another entry)... if(this_char==";") // If this character is a ; accumulator++ // Increment the accumulator (Which defaults to 0) if(this_char=="#"){ // If it's # however write(chr(accumulator%127)) // Write the character value of the accumlator % 127, and reset the accumulator. accumulator=0 } when 0 second pass // When 0 seconds pass, to prevent stack overflow, increment the index. Which loops. index++ } } // Start off the index. index = 0 

Try it online!

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

Pyth, 18 bytes

My misunderstanding works anyways... hmm?

Jcw"#"VtlJpC/@JN"; 

Explanation:

Jcw"#" Split the input by "#" and store it in J VtlJ For the length of J - 1... p Print without newline... C/@JN"; Character from charcode (length of ';'s at the Nth position in J) 

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Doesn't work. You need this. (Does Pyth have a constant tho?) \$\endgroup\$ Commented Jan 23, 2020 at 10:56
0
\$\begingroup\$

Clojure, 69 bytes

#(reduce(fn[a c](case c\;(inc a)\#(do(print(char(mod a 127)))0)a))0%) 

A simple reduction over the code. Alters the accumulator accordingly for each character that's read.

(defn interpret [code] (reduce (fn [acc chr] (case chr \; (inc acc) \# (do (print (char (mod acc 127))) ; Print the char, 0) ; then reset the accumulator acc)) ; An ignored character; don't do anything 0 ; The initial accumulator code)) 
\$\endgroup\$
0
\$\begingroup\$

Kotlin, 105 bytes

Submission

fun d(l:String):String=l.split("#").map{(it.length%127).toChar()}.joinToString("").removeSuffix("\u0000") 

TryItOnline

Link

Explanation

  • It splits the string into ; chunks
  • Then it changes them into characters
  • It joins them into a string
  • Then it removes the null byte from the end
\$\endgroup\$
0
\$\begingroup\$

Ahead, 26 bytes

r o%721$< ~>j@i:'#=n';=+~ 

Try it online!

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

Noether, 42 bytes

I~sL(si/~c{";"=}{!a}c{"#"=}{a127MBP0~a}!i) 

Try it online!

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

Clojure, 65 bytes

(fn[c](map #(char(mod((frequencies %)\;)127))(re-seq #"[^#]+"c))) 

Splits the code by '#', counts the number of ';', and turns the number (mod 127) into its ascii value

Try it online!

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

Swift, 117 bytes

func f(i:String){var a=0;for c in i{if c==";" {a+=1}else{print(Character(UnicodeScalar(a%127)!),terminator:"");a=0}}} 

Expanded out:

func f(i: String) { var a = 0 for c in i { if c==";" { a += 1 } else { print(Character(UnicodeScalar(a%127)!),terminator:"") a=0 } } } 

Run it online

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

Pascal (FPC), 134 133 122 bytes

var c:char;a:word;begin repeat read(c);if c='#'then begin write(chr(a mod 127));a:=0 end;if c=';'then Inc(a)until eof end. 

Try it online!

Assumes non-empty input.

\$\endgroup\$
1
  • \$\begingroup\$ −5 Bytes: The two if‑statements can be merged into one case‑statement. \$\endgroup\$ Commented Mar 13, 2024 at 15:32
0
\$\begingroup\$

Haskell, 73 bytes

f[]a="" f(c:s)a|c==';'=f s(a+1)|c=='#'=toEnum(a`mod`127):f s 0|0<1=f s a 
\$\endgroup\$
2
  • 1
    \$\begingroup\$ It looks like you require f to be called with an additional argument, however the question only allows taking a string as argument. Therefore you need to add something like g x=f x 0, or by swapping the arguments just the anonymous function f 0: Try it online! \$\endgroup\$ Commented Aug 11, 2018 at 11:09
  • 1
    \$\begingroup\$ However you can save some bytes by replacing True with 0<1, moving f a[]="" to the last line and writing it as f a e=e and by replacing f by an infix operator. \$\endgroup\$ Commented Aug 11, 2018 at 11:13
0
\$\begingroup\$

Forth (gforth), 77 bytes

: f 0 tuck do over i + c@ '# - ?dup if 24 = - else 127 mod emit 0 then loop ; 

Try it online!

Code Explanation

: f \ start a new word definition 0 tuck \ put 0 on the top of the stack and stick a copy behind the second stack item do \ begin a counted loop from 0 to string length - 1 over i + \ get the address of the next character c@ '# - \ get the next character's ascii value and subtract ascii # (35) ?dup \ if result is not 0, duplicate if \ if result is true (not 0) 24 = - \ check if result = 24, and subtract -1 from accumulator if it is (0 otherwise) else \ else (if result was equal to 35) 127 mod \ get accumulator mod 127 emit 0 \ output accumulator and replace with 0 then \ end if loop \ end loop ; \ end word definition 
\$\endgroup\$
0
\$\begingroup\$

VBA (Excel) 103 Bytes

Function a(b) For Each c In Split(b,"#") a=a &Chr((Len(c)-Len(Replace(c,";","")))Mod 127) Next End Function 

Un-golfed With Comments:

Function fromSemiHash(myString) 'SemiHash is how I think it should be pronounced :D 'For each string in myString split by hashes For Each littleString In Split(myString,"#") 'Append the char from((the length of everything minus length of everything but ;'s) mod 127) toSemiHash = toSemiHash & Chr((Len(littleString) - Len( Replace( littleString , ";" ,""))) Mod 127) Next littleString End Function 
\$\endgroup\$
0
\$\begingroup\$

PHP, 84 bytes

First attempt 144 133 bytes

I was able to remove 11 by using all ternary conditions, this required adding some ( ) to cement in the operation order. PHP has a weird thing with that.

function f($s,$i,$c,$r){echo''==($a=$s[$i])?$r:('#'==$a?f($s,++$i,0,$r.=chr($c%127)):(';'==$a?f($s,++$i,++$c,$r):f($s,++$i,$c,$r)));} 

Test it like this:

error_reporting(0); $strings =[';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;h;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;o', ';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#' ]; foreach($strings as $s){ f($s,0,0,''); echo "\n"; } function f($s,$i,$c,$r){echo''==($a=$s[$i])?$r:('#'==$a?f($s,++$i,0,$r.=chr($c%127)):(';'==$a?f($s,++$i,++$c,$r):f($s,++$i,$c,$r)));} 

Output

Hello, World! ;# 2d����{��� ! 

Sandbox

Notes/Explanation

This is a recursive function. Most of the space savings comes from using ternary conditionals,short variable names and grouping some of the setters into the aforementioned conditions. It takes 4 input arguments and sets 1 local variable:

Arguments/Variables

$s - the ;# string to parse.

$i - the iterator, to keep track of the current position in the string, starts at 0.

$c - the register keeps the count of ; prior to #, starts at 0.

$r - the results, the output of the parser, starts as an empty string.

Expanded version:

function f($s,$i,$c,$r){ if( '' == ( $a = $s[$i] ) ){ echo $r; }else{ if( '#' == $a ){ f( $s, ++$i, 0, $r.=chr( $c % 127 )); }else{ if( ';' == $a ){ f( $s, ++$i, ++$c, $r); }else{ f( $s, ++$i, $c, $r); } } } } 

Update attempt 2, 77 84 Bytes (PHP < 7)

Had to add aomw to fix a bug with it having an empty element in the array at the end.

 function f($s){foreach(split('#',$s)as$a)echo!$a?'':chr(substr_count($a,';')%127);} 

You can change split to explode to make it compatible with PHP7, but add 2 bytes. Test it the same as above, produces the same output.

Sandbox2

Expanded version:

function f($s){ $array = split('#',$s) foreach($array as $a){ if(!$a){ echo ''; }else{ $count = substr_count($a,';'); echo chr($count%127); } } } 

It's shorter, simpler, and should be faster. The key to this one was substr_count which I already know about but didn't think of right away, as I was a bit rushed for time on the first attempt. After thinking about it some, I came up with this and almost cut it in half. Not bad!

Basically it splits it on the # and then counts the occurrences of ; in each array item and outputs the character that generates.

Cheers!

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

Kotlin, 77 bytes

{Regex(";*#").findAll(it).fold(""){a,v->a+((v.value.length-1)%127).toChar()}} 

Try it online!

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

Whitespace, 119 bytes

[S S S N _Push_0][N S S N _Create_Label_LOOP][S N S _Duplicate_top][S N S _Duplicate_top][T N T S _Read_STDIN_as_character][T T T _Retrieve][S N S _Duplicate_input][S S S T S S S T T N _Push_35][T S S T _Subtract][N T S S N _If_0_Jump_to_Label_PRINT_CHAR][S S S T T T S T T N _Push_59][T S S T _Subtract][N T S T N _If_0_Jump_to_Label_INCREASE][N S N N _Jump_to_Label_LOOP][N S S S N _Create_Label_PRINT_CHAR][S N N _Discard_top][S S S T T T T T T T N _Push_127][T S T T _Modulo][T N S S _Print_as_character][S S S N _Push_0][N S N N _Jump_to_Label_LOOP][N S S T N _Create_Label_INCREASE][S S S T N _Push_1][T S S S _Add][N S N N _Jump_to_Label_LOOP] 

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Pseudo-code:

Integer i = 0 Label LOOP: Character c = STDIN as character If(c == '#'): Jump to Label PRINT_CHAR If(c == ';'): Jump to Label INCREASE Jump to Label LOOP Label PRINT_CHAR: i = i modulo-127 Print i as character to STDOUT i = 0 Jump to Label LOOP Label INCREASE: i = i + 1 Jump to Label LOOP 
\$\endgroup\$
0
\$\begingroup\$

Rutger, 170 bytes

a=0; f=Each[Array[$Argv]]; f=f[@c]; f=f[{p=Add[$a];s=Equal[";"];h=Equal["#"];a=p[s[$c]]];i=If[{h[$c];}];i=i[{m=Modulo[$a];a=0;PrintEnd[Char[m[127]]];}];Do[$i];}]; Do[$f]; 

Try it online!

Man, Rutger is verbose

How it works

accumulator = 0; each = Each[Array[$Argv]]; // Read a string from argv, cast to list and create an each loop each = each[@char]; // Iterate over each character each = each[{ 	plus = Add[$accumulator]; // Partial function to add a value to the accumulator 	semicolon = Equal[";"]; // Comparison function to ";" 	hash = Equal["#"]; // Comparison function to "#" 	accumulator = plus[semicolon[$char]]; // Add 1 to $accumulator if $char is a semicolon 	if = If[{ 		hash[$char]; // If $char is a hash 	}]; 	if = if[{ 		mod = Modulo[$accumulator]; // Partial function to mod the accumulator 		accumulator = 0; // Reset the accumulator to 0 		PrintEnd[Char[mod[127]]]; // Print, without a trailing newline, the accumulator, mod 127, converted to char 	}]; 	Do[$if]; // Run the if statement }]; Do[$each]; // Run the each loop 
\$\endgroup\$
0
\$\begingroup\$

Thunno 2 J, 13 bytes

'#/ṫı';c127%C 

Attempt This Online!

Port of Adnan's 05AB1E answer.

Explanation

'#/ṫı';c127%C # Implicit input '#/ # Split on "#" ṫ # Remove the last item ı # Map over the list: ';c # Count of ";"s 127% # Mod 127 C # Convert to character # Implicit output, joined 
\$\endgroup\$
1 2 3 4
5

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.