6
2
Introduction
From Esolangs.org :
Pi is based on the brainfuck language and uses the same instructions as it. Pi works by calculating pi digits and introducing errors in some random digits of them, encoding obfuscated brainfuck instructions. Instructions are encoded as below:
'>' '<' '+' '-' '.' ',' '[' ']' 0 1 2 3 4 5 6 7 8
But, as we need to identify which pi digits are incorrect, we move each instruction in the table one position to the right starting at the position that is initially over the correct pi digit that is where we are inserting the instruction. For example, if the pi digit in the position we are inserting the instruction is 4, the table would be moved as follows:
'>' '<' '+' '-' '.' ',' '[' ']' 0 1 2 3 4 5 6 7 8 9
Then the instruction would be converted to a digit that would be inserted replacing the correct digit.
Brainfuck explanation
Brainfuck is not very difficult.
Imagine an infinite byte array, initialized to zero, and a pointer on a value of this array.
>
increments the pointer<
decrements the pointer+
increments the pointed value-
decrements the pointed value.
prints the pointed value,
sets the pointed value (value is taken from stdin)[
defines the beginning of a loop, this loop is entered if current value is not zero]
is the end of the loop
Objective
In any language, write an interpreter for the esoteric Pi language.
- Correct pi digits must be taken from
http://pastebin.com/raw.php?i=gUbdbzLr
, no URL shortener allowed. (JavaScript is allowed to run from pastebin.com domain but the full URL must appear in the code) - Only
[]<>+-.
equivalent have to be handled, you can ignore inputs (,
equivalent) - The input string length will be below 100,000
- You can write a full program and take the input string from stdin, or write a function and take the input string from argument.
- You don't have to support inifinite array (100 bytes is fine), but you have to support negative pointers.
- In case of overflow, wrap the value :
-1 => 255
and256 => 0
.
Examples
3.14159265358979323842264332327250288412716939927513582397492459230721640628220899867803480534311206298214838653322233664709084463955358323172235940832848311725028410370193853110525964460294895293032196422880097562591344612147514823378178346528120090214562856642346134861345532264821332360736034914137372428700663631558417448152392396222925459170536432789259026051133013014882046252138214295194153160243205227036275959395309212613732192261379310211855807440237946274952735182575273489122743848301134912983467436444065634308652133494633522473749030217386093370277033921317659317670238267581846066440
This input value must return Hello World!
3.14152322358878323222264326032220288236031386837182584807480228230223643448624338864343482343244432222334808651322320664708322260855054333172535843232848113435028410274433852444334335
Taken from here and converted to Pi, outputs 6*7=42
(don't forget to upvote this awesome answer)
3.1415826535887832384626433832785028846644334334334433443333333344433433434334433333434470302114801731130077382277380418061543333433343344443434333434433344433344334443443702032238007311300810737227041222326030211380073113008107373170312223223233332323222222222322232222332222324738807122323233223233222322223322322322223222232332332443434334343434352222232232233332232232222332222332225222232232332322223223232222222232223233223344343443443344434433334333344333343333334343333343433344433434344443334433443344432232222223223332222222223322223232333222232222332232223323223223222232222222322222243434444443335434534343343433333344343333333434343434333443333343444433343444333333334353232233222223222322233322223333323332232223222323222322322222232322232322323335333333334453423522233222232232344334433335722222764333434443343444434344333334434343444334348644444433433343333333444434343443434333334334443704811648806122222233222232222232222222222232222232222232233444433433444443442222333222323322333222223223223333225222223222222223222232322223232332233222332253333333343443333443344333443334343334443433333334343334343333343433444433343433422223223222232222222222222323223232332322332233223322222323332222232322222322233322354343343333335333533333433333334334333333433334434333433334434333334334333344344443334442223233322233233222223323223223233222333222232233222222233222222223222323223234434333443443432422232223322232353344433434654434444334732222222324737038217381103711688856808272107
This one is taken from my answer here and can be used to test input if you decide to handle it.
Winning criteria
This is a code-golf, lowest score wins !
Score computation :
- 1 byte = 1 point
- +100 points if you choose to take the pi digits from a local file.
- -50 points if you handle inputs (
,
) too (single ASCII character per input; if your language does not support STDIN, prompt for input once and then read a character at a time from that input). - -100 points if you compute the pi digits yourself.
Small note : I have wrote an interpreter and checked the example, it is correct and is equivalent to
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
BF code. – Michael M. – 2014-05-28T20:40:22.130"-200 points if you compute the pi digits yourself." That may be a bit extreme; isn't the tag [tag:code-golf] sufficient? – primo – 2014-05-29T07:07:48.077
@primo, what's extreme ? The value of the bonus or the difficulty to compute pi digits ? – Michael M. – 2014-05-29T07:12:21.433
The value of the bonus. For example, Perl:
use bigint;$\=$\/~(2*$_)*~$_+2e999for-3319..-2;print
- 52 bytes. Similarly short representations exist for many other languages. – primo – 2014-05-29T07:48:02.150@primo, well, the bonus is now -100. – Michael M. – 2014-05-29T07:51:51.170
@m.buettner, you can but I don't think you will have enough precision. – Michael M. – 2014-05-29T07:52:12.780
@m.buettner, I suppose there is a computation behind, then the bonus can be applied. – Michael M. – 2014-05-29T07:54:46.707
a single character, you have to encode (ASCII). – Michael M. – 2014-05-29T13:49:14.857
@m.buettner, prompt the string once and read it sequentially after. – Michael M. – 2014-05-29T14:37:12.557
@Michael okay, dropped it from my answer. I can't do that in 50 characters. (I don't think the other Mathematica answer does it either, though.) – Martin Ender – 2014-05-29T14:45:22.183