Initial Commit
This commit is contained in:
+69
@@ -0,0 +1,69 @@
|
|||||||
|
#!~/.pyenv/versions/3.12.9/bin/python
|
||||||
|
#
|
||||||
|
# Copyright (c) 2024 Cutieguwu | Olivia Brooks
|
||||||
|
#
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Title: binder-calculator
|
||||||
|
# @Author: Cutieguwu | Olivia Brooks
|
||||||
|
# @Description: Calculates ranges of optical disc binders.
|
||||||
|
#
|
||||||
|
# @Script: main.py
|
||||||
|
# @Date Created: 22 Mar, 2024
|
||||||
|
# @Last Modified: 22 Mar, 2024
|
||||||
|
# @Last Modified by: Cutieguwu | Olivia Brooks
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Domain:
|
||||||
|
_start: int
|
||||||
|
_end: int
|
||||||
|
|
||||||
|
def get_start(self) -> int:
|
||||||
|
return self._start
|
||||||
|
|
||||||
|
def get_end(self) -> int:
|
||||||
|
return self._end
|
||||||
|
|
||||||
|
def get_range(self) -> tuple[int, int]:
|
||||||
|
return (self.get_start(), self.get_end())
|
||||||
|
|
||||||
|
|
||||||
|
class Calculator:
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.BINDER_SIZE: int = 128
|
||||||
|
|
||||||
|
def calculate_domain(self, index: int) -> Domain:
|
||||||
|
return Domain(
|
||||||
|
self.calc_start(index),
|
||||||
|
self.calc_end(index)
|
||||||
|
)
|
||||||
|
|
||||||
|
def calc_start(self, index: int) -> int:
|
||||||
|
return ((index - 1) * self.BINDER_SIZE) + 1
|
||||||
|
|
||||||
|
def calc_end(self, index: int) -> int:
|
||||||
|
return (index * self.BINDER_SIZE)
|
||||||
|
|
||||||
|
def fmt_for_register(number: int, max_int_len: int) -> str:
|
||||||
|
x = str(number)
|
||||||
|
y = str('0' * (max_int_len - x.__len__()))
|
||||||
|
|
||||||
|
return y + x # this is what I'd expect y.join(x) to do... but no.
|
||||||
|
|
||||||
|
binders_total: int = 10
|
||||||
|
binder_index: int = 0
|
||||||
|
max_int_len: int = str(Calculator().calc_end(binders_total)).__len__()
|
||||||
|
|
||||||
|
calculator = Calculator()
|
||||||
|
|
||||||
|
while binder_index < binders_total:
|
||||||
|
binder_index += 1
|
||||||
|
|
||||||
|
domain: Domain = calculator.calculate_domain(binder_index)
|
||||||
|
start: str = fmt_for_register(domain.get_start(), max_int_len)
|
||||||
|
end: str = fmt_for_register(domain.get_end(), max_int_len)
|
||||||
|
|
||||||
|
print(f"Binder {binder_index}: {start} - {end}")
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#!~/.pyenv/versions/3.12.9/bin/python
|
||||||
|
#
|
||||||
|
# Copyright (c) 2024 Cutieguwu | Olivia Brooks
|
||||||
|
#
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# @Title: binder-calculator
|
||||||
|
# @Author: Cutieguwu | Olivia Brooks
|
||||||
|
# @Description: Calculates ranges of optical disc binders.
|
||||||
|
#
|
||||||
|
# @Script: main_alt.py
|
||||||
|
# @Date Created: 23 Mar, 2024
|
||||||
|
# @Last Modified: 23 Mar, 2024
|
||||||
|
# @Last Modified by: Cutieguwu | Olivia Brooks
|
||||||
|
# --------------------------------------------
|
||||||
|
|
||||||
|
BINDER_SIZE: int = 128
|
||||||
|
BINDERS_TOTAL: int = 10
|
||||||
|
MAX_INT_LEN: int = str(BINDERS_TOTAL * BINDER_SIZE).__len__()
|
||||||
|
|
||||||
|
def fmt_for_register(number: int) -> str:
|
||||||
|
x = str(number)
|
||||||
|
y = str('0' * (MAX_INT_LEN - x.__len__()))
|
||||||
|
|
||||||
|
return y + x # this is what I'd expect y.join(x) to do... but no.
|
||||||
|
|
||||||
|
|
||||||
|
binder_index: int = 0
|
||||||
|
end: str = '0'
|
||||||
|
|
||||||
|
while binder_index < BINDERS_TOTAL:
|
||||||
|
start: str = fmt_for_register(int(end) + 1)
|
||||||
|
|
||||||
|
binder_index += 1
|
||||||
|
|
||||||
|
end = fmt_for_register(binder_index * BINDER_SIZE)
|
||||||
|
|
||||||
|
print(f"Binder {binder_index}: {start} - {end}")
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user