Introductory Exercises
Contents
- 1 Introductory Exercises
- 1.1 Problems with numbers (no sequences as input)
- 1.1.1 First Degree Equation ^{i}
- 1.1.2 Second Degree Equation ^{i}
- 1.1.3 Divisibility Test ^{i}
- 1.1.4 Leap Year Test ^{i}
- 1.1.5 k^{th} digit
- 1.1.6 Triangle Edges ^{i}
- 1.1.7 Swap Variables ^{i}
- 1.1.8 Swap Variables Restricted ^{i h}
- 1.1.9 Divisors
- 1.1.10 Primality
- 1.1.11 Reverse Digits
- 1.1.12 Multiple Count ^{i h}
- 1.1.13 Leap Year Count ^{i h}
- 1.1.14 Palindrome ^{h}
- 1.1.15 Sort numbers ^{i}
- 1.1.16 Sort more numbers ^{i h}
- 1.1.17 GCD and LCM
- 1.1.18 Prime Factors
- 1.1.19 Numbers with two digits
- 1.1.20 Decimal Fraction ^{h}
- 1.1.21 Number Guessing
- 1.1 Problems with numbers (no sequences as input)
Introductory Exercises
This is a small list of exercises for beginners. Some of them require minimal math knowledge. I will try and make references to that knowledge, when possible.
Problems with numbers (no sequences as input)
First Degree Equation ^{i}
Solve the first degree equation with one variable: ax + b = 0
, given a
and b
as input.
Second Degree Equation ^{i}
Solve the second degree equation with one variable: ax^{2} + bx + c = 0
, given a, b
and c
as input.
Divisibility Test ^{i}
Find out if n
is divisible by k
.
Leap Year Test ^{i}
Find out if year y
is a leap year.
k^{th} digit
Extract the k^{th} digit of a number, counting digits from right to left
Triangle Edges ^{i}
Can three input numbers be the lengths of the three edges of a triangle?
Swap Variables ^{i}
Given variables a
and b
exchange their values so that in the end a
will contain the old value of b
and b
will contain the old value of a
.
Swap Variables Restricted ^{i h}
Given variables a
and b
exchange their values so that in the end a
will contain the old value of b
and b
will contain the old value of a
, without using any other variables.
Divisors
Display all of number n
's divisors.
Primality
Is number n
a prime number?
Reverse Digits
Display in reverse order the digits of a number n
Multiple Count ^{i h}
How many integers divisible by n
lie in interval [a, b]
?
Leap Year Count ^{i h}
How many years between y1
and y2
are leap years?
Palindrome ^{h}
Is number n
a [palindrome]? A palindrome is a symmetrical number, like 15351 or 12233221.
Sort numbers ^{i}
Display three input integers in ascending order.
Sort more numbers ^{i h}
Display five input integers in ascending order. Make the flow chart fit on one letter page.
GCD and LCM
Find the [greates common divisor] and the [lowest common multiple] of two numbers. Use [Euclid's algorithm]. Example: GCD of 24 and 32 is 8.
Prime Factors
Display the [prime factor decomposition] of input number n
. Example: 1176 = 2^{3} x 3^{1} x 7^{2}
Numbers with two digits
Is number n
formed with exactly 2 digits repeated any number of times? 23223 and 900990 are such numbers, while 593 and 44002 are not.
Decimal Fraction ^{h}
Display fraction m/n
in decimal format, with the period between brackets. Example: 13/30 = 0.4(3)
Number Guessing
Guess a number between 1 and 1024 by asking questions of the form "is the number greater or equal to x".
Legend:
- ^{i} means that the problem can be solved without loops, using only if-then-else structures.
- ^{h} means hard. The problem is difficult.