Removed spaces from top-level directory names.

Spaces tend to cause annoyances in a Unix-style shell environment.
This change fixes that.
This commit is contained in:
Chris Reuter
2021-11-21 18:30:21 -05:00
parent df2e7426eb
commit d26dbf036a
1725 changed files with 0 additions and 0 deletions

7
64_Nicomachus/README.md Normal file
View File

@@ -0,0 +1,7 @@
### Nicomachus
As published in Basic Computer Games (1978)
https://www.atariarchives.org/basicgames/showpage.php?page=117
Downloaded from Vintage Basic at
http://www.vintage-basic.net/games.html

View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Microsoft C#](https://docs.microsoft.com/en-us/dotnet/csharp/)

View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Oracle Java](https://openjdk.java.net/)

View File

@@ -0,0 +1,185 @@
import java.util.Arrays;
import java.util.Scanner;
/**
* Game of Nichomachus
* <p>
* Based on the Basic game of Nichomachus here
* https://github.com/coding-horror/basic-computer-games/blob/main/64%20Nicomachus/nicomachus.bas
* <p>
* Note: The idea was to create a version of the 1970's Basic game in Java, without introducing
* new features - no additional text, error checking, etc has been added.
*/
public class Nicomachus {
public static final long TWO_SECONDS = 2000;
// Used for keyboard input
private final Scanner kbScanner;
private enum GAME_STATE {
START_GAME,
GET_INPUTS,
RESULTS,
PLAY_AGAIN
}
int remainderNumberDividedBy3;
int remainderNumberDividedBy5;
int remainderNumberDividedBy7;
// Current game state
private GAME_STATE gameState;
public Nicomachus() {
kbScanner = new Scanner(System.in);
gameState = GAME_STATE.START_GAME;
}
/**
* Main game loop
*/
public void play() throws Exception {
do {
switch (gameState) {
case START_GAME:
intro();
gameState = GAME_STATE.GET_INPUTS;
break;
case GET_INPUTS:
System.out.println("PLEASE THINK OF A NUMBER BETWEEN 1 AND 100.");
remainderNumberDividedBy3 = displayTextAndGetNumber("YOUR NUMBER DIVIDED BY 3 HAS A REMAINDER OF? ");
remainderNumberDividedBy5 = displayTextAndGetNumber("YOUR NUMBER DIVIDED BY 5 HAS A REMAINDER OF? ");
remainderNumberDividedBy7 = displayTextAndGetNumber("YOUR NUMBER DIVIDED BY 7 HAS A REMAINDER OF? ");
gameState = GAME_STATE.RESULTS;
case RESULTS:
System.out.println("LET ME THINK A MOMENT...");
// Simulate the basic programs for/next loop to delay things.
// Here we are sleeping for one second.
Thread.sleep(TWO_SECONDS);
// Calculate the number the player was thinking of.
int answer = (70 * remainderNumberDividedBy3) + (21 * remainderNumberDividedBy5)
+ (15 * remainderNumberDividedBy7);
// Something similar was in the original basic program
// (to test if the answer was 105 and deducting 105 until it was <= 105
while (answer > 105) {
answer -= 105;
}
do {
String input = displayTextAndGetInput("YOUR NUMBER WAS " + answer + ", RIGHT? ");
if (yesEntered(input)) {
System.out.println("HOW ABOUT THAT!!");
break;
} else if (noEntered(input)) {
System.out.println("I FEEL YOUR ARITHMETIC IS IN ERROR.");
break;
} else {
System.out.println("EH? I DON'T UNDERSTAND '" + input + "' TRY 'YES' OR 'NO'.");
}
} while (true);
gameState = GAME_STATE.PLAY_AGAIN;
break;
case PLAY_AGAIN:
System.out.println("LET'S TRY ANOTHER");
gameState = GAME_STATE.GET_INPUTS;
break;
}
// Original basic program looped until CTRL-C
} while (true);
}
private void intro() {
System.out.println(addSpaces(33) + "NICOMA");
System.out.println(addSpaces(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
System.out.println();
System.out.println("BOOMERANG PUZZLE FROM ARITHMETICA OF NICOMACHUS -- A.D. 90!");
System.out.println();
}
/*
* Print a message on the screen, then accept input from Keyboard.
* Converts input to an Integer
*
* @param text message to be displayed on screen.
* @return what was typed by the player.
*/
private int displayTextAndGetNumber(String text) {
return Integer.parseInt(displayTextAndGetInput(text));
}
/*
* Print a message on the screen, then accept input from Keyboard.
*
* @param text message to be displayed on screen.
* @return what was typed by the player.
*/
private String displayTextAndGetInput(String text) {
System.out.print(text);
return kbScanner.nextLine();
}
/**
* Return a string of x spaces
*
* @param spaces number of spaces required
* @return String with number of spaces
*/
private String addSpaces(int spaces) {
char[] spacesTemp = new char[spaces];
Arrays.fill(spacesTemp, ' ');
return new String(spacesTemp);
}
/**
* Checks whether player entered Y or YES to a question.
*
* @param text player string from kb
* @return true of Y or YES was entered, otherwise false
*/
private boolean yesEntered(String text) {
return stringIsAnyValue(text, "Y", "YES");
}
/**
* Checks whether player entered N or NO to a question.
*
* @param text player string from kb
* @return true of N or NO was entered, otherwise false
*/
private boolean noEntered(String text) {
return stringIsAnyValue(text, "N", "NO");
}
/**
* Check whether a string equals one of a variable number of values
* Useful to check for Y or YES for example
* Comparison is case insensitive.
*
* @param text source string
* @param values a range of values to compare against the source string
* @return true if a comparison was found in one of the variable number of strings passed
*/
private boolean stringIsAnyValue(String text, String... values) {
return Arrays.stream(values).anyMatch(str -> str.equalsIgnoreCase(text));
}
public static void main(String[] args) throws Exception {
Nicomachus nicomachus = new Nicomachus();
nicomachus.play();
}
}

View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Shells)

View File

@@ -0,0 +1,9 @@
<html>
<head>
<title>NICOMACHUS</title>
</head>
<body>
<pre id="output" style="font-size: 12pt;"></pre>
<script src="nicomachus.js"></script>
</body>
</html>

View File

@@ -0,0 +1,91 @@
// NICOMACHUS
//
// Converted from BASIC to Javascript by Oscar Toledo G. (nanochess)
//
function print(str)
{
document.getElementById("output").appendChild(document.createTextNode(str));
}
function input()
{
var input_element;
var input_str;
return new Promise(function (resolve) {
input_element = document.createElement("INPUT");
print("? ");
input_element.setAttribute("type", "text");
input_element.setAttribute("length", "50");
document.getElementById("output").appendChild(input_element);
input_element.focus();
input_str = undefined;
input_element.addEventListener("keydown", function (event) {
if (event.keyCode == 13) {
input_str = input_element.value;
document.getElementById("output").removeChild(input_element);
print(input_str);
print("\n");
resolve(input_str);
}
});
});
}
function tab(space)
{
var str = "";
while (space-- > 0)
str += " ";
return str;
}
var str;
var b;
// Main program
async function main()
{
print(tab(33) + "NICOMA\n");
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
print("\n");
print("\n");
print("\n");
print("BOOMERANG PUZZLE FROM ARITHMETICA OF NICOMACHUS -- A.D. 90!\n");
while (1) {
print("\n");
print("PLEASE THINK OF A NUMBER BETWEEN 1 AND 100.\n");
print("YOUR NUMBER DIVIDED BY 3 HAS A REMAINDER OF");
a = parseInt(await input());
print("YOUR NUMBER DIVIDED BY 5 HAS A REMAINDER OF");
b = parseInt(await input());
print("YOUR NUMBER DIVIDED BY 7 HAS A REMAINDER OF");
c = parseInt(await input());
print("\n");
print("LET ME THINK A MOMENT...\n");
print("\n");
d = 70 * a + 21 * b + 15 * c;
while (d > 105)
d -= 105;
print("YOUR NUMBER WAS " + d + ", RIGHT");
while (1) {
str = await input();
print("\n");
if (str == "YES") {
print("HOW ABOUT THAT!!\n");
break;
} else if (str == "NO") {
print("I FEEL YOUR ARITHMETIC IS IN ERROR.\n");
break;
} else {
print("EH? I DON'T UNDERSTAND '" + str + "' TRY 'YES' OR 'NO'.\n");
}
}
print("\n");
print("LET'S TRY ANOTHER.\n");
}
}
main();

View File

@@ -0,0 +1,34 @@
2 PRINT TAB(33);"NICOMA"
4 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
6 PRINT: PRINT: PRINT
10 PRINT "BOOMERANG PUZZLE FROM ARITHMETICA OF NICOMACHUS -- A.D. 90!"
20 PRINT
30 PRINT "PLEASE THINK OF A NUMBER BETWEEN 1 AND 100."
40 PRINT "YOUR NUMBER DIVIDED BY 3 HAS A REMAINDER OF";
45 INPUT A
50 PRINT "YOUR NUMBER DIVIDED BY 5 HAS A REMAINDER OF";
55 INPUT B
60 PRINT "YOUR NUMBER DIVIDED BY 7 HAS A REMAINDER OF";
65 INPUT C
70 PRINT
80 PRINT "LET ME THINK A MOMENT..."
85 PRINT
90 FOR I=1 TO 1500: NEXT I
100 D=70*A+21*B+15*C
110 IF D<=105 THEN 140
120 D=D-105
130 GOTO 110
140 PRINT "YOUR NUMBER WAS";D;", RIGHT";
160 INPUT A$
165 PRINT
170 IF A$="YES" THEN 220
180 IF A$="NO" THEN 240
190 PRINT "EH? I DON'T UNDERSTAND '";A$;"' TRY 'YES' OR 'NO'."
200 GOTO 160
220 PRINT "HOW ABOUT THAT!!"
230 GOTO 250
240 PRINT "I FEEL YOUR ARITHMETIC IS IN ERROR."
250 PRINT
260 PRINT "LET'S TRY ANOTHER."
270 GOTO 20
999 END

View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Pascal](https://en.wikipedia.org/wiki/Pascal_(programming_language))

View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Perl](https://www.perl.org/)

View File

@@ -0,0 +1,46 @@
#!/usr/bin/perl
use strict;
print ' 'x 33 . "NICOMA\n";
print ' 'x 15 . "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n";
print "\n\n\n";
print "BOOMERANG PUZZLE FROM ARITHMETICA OF NICOMACHUS -- A.D. 90!\n";
while (1) {
print "\n";
print "PLEASE THINK OF A NUMBER BETWEEN 1 AND 100.\n";
print "YOUR NUMBER DIVIDED BY 3 HAS A REMAINDER OF";
print "? "; chomp(my $A = <STDIN>);
print "YOUR NUMBER DIVIDED BY 5 HAS A REMAINDER OF";
print "? "; chomp(my $B = <STDIN>);
print "YOUR NUMBER DIVIDED BY 7 HAS A REMAINDER OF";
print "? "; chomp(my $C = <STDIN>);
print "\n";
print "LET ME THINK A MOMENT...\n";
print "\n";
for (my $I=1; $I<=1500; $I++) { }
my $D= 70*$A+21*$B+15*$C;
while ($D>105) {
$D= $D-105;
}
print "YOUR NUMBER WAS $D, RIGHT";
my $Flag=0;
do {
print "? "; chomp($A = uc(<STDIN>));
print "\n";
if ($A eq "YES") { print "HOW ABOUT THAT!!\n"; $Flag=1; }
if ($A eq "NO") { print "I FEEL YOUR ARITHMETIC IS IN ERROR.\n"; $Flag=1; }
if ($Flag==0) { print "EH? I DON'T UNDERSTAND '$A' TRY 'YES' OR 'NO'.\n"; }
} until ($Flag==1);
print "\n";
print "LET'S TRY ANOTHER.\n";
} #goto Line20;
exit;

View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Python](https://www.python.org/about/)

View File

@@ -0,0 +1,78 @@
"""
NICOMACHUS
Math exercise/demonstration
Ported by Dave LeCompte
"""
"""
PORTING NOTE
The title, as printed ingame, is "NICOMA", hinting at a time when
filesystems weren't even 8.3, but could only support 6 character
filenames.
"""
import time
def print_with_tab(spaces_count, msg):
if spaces_count > 0:
spaces = " " * spaces_count
else:
spaces = ""
print(spaces + msg)
def get_yes_or_no():
while True:
response = input().upper()
if response == "YES":
return True
elif response == "NO":
return False
print(f"EH? I DON'T UNDERSTAND '{response}' TRY 'YES' OR 'NO'.")
def play_game():
print("PLEASE THINK OF A NUMBER BETWEEN 1 AND 100.")
print("YOUR NUMBER DIVIDED BY 3 HAS A REMAINDER OF")
a = int(input())
print("YOUR NUMBER DIVIDED BY 5 HAS A REMAINDER OF")
b = int(input())
print("YOUR NUMBER DIVIDED BY 7 HAS A REMAINDER OF")
c = int(input())
print()
print("LET ME THINK A MOMENT...")
print()
time.sleep(2.5)
d = (70 * a + 21 * b + 15 * c) % 105
print(f"YOUR NUMBER WAS {d}, RIGHT?")
response = get_yes_or_no()
if response:
print("HOW ABOUT THAT!!")
else:
print("I FEEL YOUR ARITHMETIC IS IN ERROR.")
print()
print("LET'S TRY ANOTHER")
def main():
print_with_tab(33, "NICOMA")
print_with_tab(15, "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
print()
print()
print()
print("BOOMERANG PUZZLE FROM ARITHMETICA OF NICOMACHUS -- A.D. 90!")
print()
while True:
play_game()
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Ruby](https://www.ruby-lang.org/en/)

View File

@@ -0,0 +1,3 @@
Original BASIC source [downloaded from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Visual Basic .NET](https://en.wikipedia.org/wiki/Visual_Basic_.NET)