DeaD_EyE

Frontplatten

Sep 21st, 2021 (edited)
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 0 0
  1. import itertools
  2.  
  3.  
  4. FRONTPLATTEN = (5, 3, 7, 8, 12, 24)
  5.  
  6. def f_kombi(platz):
  7.     multiplikatoren = [list(range(0, platz // m + 1)) for m in FRONTPLATTEN]
  8.     for multi in itertools.product(*multiplikatoren):
  9.         if sum(f * m for f, m in zip(FRONTPLATTEN, multi)) == platz:
  10.             yield multi
  11.  
  12.  
  13. def ausgabe(platz, ergebnisse=None):
  14.     vers = 16
  15.     iterator = f_kombi(platz)
  16.     if ergebnisse is not None:
  17.         iterator = itertools.islice(f_kombi(platz), 0, ergebnisse)
  18.     for multi in iterator:
  19.         print("Frontplatten".ljust(vers) + ":", " | ".join(f"{f:>2d}" for f in FRONTPLATTEN))
  20.         print("-" * 12, " " * 6, " | ".join("  " for _ in range(len(FRONTPLATTEN))),sep="")
  21.         print("Anzahl".ljust(vers) + ":", " | ".join(f"{m:>2d}" if m != 0 else "  " for m in multi))
  22.         s = tuple(f * m for f, m in zip(FRONTPLATTEN, multi))
  23.         s = " | ".join(f"{ss:>2d}" if ss != 0 else "  " for ss in s)
  24.         print(f"{'Produkte':<{vers}}: {s} => {platz}", end="\n\n\n")
  25.        
  26.     print("Ich hab zuviel CDL getrunken")
  27.  
  28.  
  29. # Frontplatten    :  5 |  3 |  7 |  8 | 12 | 24
  30. # ------------         |    |    |    |    |  
  31. # Anzahl          :    |  1 |  1 |    |    |  
  32. # Produkte        :    |  3 |  7 |    |    |    => 10
  33.  
  34.  
  35. # Frontplatten    :  5 |  3 |  7 |  8 | 12 | 24
  36. # ------------         |    |    |    |    |  
  37. # Anzahl          :  2 |    |    |    |    |  
  38. # Produkte        : 10 |    |    |    |    |    => 10
  39.  
  40.  
  41. # Ich hab zuviel CDL getrunken
Add Comment
Please, Sign In to add comment