Permalink
Browse files

uploaded project 1

  • Loading branch information...
georgewpotts committed Dec 2, 2019
0 parents commit f15342853acac0b21d99ba2b3ca3856df2932594
Showing with 189 additions and 0 deletions.
  1. +189 −0 Projects/project-code-challenge.ipynb
@@ -0,0 +1,189 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"http://imgur.com/1ZcRyrc.png\" style=\"float: left; margin: 20px; height: 55px\">\n",
"\n",
"# Project 1: Python Coding Exercises\n",
"\n",
"_Authors: Joseph Nelson (DC) _\n",
"\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following code challenges are drawn from common exercises used in technical interviews.\n",
"\n",
"Please note that there may be several ways to approach each challenge. If you get stuck, try mapping out your approach in pseudocode first. Finally, while solutions to problems like these may be found online, remember that if you copy/paste code that you can't explain, you'll be missing out on the point of the project. The only way to truly learn a new skill is through practice, trial, and error - we can only help you improve by understanding where you are having trouble."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Challenge 1: Largest Palindrome\n",
"A palindromic number reads the same both ways. For example, 1234321 is a palindrome. The largest palindrome made from the product of two two-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two three-digit numbers. Afterward, write a brief explanation walking through your code's logic in markdown."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"a=1000\n",
"b=1000\n",
"\n",
"for a in range(999,100,-1):\n",
" for b in range (a, 100, -1):\n",
" prod=a*b\n",
" print(a,b)\n",
" proddig=prod\n",
" #test palindrome\n",
" prod_reverse=0\n",
" while(proddig==prod_reverse):\n",
" dig=proddig%10\n",
" prod_reverse=prod_reverse*10+dig\n",
" proddig=proddig//10\n",
" print(\"Reverse of the number:\",prod_reverse)\n",
"\n",
"print(prod)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"### Challenge 2: Summation of Primes\n",
"The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below 2,000. Afterward, write a brief explanation walking through your code's logic in markdown."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def isPrime(n):\n",
" if n < 2: return \"Neither prime, nor composite\"\n",
" for i in range(2, int(n**0.5) + 1):\n",
" if n % i == 0:\n",
" return False\n",
" return True\n",
"\n",
"sum = 0\n",
"for i in range(2, 2000):\n",
" if isPrime(i):\n",
" sum += i\n",
"\n",
"print (sum)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Challenge 3: Multiples of 3 and 5\n",
"If we list all of the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6, and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 and 5 below 1,000. Afterward, write a brief explanation walking through your code's logic in markdown."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#Challenge 3: Multiples of 3 and 5\n",
"\n",
"#If we list all of the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6, and 9. \n",
"#The sum of these multiples is 23. Find the sum of all the multiples of 3 and 5 below 1,000. \n",
"#Afterward, write a brief explanation walking through your code's logic in markdown.\n",
"\n",
"#Create a list of all bumbers below 100 that are multiples of 3\n",
"\n",
"def divs3(n):\n",
" if n%3==0:\n",
" return (n)\n",
"\n",
"def divs5(n):\n",
" if n%5==0:\n",
" return (n)\n",
"set3=[]\n",
"set5=[]\n",
"while x in range (1,100):\n",
" print(divs3(x))\n",
" print(divs5(x))\n",
" set3.append(divs3(x))\n",
" set5.append(divs5(x))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Challenge 4: String Compressor\n",
"Implement a method to perform basic string compression using the counts of repeated characters. (This is called run-length encoding.) For example, the string \"aabcccccaaa\" would become a2b1c5a3. If the “compressed” string would not become smaller than the original string, your method should return the original string. You can assume the string has only uppercase and lowercase letters (a–z). Specify whether your solution is case sensitive or case insensitive and what you would need to change to make it the other. Afterward, write a brief explanation walking through your code's logic in markdown."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### *BONUS* Challenge: FizzBuzz\n",
"Write a program that prints all of the numbers from 1 to 100. For multiples of 3, instead of the number, print \"Fizz;\" for multiples of 5, print \"Buzz.\" For numbers that are multiples of both 3 and 5, print \"FizzBuzz.\" Afterward, write a brief explanation walking through your code's logic in markdown."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"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",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit f153428

Please sign in to comment.