Skip to content

Instantly share code, notes, and snippets.

Eric Normand ericnormand

View GitHub Profile
ericnormand / 00 quadratic
Last active Jul 3, 2020
385 - Newsletter
View 00 quadratic

roots of a quadratic equation

Quadratic equations can be represented by three numbers, a, b, and c, which are the coefficient of x^2, the coefficient of x, and the constant term. The roots of a quadratic equation are everywhere where it touches the x axis, meaning the equation is equal to zero.

You can use the quadratic formula which calculates the roots. In fact, that's your task: write a function that returns the roots of a quadratic equation using the quadratic formula. Here is more information about it.

Note: you don't have to return complex roots if the curve does not cross the x-axis.

Thanks to this site for the challenge idea where it is considered Medium level in Python.

View 00 parallel

parallel lines

There are different ways to express the equation of a line. Here's one way:

2x + 4y = 1
 x + 2y = 1

The x and the y are always the same, but we can sub out variables for the three numbers:

View 00 iterated square

iterated square root

If you iteratively apply the square root, you will eventually get a number strictly less than two. Write a function that figures out how many times you have to apply the square root it results in a number less than two.


(iter-sqrt 1) ;=> 0 (since 1 is already less than 2)
(iter-sqrt 2) ;=> 1 (since the square root of 2 is less than 2)
(iter-sqrt 256) ;=> 4
View 00

unique values

Let's keep it easy this week as we get back into it.

Write a function called uniques that takes a sequence of values. That sequence is going to have zero or more unique values. The rest will repeat at least once. Your job is to return the unique values in the same order as they appear in the argument sequence.


(uniques [1 2 3 4 5 6 1 2 3 5 6]) ;=> (4)
View 00 Medication

Medication contraindications

You probably know this, but here's some background so we're all on the same page. Some medicines shouldn't be taken in combination. When two medications shouldn't be taken together, it's called a contraindication.

(def patient-medications [{:name "Blythenal"
                           :rxNorm "blyth"}
                          {:name "Masbutol"
                           :rxNorm "masbut"}
                          {:name "Welbutril"
View 00 Word

Word segmentation

One of the issues with domain names is that spaces aren't allowed. So we get domain names like this:

  • (Pen Island)
  • (Experts Exchange)

Now we also have the problem with #hashtags on social media platforms.

We want to be able to take a string without spaces and insert the spaces so that the words are separated and our gradeschool teacher can be happy again.

View 00


We need to classify patterns into four different categories:

  1. horizontally symmetrical
  2. vertically symmetrical
  3. perfect (both vertically and horizontally symmetrical)
  4. imperfect (neither vertically nor horizontally symmetrical)

Patterns are two-dimmensional. We will represent them with vectors of vectors. Each inner vector is a row.

View 00 Sudoku

Sudoku Validator

Write a function that validates a finished sudoku board. It should take a vector of vectors. The inner vectors represent rows from the sudoku board. The rows should contain nine integers. If the board is well-played, the function should return true, otherwise, false.

(sudoku-valid? [[ 1 5 2 4 8 9 3 7 6 ]
                [ 7 3 9 2 5 6 8 4 1 ]
                [ 4 6 8 3 7 1 2 9 5 ]
                [ 3 8 7 1 2 4 6 5 9 ]
                [ 5 9 1 7 6 3 4 2 8 ]
View 00 Distance to nearest

Distance to nearest vowel

Write a function that takes a string as argument. Each character in the string will be a letter. The function should return a sequence containing the distances from each corresponding letter in the string to the nearest vowel in the string.

For example:

(nearest-vowels "aeiou") ;=> [0 0 0 0 0]  ;; if the letter is a vowel, the distance is 0
(nearest-vowels "babbb") ;=> [1 0 1 2 3]
(nearest-vowels "babbba") ;=> [1 0 1 2 1 0]
View 00 Poker Hands,

Poker hand ranking, revisited

Last week, the challenge was to write a function to score a poker hand. It took a hand of poker cards and returned a keyword naming the hand. For instance:

(score [[3 :diamonds] [3 :hearts] [3 :spades] [5 :hearts] [:king :clubs]])
=> :three-of-a-kind ;; three 3s

Cards are represented as a tuple of rank (number or name if it's a face card) and suit. Face card names are the keywords :ace, :king, :queen, :jack. Suits are :diamonds, :spades, :hearts, :clubs.

You can’t perform that action at this time.