40
\$\begingroup\$

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>

jrtapsell
1,0037 silver badges15 bronze badges
asked May 23, 2017 at 6:06
\$\endgroup\$
19
  • 12
    \$\begingroup\$ Brilliant! Glad to see ;# is getting attention! \$\endgroup\$ Commented May 23, 2017 at 6:41
  • 1
    \$\begingroup\$ You can test your output here, as ;#+ is a superset of ;#. \$\endgroup\$ Commented May 23, 2017 at 7:02
  • 3
    \$\begingroup\$ Can the output contain additional character? ;# ignores all other characters, so the generated program would still work. \$\endgroup\$ Commented May 23, 2017 at 7:23
  • 3
    \$\begingroup\$ @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. \$\endgroup\$ Commented May 24, 2017 at 7:16
  • 3
    \$\begingroup\$ This isn't really transpiling. "Generate #; code" is a better title. I'm going to change it to that. \$\endgroup\$ Commented May 24, 2017 at 20:24

87 Answers 87

1
2 3
54
\$\begingroup\$

;#+, 61 bytes

Outgolfed by Conor O'Brien

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

Try it online!

Note that the input has a trailing null byte.

answered May 23, 2017 at 8:05
\$\endgroup\$
2
  • 14
    \$\begingroup\$ Points for style. \$\endgroup\$ Commented May 23, 2017 at 8:19
  • 2
    \$\begingroup\$ I approve of this answer :D definitely the right language for the job \$\endgroup\$ Commented May 23, 2017 at 13:41
36
\$\begingroup\$

;#+, 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
answered May 23, 2017 at 13:58
\$\endgroup\$
6
  • 1
    \$\begingroup\$ All this from a joke language I made when I was bored. I'm flattered. \$\endgroup\$ Commented May 23, 2017 at 14:11
  • \$\begingroup\$ @RandomUser :D it's a fun concept to play around with \$\endgroup\$ Commented May 23, 2017 at 14:59
  • \$\begingroup\$ huh. What if I want the program to print out a null byte in ;#? \$\endgroup\$ Commented Aug 15, 2017 at 13:44
  • \$\begingroup\$ # @tuskiomi. Try it online! \$\endgroup\$ Commented Aug 15, 2017 at 18:06
  • \$\begingroup\$ @ConorO'Brien how would I input that into your program? \$\endgroup\$ Commented Aug 15, 2017 at 18:10
13
\$\begingroup\$

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

answered May 23, 2017 at 6:30
\$\endgroup\$
4
  • \$\begingroup\$ Could you do O";ẋ;€"# instead? \$\endgroup\$ Commented May 23, 2017 at 6:38
  • \$\begingroup\$ @Emigna Ah, yes, thanks. I don't quite get how that works but I kind of understand it. Thanks! \$\endgroup\$ Commented May 23, 2017 at 6:40
  • 4
    \$\begingroup\$ ;€ can become p. \$\endgroup\$ Commented May 23, 2017 at 7:10
  • \$\begingroup\$ @Dennis Oh now I understand how that works. Thanks! :) \$\endgroup\$ Commented May 23, 2017 at 12:11
13
\$\begingroup\$

brainfuck, (削除) 59 (削除ここまで) (削除) 54 (削除ここまで) 33 bytes

-21 bytes with KSab's bfbrute tool.

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

Try it online!

answered May 23, 2017 at 8:18
\$\endgroup\$
11
\$\begingroup\$

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 '#'.
answered May 23, 2017 at 7:16
\$\endgroup\$
8
  • 2
    \$\begingroup\$ しかく = what the heck? \$\endgroup\$ Commented May 23, 2017 at 8:47
  • 2
    \$\begingroup\$ 2 is the multiplication command? GS2 is weird :P \$\endgroup\$ Commented May 23, 2017 at 10:34
  • 1
    \$\begingroup\$ @EriktheOutgolfer executes the code for each of the input's character's code point o_O \$\endgroup\$ Commented May 23, 2017 at 12:15
  • \$\begingroup\$ @EriktheOutgolfer That sounds fancier than it is. しかく is just map, and GS2 implements strings as lists of integers. \$\endgroup\$ Commented May 23, 2017 at 15:43
  • \$\begingroup\$ @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... \$\endgroup\$ Commented May 23, 2017 at 15:48
10
\$\begingroup\$

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.
answered May 23, 2017 at 13:19
\$\endgroup\$
1
  • \$\begingroup\$ +1 I just love languages such as this and Mornington Crescent, the code is just so beautiful! \$\endgroup\$ Commented May 26, 2017 at 10:55
10
\$\begingroup\$

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
answered May 23, 2017 at 19:55
\$\endgroup\$
2
  • \$\begingroup\$ That's impressively small for Brainf*ck. \$\endgroup\$ Commented May 23, 2017 at 21:48
  • \$\begingroup\$ almost competes with the python answer. Impressive. \$\endgroup\$ Commented Jun 9, 2017 at 16:07
9
\$\begingroup\$

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
answered May 23, 2017 at 6:09
\$\endgroup\$
1
  • \$\begingroup\$ -1 without Ç by taking input as a list of codepoints. \$\endgroup\$ Commented Apr 21, 2021 at 19:44
8
\$\begingroup\$

Python 3, 39 bytes

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

Try it online!

answered May 23, 2017 at 6:10
\$\endgroup\$
3
  • 3
    \$\begingroup\$ for s in input():print(";"*ord(s)+"#") is one byte shorter. \$\endgroup\$ Commented May 23, 2017 at 7:01
  • 3
    \$\begingroup\$ @ovs that moment when you assume a list comprehension is shorter. \$\endgroup\$ Commented May 23, 2017 at 12:09
  • 2
    \$\begingroup\$ That doesn't accept a string with a newline does it? \$\endgroup\$ Commented May 24, 2017 at 12:34
5
\$\begingroup\$

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

answered May 23, 2017 at 7:06
\$\endgroup\$
5
\$\begingroup\$

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"
answered May 23, 2017 at 7:08
\$\endgroup\$
2
  • 4
    \$\begingroup\$ We need more F# answer \$\endgroup\$ Commented May 23, 2017 at 8:54
  • \$\begingroup\$ @aloisdg I'll do my best :) \$\endgroup\$ Commented May 23, 2017 at 14:56
5
\$\begingroup\$

Python 2 - 36 bytes

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

Try it online!

answered May 23, 2017 at 12:07
\$\endgroup\$
5
\$\begingroup\$

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.

answered May 24, 2017 at 7:20
\$\endgroup\$
7
  • \$\begingroup\$ It need to join result strings. \$\endgroup\$ Commented Sep 7, 2018 at 8:55
  • \$\begingroup\$ @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.« \$\endgroup\$ Commented Sep 7, 2018 at 10:39
  • \$\begingroup\$ as you wish :-) \$\endgroup\$ Commented Sep 7, 2018 at 11:10
  • \$\begingroup\$ quotation marks can be removed. $args is enough. \$\endgroup\$ Commented Sep 7, 2018 at 13:49
  • \$\begingroup\$ Unless the argument is numeric. \$\endgroup\$ Commented Sep 7, 2018 at 14:28
4
\$\begingroup\$

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
answered May 23, 2017 at 16:42
\$\endgroup\$
1
  • \$\begingroup\$ -2 Bytes Only -1 if you’re avoiding negative cells \$\endgroup\$ Commented Dec 19, 2017 at 5:29
4
\$\begingroup\$

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.

answered May 23, 2017 at 19:49
\$\endgroup\$
3
  • \$\begingroup\$ Why do you need the <>""? \$\endgroup\$ Commented Jun 19, 2017 at 16:01
  • \$\begingroup\$ @CalculatorFeline Without it I would be left with a list of strings for each character. StringJoining (<>) the empty string concatenates each string. \$\endgroup\$ Commented Jun 20, 2017 at 16:18
  • \$\begingroup\$ Forgot about that :P \$\endgroup\$ Commented Jun 20, 2017 at 16:32
4
\$\begingroup\$

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])+"#")
answered May 23, 2017 at 7:13
\$\endgroup\$
8
  • \$\begingroup\$ \n should becomes ;;;;;;;;;;#. \$\endgroup\$ Commented May 23, 2017 at 9:13
  • \$\begingroup\$ Hmm ... that's strange. Guess I'll have to roll back to the longer solution, so. Thank, @Neil. \$\endgroup\$ Commented May 23, 2017 at 9:17
  • 2
    \$\begingroup\$ I think you could change . to [^], which would still leave it a byte shorter than map/join? \$\endgroup\$ Commented May 23, 2017 at 9:18
  • \$\begingroup\$ Yup, that did the job, @Neil :) \$\endgroup\$ Commented May 23, 2017 at 9:23
  • \$\begingroup\$ 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. \$\endgroup\$ Commented May 23, 2017 at 21:55
3
\$\begingroup\$

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.

answered May 23, 2017 at 9:41
\$\endgroup\$
3
\$\begingroup\$

Perl, 24 bytes

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

Run with perl -pe.

Alternative solution:

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

Run with perl -nE.

answered May 23, 2017 at 9:56
\$\endgroup\$
3
\$\begingroup\$

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.
answered May 23, 2017 at 15:42
\$\endgroup\$
3
\$\begingroup\$

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
answered May 23, 2017 at 12:53
\$\endgroup\$
3
\$\begingroup\$

R, (削除) 59 (削除ここまで) 56 bytes

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

Try it online!

answered May 23, 2017 at 19:46
\$\endgroup\$
1
  • \$\begingroup\$ After 3 years, I've finally managed to find a shorter approach... \$\endgroup\$ Commented Sep 27, 2020 at 16:33
3
\$\begingroup\$

Befunge-98 (FBBI), (削除) 23 (削除ここまで) (削除) 17 (削除ここまで) 10 bytes

-5 bytes thanks to Jo King.

"#@~k:*k,;

Try it online!

answered May 23, 2017 at 7:06
\$\endgroup\$
1
  • 1
    \$\begingroup\$ @JoKing Thanks a lot. I was able to golf two bytes more off. This now on par with Pyth, Husk and CJam! \$\endgroup\$ Commented Sep 7, 2018 at 17:13
2
\$\begingroup\$

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
answered May 23, 2017 at 6:15
\$\endgroup\$
2
\$\begingroup\$

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

answered May 23, 2017 at 6:58
\$\endgroup\$
2
\$\begingroup\$

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.

answered May 23, 2017 at 7:56
\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$ Commented May 23, 2017 at 8:19
  • \$\begingroup\$ Your Ruby-fu exceeds mine, @manatwork - I'd forgotten about bytes. I've asked OP about newlines up top and will edit this afterwards. \$\endgroup\$ Commented May 23, 2017 at 8:24
2
\$\begingroup\$

PHP, 54 Bytes

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

Try it online!

answered May 23, 2017 at 8:58
\$\endgroup\$
2
\$\begingroup\$

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.
answered May 23, 2017 at 9:28
\$\endgroup\$
2
\$\begingroup\$

PHP, 48 bytes

for(;$c?:~$c=~ord($argn[$i++]);)echo";#"[!++$c];
answered May 23, 2017 at 9:49
\$\endgroup\$
2
\$\begingroup\$

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

answered May 23, 2017 at 14:21
\$\endgroup\$
2
\$\begingroup\$

Pyth, 10 bytes

sm_+\#*\;C

Try it!

answered May 23, 2017 at 21:46
\$\endgroup\$
1
2 3

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.