Gen-AI Developer Classroom notes 22/Feb/2025

Project euler Problems

Operators

  • Assignment
# Assigning memory location to a variable
a = 5
  • Arthimetic
+
-
*
// (integer division quotient)
% (modulus remainder)
/ (division)
  • Equality
== (equals)
!= (not equals)
  • Logical
and
or
not
  • Comparision
<
<=
>
>=

Problem 1

result = 0
limit = 10
index = 1
until index < limit do the following
  if (index % 3 == 0) or (index % 5 == 0) then
        result = index + result
  end
  index = index + 1
end

  • Steps (Algorithm)
result = 0
limit = 10

Problem 6

sum = 0
square_sum = 0
result = 0
limit = 3
index = 1
until index <= limit do the following
  sum = sum + index
  square_sum = square_sum + (index * index)
  index = index + 1
end
sum_square = sum * sum
result = sum_square - square_sum
print sum_square

Problem 2

a = 1
b = 2
result = 2
limit = 100
until (a + b) < limit
    c = a + b
    if c%2 == 0 then
      result = result + c
    a = b
    b = c
end
print result

Problem 3

inputs:
  number
  index
steps:
  return number%index == 0
  • Example is_factor(10,3) => False is_factor(100,10) => True
  • is_prime(number)
inputs: number
output: True if prime False otherwise
steps:
    index = 2
    result = True
    unless index < number do the following
      if is_factor(number, index) == True:
         result = False
         exit
      end
      index = index + 1
    end
    return result
  • Example is_prime(10) = False, is_prime(21) => False, is_prime(11) => true
  • Solution
number = 70
index = number//2
until index > 2 do the following
  if is_factor(number,index) and is_prime(index) == true then
        print index
        exit
  end
  index = index - 1
end
  • Exercise: Try Problem 5 and 9

By continuous learner

enthusiastic technology learner

Leave a Reply

Discover more from Direct AI Powered By Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading