about summary refs log tree commit diff stats
path: root/calc_position.py
blob: 1108ff15423ddb2956020c1d3168fa72dba73ee1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import re

with open("pi_million", "r") as f:
    text = f.read()

try:
    number = int(input("Search for: "))
except ValueError:
    print("Input has to be a number")
    exit()

match = re.search(rf"{number}", text)

if match:
    i = int(match.start(0)) + 1
else:
    print("Number could not be found")
    exit()

num_rows = 46
num_cols = 52

first_line = 36
first_page = 40 * 52

if i <= first_line:
    print("Page 3, Line 1, Position " + str(i))
    exit(0)

i -= first_line

if i <= first_page:
    line = i // num_cols + 2
    col = i % num_cols
    print("Page 3, Line " + str(line) + ", Position " + str(col))
    exit(0)

i -= first_page

page = i // (num_rows * num_cols) + 2
i -= (page - 2) * num_rows * num_cols

line = i // num_cols
col = i % num_cols

print("Page " + str(page + 2) + ", Line " + str(line) + ", Position " + str(col))