Generate ;# code

37

4

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>

kalsowerus

Posted 2017-05-23T06:06:10.690

Reputation: 1 894

9Brilliant! Glad to see ;# is getting attention! – caird coinheringaahing – 2017-05-23T06:41:30.340

1

You can test your output here, as ;#+ is a superset of ;#.

– Adám – 2017-05-23T07:02:38.213

@Adám I'll be damned, it's already on TIO – kalsowerus – 2017-05-23T07:14:21.677

3Can the output contain additional character? ;# ignores all other characters, so the generated program would still work. – Dennis – 2017-05-23T07:23:07.003

1@Dennis Yes it can – kalsowerus – 2017-05-23T07:26:25.643

1When the input contains a newline, do you need the output to contain 13 ; and a #? – Chowlett – 2017-05-23T08:21:24.527

@Chowlett Well, depends on what newline sequence was used in the input. \n should be 10 ; and \r should be 13 ;. – kalsowerus – 2017-05-23T08:37:45.397

Uh, yes. I meant 10. <.<; – Chowlett – 2017-05-23T08:43:44.093

None of the answers implement the modulus you've aksed (and I think you meant % 128). – Benoît – 2017-05-24T04:37:04.303

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 – 2017-05-24T07:16:31.770

Can you edit the fact that the output may contain additional characters other than ; and # into the question, please? A few people, myself included, may be able to save some bytes with that knowledge. – Shaggy – 2017-05-24T11:40:59.920

@Shaggy: But that is part of the question; you're supposed to output valid ;# code and in ;# code anything except ; or # is simply ignored. Thus you can have other characters in it, as they don't change the validity of the ;# program. – Joey – 2017-05-24T13:54:32.227

@Joey, the fact that "all other characters are ignored" is mentioned in the intro doesn't necessarily explicitly permit any other characters in the output. – Shaggy – 2017-05-24T13:57:08.077

2This isn't really transpiling. "Generate #; code" is a better title. I'm going to change it to that. – Mego – 2017-05-24T20:24:32.240

Can we take input as an array of individual characters? – Shaggy – 2017-05-25T18:10:22.600

@Shaggy Sorry for the (very) late answer. The input should be taken as a string, I will clarify this. – kalsowerus – 2017-05-29T06:20:23.333

Answers

49

;#+, 61 bytes

Outgolfed by Conor O'Brien

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

Try it online!

Note that the input has a trailing null byte.

ovs

Posted 2017-05-23T06:06:10.690

Reputation: 21 408

12Points for style. – Chowlett – 2017-05-23T08:19:55.180

1I approve of this answer :D definitely the right language for the job – Conor O'Brien – 2017-05-23T13:41:50.307

33

;#+, 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

Conor O'Brien

Posted 2017-05-23T06:06:10.690

Reputation: 36 228

1All this from a joke language I made when I was bored. I'm flattered. – caird coinheringaahing – 2017-05-23T14:11:21.927

@RandomUser :D it's a fun concept to play around with – Conor O'Brien – 2017-05-23T14:59:35.833

huh. What if I want the program to print out a null byte in ;#? – tuskiomi – 2017-08-15T13:44:08.993

# @tuskiomi. Try it online! – Conor O'Brien – 2017-08-15T18:06:55.087

@ConorO'Brien how would I input that into your program? – tuskiomi – 2017-08-15T18:10:01.007

@tuskiomi With this program, you can't It is not needed, however, since we are guaranteed that "It will only contain printable ASCII characters and newlines." – Conor O'Brien – 2017-08-15T18:11:11.007

13

brainfuck, 59 54 bytes

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

Try it online!

ovs

Posted 2017-05-23T06:06:10.690

Reputation: 21 408

12

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

HyperNeutrino

Posted 2017-05-23T06:06:10.690

Reputation: 26 575

Could you do O”;ẋ;€”# instead? – Emigna – 2017-05-23T06:38:08.143

@Emigna Ah, yes, thanks. I don't quite get how that works but I kind of understand it. Thanks! – HyperNeutrino – 2017-05-23T06:40:04.703

4;€ can become p. – Dennis – 2017-05-23T07:10:13.653

@Dennis Oh now I understand how that works. Thanks! :) – HyperNeutrino – 2017-05-23T12:11:00.443

11

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 '#'.

Dennis

Posted 2017-05-23T06:06:10.690

Reputation: 196 637

2 = what the heck? – Erik the Outgolfer – 2017-05-23T08:47:33.490

12 is the multiplication command? GS2 is weird :P – ETHproductions – 2017-05-23T10:34:13.253

1@EriktheOutgolfer executes the code for each of the input's character's code point o_O – Mr. Xcoder – 2017-05-23T12:15:52.730

@EriktheOutgolfer That sounds fancier than it is. is just map, and GS2 implements strings as lists of integers. – Dennis – 2017-05-23T15:43:32.680

@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 – 2017-05-23T15:48:33.203

Considering that the program is usually non-printing, wouldn't it be easier to just paste a hexdump? ■ seems to be 0xFE and • seems to be 0x7 (in CP437), but took me a while to figure that out. – Joey – 2017-05-23T16:31:52.050

