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>

\$\endgroup\$
19
  • 11
    \$\begingroup\$ Brilliant! Glad to see ;# is getting attention! \$\endgroup\$ May 23, 2017 at 6:41
  • 1
    \$\begingroup\$ You can test your output here, as ;#+ is a superset of ;#. \$\endgroup\$
    – Adám
    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\$
    – Dennis
    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\$
    – Joey
    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\$
    – user45941
    May 24, 2017 at 20:24

87 Answers 87

2
\$\begingroup\$

Röda, 24 bytes

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

Try it online!

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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
\$\endgroup\$
2
\$\begingroup\$

Brain-Flak, 94 bytes

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

Try it online!

\$\endgroup\$
2
\$\begingroup\$

R, 48 bytes

cat(strrep(';',utf8ToInt(scan(,''))),'',sep='#')

Try it online!

Outputs 'pure' ;# code with no other characters.


R, 43 bytes

paste(strrep(';',utf8ToInt(scan(,''))),'#')

Try it online!

Outputs 'dirty' ;# code with various other characters ([,],0-9, ,") that are all ignored.

\$\endgroup\$
2
\$\begingroup\$

Rockstar, 216 201 191 175 bytes

This started out a lot shorter until I remembered that we had to handle line breaks in the input - each line in Rockstar is a separate input - and then discovered, in what I can only assume to be a bug, that the space character passes equality tests with the empty string \t, \n & 0.

listen to S
O's""
while S
X's0
while S at X
Y's31
C's-1
until C is S at X
build Y up
cast Y into C

let O be+";"*Y+"#"
build X up

listen to S
if S
let O be+";"*10+"#"


say O

Try it here (Code will need to be pasted in)

This 151 byte version includes a newline after each #, which, although being valid in ;# as they're simply ignored, would fail when passed back to my Rockstar interpreter.

listen to S
while S
X's0
while S at X
Y's31
C's-1
until C is S at X
build Y up
cast Y into C

say ";"*Y+"#"
build X up

listen to S
if S
say ";"*10+"#"
\$\endgroup\$
2
\$\begingroup\$

A0A0, 103 057 102 945 bytes

https://gist.github.com/stefvanschie/a32e23f45553fc19b79b9cb7159c7e04

(I think putting that many characters into a codebox here is a bit too much.)

Yes, I'm serious. A0A0 has loops, but this solution would require nested loops (a loop for reading a character and within that a loop for printing the right amount of semicolons). I'm not even certain if nested loops are possible at all. I have a solution that can display the correct code for a single character, since that doesn't require any nested loops in only 143 bytes. If anyone knows how to do this, please let me know. The code for a single character is also on the gist.

The reason this is still possible is by using a dirty work-around: write code for every single character, then jump to that spot for the right character. Since there are only a finite amount of printable ASCII characters and you can't go above character 126 because of the modulo 127, this is possible. This is where the byte count comes from. I generated almost 600 lines of code that does exactly that.

The important part is at the top

A0A0
A0C3G1G1G1G1A0
A0I1D8M5V0G0A0
A0A1G-3G-3G-3G-3A0
G-3

Most of this serves as an infinite loop, but the code in between A0 on the third line is actual important code.

I1D8M5V0G0
I1         ; reads a character and stores it on the next operand as its ascii value
  D8       ; subtracts 8 from the operand
    M5     ; multiply the operand by 5
      V0   ; the operand, value is put on the next instruction
        G0 ; set by the operand, jumps this amount of lines down

On every correct line you can find a loop with the right amount of prints for each semicolon P59 and hash tag P35, as well as another jump to jump back to this input loop.

Rev: Improved positioning of the character prints

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

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
\$\endgroup\$
1
\$\begingroup\$

PowerShell, 36 Bytes

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

just prints ;s and then a #

\$\endgroup\$
1
  • \$\begingroup\$ You can compact it: -join($args|% t*y|%{';'*$_+'#'}) 32 bytes )) \$\endgroup\$
    – mazzy
    Sep 7, 2018 at 8:57
1
\$\begingroup\$

Wolfram Mathematica, 69 bytes

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

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

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

shortC, 27 bytes

c;AO;~(c=G);J"#"))Wc--)J";"
\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
6
  • \$\begingroup\$ How do you run this? I'm trying to execute this and it doesn't terminate. Is it not supposed to? \$\endgroup\$ May 23, 2017 at 21:41
  • \$\begingroup\$ @PatrickRoberts It's waiting for input. See the getchar()? \$\endgroup\$
    – MD XF
    May 23, 2017 at 21:42
  • \$\begingroup\$ Yes, but after I provide input, it prints, and still doesn't terminate. That's what I mean. \$\endgroup\$ May 23, 2017 at 21:43
  • \$\begingroup\$ @PatrickRoberts It terminates upon EOF. \$\endgroup\$
    – MD XF
    May 23, 2017 at 21:45
  • 1
    \$\begingroup\$ @PatrickRoberts You can type it during execution, just hit Ctrl+D at the end (assuming you're on Linux). \$\endgroup\$
    – MD XF
    May 23, 2017 at 21:46
1
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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 \$\endgroup\$
    – MickyT
    May 31, 2017 at 22:56
  • \$\begingroup\$ I must admit, I'm impressed! I'll have to take these ideas into consideration for future cubix submissions. \$\endgroup\$
    – Giuseppe
    Jun 6, 2017 at 19:14
1
\$\begingroup\$

Braingolf, 11 bytes

&([#;]##)&@

Try it online!

Ooh, moderately golfy

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

Ly, 18 bytes

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

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Unfortunately your language seems to be newer than the challenge post. You should mark it as "non competing". Great answer though! \$\endgroup\$
    – kalsowerus
    Aug 11, 2017 at 9:19
  • 2
    \$\begingroup\$ @kalsowerus I believe we have a consensus against this. \$\endgroup\$
    – LyricLy
    Aug 11, 2017 at 9:28
  • \$\begingroup\$ @LirycLy Oh, I must have missed that. Thanks for the update. \$\endgroup\$
    – kalsowerus
    Aug 11, 2017 at 9:39
1
\$\begingroup\$

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.

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

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
\$\endgroup\$
0
1
\$\begingroup\$

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

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

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
\$\endgroup\$
1
\$\begingroup\$

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 "#"
\$\endgroup\$
1
\$\begingroup\$

Add++, 18 bytes

L^,€O59C€*"#"€Ω+BF

Try it online!

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

Stax, 7 6 bytes

ç`5≡Tf

Run and debug it

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

Vyxal Ks, 8 7 6 bytes

-1 -2 thanks to Aaron Miller

\;*\#+

Try it Online!

\;*\#+    # Full program
          # Vectorized: Replace each...
          # (K flag) ordinal character in (implicit) input...
\;        # with the character `;`...
  *       # repeated that many times, and...
   \#+    # add the character `#`
          # (s flag) Concatenate results and output
\$\endgroup\$
2
1
\$\begingroup\$

Excel, 56 bytes

=CONCAT(REPT(";",CODE(MID(A1,SEQUENCE(LEN(A1)),1)))&"#")

Could be 8 bytes shorter to output an array of cells ending with #.

VBA (immediate window), 73 bytes

d="":for i=1to len([a1]):d=d &string(asc(mid([a1],i,1)),";") &"#":next:?d
\$\endgroup\$
1
  • \$\begingroup\$ You can get the VBA version down to 70 bytes as d="":for i=1to[len(a1)]:d=d+string(asc(mid([a1],i,1)),";")+"#":next:?d \$\endgroup\$ Sep 3, 2021 at 14:23
0
\$\begingroup\$

C (72 bytes)

main(c){while((c=getchar())!=-1){while(c--)putchar(';');putchar('#');}}
\$\endgroup\$
2
  • 3
    \$\begingroup\$ You 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). \$\endgroup\$
    – user62131
    May 23, 2017 at 8:03
  • \$\begingroup\$ Why community wiki? \$\endgroup\$
    – MD XF
    May 23, 2017 at 21:47
0
\$\begingroup\$

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!
\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

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
    }
}
\$\endgroup\$
0
\$\begingroup\$

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.

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

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!"));
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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