3.2 KiB
3.2 KiB
💻 Assignment 01
Requirements
- Solve one problem statement from each set
- Write the solution to each problem statement in its corresponding Python module (
p1.py,p2.pyandp3.pyrespectively). - Use functions, input parameters and return values
- Each function only does one thing!
- Do not use global variables
- Provide the user relevant messages regarding expected input and the meaning of the program’s output.
- Assignment should be completed by week 2, hard deadline is week 3.
Problem Statements
First Set
- Generate the first prime number larger than a given natural number
n. - Given natural number
n, determine the prime numbersp1andp2such thatn = p1 + p2(check the Goldbach hypothesis). - For a given natural number
nfind the minimal natural numbermformed with the same digits. (e.g.n=3658, m=3568). - For a given natural number
nfind the largest natural number written with the same digits. (e.g.n=3658, m=8653). - Generate the largest prime number smaller than a given natural number
n. If such a number does not exist, a message should be displayed.
Second Set
- Determine a calendar date (as year, month, day) starting from two integer numbers representing the year and the day number inside that year (e.g. day number 32 is February 1st). Take into account leap years. Do not use Python's inbuilt date/time functions.
- Determine the twin prime numbers
p1andp2immediately larger than the given non-null natural numbern. Two prime numberspandqare called twin ifq - p = 2. - Find the smallest number
mfrom the Fibonacci sequence, defined byf[0]=f[1]=1,f[n]=f[n-1] + f[n-2], forn > 2, larger than the given natural numbern. (e.g.for n = 6, m = 8). - Consider a given natural number
n. Determine the productpof all the proper factors ofn. - The palindrome of a number is the number obtained by reversing the order of its digits (e.g. the
palindrome of 237 is 732). For a given natural numbern, determine its palindrome. - The numbers
n1andn2have the propertyPif their writing in base 10 uses the same digits (e.g.2113 and 323121). Determine whether two given natural numbers have propertyP.
Third Set
- Determine the age of a person, in number of days. Take into account leap years, as well as the date of birth and current date
(year, month, day). Do not use Python's inbuilt date/time functions. - Determine the
n-thelement of the sequence1,2,3,2,5,2,3,7,2,3,2,5,...obtained from the sequence of natural numbers by replacing composed numbers with their prime divisors, without memorizing the elements of the sequence. - Determine the
n-thelement of the sequence1,2,3,2,2,5,2,2,3,3,3,7,2,2,3,3,3,...obtained from the sequence of natural numbers by replacing composed numbers with their prime divisors, each divisordbeing writtendtimes, without memorizing the elements of the sequence. - Generate the largest perfect number smaller than a given natural number
n. If such a number does not exist, a message should be displayed. A number is perfect if it is equal to the sum of its divisors, except itself. (e.g.6 is a perfect number, as 6=1+2+3).