08-2a auch mit math.lcm()
This commit is contained in:
18
08/08-2a.py
18
08/08-2a.py
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user