Computer Science / Modular Arithmetic Help

Status
Not open for further replies.

Crazysah

Contributor
Hey, so I have this problem and I need some kind of help:

For each sentence, write a corresponding equation using modular arithmetic. Example: "If Monday is the first day of the week and Sunday is the seventh day of the week, then four days past Saturday (the sixth day) is Wednesday (the third day)" corresponds to the equation

(6 + 4) mod 7 = 3


  • "Eighteen-hundred hours in military time is what we might call six p.m."


  • "In a shift cipher with key 7, plaintext letter w becomes ciphertext letter D."

Also, this problem:

An algorithm.

input b

p ↠0

while b > 0:

p ↠p + 3

b ↠b - 1

output p
  • What does this algorithm output when given, respectively, input values of 2, 3, and 5?
  • In a clear and concise sentence explain what this algorithm computes.
  • Is this an efficient algorithm? Can you think of a more efficient way to achieve the same result? Explain.


Thanks,

Crazysah
 
(1800/100) - 12 = 6

w = 23, D = 4, 23 + 7 = 30 - 26 = 4 (not sure about this)

The algorithm is a bit ambiguous. Do you output p in every iteration? Assuming its only computed at the end of while loop,

Output= 6, 9, 15

Algo computes multiplication by 3 (or 3's times-table)

On first look, doesn't seem to fail for any value. Might need second opinion.
 
Status
Not open for further replies.