Notes 2 Applications
Notes 2 Applications
Applications
Computing the Day of the Week
❖ A function that is related to the modulo function is called the
floor function
❖ Floor Function
– also called the greatest integer function
– denoted by x
– the greatest integer that is less than or equal to x
Example:
17
3.2 = 3 =4
4
10.96 = 10 −8.5 = -9
1
=0
2
Zeller’s Congruence
Using the floor function, we can write a formula that gives the day of the week
for any date. The formula, known as Zeller’s congruence, is given by:
where,
d – day of the month
m – month where, 1 – March
2 – April, . . .
11 – January
12 – February
c – first 2 digits of the year
y – last 2 digits of the year; if the month is January or February,
y is the last two digits of the year minus 1
x – day of the week using 0 – Sunday,
1 – Monday, . . . ,
6 – Saturday
❑ Example 1:
d=4
m=5
c = 17
y = 76
13 5 −1 76 17
x + + + 4 + 76 − 2(17) 𝑚𝑜𝑑 7
5 4 4
12 + 19 + 4 + 4 + 76 − 34 mod 7
81 mod 7
4 , Thursday
❑ Example 2:
d = 16
m = 11
c = 20
y = -1 (since the month is January, y = 0-1 = -1)
13(11)−1 −1 20
x + + + 16 + −1 − 2(20) 𝑚𝑜𝑑 7
5 4 4
28 + −1 + 5 + 16 + −1 − 40 mod 7
7 mod 7
0, Sunday
Example:
Answer: 0
Universal Product Code (UPC)
• used for commercial identification of products
• a 12-digit number that satisfies a congruence equation that is
similar to the one for ISBNs. The last digit is the check digit.
❑ Example:
1-32342-65973- 9
ANSWER: 2
CREDIT CARD NUMBERS
Credit card numbers are normally 16 digits long. To determine
whether a credit card number is valid or not, we use Luhn’s
algorithm:
1) Read the digits from right to left. Double every other digit
beginning with the 2nd to the last digit. If the answer is a
two-digit number after being doubled, treat the number as
two individual digits.
2) Add the new list of digits. If the card is valid, the sum must
be congruent to 0 mod 10.
Example:
Is the credit card number valid or not?
Reading from right to left, underline every other digit beginning
with the second-to-last digit. Next double each of the underlined
digits.
= 60 mod 10
0
Answer:
68mod 10 ≠ 0, Not Valid