Jump to content

FizzBuzz: Difference between revisions

1,981 bytes added ,  1 year ago
Line 3,704:
 
=={{header|Enguage}}==
<syntaxhighlight lang="Enguage">FizzBuzz"</syntaxhighlight>
 
This source code is supposed to look like plain old English but is, in fact, executable. When used in an Android app, it gives the user direct access to computational abilities of your phone.
 
It is taken from [https://bitbucket.org/martinwheatman/enguage/src/develop/etc/dict/f/fizzbuzz.entry the dictionary entry for fizzbuzz]
 
This shows the interpretation of two utterances, the latter of which are called recursively. Enguage is not very efficient, but that's not its goal!
 
NB. Any line beginning with a '#' is a comment, like Unix shells, but any comment following the ']' character are unit tests exercising this code.
 
<pre>
On "what is the fizzbuzz of N":
is N divisible by 5 and 3;
if so, reply "fizzbuzz";
is N divisible by 5;
if so, reply "buzz";
is N divisible by 3;
if so, reply "fizz";
reply "N".
On "do fizzbuzz between N and LIMIT":
what is the fizzbuzz of N;
remember this;
set next to the evaluation of N + 1;
NEXT is equal to LIMIT;
if so, what is the fizzbuzz of LIMIT;
if not, do fizzbuzz between NEXT and LIMIT.
#] what is the fizzbuzz of 1: 1.
#] what is the fizzbuzz of 12: fizz.
#] what is the fizzbuzz of 25: buzz.
#] what is the fizzbuzz of 75: fizzbuzz.
 
#] set limit to 5.
#] do fizzbuzz between 1 and LIMIT.
</pre>
 
On downloading this repo, if git and make are installed, this unit test can be run with:
<pre>
$ git clone https://github.com/martinwheatman/enguage.git
$ cd enguage
$ make jar
$ export PATH=$PATH:./sbin
$ java -jar lib/enguage.jar -T fizzbuzz
</pre>
 
Output:
<pre>
TEST: fizzbuzz
==============
 
user> what is the fizzbuzz of 1.
enguage> 1.
 
user> what is the fizzbuzz of 12.
enguage> fizz.
 
user> what is the fizzbuzz of 25.
enguage> buzz.
 
user> what is the fizzbuzz of 75.
enguage> fizzbuzz.
 
user> set limit to 5.
enguage> ok , limit is set to 5.
 
user> do fizzbuzz between 1 and LIMIT.
enguage> 1 . 2 . fizz . 4 . buzz.
1 test group(s) found
+++ PASSED 6 tests in 442ms +++
</pre>
 
=={{header|Erlang}}==
49

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.