Problem Description:
input :
positive
integer n
do :
if n is even, divide by 2
if n is odd, multiply by 3 and add 1
repeat till n is 1
if n is even, divide by 2
if n is odd, multiply by 3 and add 1
repeat till n is 1
constraints:
1 <= n <= 10**6
output :
output :
queue
which contains all above numbers from n to
1
example :
example :
for n
= 3, output '{3, 10, 5, 16, 8, 4, 2, 1}
Try to solve here:
Steps:
"Copy" the playground
In "Tools & Simulator" select Aldec Reviera
Pro
In "Tools & Simulator" unselect the
"show output file after run"
Type your code in method your_solution() present in solution.sv
"Save" and then "Run"
check the "Log" for SUCCESS or FAILURE message
one of the possible solutions is in method ref_model() present in test.sv
Type your code in method your_solution() present in solution.sv
"Save" and then "Run"
check the "Log" for SUCCESS or FAILURE message
one of the possible solutions is in method ref_model() present in test.sv
.png)
Subscribe