@Joey Added a hexdump. Unfortunately, the interpreter on TIO (only) takes CP-437 encoded source code, for reasons I no longer remember. Hexdumps would have indeed been a better choice. – Dennis – 2017-05-23T16:40:29.063

@Dennis Ooh so GS2's strings are like GolfScript's (where to get a char at a specific index you do 1/= and even \1/= sometimes) in a sense. – Erik the Outgolfer – 2017-05-24T08:27:10.410

10

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.

Engineer Toast

Posted 2017-05-23T06:06:10.690

Reputation: 5 769

+1 I just love languages such as this and Mornington Crescent, the code is just so beautiful! – Karl-Johan Sjögren – 2017-05-26T10:55:55.303

9

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

Emigna

Posted 2017-05-23T06:06:10.690

Reputation: 50 798

9

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

Mika Lammi

Posted 2017-05-23T06:06:10.690

Reputation: 1 151

That's impressively small for Brainf*ck. – MD XF – 2017-05-23T21:48:44.830

almost competes with the python answer. Impressive. – raddish0 – 2017-06-09T16:07:28.980

7

Python 3, 39 bytes

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

Try it online!

Leaky Nun

Posted 2017-05-23T06:06:10.690

Reputation: 45 011

2for s in input():print(";"*ord(s)+"#") is one byte shorter. – ovs – 2017-05-23T07:01:22.053

1@ovs that moment when you assume a list comprehension is shorter. – Mr. Xcoder – 2017-05-23T12:09:36.747

1That doesn't accept a string with a newline does it? – Tim – 2017-05-24T12:34:05.700

5

><>, 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.

Not a tree

Posted 2017-05-23T06:06:10.690

Reputation: 3 106

5

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"

Brunner

Posted 2017-05-23T06:06:10.690

Reputation: 331

4We need more F# answer – aloisdg moving to codidact.com – 2017-05-23T08:54:34.973

@aloisdg I'll do my best :) – Brunner – 2017-05-23T14:56:20.987

5

Python 2 - 36 bytes

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

Try it online!

Mr. Xcoder

Posted 2017-05-23T06:06:10.690

Reputation: 39 774

5

PowerShell, 29 27 25 bytes

$args|% t*y|%{';'*$_+'#'}

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

Joey

Posted 2017-05-23T06:06:10.690

Reputation: 12 260

It need to join result strings. – mazzy – 2018-09-07T08:55:36.463

@mazzy: From the task description: »As long as the program is valid, it may contain excess characters other than # and ; as all other characters are ignored.« – Joey – 2018-09-07T10:39:29.570

as you wish :-) – mazzy – 2018-09-07T11:10:58.480

quotation marks can be removed. $args is enough. – mazzy – 2018-09-07T13:49:25.590

Unless the argument is numeric. – Joey – 2018-09-07T14:28:18.923

?! rule: The input is a string.... But as you wish ;-) – mazzy – 2018-09-07T14:46:28.217

Ah, good point. – Joey – 2018-09-07T14:57:01.450

4

JavaScript, 55 54 51 50 48 bytes

s=>1+[...s].map(c=>";".repeat(Buffer(c)[0])+"#")

Try it online

  • 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(Buffer(c)[0])+"#")

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

a=>a.map(c=>";".repeat(Buffer(c)[0])+"#")

Shaggy

Posted 2017-05-23T06:06:10.690

Reputation: 24 623

\n should becomes ;;;;;;;;;;#. – Neil – 2017-05-23T09:13:37.067

Hmm ... that's strange. Guess I'll have to roll back to the longer solution, so. Thank, @Neil. – Shaggy – 2017-05-23T09:17:10.540

2I think you could change . to [^], which would still leave it a byte shorter than map/join? – Neil – 2017-05-23T09:18:50.367

Yup, that did the job, @Neil :) – Shaggy – 2017-05-23T09:23:24.800

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 – 2017-05-23T21:55:10.730

4

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

Zack C.

Posted 2017-05-23T06:06:10.690

Reputation: 491

-2 Bytes Only -1 if you’re avoiding negative cells – Jo King – 2017-12-19T05:29:51.967

4

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.

ngenisis

Posted 2017-05-23T06:06:10.690

Reputation: 4 600

Why do you need the <>""? – CalculatorFeline – 2017-06-19T16:01:12.183

@CalculatorFeline Without it I would be left with a list of strings for each character. StringJoining (<>) the empty string concatenates each string. – ngenisis – 2017-06-20T16:18:06.083

Forgot about that :P – CalculatorFeline – 2017-06-20T16:32:23.580

3

Befunge-98 (FBBI), 23 17 10 bytes

-5 bytes thanks to Jo King.

"#@~k:*k,;

Try it online!

ovs

Posted 2017-05-23T06:06:10.690

Reputation: 21 408

1@JoKing Thanks a lot. I was able to golf two bytes more off. This now on par with Pyth, Husk and CJam! – ovs – 2018-09-07T17:13:08.707

3

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.

L3viathan

Posted 2017-05-23T06:06:10.690

Reputation: 3 151

3

Perl, 24 bytes

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

Run with perl -pe.

Alternative solution:

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

Run with perl -nE.

Grimmy

Posted 2017-05-23T06:06:10.690

Reputation: 12 521

3

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

Beta Decay

Posted 2017-05-23T06:06:10.690

Reputation: 21 478

3

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.

Business Cat

Posted 2017-05-23T06:06:10.690

Reputation: 8 927

2

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

Mego

Posted 2017-05-23T06:06:10.690

Reputation: 32 998

2

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

Adám

Posted 2017-05-23T06:06:10.690

Reputation: 37 779

2

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.

Chowlett

Posted 2017-05-23T06:06:10.690

Reputation: 221

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 – 2017-05-23T08:19:24.343

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 – 2017-05-23T08:24:22.030

2

PHP, 54 Bytes

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

Try it online!

Jörg Hülsermann

Posted 2017-05-23T06:06:10.690

Reputation: 13 026

2

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.

Martin Ender

Posted 2017-05-23T06:06:10.690

Reputation: 184 808

2

PHP, 48 bytes

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

user63956

Posted 2017-05-23T06:06:10.690

Reputation: 1 571

2

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

manatwork

Posted 2017-05-23T06:06:10.690

Reputation: 17 865

2

Pyth, 10 bytes

sm_+\#*\;C

Try it!

KarlKastor

Posted 2017-05-23T06:06:10.690

Reputation: 2 352

2

Röda, 24 bytes

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

Try it online!

fergusq

Posted 2017-05-23T06:06:10.690

Reputation: 4 867

2

Brachylog, 15 bytes

ạ{;";"j₍,"#"}ᵐc

Try it online!

ạ                   % Convert the string into its ascii codes
 {          }ᵐ      % map this over each resulting code:
  ;";"j₍            %   repeat ";" that many times
        ,"#"        %   tack on a "#" at the end of that
              c     % at the end of the map, concatenate the results of the map

sundar - Reinstate Monica

Posted 2017-05-23T06:06:10.690

Reputation: 5 296

1

CJam, 12 10 bytes

q{i';*'#}%

Explanation:

q           e# Read input
 {          e# For each character in the input:
  i         e#  Get code point
   ';*      e#  Repeat ';' that many times
      '#    e#  Add a '#'
        }%  e# End for
e# Implicit output

Esolanging Fruit

Posted 2017-05-23T06:06:10.690

Reputation: 13 542

1

Japt, 10 9 bytes

c@'#i';pX

Try it


Explanation

     :Implicit input of string U
c@   :Map over the codepoints of characters in the string
'#   :"#"
i    :Prepend
';   :";"
p    :repeated
X    :The current codepoint times

Shaggy

Posted 2017-05-23T06:06:10.690

Reputation: 24 623

1

PowerShell, 36 Bytes

-join([char[]]"$args"|%{';'*$_;'#'})

just prints ;s and then a #

colsw

Posted 2017-05-23T06:06:10.690

Reputation: 3 195

You can compact it: -join($args|% t*y|%{';'*$_+'#'}) 32 bytes )) – mazzy – 2018-09-07T08:57:22.597

1

Wolfram Mathematica, 69 bytes

