Skip to content

Instantly share code, notes, and snippets.

@davidventuri
davidventuri / aind_warmup_knights_knaves.md
Last active November 14, 2023 13:44
Logic puzzles. Knights must tell the truth. Knaves always lie.

Knights & Knaves

You are shipwrecked on an unknown island where there are two kinds of people - knights & knaves. Knights always tell the truth and knaves always lie. To survive, you need to know who is who.

For each person in the following scenarios, can you figure out if they are a knight or a knave? Support your answer with a logical justification / proof.

1. Persons: A & B

  • A says: “B is a knave.”
@davidventuri
davidventuri / aind_warmup_is_narcissistic.py
Last active November 17, 2016 21:45
Returns true if x is a narcissistic number.
"""A _narcissistic number_ is an `n`-digit whole number that is equal to the
sum of its digits raised to the power `n`.
For instance, `153` is such a 3-digit number (`1^3 + 5^3 + 3^3 = 153`)
and `8208` is a 4-digit example (`8^4+ 2^4 + 0^4 + 8^4 = 8208`).
Write a function `is_narcissistic(x)` that returns _true_ if `x` is
narcissistic. Now use this to find as many narcissistic numbers as you can.
How high up can you go?
Note: 1-digit numbers are all trivially narcissistic, so you may skip them.
@davidventuri
davidventuri / report.md
Created June 20, 2016 16:13
Toronto OpenStreetMap Data Case Study