Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Transpile ;# into your language

Related to: Make a ;# interpreter and Generate ;# code

;# - A Whirlwind Guide

This is a simple language with two commands. Its only data structure is an accumulator, which is initialized to 0.

  1. ; Increment the accumulator

  2. # Calculate the value of the accumulator modulo 127, and print the corresponding ASCII character. Then, reset the accumulator to 0.

The source code may contain additional characters (printable ASCII + whitespace), but these are treated as comments and have no effect on program execution.

Challenge

Since most computers do not come with ;# preinstalled, it would be very useful to have a tool that can convert ;# code into a different language. In this challenge, you shall write a program to accomplish this.

Input

Some ;# source code, taken via argument or STDIN. This source code may contain (comment) characters other than ; or #.

Output

Code, in the same language as your submission, which, when executed, prints/returns the same string as the original ;# code. This resultant code may output a trailing newline after the target string, if that is more convenient for your language.

Notes

One thing to look out for is escape sequences, such as code that prints backslashes or prints quote marks. Also look out for ;# code that could contain things that look like keywords or commands in your language.

Additional restrictions

All programs must terminate (I normally consider this a default, but someone asked about it so I'm stating it here).

Examples

input: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#
output (python): print(";#")
input: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#
output (element): \'`

Answer*

Draft saved
Draft discarded
Cancel
6
  • \$\begingroup\$ Unfortunately this not plays nice with the "This source code may contain (comment) characters other than ; or #." part of requirement. \$\endgroup\$ Commented May 25, 2017 at 9:38
  • \$\begingroup\$ @manatwork Fixed, will make golfier later. \$\endgroup\$ Commented May 25, 2017 at 14:32
  • \$\begingroup\$ Was enough to change the regular expression /;+#//.*?#/ and the code block s.length-1s.count(?;). BTW, your math is also wrong, as % has higher priority than -, so should be (s.length-1)%127. And in .gsub's code block you can access the captured groups with $&, 1ドル, ... so the |s| code block parameter usually is not feasible. And the string interpolation stringifies: {"$><<#{$&.count(?;)%127}.chr;"}. Try it online! \$\endgroup\$ Commented May 25, 2017 at 14:48
  • \$\begingroup\$ @manatwork thank you so much! I think your comment has doubled my ruby knowledge. \$\endgroup\$ Commented May 25, 2017 at 16:16
  • \$\begingroup\$ It's late, but the code challenge itself was bumped recently by a modified answer so whatever. gsub modifies $_ directly, which means that you don't need to re-assign it. HOWEVER, you have issues if you have comment characters after your last #... see here \$\endgroup\$ Commented Aug 15, 2017 at 21:10

AltStyle によって変換されたページ (->オリジナル) /