Related to: Make a ;# interpreter

In the above linked challenge the task was to create an interpreter for the esoteric language ;#.

The ;# language

The language has exactly two commands: ; and # (all other characters are ignored by the interpreter):

;: Increment the accumulator

#: Modulo the accumulator by 127, print the corresponding ASCII character and reset the accumulator to 0.

Challenge

Because I am lazy but still want to test some more testcases, I need a program or function which converts plain text to ;# code.

Input

The input is a string, taken either as argument or through stdin. It will only contain printable ASCII characters and newlines.

Output

The output is the generated ;# program by returning, or printing to stdout. As long as the program is valid, it may contain excess characters other than # and ; as all other characters are ignored.

Examples

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

Input: ABC
Output: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#

Input: ;#
Output: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#

Leaderboard

var QUESTION_ID=122139,OVERRIDE_USER=73772;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

  • 8
    Brilliant! Glad to see ;# is getting attention! – caird coinheringaahing May 23 '17 at 6:41
  • 1
    You can test your output here, as ;#+ is a superset of ;#. – Adám May 23 '17 at 7:02
  • 3
    Can the output contain additional character? ;# ignores all other characters, so the generated program would still work. – Dennis May 23 '17 at 7:23
  • 2
    @Benoît: The modulus is irrelevant when generating code, since it's always easier to generate code that uses the minimum number of ;. Secondly, 127 is correct, as stated in the linked question that contains the specification of the ;# language. – Joey May 24 '17 at 7:16
  • 2
    This isn't really transpiling. "Generate #; code" is a better title. I'm going to change it to that. – Mego May 24 '17 at 20:24

66 Answers 66

;#+, 61 bytes

Outgolfed by Conor O'Brien

