Lecture 2

This commit is contained in:
Oliver Hofmann
2024-04-11 11:18:58 +02:00
parent 74f4161fe7
commit 2bf815757f
3 changed files with 58 additions and 1 deletions
+10
View File
@@ -328,3 +328,13 @@ def read_int_sequence(filename: str) -> AlgoDatArray:
for i in range(len(l)):
a[i].value = l[i]
return a
def read_int_sequence_limited(filename: str, limit: int) -> AlgoDatArray:
"""Reads a sequence of integers from a file and returns an AlgoDatArray object."""
with open(filename, "r") as file:
l = list(map(int, file.read().split()))
size = min(len(l), limit)
a = AlgoDatArray(size)
for i in range(size):
a[i].value = l[i]
return a