Skip to content

Instantly share code, notes, and snippets.

@StevenMeiklejohn
Created June 1, 2023 12:08
Show Gist options
  • Save StevenMeiklejohn/37f03648cc86bb5373e2e238cb2204b0 to your computer and use it in GitHub Desktop.
Save StevenMeiklejohn/37f03648cc86bb5373e2e238cb2204b0 to your computer and use it in GitHub Desktop.

Let's consider the code that solves the Bulls & Cows problem. What can we learn from it?

Task

Create a four digit random number from the digits 1 to 9, without duplication.

The program should:

  • ask for guesses to this number
  • reject guesses that are malformed
  • print the score for the guess
  • allow the user to quit

The score is computed as:

  1. The player wins if the guess is the same as the randomly chosen number, and the program ends.
  2. A score of one bull is accumulated for each digit in the guess that equals the corresponding digit in the randomly chosen initial number.
  3. A score of one cow is accumulated for each digit in the guess that also appears in the randomly chosen number, but in the wrong position.

Given what we've learned, attempt the following challenges:

(ideas here https://rosettacode.org/wiki/Category:Programming_Tasks)

  1. Create a Sharing terminal app that asks the user to input a name and then returns a string saying:

One for name, one for me.

However, if the terminal input doesn't include a name, the returned string should say:

One for you, one for me.

(source - https://exercism.org/tracks/javascript/exercises/two-fer)

  1. Leap Year - create an app that asks you to input a year in the terminal and prints a message saying whether that year is a leap year or not. Consideration - a leap year is one that is divisible by 4, except if it is divisible by 100, unless it is also divisible by 400. For example, 1900 and 1997 are not leap years but 1996 and 2000 are.

(source - https://exercism.org/tracks/javascript/exercises/leap)

  1. Acronym - create an app where the user is asked to input a three-word phrase in the terminal and then is given back a three-letter acronym of it in capital letters, i.e. structured query language giving back SQL.

(source - https://exercism.org/tracks/javascript/exercises/acronym)

  1. Isogram - create a terminal app that checks whether a word you input is an isogram, i.e. not containing multiple instances of the same letter.

(source - https://exercism.org/tracks/javascript/exercises/isogram)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment