08-2a auch mit math.lcm()

This commit is contained in:
2023-12-09 10:14:33 +01:00
parent 457a1d4c48
commit 2d3d4ba109
5 changed files with 218 additions and 5 deletions

View File

@@ -1,9 +1,8 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from time import time
from itertools import chain
import math
startzeit = time()
dic = {}
rl = ""
source = []
@@ -52,6 +51,15 @@ for s in source:
loops.append(counter)
print(loops)
# LCM von math Bibliothek
print()
print("Mit math.lcm()")
print("Kleinstes gemeinsames Vielfaches (Least Common Multiplier):", math.lcm(*loops))
# Eigene LCM-Funktion (Primfaktoren -> multiplizieren)
print()
print("Meine eigene lcm..")
teiler_liste = []
for n in loops:
li = []
@@ -64,14 +72,16 @@ for n in loops:
break
if not li:
teiler_liste.append(n)
print("erstmal alle Primfaktoren ermitteln")
print("Teiler-Liste:", teiler_liste)
unique_teiler = []
for teiler in teiler_liste:
if teiler not in unique_teiler:
unique_teiler.append(teiler)
print("ohne doppelte Einträge:", unique_teiler)
solution = 1
for tt in unique_teiler:
solution *= tt
print("Lösung:", solution)
print("alles multipliziert -> Lösung:", solution)