Skip to content

Latest commit

 

History

History
33 lines (31 loc) · 781 Bytes

README.md

File metadata and controls

33 lines (31 loc) · 781 Bytes

Primitive Calculator

A primitive calculator has been programmed that can perform the following three operations with the current number X:

  • subtract 1 from X
  • divide X by 2
  • divide X by 3

Given a positive integer n, the calculator determines the minimum number of operations needed to obtain 1 starting from the number n.

Samples

Please enter a number: 25
n = 25
Number of operations = 5
Sequence of operations: [1 2 2 2 3]
Please enter a number: 394
n = 394
Number of operations = 10
Sequence of operations: [2 1 2 2 1 2 2 2 2 3]
Please enter a number: 6
n = 6
Number of operations = 2
Sequence of operations: [2 3]
Please enter a number: 9999
n = 9999
Number of operations = 16
Sequence of operations: [3 3 1 2 3 1 2 2 2 1 2 1 2 1 2 2]