From 9b22b8cae1fbe55034952bf31b0c6ef5160eae6d Mon Sep 17 00:00:00 2001 From: Michael Adams Date: Tue, 8 Aug 2023 19:04:03 -0700 Subject: [PATCH 1/3] Nim port of Buzzword --- .../20_Buzzword/nim/buzzword.nim | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 00_Alternate_Languages/20_Buzzword/nim/buzzword.nim diff --git a/00_Alternate_Languages/20_Buzzword/nim/buzzword.nim b/00_Alternate_Languages/20_Buzzword/nim/buzzword.nim new file mode 100644 index 000000000..dfba31c9d --- /dev/null +++ b/00_Alternate_Languages/20_Buzzword/nim/buzzword.nim @@ -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!" From dd7d3c4c26c250bf34ee9d8ebb17514f332cfd08 Mon Sep 17 00:00:00 2001 From: Michael Adams Date: Tue, 8 Aug 2023 20:57:33 -0700 Subject: [PATCH 2/3] Nim port of RockScissorsPaper Revised via Nim Discord --- .../nim/rockscissors.nim | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 00_Alternate_Languages/74_Rock_Scissors_Paper/nim/rockscissors.nim diff --git a/00_Alternate_Languages/74_Rock_Scissors_Paper/nim/rockscissors.nim b/00_Alternate_Languages/74_Rock_Scissors_Paper/nim/rockscissors.nim new file mode 100644 index 000000000..af2d1b1ac --- /dev/null +++ b/00_Alternate_Languages/74_Rock_Scissors_Paper/nim/rockscissors.nim @@ -0,0 +1,71 @@ +import std/[random,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." + if p == SCISSORS and c == PAPER: + playerWins += 1 + result = "SCISSORS CUTS PAPER. YOU WIN." + if p == PAPER and c == SCISSORS: + cpuWins += 1 + result = "SCISSORS CUTS PAPER. I WIN." + if p == PAPER and c == ROCK: + playerWins += 1 + result = "PAPER COVERS ROCK. YOU WIN." + if p == ROCK and c == PAPER: + cpuWins += 1 + result = "PAPER COVERS ROCK. I WIN." + if p == ROCK and c == SCISSORS: + playerWins += 1 + result = "ROCK CRUSHES SCISSORS. YOU WIN." + if p == SCISSORS and c == ROCK: + cpuWins += 1 + result = "ROCK CRUSHES SCISSORS. 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!!" From aa0056624481b56e8b5dce40ad5a2f4ed0b0b8ed Mon Sep 17 00:00:00 2001 From: Michael Adams Date: Tue, 8 Aug 2023 22:09:02 -0700 Subject: [PATCH 3/3] Enhancement from Nim Discord --- .../nim/rockscissors.nim | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/00_Alternate_Languages/74_Rock_Scissors_Paper/nim/rockscissors.nim b/00_Alternate_Languages/74_Rock_Scissors_Paper/nim/rockscissors.nim index af2d1b1ac..3c0cda0c5 100644 --- a/00_Alternate_Languages/74_Rock_Scissors_Paper/nim/rockscissors.nim +++ b/00_Alternate_Languages/74_Rock_Scissors_Paper/nim/rockscissors.nim @@ -1,4 +1,4 @@ -import std/[random,strutils] +import std/[random,strformat,strutils] type symbol = enum @@ -20,24 +20,21 @@ proc outcome(p: symbol, c: symbol): string = if p == c: ties += 1 result = "TIE GAME. NO WINNER." - if p == SCISSORS and c == PAPER: - playerWins += 1 - result = "SCISSORS CUTS PAPER. YOU WIN." - if p == PAPER and c == SCISSORS: - cpuWins += 1 - result = "SCISSORS CUTS PAPER. I WIN." - if p == PAPER and c == ROCK: - playerWins += 1 - result = "PAPER COVERS ROCK. YOU WIN." - if p == ROCK and c == PAPER: - cpuWins += 1 - result = "PAPER COVERS ROCK. I WIN." - if p == ROCK and c == SCISSORS: - playerWins += 1 - result = "ROCK CRUSHES SCISSORS. YOU WIN." - if p == SCISSORS and c == ROCK: - cpuWins += 1 - result = "ROCK CRUSHES SCISSORS. I WIN." + 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"