;;;;;;;(~;;;;;~-;-)~>:~;;;;(~;;;;;;~-;-)~>~-*((;~<#~):<#-:-*)

Try it online!

Note that the input has a trailing null byte.

  • 12
    Points for style. – Chowlett May 23 '17 at 8:19
  • 1
    I approve of this answer :D definitely the right language for the job – Conor O'Brien May 23 '17 at 13:41

;#+, 40 bytes

;;;;;~+++++++>~;~++++:>*(-(;~<#~):<#-*:)

Try it online! Input is terminated with a null byte.

Explanation

The code is split into two parts: generation and iteration.

Generation

;;;;;~+++++++>~;~++++:>

This puts the constants ; and # into memory as such:

;;;;;~+++++++>~;~++++:>
;;;;;                     set A to 5
     ~                    swap A and B
      +++++++             add B to A 7 times
                          (A, B) = (5*7, 5) = (35, 5)
             >            write to cell 0
              ~           swap A and B
               ;          increment A
                ~         swap A and B
                          (A, B) = (35, 6)
                 ++++     add B to A 4 times
                          (A, B) = (59, 6)
                     :    increment cell pointer
                      >   write to cell 1

Iteration

*(-(;~<#~):<#-*:)
*                    read a character into A
 (            * )    while input is not a null byte:
  -                  flip Δ
   (     )           while A != 0
    ;                decrement
     ~               swap A and B
      <              read ";" into A
       #             output it
        ~            swap A and B
           :         decrement cell pointer
            <        read "#" into A
             #       output it
              -      flip Δ
               *     take another character from input
                :    increment cell pointer
  • 1
    All this from a joke language I made when I was bored. I'm flattered. – caird coinheringaahing May 23 '17 at 14:11
  • @RandomUser :D it's a fun concept to play around with – Conor O'Brien May 23 '17 at 14:59
  • huh. What if I want the program to print out a null byte in ;#? – tuskiomi Aug 15 '17 at 13:44
  • # @tuskiomi. Try it online! – Conor O'Brien Aug 15 '17 at 18:06
  • @ConorO'Brien how would I input that into your program? – tuskiomi Aug 15 '17 at 18:10

brainfuck, 59 54 bytes

+++++[<+++++++>-]++++++[>++++++++++<-]>-<,[[>.<-]<.>,]

Try it online!

Jelly, 10 8 7 bytes

O”;ẋp”#

Try it online!

O”;ẋp”#  Main Link
O        Map over `ord` which gets the codepoint of every character
 ”;ẋ     Repeat ';' the required number of times
     ”#  '#'
    p    Cartesian Product; this puts a '#' at the end of each element in the array

Implicit Output shows as a single string

-2 bytes thanks to @Emigna
-1 byte thanks to @Dennis

  • Could you do O”;ẋ;€”# instead? – Emigna May 23 '17 at 6:38
  • @Emigna Ah, yes, thanks. I don't quite get how that works but I kind of understand it. Thanks! – HyperNeutrino May 23 '17 at 6:40
  • 4
    ;€ can become p. – Dennis May 23 '17 at 7:10
  • @Dennis Oh now I understand how that works. Thanks! :) – HyperNeutrino May 23 '17 at 12:11

Taxi, 779 bytes

Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to Chop Suey.Go to Chop Suey:n 1 r 1 l 4 r 1 l.[c]Switch to plan "e" if no one is waiting.Pickup a passenger going to Charboil Grill.Go to Charboil Grill:n 1 l 3 l 3 l.Pickup a passenger going to The Underground.Go to Writer's Depot:w 1 r.[p]; is waiting at Writer's Depot.Pickup a passenger going to Post Office.Go to Post Office:n 1 r 2 r 1 l.Go to The Underground:n 1 r 1 l.Switch to plan "n" if no one is waiting.Pickup a passenger going to The Underground.Go to Zoom Zoom:n 3 l 2 r.Go to Writer's Depot:w.Switch to plan "p".[n]# is waiting at Writer's Depot.Go to Writer's Depot:n 3 l 2 l.Pickup a passenger going to Post Office.Go to Post Office:n 1 r 2 r 1 l.Go to Chop Suey:n 1 r 1 l 4 r 1 l.Switch to plan "c".[e]

Try it online!

Ungolfed:

Go to Post Office: west 1st left 1st right 1st left.
Pickup a passenger going to Chop Suey.
Go to Chop Suey: north 1st right 1st left 4th right 1st left.
[c]
Switch to plan "e" if no one is waiting.
Pickup a passenger going to Charboil Grill.
Go to Charboil Grill: north 1st left 3rd left 3rd left.
Pickup a passenger going to The Underground.
Go to Writer's Depot: west 1st right.
[p]
; is waiting at Writer's Depot.
Pickup a passenger going to Post Office.
Go to Post Office: north 1st right 2nd right 1st left.
Go to The Underground: north 1st right 1st left.
Switch to plan "n" if no one is waiting.
Pickup a passenger going to The Underground.
Go to Zoom Zoom: north 3rd left 2nd right.
Go to Writer's Depot: west.
Switch to plan "p".
[n]
# is waiting at Writer's Depot.
Go to Writer's Depot: north 3rd left 2nd left.
Pickup a passenger going to Post Office.
Go to Post Office: north 1st right 2nd right 1st left.
Go to Chop Suey: north 1st right 1st left 4th right 1st left.
Switch to plan "c".
[e]

Explanation:

Pick up stdin and split it into characters.
Covert each character to ASCII.
Print ";" as you count down from that ASCII to zero.
Print "#".
Pickup the next character and repeat until done.
  • +1 I just love languages such as this and Mornington Crescent, the code is just so beautiful! – Karl-Johan Sjögren May 26 '17 at 10:55

GS2, 6 bytes

■•;2•#

Try it online!

Reversible hexdump (xxd)

0000000: ff 07 3b 32 07 23                                ■•;2•#

How it works

■       Map the rest of the program over  all code points C of the input.
 •;         Push ';'.
   2        Multiply; repeat ';' C times.
    •#      Push '#'.
  • 2
    = what the heck? – Erik the Outgolfer May 23 '17 at 8:47
  • 1
    2 is the multiplication command? GS2 is weird :P – ETHproductions May 23 '17 at 10:34
  • 1
    @EriktheOutgolfer executes the code for each of the input's character's code point o_O – Mr. Xcoder May 23 '17 at 12:15
  • @EriktheOutgolfer That sounds fancier than it is. is just map, and GS2 implements strings as lists of integers. – Dennis May 23 '17 at 15:43
  • @ETHproductions GS2 isn't character-based; it interprets the source code as a raw byte stream, and there's usually no connection between the instruction and the CP-437 character the byte encodes. In x86_64 byte code, 2 is XOR... – Dennis May 23 '17 at 15:48

Brainfuck, 43 bytes

+[+[<]>->++]--[>--<+++++++]>-<,[[<.>-]>.<,]

Null byte terminates the program.

Explanation

+[+[<]>->++]          59 (semicolon) location 5
--[>--<+++++++]>-       35 (hash) location 7
<,[                     input location 6
    [   while input byte not 0
        <.>     print semicolon
        -       decrement input byte
    ]
    >.< print hash
,]  loop while input not null
  • That's impressively small for Brainf*ck. – MD XF May 23 '17 at 21:48
  • almost competes with the python answer. Impressive. – raddish0 Jun 9 '17 at 16:07

05AB1E, 8 bytes

Ç';×'#«J

Try it online!

Explanation

Ç          # convert each input char to its ascii value
 ';×       # repeat ";" those many times
    '#«    # append a "#" to each run of semi-colons
       J   # join to string

Python 3, 39 bytes

[print(";"*ord(s)+"#")for s in input()]

Try it online!

  • 1
    for s in input():print(";"*ord(s)+"#") is one byte shorter. – ovs May 23 '17 at 7:01
  • 1
    @ovs that moment when you assume a list comprehension is shorter. – Mr. Xcoder May 23 '17 at 12:09
  • 1
    That doesn't accept a string with a newline does it? – Tim May 24 '17 at 12:34

F#, 79 bytes

let c i=System.String.Join("#",Seq.map(fun c->String.replicate(int c)";")i)+"#"

Try it online!

Expanded

// string -> string
let convert input =
    System.String.Join(
        "#",      // join the following char seq with "#"
        input     // replicate ";" n times where n = ASCII value of char c
        |> Seq.map (fun c-> String.replicate (int c) ";") 
    ) + "#" // and add the last "#" to the output

convert takes the input string and outputs a ;# program

Usage

convert "Hello, World!" |> printfn "%s"
convert "ABC" |> printfn "%s"
convert ";#" |> printfn "%s"
  • 4
    We need more F# answer – aloisdg May 23 '17 at 8:54
  • @aloisdg I'll do my best :) – Brunner May 23 '17 at 14:56

><>, 22 bytes

i:0(?;\"#"o
o1-:?!\";"

Try it online, or at the fish playground

Input is STDIN, output is STDOUT. In ><>, characters and ASCII codes are the same thing, so all we need to do is read a character, print ";" and decrement the character until it's 0, then print "#" and loop until there's no more input left.

Mathematica, 49 bytes

StringRepeat[";",#]<>"#"&/@ToCharacterCode@#<>""&

Explanation

enter image description here

Converts the input string to a list of character codes, then Maps the function StringRepeat[";",#]<>"#"& over the list, then StringJoins the result with the empty string.

  • Why do you need the <>""? – CalculatorFeline Jun 19 '17 at 16:01
  • @CalculatorFeline Without it I would be left with a list of strings for each character. StringJoining (<>) the empty string concatenates each string. – ngenisis Jun 20 '17 at 16:18
  • Forgot about that :P – CalculatorFeline Jun 20 '17 at 16:32

PowerShell, 29 bytes

[char[]]"$args"|%{';'*$_+'#'}

Pretty straightforward. Takes input as command-line argument. Output is a valid ;# program that prints the requested text.

Python 2 - 36 bytes

for i in input():print';'*ord(i)+'#'

Try it online!

Aceto, 19 bytes

Since there's an interpreter in Aceto, I thought there outta be an Aceto answer to this challenge as well. It fits neatly in a 2rd order Hilbert curve:

\n;*
'o'p
`!#'
,dpO

First of all, we read a single character (,) and duplicate and negate it to test whether it is a newline (d!, when reading a newline, an empty character is normally pushed on the stack). I then use what I think is a pretty clever trick to handle the newline case compactly:

`'\n

If the value on the stack is True (we read a newline), that code means: do (`) put a character literal on the stack ('), which is a newline: \n.

If the value on the stack is False (we didn't read a newline), that code means: don't (`) read a character literal ('). That means the next character is executed as a command. Fortunately, a backslash escapes the next command (it makes it so that it doesn't get executed), so n doesn't print a newline (which is what n usually does).

The rest of the code is straightforward; we convert the character on the stack to the integer of its unicode codepoint (o), we push a literal semicolon (';), multiply the number with the string (*, like in Python), print the result, push a literal (') #, print it too, and go back to the Origin.

Run with -F if you want to see immediate results (because buffering), but it works without, too.

Perl, 24 bytes

s/./";"x(ord$&)."#"/ges

Run with perl -pe.

Alternative solution:

say";"x ord,"#"for/./gs

Run with perl -nE.

Solace, 11 bytes

Yay, new languages.

';@jx{'#}Ep

Explanation

';           Push the code point of ';' (59).
  @j         Push the entire input as a list of code points.
    x        For each code point in the input, repeat 59 that many times.
     {  }E   For each resulting list of 59s:
      '#      Push the code point of '#' (35).
          p  Flatten and print as unicode characters.

Fourier, 19 bytes

$(I(`;`&j)`#`0~j&i)

Try it on FourIDE!

To run, you must enclose the input string in quotation marks.

Explanation pseudocode

While i != Input length
    temp = pop first char of Input
    While j != Char code of temp
        Print ";"
        Increment j
    End While
    Print "#"
    j = 0
    Increment i
End While

brainfuck, 47 bytes

+++++++[->++++++++>+++++<<]>+++<,[[>.<-]>>.<<,]

Try it online!

See also: ovs's answer, which takes a similar approach, but with a different method of generating constants and a different cell layout.


Explanation:

This challenge lines up with the brainfuck spec pretty well, which means the solution is essentially trivial. Brainfuck takes input as ASCII values, which is exactly what ;# need to output as.

The schematic for transpiling is simple: Generate the ASCII value for ; and #, print ; equal to the ASCII value of the input character, print #, repeat for every input.

+++++++[-             7
         >++++++++       * 8 = 56
         >+++++<<        * 5 = 35 (#)
       ]>+++<                  56 + 3 = 59 (;)
,[                    Input into first cell
  [>.<-]              Print ;'s equal to ASCII input
  >>.<<,              Print one #
 ]                    End on EOF
  • -2 Bytes Only -1 if you’re avoiding negative cells – Jo King Dec 19 '17 at 5:29

JavaScript (ES6), 55 54 51 50 bytes

s=>1+[...s].map(c=>";".repeat(c.charCodeAt())+"#")
  • 1 byte saved thanks to Neil.

Alternatives

If we can take input as an array of individual characters then 5 bytes can be saved.

a=>1+a.map(c=>";".repeat(c.charCodeAt())+"#")

If we can also output as an array then 2 more bytes can be saved.

a=>a.map(c=>";".repeat(c.charCodeAt())+"#")

Try It

Test the output here.

f=
s=>1+[...s].map(c=>";".repeat(c.charCodeAt())+"#")
o.innerText=f(i.value="Hello, World!")
oninput=_=>o.innerText=f(i.value)
p{font-family:monospace;word-break:break-word}
<input id=i><p id=o>

  • \n should becomes ;;;;;;;;;;#. – Neil May 23 '17 at 9:13
  • Hmm ... that's strange. Guess I'll have to roll back to the longer solution, so. Thank, @Neil. – Shaggy May 23 '17 at 9:17
  • 2
    I think you could change . to [^], which would still leave it a byte shorter than map/join? – Neil May 23 '17 at 9:18
  • Yup, that did the job, @Neil :) – Shaggy May 23 '17 at 9:23
  • Just a heads up, the join() in your previous answer was unnecessary given the specification for ;#, and you can also declare that the input for your function is an array of characters, though the second suggestion is a bit of a stretch. Either way, that brings you down to at most 48 bytes. – Patrick Roberts May 23 '17 at 21:55

Actually, 11 bytes

O⌠';*'#o⌡MΣ

Try it online!

Explanation:

O⌠';*'#o⌡MΣ
O            convert string to list of ASCII ordinals
 ⌠';*'#o⌡M   for each ordinal:
  ';*          repeat ";" that many times
     '#o       append "#"
          Σ  concatenate

APL (Dyalog), 18 bytes

'#',¨⍨';'⍴¨⍨⎕UCS

Try it online!

⎕UCS Convert to Unicode code points

';'⍴¨⍨ use each code point to reshape ( = RhoR; Reshape) a semicolon

#',¨⍨ append a hash to each string

Ruby, 28 25 bytes

24 bytes, plus the -n command line switch to repeatedly operate on stdin.

$_.bytes{|b|$><<?;*b+?#}

3 bytes saved (and output corrected on newlines!) thanks to manatwork.

  • You could avoid the use of .ord by working directly with character codes: $_.bytes{|b|$><<?;*b+?#}. There is difference: this one also encodes the newline in the input. Not sure what the question owner intends to say by “It will only contain printable ASCII characters and newlines.”, but to me sounds like newlines should be encoded too. – manatwork May 23 '17 at 8:19
  • Your Ruby-fu exceeds mine, @manatwork - I'd forgotten about bytes. I've asked OP about newlines up top and will edit this afterwards. – Chowlett May 23 '17 at 8:24

PHP, 54 Bytes

for(;$o=ord($argn[$i++]);)echo str_repeat(";",$o)."#";

Try it online!

Alice, 12 bytes

'#I.h%&';d&O

Try it online!

Explanation

'#    Push 35, the code point of '#'.
I     Read a code point C from STDIN. Pushes -1 at EOF.
.h%   Compute C%(C+1). For C == -1, this terminates the program due to division
      by zero. For C > -1, this just gives back C, so it does nothing.
&';   Pop C and push that many 59s (the code point of ';').
d     Push the stack depth, which is C+1.
&O    Print that many code points from the top of the stack.
      The IP wraps around to the beginning and another iteration of this
      loop processes the next character.

PHP, 48 bytes

for(;$c?:~$c=~ord($argn[$i++]);)echo";#"[!++$c];

jq, 30 characters

(26 characters code + 4 characters command line options)

explode|map(";"*.+"#")|add

Sample run:

bash-4.4$ jq -Rr 'explode|map(";"*.+"#")|add' <<< 'Hello, World!' | jq -Rrj '[scan(".*?#")|gsub("[^;]";"")|length%127]|implode'
Hello, World!

On-line test

Pyth, 10 bytes

sm_+\#*\;C

Try it!

Röda, 24 bytes

{chars|[";"*ord(_),"#"]}

Try it online!

Befunge-98 (FBBI), 23 17 bytes

';#@~1-k:>:#,_'#,

Try it online!

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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