Challenge
Given a string as input, golf down the Fourier program which outputs that string.
In Fourier there is no easy way to output a string: you have to go through each character code and output that as a character.
Fourier
The language is based upon an accumulator, a global variable which is initialised to 0 at the start of the program. This is used by almost every operator in the language. Only some do not change the value of the accumulator.
Character out
a
Takes the value of the accumulator as the ASCII code and outputs the character. Does not change the value of the accumulator.
If the accumulator is greater than 255, the program will return an error. Likewise if the accumulator is less than 0.
Number out
o
Outputs the value of the accumulator. Does not change the value of the accumulator.
Increase
^
Increase the accumulator by one.
Decrease
v
Decrease the accumulator by one.
Add
+x
Sets the accumulator to the value of the accumulator plus the value of x.
Subtract
-x
Sets the accumulator to the value of the accumulator minus the value of x.
Multiply
*x
Sets the accumulator to the value of the accumulator multiplied by the value of x.
Divide
/x
Sets the accumulator to the value of the accumulator divided by the value of x. (Note that this is integer division, so 1/6
results in 0
)
Number
n
Set the accumulator to the integer n.
Note
Here, x
and n
can be any integer from 0
to 2^32-1
inclusive.
More information
You must only use the operators described above. Therefore your outputted Fourier program is invalid if it uses any of the following (note that the following operators are allowed for the bounty):
- Repeat loops
- If statements
- Variables
- Random
- Modulo
- User Input
- Greater/Less than operators
- Equality operators
- Clear screen
- Time delay
- Date functions
Your program can either be a full program or a function, taking in input via STDIN, a file or function arguments. You may also take input straight from the Internet.
Note that if there is a vv
in your code, you should replace it with -2
. The same goes for ^^
, replacing it with +2
.
Examples
If the input is 7n
, then the expected program is:
55a110a
But you can save one byte with
55a*2a
Another way is
7o110a
Using number out.
Similarly if the input is Hello
, then the expected program is:
72a101a108a108a111a
You can golf it down by 3 bytes (because outputting doesn't change the accumulator):
72a101a108aa111a
But wait, we can use the addition operator, saving 2 bytes:
72a101a+7aa+3a
Formatting
Because I'll be using Martin Büttner's Stack Snippet leaderboard, please could you format the title like so:
# <Language name>, <length of total output> bytes
Then, you can put anything you wish below the title.
Winning
You should post the length of Fourier programs (produced by your code) to output this text file and this text file. Your score is the combined length of both Fourier programs in bytes (non-ASCII characters aren't used in Fourier so it doesn't really make a difference).
The person with the lowest scores wins. If there is a tie, the shortest program in bytes wins.
Bounty
This 500 rep bounty is for a new answer which golfs the strings using any of Fourier's functions. That includes variables, loops and if statements etc. This new answer will not be accepted.
Leaderboard
Refer to formatting section above:
var QUESTION_ID=55384;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),e.has_more?getAnswers():process()}})}function shouldHaveHeading(e){var a=!1,r=e.body_markdown.split("\n");try{a|=/^#/.test(e.body_markdown),a|=["-","="].indexOf(r[1][0])>-1,a&=LANGUAGE_REG.test(e.body_markdown)}catch(n){}return a}function shouldHaveScore(e){var a=!1;try{a|=SIZE_REG.test(e.body_markdown.split("\n")[0])}catch(r){}return a}function getAuthorName(e){return e.owner.display_name}function process(){answers=answers.filter(shouldHaveScore).filter(shouldHaveHeading),answers.sort(function(e,a){var r=+(e.body_markdown.split("\n")[0].match(SIZE_REG)||[1/0])[0],n=+(a.body_markdown.split("\n")[0].match(SIZE_REG)||[1/0])[0];return r-n});var e={},a=1,r=null,n=1;answers.forEach(function(s){var t=s.body_markdown.split("\n")[0],o=jQuery("#answer-template").html(),l=(t.match(NUMBER_REG)[0],(t.match(SIZE_REG)||[0])[0]),c=t.match(LANGUAGE_REG)[1],i=getAuthorName(s);l!=r&&(n=a),r=l,++a,o=o.replace("{{PLACE}}",n+".").replace("{{NAME}}",i).replace("{{LANGUAGE}}",c).replace("{{SIZE}}",l).replace("{{LINK}}",s.share_link),o=jQuery(o),jQuery("#answers").append(o),e[c]=e[c]||{lang:c,user:i,size:l,link:s.share_link}});var s=[];for(var t in e)e.hasOwnProperty(t)&&s.push(e[t]);s.sort(function(e,a){return e.lang>a.lang?1:e.lang<a.lang?-1:0});for(var o=0;o<s.length;++o){var l=jQuery("#language-template").html(),t=s[o];l=l.replace("{{LANGUAGE}}",t.lang).replace("{{NAME}}",t.user).replace("{{SIZE}}",t.size).replace("{{LINK}}",t.link),l=jQuery(l),jQuery("#languages").append(l)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",answers=[],page=1;getAnswers();var SIZE_REG=/\d+(?=[^\d&]*(?:<(?:s>[^&]*<\/s>|[^&]+>)[^\d&]*)*$)/,NUMBER_REG=/\d+/,LANGUAGE_REG=/^#*\s*([^,]+)/;
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> <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>