2017-03-29 16:45:04 +08:00
{
" cells " : [
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges). "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" # Challenge Notebook "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ## Problem: Generate a list of primes. \n " ,
" \n " ,
" * [Constraints](#Constraints) \n " ,
" * [Test Cases](#Test-Cases) \n " ,
" * [Algorithm](#Algorithm) \n " ,
" * [Code](#Code) \n " ,
" * [Unit Test](#Unit-Test) \n " ,
" * [Solution Notebook](#Solution-Notebook) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ## Constraints \n " ,
" \n " ,
" * Is it correct that 1 is not considered a prime number? \n " ,
" * Yes \n " ,
" * Can we assume the inputs are valid? \n " ,
" * No \n " ,
" * Can we assume this fits memory? \n " ,
" * Yes "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ## Test Cases \n " ,
" \n " ,
" * None -> Exception \n " ,
" * Not an int -> Exception \n " ,
2017-12-07 09:10:38 +08:00
" * 20 -> [False, False, True, True, False, True, False, True, False, False, False, True, False, True, False, False, False, True, False, True] "
2017-03-29 16:45:04 +08:00
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ## Algorithm \n " ,
" \n " ,
" Refer to the [Solution Notebook](). If you are stuck and need a hint, the solution notebook ' s algorithm discussion might be a good place to start. "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ## Code "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 3 ,
2020-07-15 09:23:57 +08:00
" metadata " : { } ,
2017-03-29 16:45:04 +08:00
" outputs " : [ ] ,
" source " : [
" class PrimeGenerator(object): \n " ,
" \n " ,
" def generate_primes(self, max_num): \n " ,
" # TODO: Implement me \n " ,
" pass "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ## Unit Test "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" **The following unit test is expected to fail until you solve the challenge.** "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : null ,
2020-07-15 09:23:57 +08:00
" metadata " : { } ,
2017-03-29 16:45:04 +08:00
" outputs " : [ ] ,
" source " : [
" # %lo ad test_generate_primes.py \n " ,
2020-07-15 09:23:57 +08:00
" import unittest \n " ,
2017-03-29 16:45:04 +08:00
" \n " ,
" \n " ,
2020-07-15 09:23:57 +08:00
" class TestMath(unittest.TestCase): \n " ,
2017-03-29 16:45:04 +08:00
" \n " ,
" def test_generate_primes(self): \n " ,
" prime_generator = PrimeGenerator() \n " ,
2020-07-15 09:23:57 +08:00
" self.assertRaises(TypeError, prime_generator.generate_primes, None) \n " ,
" self.assertRaises(TypeError, prime_generator.generate_primes, 98.6) \n " ,
" self.assertEqual(prime_generator.generate_primes(20), [False, False, True, \n " ,
2017-03-29 16:45:04 +08:00
" True, False, True, \n " ,
" False, True, False, \n " ,
" False, False, True, \n " ,
" False, True, False, \n " ,
" False, False, True, \n " ,
" False, True]) \n " ,
" print( ' Success: generate_primes ' ) \n " ,
" \n " ,
" \n " ,
" def main(): \n " ,
" test = TestMath() \n " ,
" test.test_generate_primes() \n " ,
" \n " ,
" \n " ,
" if __name__ == ' __main__ ' : \n " ,
" main() "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ## Solution Notebook \n " ,
" \n " ,
" Review the [Solution Notebook]() for a discussion on algorithms and code solutions. "
]
}
] ,
" metadata " : {
" kernelspec " : {
" display_name " : " Python 3 " ,
" language " : " python " ,
" name " : " python3 "
} ,
" language_info " : {
" codemirror_mode " : {
" name " : " ipython " ,
" version " : 3
} ,
" file_extension " : " .py " ,
" mimetype " : " text/x-python " ,
" name " : " python " ,
" nbconvert_exporter " : " python " ,
" pygments_lexer " : " ipython3 " ,
2020-07-15 09:23:57 +08:00
" version " : " 3.7.2 "
2017-03-29 16:45:04 +08:00
}
} ,
" nbformat " : 4 ,
2020-07-15 09:23:57 +08:00
" nbformat_minor " : 1
2017-03-29 16:45:04 +08:00
}