slovo/benchmarks/array-index-loop/python/array_index_loop.py
2026-05-22 08:38:43 +02:00

35 lines
695 B
Python

LOOP_COUNT = 1_000_000
EXPECTED_CHECKSUM = 3_875_007
DIGITS = [3, 1, 4, 1, 5, 9, 2, 6]
def configured_loop_count() -> int:
try:
value = int(input().strip())
except (EOFError, ValueError):
return LOOP_COUNT
return value if value > 0 else LOOP_COUNT
def array_index_loop(limit: int) -> int:
i = 0
acc = 7
while i < limit:
acc += DIGITS[i % 8]
acc = acc - 1_000_000_000 if acc > 1_000_000_000 else acc
i += 1
return acc
def main() -> int:
result = array_index_loop(configured_loop_count())
print(result)
return 0 if result == EXPECTED_CHECKSUM else 1
if __name__ == "__main__":
raise SystemExit(main())