FromCharacterCode[Flatten[{Table[59,{,#}],38}&/@ToCharacterCode[x]]]

Table[59,{,#}] is a short replacement for ConstantArray[].

Sauron

Posted 2017-05-23T06:06:10.690

Reputation: 41

1

R, 59 56 bytes

for(x in utf8ToInt(scan(,'')))cat(rep(';',x),'#',sep="")

Try it online!

Giuseppe

Posted 2017-05-23T06:06:10.690

Reputation: 21 077

1

C, 61 57 bytes

c;f(){for(;~(c=getchar());puts("#"))while(c--)puts(";");}

Hope you don't mind a newline after every character :P However, this is allowed, as it doesn't affect the program, since all bytes aside from ;# are ignored.

MD XF

Posted 2017-05-23T06:06:10.690

Reputation: 11 605

How do you run this? I'm trying to execute this and it doesn't terminate. Is it not supposed to? – Patrick Roberts – 2017-05-23T21:41:55.903

@PatrickRoberts It's waiting for input. See the getchar()? – MD XF – 2017-05-23T21:42:17.727

Yes, but after I provide input, it prints, and still doesn't terminate. That's what I mean. – Patrick Roberts – 2017-05-23T21:43:55.763

@PatrickRoberts It terminates upon EOF. – MD XF – 2017-05-23T21:45:01.417

Ah, got it. I had to use echo 'Hello, World!' | ./test rather than typing it during execution. – Patrick Roberts – 2017-05-23T21:45:46.427

1@PatrickRoberts You can type it during execution, just hit Ctrl+D at the end (assuming you're on Linux). – MD XF – 2017-05-23T21:46:16.173

1

shortC, 27 bytes

c;AO;~(c=G);J"#"))Wc--)J";"

MD XF

Posted 2017-05-23T06:06:10.690

Reputation: 11 605

1

Cubix, 19 bytes

-5 bytes thanks to @MickyT!

i.#';UoU^!.$U@?(';o

on a cube:

    i .
    # '
; U o U ^ ! . $
U @ ? ( ' ; o .
    . .
    . .

this version is much cleverer than the prior one (my version) with moving the instruction pointer around, using U (left-hand u-turn) and the way the adjacencies on the cube to loop and produce the correct output. Explanation to follow.

Old Version, 24 bytes:

..@.;i?...>;'(/!.;o;W'.#

Try it online! and Watch it online! (the latter might be really slow)

Since this question had a relatively simple I/O scheme, I figured this would be a good fit for a Cubix solution. I still spent a few days trying to solve it, though. The breakthrough was when I tried using !, which skips the next instruction if the top of the stack is truthy (not zero, I think), enabling something like a while loop.

Cubified:

    . .
    @ .
; i ? . . . > ;
' ( / ! . ; o ;
    W '
    . #

The instruction pointer starts at the top left corner of the leftmost face, pointing east. Here's the code:

Outer loop:

; - pop the top item off the stack. does nothing at the beginning since the stack is empty.
i - read in the ascii character as an integer. Reads -1 at end of input.
? - turns right if the top of the stack is positive, and left if negative.
@ - if negative (end of input), ends the program
/ - mirrors the direction pointer (swapping S<->W and N<->E), entering the inner loop

Inner loop:

( - decrements the top of the stack (the ascii value of the input)
' - pushes the next char
; - the semicolon
o - outputs as a char
; - pops the top of the stack
! - ignores the next instruction if the top of the stack is not zero

then when the appropriate number of ; have been printed,

/ - the IP is moving W, so it now switches S
W - move the IP left
' - push the next char
# - pushes this char
o - prints #
> - points the IP east
; - pop the top of the stack

and then returns to the top of the outer loop.

Giuseppe

Posted 2017-05-23T06:06:10.690

Reputation: 21 077

I have had a crack at remove some of the no-ops in your code. I managed to trim of a few bytes for i.#';UoU^!.$U@?(';o. It gets a bit messy in there, but it works – MickyT – 2017-05-31T22:56:14.417

I must admit, I'm impressed! I'll have to take these ideas into consideration for future cubix submissions. – Giuseppe – 2017-06-06T19:14:21.697

1

Ly, 18 bytes

&ir[[";"o1-]"#"op]

Try it online!

LyricLy

Posted 2017-05-23T06:06:10.690

Reputation: 3 313

Unfortunately your language seems to be newer than the challenge post. You should mark it as "non competing". Great answer though! – kalsowerus – 2017-08-11T09:19:35.657

2

@kalsowerus I believe we have a consensus against this.

– LyricLy – 2017-08-11T09:28:27.640

@LirycLy Oh, I must have missed that. Thanks for the update. – kalsowerus – 2017-08-11T09:39:32.280

1

Braingolf, 11 bytes

&([#;]##)&@

Try it online!

Ooh, moderately golfy

Skidsdev

Posted 2017-05-23T06:06:10.690

Reputation: 9 656

1

Befunge-93, 31 28 26 bytes

Edit: -2 bytes thanks to James Holderness

#;"~1+:!#@_>1#\-#,: #\_$$,

Try it Online

How it works

#;"          Adds # and ; to the stack
   ~1+:!#@_  Gets the input and dupes it. Ends if the input is eof
           >1#\-#,: #\_ Prints a semi-colon until the input byte reaches 0
                       $$, Prints the ending hash and loops back round

Jo King

Posted 2017-05-23T06:06:10.690

Reputation: 38 234

1

Pushy, 12 bytes

@$:59'.;35'.

Try it online!

This prints each character of the ;# code on a newline. To condense the code, simply prepend N to the program to remove the printing delimiter.

FlipTack

Posted 2017-05-23T06:06:10.690

Reputation: 13 242

1

Minecraft Functions (18w11a, 1.13 snapshots), 861 bytes

Uses four functions

a

scoreboard objectives add a dummy
scoreboard objectives add b dummy
scoreboard objectives add c dummy
scoreboard objectives add d dummy
scoreboard objectives add e dummy
scoreboard players set x a 0
scoreboard players set x b 0
scoreboard players set x c 1000
scoreboard players set x d 0
scoreboard players set x e 1
function b
function c

b

scoreboard players operation x b = x i
scoreboard players operation x b %= x c
scoreboard players operation x a *= x c
scoreboard players operation x a += x b
scoreboard players operation x i /= x c
execute if score x i > x d run function b

c

scoreboard players operation x i = x a
scoreboard players operation x i %= x c
function d
tellraw @s "#"
scoreboard players operation x a /= x c
execute if score x a > x d run function c

d

tellraw @s ";"
scoreboard players operation x i -= x e
execute if score x i > x d run function d

"Takes input" from a scoreboard objective named i, create it with /scoreboard objectives add i dummy and then set it using /scoreboard players set x i 5. Then call the function using /function a

Limitations:

Minecraft does not really support strings, or input, or much of anything really, so due to language limitations, input is passed to the i scoreboard, as ascii values, so "ABC" would be 65066067.

However, due to another limitation, scoreboard objectives can only store numbers with 10 or less digits, so all strings must be passed in chunks of three letters. For example, "Hello, World!" must be converted to '072101108', '108111044', '032087111', '114108100', '033' and the function must be called for each of these numbers. Hope that counts as a valid input method.

This python function will convert the strings, it does not change the string in any way, other than getting the ascii representation,

def convert(string):
    line = ''.join('{:0>3}'.format(ord(c)) for c in string)
    print([line[i:i+9] for i in range(0, len(line), 9)])

Minecraft may not have been the best choice of language.

Noskcaj

Posted 2017-05-23T06:06:10.690

Reputation: 421

1

Canvas, 5 bytes

c;×#]

Try it here!

Explanation:

{    ] map over the characters of the input
 c     convert the character to its unicode codepoint
  ;×   repeat ";" that many times
    #  push "#"

dzaima

Posted 2017-05-23T06:06:10.690

Reputation: 19 048

0

C (72 bytes)

main(c){while((c=getchar())!=-1){while(c--)putchar(';');putchar('#');}}

AKX

Posted 2017-05-23T06:06:10.690

Reputation: 101

3You could probably write >-1 rather than !=-1 to save a byte. Also, printf is shorter than putchar (and puts would be shorter still; you'd put a lot of stray newlines in the output, but those are specified as ignored). – None – 2017-05-23T08:03:21.700

Why community wiki? – MD XF – 2017-05-23T21:47:22.460

0

Gema, 28 charcters

?=@repeat{@char-int{?};\;}\#

Sample run:

bash-4.4$ gema '?=@repeat{@char-int{?};\;}\#' <<< 'Hello, World!' | gema '\A=@set{a;0};\;=@incr{a};\#=@int-char{@mod{$a;127}}@set{a;0};?='
Hello, World!

manatwork

Posted 2017-05-23T06:06:10.690

Reputation: 17 865

0

QBIC, 36 bytes

[_l;||[asc(_sA,a,1|)|Z=Z+@;`]Z=Z+@#`

Explanation

[_l;||        FOR a = 1 to LEN(A$) # A$ is read from the vmd line
[asc(...)     FOR b = 1 to the ASCII value of
   _sA,a,1|     The next char of A$
Z=Z+@;`       Add the increment instruction to Z$
]         NEXT increment instruction
Z=Z+@#`       When all incrementers are added, issue a print-command
              NEXT for the outer FOR loop is added inplicitly at EOF
              Z$ is printed implicitly at EOF

steenbergh

Posted 2017-05-23T06:06:10.690

Reputation: 7 772

0

Go, 91 bytes

import(."fmt";."strings")
func f(s string){for _,c:=range s{Print(Repeat(";",int(c))+"#")}}

Try it online!

Explanation

import( . "fmt"                     // fmt import to print stuff out
        . "strings"                 // strings import for string manipulation
)                                   // the dots import into the global namespace

func transpile(str string) {        // function that takes a string argument
    for _, char := range str {      // iterate over the runes (characters) in str
        Print(                      // print x without newline where x is...
              Repeat(";",           // ...";" repeated y times where y is... 
                     int(char)) +   // ...the ASCII integer of the rune and...
              "#")                  // ..."#" to end it
    }
}

totallyhuman

Posted 2017-05-23T06:06:10.690

Reputation: 15 378

0

Bean, 48 bytes

00000000: 53d0 80c3 cf53 d080 a078 2080 7b23 8100  SÐ.ÃÏSÐ. x .{#..
00000010: 0020 8088 40a0 5f4c d3d0 80a3 8101 2080  . ..@ _LÓÐ.£.. .
00000020: b553 5080 a05f 2080 ad8b 2381 020a 3b23  µSP. _ ...#...;#

Try it online!

Equivalent JavaScript (ES6):

[..._.join("\n")].map((c)=>";".repeat(c.charCodeAt())+"#");

Explanation

Taking multiline standard input as an array of string lines in _, it first joins them with \n and spreads the resulting string into an array of characters, which is then mapped like in @Shaggy's answer.

The difference is, it outputs the raw array of ;# strings that represent each character, but because the language specification will ignore all of the following characters: []' , this is valid behavior.

Patrick Roberts

Posted 2017-05-23T06:06:10.690

Reputation: 2 475

0

C# 54 + 18 = 72 Bytes

using System.Linq;
s=>string.Join("",s.Select(c=>new string(';',c)+"#"));

Ungolfed full program and explanation

using System.Linq;

class P
{
    static void Main()
    {
        System.Func<string, string> f =
            s => string.Join("",       //4. Join the results separated by an empty string and implicitly return
                s.Select(c =>          //1. For each character in the input
                    new string(';', c) //2. Implicitly convert the character to an int with the ASCII-Code and create a new string with that many ;
                    + "#"));           //3. Add a #

        System.Console.WriteLine(f(";#"));
        System.Console.WriteLine(f("ABC"));
        System.Console.WriteLine(f("Hello World!"));
    }
}

raznagul

Posted 2017-05-23T06:06:10.690

Reputation: 424

0

Husk, 13 10 bytes

ṁȯ`:'#R';c

Try it online!

Ungolfed/Explained

ṁȯ          -- map function and concatenate result
         c  --   ASCII order of element times
      R';   --   repeat ';' and
  `:'#      --   append '#'

ბიმო

Posted 2017-05-23T06:06:10.690

Reputation: 15 345

0

Haskell, 50 32 bytes

This is a direct port of my Husk answer:

((\n->(';'<$['\1'..n])++"#")=<<)

Try it online!

Thanks @Laikoni for saving me 18 bytes!

ბიმო

Posted 2017-05-23T06:06:10.690

Reputation: 15 345

0

Python 3, 51 bytes

[print(''.join((';'*ord(i)+'#')for i in input()))] 

Try it online!

Rohit-Pandey

Posted 2017-05-23T06:06:10.690

Reputation: 169

0

q/kdb+, 24 bytes

Solution:

{,["#"sv(7h$x)#'";"]"#"}

Explanation:

q is interpreted right-to left. We cast the input to it's ASCII values, thus "Hello, World!" becomes 72 101 108 108 111 44 32 87 111 114 108 100 33. We then take this many of the ; character, which gives us a list of lists. These lists are joined together with #, then we a # on the end to terminate the string.

{,["#"sv(7h$x)#'";"]"#"} / the solution
{                      } / lambda function
 ,[                ]"#"  / concatenate with "#"
              #'         / apply each-left take (#) each-right
                ";"      / the right (the character ;)
        (7h$x)           / the left (input cast to ASCII values)
   "#"sv                 / join these lists back together with "#"

Bonus:

Could save 1 byte moving the cast outside the function, but that's a bit underhand:

{,["#"sv x#'";"]"#"}7h$

Taking inspiration from the APL solution and the above yields a 22 byte solution:

{raze(x#'";"),'"#"}7h$

which becomes 20 bytes in k

{,/(x#'";"),'"#"}7h$

streetster

Posted 2017-05-23T06:06:10.690

Reputation: 3 635

0

Charcoal, 8 bytes

FS⁺×;℅ι#

Try it online!

Explanation (for those too lazy to click the link)

F         For
 S        each character in next input as string
   ⁺    #  Append "#"
    × ℅ι   Multiply (repeat) by the character code of i (loop variable)
     ;     ";"

ASCII-only

Posted 2017-05-23T06:06:10.690

Reputation: 4 687

0

Common Lisp, 71 bytes

(lambda(s)(map'list(lambda(x)(format t"~v,,,v<~>#"(char-code x)#\;))s))

Try it online!

Renzo

Posted 2017-05-23T06:06:10.690

Reputation: 2 260

0

SNOBOL4 (CSNOBOL4), 90 bytes

	N =INPUT
T	N LEN(1) . L REM . N :F(END)
	&ALPHABET L @X
	OUTPUT =DUPL(';',X) '#' :(T)
END

Try it online!

	N =INPUT			;* read input
T	N LEN(1) . L REM . N :F(END)	;* set L to the first character, N to the REMainder, and
					;* if there is no match (N is empty), goto END
	&ALPHABET L @X			;* @ssign X with the value of the match of L inside &ALPHABET (all ASCII chars)
	OUTPUT =DUPL(';',X) '#' :(T)	;* set OUTPUT to ';' duplicated X times concatenated with '#', and a newline
					;* then goto T
END

Giuseppe

Posted 2017-05-23T06:06:10.690

Reputation: 21 077

0

Kotlin, 49 bytes

{it.map{('a'-97..it).map{print(';')}
print('#')}}

Beautified

        {
            it.map {
                ('a'-97..it).map { print(';') }
                print('#')
            }
        }

Test

import java.io.ByteArrayOutputStream
import java.io.PrintStream

/**
 * @author James Tapsell
 */
var o: (String) -> Unit =
{it.map{('a'-97..it).map{print(';')}
print('#')}}

data class Test(val input: String, val output: String)

val tests = listOf(
        Test("Hello, World!", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#"),
        Test("ABC", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#"),
        Test(";#", ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#")
)

fun main(args: Array<String>) {
    tests.forEach {
        val out = ByteArrayOutputStream()
        System.setOut(PrintStream(out))
        o(it.input)
        val text = String(out.toByteArray())
        if (text != it.output) {
            throw AssertionError()
        }
    }
}

TIO

TryItOnline

jrtapsell

Posted 2017-05-23T06:06:10.690

Reputation: 915

0

Gol><>, 11 bytes

iEHr{R`;`#r

Try it online!

How it works

iEHr{R`;`#r

i            Input n as char
 EH          If EOF, print stack contents as chars (from top) and exit

             Stack content                     [x y z... n]
   r{        Reverse the whole stack except n  [...z y x n]
     R`;     Pop n and push that many ';'s     [...z y x ;...;]
        `#   Push '#'                          [...z y x ;...; #]
          r  Reverse stack                     [# ;...; x y z...]
             Repeat indefinitely

The r...r structure makes the invariant that the stack content is the desired string reversed.

Bubbler

Posted 2017-05-23T06:06:10.690

Reputation: 16 616

0

J, 23 Bytes

Nothing special.

,([:,&'#'#&';')"0 u:inv

Explanation:

,([:,&'#'#&';')"0 u:inv
                  u:inv   | Convert string to code points
 (            )"0         | For each item:
  [:,&'#'#&';'            | Repeat ';' n times and append #
,                         | Ravel the resulting character array

Note that the result contains lots of whitespace, since arrays have to be rectangular.

Bolce Bussiere

Posted 2017-05-23T06:06:10.690

Reputation: 970

0

Java 10, 63 bytes

c->{var s="";for(var d:c){for(;d-->0;)s+=";";s+="#";}return s;}

Try it online here.

Ungolfed version:

c -> { // lambda taking a char[] as argument and returning a String
    var s = ""; // the output String
    for(var d : c) { // iterate over all the input chars
        for(; d-- > 0 ;) // as many times as the ASCII value of the current char
            s += ";";    // append ";" to the program to compute the character
        s += "#"; // append "#" to output the character
    }
    return s; // return the finished program
}

O.O.Balance

Posted 2017-05-23T06:06:10.690

Reputation: 1 499

0

Ahead, 13 bytes

~W$:ki@j";#"~

Try it online!

snail_

Posted 2017-05-23T06:06:10.690

Reputation: 1 982

0

Noether, 21 bytes

I~sL(";"si/B*P"#"P!i)

Try it online!

Explanation:

I~s                   - Get input and store in the variable s
   L(               ) - Loop until the top of stack equals the length of s
     ";"              - Push the string ";"
        si/           - Return the character of string s at position i
           B          - Return the ASCII code of the character
            *P        - Multiply ";" by the ASCII code and print
              "#"P    - Push the string "#" and print
                  !i  - Increment i

Beta Decay

Posted 2017-05-23T06:06:10.690

Reputation: 21 478

0

Pascal (FPC), 94 bytes

var c:char;i:word;begin repeat read(c);for i:=1to ord(c)do write(';');write('#')until eof end.

Try it online!

Assumes non-empty input.

AlexRacer

Posted 2017-05-23T06:06:10.690

Reputation: 979

0

VBA (Excel) 82 Bytes

I really think this challenge should've been scored in the length of your program after it is converted into ;#. I would score 6769 characters (including newlines)

Function d(e)
  For i=1To Len(e)
    d=d &String(Asc(Mid(e,i,1)),";") &"#"
  Next
End Function

Note: the leading spaces aren't needed, just make it more read-able, not that I should be worried about that... just look at the output from this thing!!!

Un-golfed With Comments:

Function toSemiHash(translate)
    'For 1 to the length of the string
    For i = 1 To Len(translate)
        'Append a semicolon the char-code number of times along with a hash
        fromSemiHash = fromSemiHash & String(Asc(Mid(translate, i, 1)), ";") & "#"
    Next
End Function

seadoggie01

Posted 2017-05-23T06:06:10.690

Reputation: 181

0

PHP, 75 Bytes

This shorter then the parser I wrote for it.

Generator

function g($s){foreach(str_split($s)as$a)echo str_repeat(';',ord($a)).'#';}

You can test it like this:

$strings = [
    'Hello, World!',
    ';#',
    '!'
];

foreach($strings as $s){
    g($s); echo "\n\n";
}

function g($s){foreach(str_split($s)as$a){echo str_repeat(';',ord($a)).'#';}}

Parser (second attempt)

The one from my first attempt should work fine as well. This one is shorter, so well just use it to verify that the generator works correctly.

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

You can test both like this:

//turn of warning message or set in PHP.ini
error_reporting(0);
$s = "Hello, World!";

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

//output buffer the generator
ob_start();
    g($s);
$s=ob_get_clean();
f($s);

Output

 Hello, World!

Test both of them

A few things to note:

  • Because neither one return information, we can capture the output by using output buffering.
    • We could also put it a file, use $argv[1] for input, remove the function calls, add the shebang #!/bin/env php and run it from the terminal. Which would cut it down to around something like 65. Then we could just pipe that into the other script. So :-P
  • Because the parser is old, we have to use PHP < 7 for it. Don't worry our dev team is currently working hard on a patch to make it compatible with PHP7,(just change split to explode). They should have it done sometime in the spring after they quite code golfing and get back to work!

Lastly

My first attempt at a parser was recursive, so I thought it only fitting I make a generator that is also recursive. Unfortunately as with the first one, it's longer 89 bytes.

 function g($s,$i,$r){echo''==($a=$s[$i])?$r:g($s,++$i,$r.=str_repeat(';',ord($a)).'#');}

You can test it with the same code above:

error_reporting(0);
$s = "Hello, World!";

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

//recursive
function h($s,$i,$r){echo''==($a=$s[$i])?$r:h($s,++$i,$r.=str_repeat(';',ord($a)).'#');}

//output buffer the generator
ob_start();
   // g($s);
   h($s,0,'');
$s=ob_get_clean();
f($s);

Recursive Generator

Things that didn't make the cut

  //parser 98 bytes, strtok + do while
  function p($s){$f=strtok;$a=$f($s,'#');do{echo chr(substr_count($a,';')%127);}while($a=$f('#'));}

ArtisticPhoenix

Posted 2017-05-23T06:06:10.690

Reputation: 329

0

brainfuck, 48 bytes

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

Try it online!

How it works

+++++++[>+++++>++++++++<<-]>>+++>       'write ; and # onto the tape
,[                                      'read input as ascii values and loop
    [-<.>]                              'decrement input 1 and write ; then repeat until 0
    <<.>>                               'write #
,]                                      'read input as ascii values and loop

Prismo

Posted 2017-05-23T06:06:10.690

Reputation: 121

137 bytes – Jo King – 2018-09-08T00:42:11.037

0

J, 23 bytes

[:,[:('#',~#&';')"+3&u:

Try it online!

[:,(35,~#&59)"+&.(3&u:)

Try it online!

Posting since the existing J answer is incorrect.

How it works

[:,[:('#',~#&';')"+3&u:
                   3&u:  Convert to ASCII value
     (          )"+      Apply to each number...
           #&';'           Convert to that many ';'s
      '#',~                and add '#' to the right
   [:                    Treat the above as monadic fork
  ,                      Ravel; flatten the multidimensional array
[:                       Treat the above as monadic fork

[:,(35,~#&59)"+&.(3&u:)
              f&.g       Apply g, f, then inverse of g...
                 (3&u:)    g: convert to ASCII value
   (        )"+            f: apply to each number...
        #&59                 convert to that many 59's (charcode of ';')
    35,~                     and add 35 to the right (charcode of '#')
[:,                      Ravel the result

Both use the "+ trick to avoid numeric literal problem.

Bubbler

Posted 2017-05-23T06:06:10.690

Reputation: 16 616

0

Whitespace, 82 bytes

[N
S S N
_Create_Label_OUTER_LOOP][S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   S _Read_STDIN_as_character][T   T   T   _Retrieve][N
S S S N
_Create_Label_INNER_LOOP][S N
S _Duplicate][N
T   S T N
_If_0_Jump_to_Label_HASTAG][S S S T N
_Push_1][T  S S T   _Subtract][S S S T  T   T   S T T   N
_Push_59_;][T   N
S S _Print_as_character][N
S N
S N
_Jump_to_Label_INNER_LOOP][N
S S T   N
_Create_Label_HASHTAG][S S S T  S S S T T   N
_Push_35_#][T   N
S S _Print_as_character][N
S N
N
_Jump_to_Label_OUTER_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).

Explanation in pseudo-code:

Start OUTER_LOOP:
  Integer c = read character from STDIN
  Start INNER_LOOP:
    If(c == 0):
      Jump to function HASHTAG
    c = c - 1
    Print ";" to STDOUT
    Go to next iteration of INNER_LOOP

function HASHTAG:
  Print "#" to STDOUT
  Go to next iteration of OUTER_LOOP

Note: All characters read from STDIN in Whitespace are automatically stored in the heap as their code-point values.

Kevin Cruijssen

Posted 2017-05-23T06:06:10.690

Reputation: 67 575

0

Brain-Flak, 94 bytes

{{({}[()])<>((((((()()()){})){}{}())()){}{})<>}{}<>(((((()()()){}())){}){}{})<>}<>{({}<>)<>}<>

Try it online!

MegaTom

Posted 2017-05-23T06:06:10.690

Reputation: 3 787

0

Backhand, 27 bytes

}o" i# :" }]@_!}|{:" [; o".

Try it online!

I'm sure a shorter solution exists, given this has 6 no-ops. This prints a null byte to begin with

Explanation:

}o       Print a null byte
    i  :  }]  ! |{     Get a character of input and check if it is EOF
                   "  ; o"   If it is not, print a ;
               }| :  [       Decrement the counter and check again
                   Once the counter hits zero exit the loop
            @_    If the value was -1 (EOF) exit
           ]  !   Otherwise execute some garbage
 o" i#  "         Print a # and get the next character of input

Jo King

Posted 2017-05-23T06:06:10.690

Reputation: 38 234

0

W j d, 7 bytes

The input format is [['a','b',..]]

◘Pp½h#û

Explanation

Uncompressed:

C';*'#+M
       M % For every item in the input:
C        % Convert to a character
 ';*     % Repeat ; ASCII codepoint times
    '#+  % Append a #

Flag:j   % Join without newline
```

user85052

Posted 2017-05-23T06:06:10.690

Reputation:

0

GolfScript, 10 bytes

{";"*"#"}%

Try it online!

user85052

Posted 2017-05-23T06:06:10.690

Reputation:

0

Burlesque, 13 bytes

m{'#j**';j.*}

Try it online!

m{      # For each char in string (implicit concat)
  '#    # Push #
  j**   # Find ord(char)
  ';j.* # That many ;
 }

DeathIncarnate

Posted 2017-05-23T06:06:10.690

Reputation: 916

-1

C, 51 bytes

c;main(){for(;c||~(c=getchar());puts("#;"+!!--c));}

Outputs lots of extra newlines, and an extra ; at the end, but neither of those affect the output of the ;# program, so it should be fine.

Using puts was suggested by ais523 in a comment: Make a ;# transpiler.

~(x) is a shorter way to write (x)!=-1.

"#;"+!!--c is a pointer arithmetic equivalent of --c?";":"#;".

Grimmy

Posted 2017-05-23T06:06:10.690

Reputation: 12 521