Module 13: Points and Spans (Python code)

This commit is contained in:
David Doblas Jiménez 2021-08-09 18:38:53 +02:00
parent fe2d2e391f
commit 68cbfe9663
1 changed files with 38 additions and 5 deletions

43
a.py
View File

@ -1,6 +1,27 @@
def ToUpper(s):
return s.upper()
## ----------------------------------------------------------------------------
##-Point
class Point:
def __init__(self, r=0, c=0):
self.row = r
self.col = c
def __str__(self):
return f'({self.row},{self.col})'
## ----------------------------------------------------------------------------
##-Span
class Span:
def __init__(self, p, l, v):
self.point = p
self.len = l
self.vert = v
def __str__(self):
return f'[{self.point} len={self.len} vert={self.vert}]'
## ----------------------------------------------------------------------------
##-Words
@ -50,6 +71,8 @@ class Library:
def CreatePatternHash(self, w):
len_w = len(w)
if len_w > 7:
return
num_patterns = 1 << len_w
# print(f"PATTERN HASH on {w}")
self.word_map_[w] = []
@ -112,9 +135,19 @@ if __name__ == "__main__":
lib = Library()
lib.ReadFromFile("top_12000.txt")
lib.FindWord("D--")
grid = Grid("MY GRID")
grid.LoadFromFile("test")
grid.Check()
grid.Print()
# grid = Grid("MY GRID")
# grid.LoadFromFile("test")
# grid.Check()
# grid.Print()
p1 = Point()
p2 = Point(2, 1)
print(f"Point1 is {p1}")
print(f"Point2 is {p2}")
s1 = Span(p1, 3, True)
s2 = Span(p2, 5, False)
print(f"Span1 is {s1}")
print(f"Span2 is {s2}")