Created
December 21, 2022 11:52
-
-
Save wtsnjp/382c48cac433160476f3311cb4b9eeff to your computer and use it in GitHub Desktop.
NabeAzz in WEB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% nabeazz.web | |
\centerline{\bf A NabeAzz Program} | |
\centerline{\sl by wtsnjp} | |
\vskip .5cm | |
This is my first program to write with the \.{WEB} system. This program is a | |
solution of the NabeAzz problem, which is a well-known problem in Japanese | |
{\TeX} community as the counterpart to the FizzBuzz problem | |
(see \.{https://zrbabbler.hatenablog.com/entry/20110815/1313398638}). | |
@ First of all, decide how many numbers to print. | |
@d boundary=400 { This will be the maximum number to be printed } | |
@ This is the top level definition. | |
@p | |
program NabeAzz(output); | |
@<some routines@> | |
var | |
n: integer; | |
begin | |
writeln( @<prologue@> ); | |
@<the main loop@> | |
writeln( @<epilogue@> ); | |
end. | |
@ Here are the very simple prologue: we just setup the {\it aho} (silly) font. | |
@<prologue@>= | |
'\font\cmfi=cmfi10 at 12pt \noindent' | |
@ The number in {\it aho} form should be output with the font defined above. | |
@<procedure to write number in aho form@>= | |
procedure WriteAhoNumber(n: integer); | |
begin | |
write('{\cmfi '); | |
write(n); | |
writeln('}') | |
end; | |
@ The epilogue is also quite simple. | |
@<epilogue@>= | |
'\bye' | |
@ The main part of the program. Loop the number from one to the boundary. | |
Each number should be printed in either normal or {\it aho} form. | |
@<the main loop@>= | |
for n := 1 to boundary do AhoOrNot(n); | |
@ Now, let us think about the actual logic for the NabeAzz program. | |
@<some routines@>= | |
@<procedure to write number in aho form@> | |
@<function to judge if a multiple of three@> | |
@<function to judge if a number that has a digit of three@> | |
procedure AhoOrNot(n: integer); | |
begin | |
if MultipleOfThree(n) then | |
WriteAhoNumber(n) | |
else if HasDigitOfThree(n) then | |
WriteAhoNumber(n) | |
else writeln(n) | |
end; | |
@ The first condition to be {\it aho} is being a multiple of three. | |
This can be easily judged by using the mod operator. | |
@<function to judge if a multiple of three@>= | |
function MultipleOfThree(n: integer) : boolean; | |
begin | |
if n mod 3 <> 0 then | |
MultipleOfThree := false | |
else | |
MultipleOfThree := true | |
end; | |
@ The second condition to be {\it aho} is having the digit three. | |
This also can be easily judged by using some basic string operations. | |
@<function to judge if a number that has a digit of three@>= | |
function HasDigitOfThree(n: integer) : boolean; | |
var | |
s: string; | |
begin | |
str(n, s); | |
if pos('3', s) <> 0 then | |
HasDigitOfThree := true | |
else | |
HasDigitOfThree := false | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Makefile
Usage
The WEB system (
tangle
andweave
) and a Pascal compiler (such asfpc
) are required.To produce the NabeAzz output to
output.pdf
:To produce the documentation in
nabeazz.pdf
: