A Normal Sequence

Published by Mubashir Hassan in

Consider a sequence where the first two numbers are 0 and 1 and the next number of the sequence is the sum of the previous two numbers modulo three.

Create a function that finds the nth element of the sequence.

Examples

normal_sequence(1) ➞ 0

normal_sequence(2) ➞ 1

normal_sequence(3) ➞ 1

normal_sequence(20) ➞ 2

Notes

  • 1 ≤ N ≤ 10^19
  • A hint in comments section.
Watch a quick demo on how Edabit works.