Interpreter for a 99 Bottles of Beer program

5

Write a program (in a first language A) that interprets a "99 Bottles of Beer" program and a FizzBuzz program (both in a second language B) on its standard input. The output should go to standard output; you may implement the interpreter as a function in languages lacking standardized I/O interfaces.

Constraints

The 99-Bottles program must come from either this site's problem or from http://99-bottles-of-beer.net/. Link to (do not copy and paste) the 99-Bottles program in your answer. The specific output is not important; what matters is whether the interpreter produces exactly the same output as a more complete one does.

You may write the FizzBuzz program yourself, or you may obtain it from the Internet or another source. Do not copy and paste the program into your answer in the latter case.

Both languages (and the 99-Bottles program) must have existed prior to September 22, 2011 (when this challenge was first posted). Specifically, you may not invent your own language for the specific purpose.

Any interpreter that hardcodes a non-whitespace character or string to be sent to the output (or that accesses the Internet) is cheating and not permissible. For example, an interpreter that contains "beer", "Buzz", or even "b" as a string or character literal is not acceptable, but looping from 1 to 99 is acceptable if a corresponding print statement is not hardcoded.

Both languages' names must not begin with the same letter and must not have any three character substring in common. For example:

  • APL and AWK begin with the same letter, and so do C, C++, and C#.
  • JavaScript and VBScript have SCR in common.

Additionally, the 99-Bottles and FizzBuzz programs must not be valid in language A or any other language that the interpreter depends on – the direct use of eval, exec, or similar language features or methods to compile and execute them is expressly forbidden.

Scoring

The score is the sum of:

  • Ten times the interpreter's character count
  • Ten times the FizzBuzz program's character count.
  • The 99-Bottles program's actual character count (because it should not be a golfed program). This excludes any leading and trailing whitespace but includes whitespace used for indentation. Each newline counts as one character.

For verification, include the code of everything you have written yourself, and link to any published sources you have used.

PleaseStand

Posted 2011-09-23T02:41:06.403

Reputation: 5 369

@JB Indeed. That requirement could ruin an approach involving scanning only the first character of each token to determine its identity. – AJMansfield – 2014-01-02T16:35:48.390

1Excluding 'b' in string literals could be tough on languages that have 'b' keywords (block, begin, double, enable...) – J B – 2011-09-23T06:08:30.997

@J B, I 'block' doesn't get sent to output; I think that's ok – boothby – 2011-09-23T06:37:01.367

2I don't get this... PleaseStand, were you drunk when you wrote the question? Otherwise, why is it named "drunken"? – boothby – 2011-09-23T06:37:51.537

@boothby: It was named the "drunken" interpreter because it is supposed to interpret a 99 Bottles of Beer program, a program for which I could find published versions for many languages. I don't drink beer or any other alcoholic beverage. – PleaseStand – 2011-09-23T10:58:46.357

@J B: keywords are no strings or character literals. – oenone – 2011-09-28T07:58:38.220

Answers

3

JavaScript interpreter for C (3834)

Interpreter (180 * 10 = 1800)

f() is the function to be called.

function prvarf(x){a=arguments;i=0;s+=(t=x.replace(/%./g,function(){return a[++i]}));return t}function f(x){Function(x.replace(/int/g,'var').replace(/#|ma/g,'f//'))(s='');return s}

99-Bottles (1074)

http://99-bottles-of-beer.net/language-c-844.html

FizzBuzz (96 * 10 = 960)

Adapted from one of the programs at http://perl.guru.org/scott/misc/golf.html:

main()
{int b=0;for(;++b<101;)printf(printf("%s%s",b%3?"":"Fizz",b%5?"":"Buzz")?"\n":"%d\n",b);}

PleaseStand

Posted 2011-09-23T02:41:06.403

Reputation: 5 369

Doesn't your C interpreter directly use eval? – Ry- – 2011-10-20T18:00:08.740

1

A fun one. I don't think it broke any of the rules you laid out, but it might be considered cheating.

VB.NET (2010, needs inline Action(Of t1, t2)), running on Windows, 362:

Imports System.Windows.Forms
Module A
Sub Main()
Dim b As New WebBrowser
IO.File.WriteAllText("C:\t.htm","<body></body><script>"&Console.In.ReadToEnd&"</script>")
b.Navigate("file:///C:/t.htm")
AddHandler b.DocumentCompleted,Sub(sender,e)
Console.Write(b.Document.GetElementsByTagName("body")(0).InnerHtml)
End Sub
Do
Application.DoEvents
Loop
End Sub
End Module

It interprets JavaScript. If you run this, you'll need to go into the Task Manager and stop the process because I just looped infinitely to save characters. You'll also need to make sure there's a reference to System.Windows.Forms in the project.

I haven't tested it yet, but I will as soon as I can.

99 Bottles of Beer, 2134 characters:

http://99-bottles-of-beer.net/language-javascript-1079.html

FizzBuzz, 117 113:

for(b=document.body,i=0;++i<=100;)b.appendChild(document.createTextNode(i%3?i%5?i:'Buzz':i%5?'Fizz':'FizzBuzz'));

For a total score of 3620 + 1130 + 2134 =

6,924 6,884

Oh well...

Ry-

Posted 2011-09-23T02:41:06.403

Reputation: 5 283