Skip to content

Commit

Permalink
Merge pull request #885 from unquietwiki/main
Browse files Browse the repository at this point in the history
Nim ports of Buzzword and RockScissorsPaper
  • Loading branch information
coding-horror authored Aug 9, 2023
2 parents 70fcc44 + aa00566 commit 1ec36cf
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
34 changes: 34 additions & 0 deletions 00_Alternate_Languages/20_Buzzword/nim/buzzword.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import std/[random,strutils]

randomize()

const
words1 = ["ABILITY","BASAL","BEHAVIORAL","CHILD-CENTERED","DIFFERENTIATED","DISCOVERY","FLEXIBLE",
"HETEROGENEOUS","HOMOGENEOUS","MANIPULATIVE","MODULAR","TAVISTOCK","INDIVIDUALIZED"]
words2 = ["LEARNING","EVALUATIVE","OBJECTIVE","COGNITIVE","ENRICHMENT","SCHEDULING","HUMANISTIC",
"INTEGRATED","NON-GRADED","TRAINING","VERTICAL AGE","MOTIVATIONAL","CREATIVE"]
words3 = ["GROUPING","MODIFICATION","ACCOUNTABILITY","PROCESS","CORE CURRICULUM","ALGORITHM", "PERFORMANCE",
"REINFORCEMENT","OPEN CLASSROOM","RESOURCE","STRUCTURE","FACILITY","ENVIRONMENT"]

var
stillplaying: bool = true
prompt: string

echo spaces(26), "BUZZWORD GENERATOR"
echo spaces(15), "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
echo "\n"
echo "THIS PROGRAM PRINTS HIGHLY ACCEPTABLE PHRASES IN"
echo "'EDUCATOR-SPEAK' THAT YOU CAN WORK INTO REPORTS"
echo "AND SPEECHES. AFTER EACH PHRASE, HIT 'ENTER' FOR"
echo "ANOTHER PHRASE, OR TYPE 'N' TO QUIT."
echo "\n"
echo "HERE'S THE FIRST PHRASE..."

while stillplaying:
echo ""
echo words1[rand(0..12)], " ", words2[rand(0..12)], " ", words3[rand(0..12)]
prompt = readLine(stdin).normalize()
if prompt.substr(0, 0) == "n":
stillplaying = false

echo "COME BACK WHEN YOU NEED HELP WITH ANOTHER REPORT!"
68 changes: 68 additions & 0 deletions 00_Alternate_Languages/74_Rock_Scissors_Paper/nim/rockscissors.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import std/[random,strformat,strutils]

type
symbol = enum
PAPER = 1, SCISSORS = 2, ROCK = 3

var
cpuChoice, playerChoice, turns: int
cpuWins, playerWins, ties: int = 0

randomize()

# Function: player makes a choice
proc choose(): int =
echo "3=ROCK...2=SCISSORS...1=PAPER...WHAT'S YOUR CHOICE?"
result = readLine(stdin).parseInt()

# Function: determine the outcome
proc outcome(p: symbol, c: symbol): string =
if p == c:
ties += 1
result = "TIE GAME. NO WINNER."
else:
const
winTable = [
PAPER: (ROCK, "COVERS"),
SCISSORS: (PAPER, "CUTS"),
ROCK: (SCISSORS, "CRUSHES")
]
let (winCond, winVerb) = winTable[p]
if winCond == c:
playerWins += 1
result = fmt"{p} {winVerb} {c}. YOU WIN."
else:
let (_, winVerb) = winTable[c]
cpuWins += 1
result = fmt"{c} {winVerb} {p}. I WIN."

# Start the game
echo spaces(21), "GAME OF ROCK, SCISSORS, PAPER"
echo spaces(15), "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
echo "\n"
echo "HOW MANY GAMES?"
turns = readLine(stdin).parseInt()
while turns > 10:
echo "SORRY, BUT WE AREN'T ALLOWED TO PLAY THAT MANY."
turns = readLine(stdin).parseInt()

# Play the game
for i in 1..turns:
echo ""
echo "GAME NUMBER ", i
playerChoice = choose()
while playerChoice != 1 and playerChoice != 2 and playerChoice != 3:
echo "INVALID"
playerChoice = choose()
cpuChoice = rand(1..3) # match against range in symbol
echo "THIS IS MY CHOICE... ", symbol(cpuChoice)
echo outcome(symbol(playerChoice), symbol(cpuChoice))

# Results
echo ""
echo "HERE IS THE FINAL GAME SCORE:"
echo "I HAVE WON ", cpuWins," GAME(S)."
echo "YOU HAVE WON ", playerWins," GAME(S)."
echo "AND ", ties," GAME(S) ENDED IN A TIE."
echo ""
echo "THANKS FOR PLAYING!!"

0 comments on commit 1ec36cf

Please sign in to comment.