Skip to content

Instantly share code, notes, and snippets.

@arseniiv
Created December 27, 2023 18:59
Show Gist options
  • Select an option

  • Save arseniiv/361cb4b851ac340b761627f1b0b90afa to your computer and use it in GitHub Desktop.

Select an option

Save arseniiv/361cb4b851ac340b761627f1b0b90afa to your computer and use it in GitHub Desktop.
List intervals in various edo/edX scales that are close to each other
from collections import defaultdict
from dataclasses import dataclass
from fractions import Fraction
from itertools import pairwise
from typing import Final, Sequence
@dataclass
class EdIntervals:
ed_fractions: list[Fraction]
sources: dict[Fraction, list[int]]
def sorted_intervals(ed_sizes: Sequence[int]) -> EdIntervals:
# generate a single period without 0\N and N\N because trivial
ed_fractions = set()
sources = defaultdict(list)
for ed_size in ed_sizes:
for step_count in range(1, ed_size):
x = Fraction(step_count, ed_size)
ed_fractions.add(x)
sources[x].append(ed_size)
return EdIntervals(list(sorted(ed_fractions)), sources)
def print_confluences(data: EdIntervals, max_error: Fraction) -> None:
def cents(x: Fraction) -> str:
return f'{x * 1200 :.2f}¢'
def in_ed(x: Fraction, ed_size: int) -> str:
return f'{x * ed_size}\\{ed_size}'
def full_info(x: Fraction) -> str:
return f'{cents(x)} [{", ".join(in_ed(x, n)
for n in data.sources[x])}]'
for x1, x2 in pairwise(data.ed_fractions):
if (delta := x2 - x1) >= max_error:
continue
print(f'{full_info(x1)} is {cents(delta)} away from {full_info(x2)}')
def main() -> None:
CENT: Final = Fraction(1, 1200)
intervals = sorted_intervals([12, 17, 22, 24])
print_confluences(intervals, 10 * CENT)
if __name__ == '__main__':
main()
@arseniiv

Copy link
Copy Markdown
Author

P. S. Sorry this is all lies, this is all edX for X = 2 only because the cents are calculated with this in mind. Sorry I forgot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment