Baseline: tree as shared
This commit is contained in:
1679 files changed
+1024562
No files matched your search
@@ -0,0 +1,26 @@
|
||||
# probe: while loops, a step count, and tracking a maximum
|
||||
# status: the expected output is Programming+'s interpreter's prediction; corpus.py verify confirms or refutes it on godbolt
|
||||
# expect-stdout: longest below 30: 27 with 111 steps
|
||||
# expect-stdout: 111
|
||||
def steps(n0: Int) -> Int:
|
||||
var n = n0
|
||||
var count = 0
|
||||
while n != 1:
|
||||
if n % 2 == 0:
|
||||
n = n // 2
|
||||
else:
|
||||
n = 3 * n + 1
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
def main():
|
||||
var best = 0
|
||||
var best_n = 1
|
||||
for n in range(1, 30):
|
||||
var s = steps(n)
|
||||
if s > best:
|
||||
best = s
|
||||
best_n = n
|
||||
print("longest below 30:", best_n, "with", best, "steps")
|
||||
print(steps(27))
|
||||
Reference in new issue
Block a user