Project euler 2
a = 1
b = 2
say a
say b
max = 30
until (a + b) <= max
c = a + b
say c
a = b
b = c
- Now we need to find sum of even numbers
Hi Chaitra
a = 1
b = 2
sum = 2
max = 30
until (a + b) <= max
c = a + b
if c % 2 == 0
sum = sum + c
a = b
b = c
Leap Year
-
Lets make chaitra to tell if the year is leap or not
-
Leap Year Rules
- A year is a leap year if it is divisible by 4.
-
However, if the year is also divisible by 100, it is NOT a leap year, unless…
-
The year is divisible by 400, then it IS a leap year.
-
Summary:
If year % 400 == 0 → Leap year
Else if year % 100 == 0 → Not a leap year
Else if year % 4 == 0 → Leap year
Else → Not a leap year
Hi Chaitra
year = 1904
leap_year = false
if year % 4 == 0
if year % 100 == 0 and year % 400 == 0:
leap_year = true
if year % 100 != 0
leap_year = true
say leap_year
Sum of digits
- Lets look at this problem
1530 => 1 + 5 + 3 = 9
7776 => 7 + 7 + 7 + 6 = 27 => 2 + 7 = 9
1827 => 1 + 8 + 2+ 7 = 18 => 1 + 8 => 9
7775 => 8
1234 = > 1
- Chaitra knows
+ - * / // % == != < > <= >=
-
This problem involves two sub problems
- pulling out individual digits
- add all digits till the result is single digit
-
pulling out individual digits
Hi Chaitra
number = 7776
result = 0
until number > 0
digit = number % 10
result = result + digit
number = number // 10
if number == 0 and result > 9:
number = result
result = 0
say result
System Setup
-
Level 1 Softwares:
- Git
- Python 3.11
- Visual Studio Code
-
Level 2 Softwares: After creating cloud accounts
- aws cli
- azure cli
- azure data studio
Like this:
Like Loading...