-
Notifications
You must be signed in to change notification settings - Fork 0
/
numbers_base.py
46 lines (40 loc) · 1.3 KB
/
numbers_base.py
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
from typing import Optional, Set
class NumbersBase:
TOTAL_MAIN_NUMBERS = 5
TOTAL_LUCKY_NUMBERS = 2
MAIN_NUMBERS = 50
LUCKY_NUMBERS = 12
main_numbers: set
lucky_numbers: set
@staticmethod
def repr_formatter(numbers: Set[int]) -> str:
"""
Handles the formatting of the numbers for the repr.
:param numbers: The lotto numbers
:return: A cleaned string
"""
return str(numbers) if numbers else "{}"
@staticmethod
def clean_set(numbers_drawn: Optional[Set[int]] = None) -> Set[int]:
"""
To create a new set as they are mutable and we want to add incrementally
:param numbers_drawn: The number drawn from the bowl
:return: A new set
"""
if not numbers_drawn:
return set()
else:
return numbers_drawn
def __eq__(self, other) -> int:
"""
An attempt to compare the tickets
:param other: The other ticket
:return: True is the tickets are the same
"""
h1 = hash(f"{sorted(list(self.main_numbers))}") + hash(
f"{sorted(list(self.lucky_numbers))}"
)
h2 = hash(f"{sorted(list(other.main_numbers))}") + hash(
f"{sorted(list(other.lucky_numbers))}"
)
return h1 == h2