Lottozahlen vorhersagen

E

Elric

Guest
Ich habe mal wieder ein Rätsel. Leider weiß ich zwar die Antworten, doch bis auf Brute-Force kenn ich keine exakte Lösungsmöglichkeit, die zum Erfolg führt. Wer kann helfen?

Hier das Rätsel:

Peter träumte wieder einmal vom großen Geld. Er stellte sich gerade vor, sechs richtige im Lotto zu haben, als es plötzlich hell aufblitzte. Eine Märchenfee stand vor ihm und sagte: "Du hast einen Wunsch frei."

Ohne zu zögern reichte Peter ihr ein Stück Papier und einen Stift. "Wie wär's, wenn du mir die Lottozahlen von nächster Woche hier aufnotierst?", meinte er. "Alle sechs Lottozahlen.", sagte die Fee erstaunt, "Das sind ja gleich sechs Wünsche auf einmal, also das geht nun wirklich nicht." Dennoch notierte die Fee eine Zahl auf dem Zettel und sagte: "Wenn du alle sechs Lottozahlen von nächster Woche zusammenaddierst, dann kommst du auf dieses Ergebnis!"

Peter sah sich die Zahl an und überlegte. "Oh Gott, da gibt es sicher tausende Möglichkeiten mit sechs verschiedenen Zahlen zwischen 1 und 49 auf diese Summe zu kommen", meinte er resigniert. "OK, ich geb' dir noch einen Tipp.", sagte die Fee, "Rechne doch mal genau aus, wieviele Möglichkeiten es gibt, die diese Summe ergeben. Wenn du das Ergebnis dann mit der Zahl malnimmst, die ich dir eben aufgeschrieben habe, dann erhältst du eine sehr große Zahl von einigen Millionen, und diese Zahl kommt auch raus, wenn man alle sechs Lottozahlen miteinander malnimmt."

Peter wollte sich gerade für den Tipp bedanken, als die Fee auch schon wieder verschwand. Nun begann er zu rechnen, und bei der nächsten Lottoziehung hatte er tatsächlich sechs Richtige. Welche sechs Zahlen wurden gezogen?
 
Müssten wir nicht erstmal wissen, welche Zahl die Fee überhaupt aufgeschrieben hat?

(Gut, theoretisch dürfte es wohl auch irgendwie ohne die Zahl gehen, aber es wäre auf jeden Fall bei weiten leichter.)
 
Also im Original geht es ja gerade darum, die Lottozahlen zu errechnen...

Aber wenn du sie unbedingt willst kann ich sie dir per PM schicken...
 
es geht Tribble ja imho nicht um die Zahlen, sondern um diese Summenzahl, die die Fee aufgeschrieben hat.
 
Wenn das so ist - die Summe ist 130.
Aber auch hier gilt, dass im Originalrätsel die Angabe nicht da war.
 
also wenn ich das richtig verstanden

(a + b + c + d + e + f) = z
ANZ(a + b + c + d + e + f = z) = y
(z * y) = (a * b * c * d * e * f)

So müsste es doch mathematisch sein, oder?

Würd ich auch mit purer Brutforce knacken, aber das könnte Tage oder Wochen dauern, schließlich gibt es 13,7 Lottokombinationen.
 
nagut, "Tage oder Wochen" war dann doch etwas übertrieben. ;)

VB.Net:
Code:
Option Strict On
Option Explicit On 

Public Class LottoZahlen
    Public Shared Sub Main()
        Dim myHT As New System.Collections.Hashtable
        Dim myHTValue As HTValue
        Dim mySum As Short
        Dim myLottoKombination As LottoKombination
        Dim myCount As Long

        For a As Short = 1 To 44
            For b As Short = (a + 1S) To 45
                For c As Short = (b + 1S) To 46
                    For d As Short = (c + 1S) To 47
                        For e As Short = (d + 1S) To 48
                            For f As Short = (e + 1S) To 49
                                mySum = a + b + c + d + e + f
                                If (myHT.ContainsKey(mySum)) Then
                                    myHTValue = CType(myHT(mySum), HTValue)
                                    myLottoKombination = New LottoKombination
                                    myLottoKombination.A = a
                                    myLottoKombination.B = b
                                    myLottoKombination.C = c
                                    myLottoKombination.D = d
                                    myLottoKombination.E = e
                                    myLottoKombination.F = f
                                    myHTValue.AddALItem(myLottoKombination)
                                    myHT(mySum) = myHTValue
                                Else
                                    myHTValue = New HTValue
                                    myLottoKombination = New LottoKombination
                                    myLottoKombination.A = a
                                    myLottoKombination.B = b
                                    myLottoKombination.C = c
                                    myLottoKombination.D = d
                                    myLottoKombination.E = e
                                    myLottoKombination.F = f
                                    myHTValue.AddALItem(myLottoKombination)
                                    myHT.Add(mySum, myHTValue)
                                End If
                            Next f
                        Next e
                    Next d
                Next c
            Next b
        Next a
        For Each myDE As System.Collections.DictionaryEntry In myHT
            myCount += myHTValue.ALCount
            mySum = CShort(myDE.Key)
            myHTValue = CType(myDE.Value, HTValue)
            For i As Integer = 0 To (myHTValue.ALCount - 1)
                myLottoKombination = myHTValue.ALItem(i)
                If ((CLng(mySum) * CLng(myHTValue.ALCount)) = (CLng(myLottoKombination.A) * _
                                                               CLng(myLottoKombination.B) * _
                                                               CLng(myLottoKombination.C) * _
                                                               CLng(myLottoKombination.D) * _
                                                               CLng(myLottoKombination.E) * _
                                                               CLng(myLottoKombination.F)) _
                   ) Then System.Console.WriteLine(myLottoKombination.A.ToString.PadLeft(2) & ", " & _
                                                   myLottoKombination.B.ToString.PadLeft(2) & ", " & _
                                                   myLottoKombination.C.ToString.PadLeft(2) & ", " & _
                                                   myLottoKombination.D.ToString.PadLeft(2) & ", " & _
                                                   myLottoKombination.E.ToString.PadLeft(2) & ", " & _
                                                   myLottoKombination.F.ToString.PadLeft(2) & _
                                                   " Sum: " & mySum.ToString.PadLeft(3) & _
                                                   " Count: " & myHTValue.ALCount.ToString.PadLeft(8))
            Next i
        Next myDE
        System.Console.WriteLine()
        System.Console.WriteLine("Combinations Count: " & myCount)
        System.Console.WriteLine()
        System.Console.WriteLine("The End.")
        System.Console.ReadLine()
    End Sub
End Class

Public Class HTValue
    Private mAL As System.Collections.ArrayList

    Public Sub New()
        Me.mAL = New System.Collections.ArrayList
    End Sub

    Public ReadOnly Property ALCount() As Integer
        Get
            Return Me.mAL.Count
        End Get
    End Property

    Public ReadOnly Property ALItem(ByVal pIndex As Integer) As LottoKombination
        Get
            Return CType(Me.mAL(pIndex), LottoKombination)
        End Get
    End Property

    Public Sub AddALItem(ByVal pLottoKombination As LottoKombination)
        Me.mAL.Add(pLottoKombination)
    End Sub
End Class

Public Class LottoKombination
    Private mA As Short
    Private mB As Short
    Private mC As Short
    Private mD As Short
    Private [mE] As Short
    Private mF As Short

    Public Property A() As Short
        Get
            Return Me.mA
        End Get
        Set(ByVal pValue As Short)
            Me.mA = pValue
        End Set
    End Property

    Public Property B() As Short
        Get
            Return Me.mB
        End Get
        Set(ByVal pValue As Short)
            Me.mB = pValue
        End Set
    End Property

    Public Property C() As Short
        Get
            Return Me.mC
        End Get
        Set(ByVal pValue As Short)
            Me.mC = pValue
        End Set
    End Property

    Public Property D() As Short
        Get
            Return Me.mD
        End Get
        Set(ByVal pValue As Short)
            Me.mD = pValue
        End Set
    End Property

    Public Property E() As Short
        Get
            Return Me.mE
        End Get
        Set(ByVal pValue As Short)
            Me.mE = pValue
        End Set
    End Property

    Public Property F() As Short
        Get
            Return Me.mF
        End Get
        Set(ByVal pValue As Short)
            Me.mF = pValue
        End Set
    End Property
End Class
Output:
Code:
 5,  8, 11, 26, 37, 43 Sum: 130 Count:   140008
 1,  4,  5,  7,  9, 19 Sum:  45 Count:      532
 1,  2,  3,  4, 11, 15 Sum:  36 Count:      110
 2,  8, 11, 14, 19, 22 Sum:  76 Count:    13552

Combinations Count: 13983426

The End.

Jeder der mag, kann es sich ja lebst kompilieren und ausführen. Dazu muss das Microsoft .NET Framwork 1.1 installiert sein ("Info ob" findet man in der Systemsteuerung unter Software). dann einfach den Code oben in eine Textdatei kopieren, die als "LottoZahlen.vb" abspeichern und so kompilieren:

Code:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\vbc.exe LottoZahlen.vb
Herauskommen tut dann eine LottoZahlen.exe, die man starten kann.
 
Mein Code ist etwas kürzer. Geschrieben wurde der für Perl, weil schneller und browserfrei, PHP sollte aber auch funktionieren - aber nur im Browser.
Leider bringt er mir andere Ergebnisse. Ich weiß nur nicht warum.

Code:
$chances = 49*48*47*46*45*44 / (1*2*3*4*5*6);
print "$chances Moeglichkeiten\n\n";
for ($a=1;$a<=44;$a++) {
   for ($b=$a+1;$b<=45;$b++) {
      for ($c=$b+1;$c<=46;$c++) {
         for ($d=$c+1;$d<=47;$d++) {
            for ($e=$d+1;$e<=48;$e++) {
               for ($f=$e+1;$f<=49;$f++) {
                  # print "$a $b $c $d $e $f\n";
                  $summe = $a+$b+$c+$d+$e+$f;
                  $produkt = $a*$b*$c*$d*$e*$f;
                  if ($produkt == $summe * $chances) {
                     print "$a $b $c $d $e $f = $summe\n";

                  }
                  $loop++;

               }
            }
         }
      }
   }
}
print "$loop Durchlaeufe\n";

Ergebnis:

13983816 Moeglichkeiten

21 40 42 44 46 47 = 240
22 35 42 46 47 48 = 240
22 36 40 46 47 49 = 240
23 32 44 45 47 49 = 240
23 33 40 47 48 49 = 240
24 30 44 46 47 49 = 240
13983816 Durchlaeufe
 
hier ein kurzer Bugfix, da die Methode, die Gesamtzahl der Kombinationen auszurechnen, fehlerhaft war (am Ergebnis ändert es aber nichts:

Code:
Option Strict On
Option Explicit On 

Public Class LottoZahlen
    Public Shared Sub Main()
        Dim myHT As New System.Collections.Hashtable
        Dim myHTValue As HTValue
        Dim mySum As System.Int16
        Dim myLottoKombination As LottoKombination
        Dim myCount As System.Int64

        For a As System.Int16 = 1 To 44
            For b As System.Int16 = (a + 1S) To 45
                For c As System.Int16 = (b + 1S) To 46
                    For d As System.Int16 = (c + 1S) To 47
                        For e As System.Int16 = (d + 1S) To 48
                            For f As System.Int16 = (e + 1S) To 49
                                mySum = a + b + c + d + e + f
                                If (myHT.ContainsKey(mySum)) Then
                                    myHTValue = CType(myHT(mySum), HTValue)
                                    myLottoKombination = New LottoKombination
                                    myLottoKombination.A = a
                                    myLottoKombination.B = b
                                    myLottoKombination.C = c
                                    myLottoKombination.D = d
                                    myLottoKombination.E = e
                                    myLottoKombination.F = f
                                    myHTValue.AddALItem(myLottoKombination)
                                    myHT(mySum) = myHTValue
                                Else
                                    myHTValue = New HTValue
                                    myLottoKombination = New LottoKombination
                                    myLottoKombination.A = a
                                    myLottoKombination.B = b
                                    myLottoKombination.C = c
                                    myLottoKombination.D = d
                                    myLottoKombination.E = e
                                    myLottoKombination.F = f
                                    myHTValue.AddALItem(myLottoKombination)
                                    myHT.Add(mySum, myHTValue)
                                End If
                            Next f
                        Next e
                    Next d
                Next c
            Next b
        Next a
        For Each myDE As System.Collections.DictionaryEntry In myHT
            mySum = System.Convert.ToInt16(myDE.Key)
            myHTValue = CType(myDE.Value, HTValue)
            myCount += myHTValue.ALCount
            For i As System.Int32 = 0 To (myHTValue.ALCount - 1)
                myLottoKombination = myHTValue.ALItem(i)
                If ((System.Convert.ToInt64(mySum) * System.Convert.ToInt64(myHTValue.ALCount)) = (System.Convert.ToInt64(myLottoKombination.A) * _
                                                                                                   System.Convert.ToInt64(myLottoKombination.B) * _
                                                                                                   System.Convert.ToInt64(myLottoKombination.C) * _
                                                                                                   System.Convert.ToInt64(myLottoKombination.D) * _
                                                                                                   System.Convert.ToInt64(myLottoKombination.E) * _
                                                                                                   System.Convert.ToInt64(myLottoKombination.F) _
                                                                                                  ) _
                   ) Then System.Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}, Sum: {6}, Count: {7}", myLottoKombination.A.ToString.PadLeft(2), _
                                                                                                         myLottoKombination.B.ToString.PadLeft(2), _
                                                                                                         myLottoKombination.C.ToString.PadLeft(2), _
                                                                                                         myLottoKombination.D.ToString.PadLeft(2), _
                                                                                                         myLottoKombination.E.ToString.PadLeft(2), _
                                                                                                         myLottoKombination.F.ToString.PadLeft(2), _
                                                                                                         mySum.ToString.PadLeft(3), _
                                                                                                         myHTValue.ALCount.ToString.PadLeft(8) _
                                                  )
            Next i
        Next myDE
        System.Console.WriteLine()
        System.Console.WriteLine("Combinations Count: " & myCount)
        System.Console.WriteLine()
        System.Console.WriteLine("The End.")
        System.Console.ReadLine()
    End Sub
End Class

Public Class HTValue
    Private mAL As New System.Collections.ArrayList

    Public ReadOnly Property ALCount() As System.Int32
        Get
            Return Me.mAL.Count
        End Get
    End Property

    Public ReadOnly Property ALItem(ByVal pIndex As System.Int32) As LottoKombination
        Get
            Return CType(Me.mAL(pIndex), LottoKombination)
        End Get
    End Property

    Public Function AddALItem(ByVal pLottoKombination As LottoKombination) As System.Int32
        Return Me.mAL.Add(pLottoKombination)
    End Function
End Class

Public Class LottoKombination
    Private mA As System.Int16
    Private mB As System.Int16
    Private mC As System.Int16
    Private mD As System.Int16
    Private [mE] As System.Int16
    Private mF As System.Int16

    Public Property A() As System.Int16
        Get
            Return Me.mA
        End Get
        Set(ByVal pValue As System.Int16)
            Me.mA = pValue
        End Set
    End Property

    Public Property B() As System.Int16
        Get
            Return Me.mB
        End Get
        Set(ByVal pValue As System.Int16)
            Me.mB = pValue
        End Set
    End Property

    Public Property C() As System.Int16
        Get
            Return Me.mC
        End Get
        Set(ByVal pValue As System.Int16)
            Me.mC = pValue
        End Set
    End Property

    Public Property D() As System.Int16
        Get
            Return Me.mD
        End Get
        Set(ByVal pValue As System.Int16)
            Me.mD = pValue
        End Set
    End Property

    Public Property E() As System.Int16
        Get
            Return Me.mE
        End Get
        Set(ByVal pValue As System.Int16)
            Me.mE = pValue
        End Set
    End Property

    Public Property F() As System.Int16
        Get
            Return Me.mF
        End Get
        Set(ByVal pValue As System.Int16)
            Me.mF = pValue
        End Set
    End Property
End Class
Ergebnis:
Code:
 5,  8, 11, 26, 37, 43, Sum: 130, Count:   140008
 1,  4,  5,  7,  9, 19, Sum:  45, Count:      532
 1,  2,  3,  4, 11, 15, Sum:  36, Count:      110
 2,  8, 11, 14, 19, 22, Sum:  76, Count:    13552

Combinations Count: 13983816

The End.
 
Respekt für die programmier-technische Leistung, aber haben wir keinen Mathe-Studenten hier, der den "klassischen" Lösungsweg finden kann?
 
hier ein kurzer Bugfix, da die Methode, die Gesamtzahl der Kombinationen auszurechnen, fehlerhaft war (am Ergebnis ändert es aber nichts:

Code:
Option Strict On
Option Explicit On 

Public Class LottoZahlen
    Public Shared Sub Main()
        Dim myHT As New System.Collections.Hashtable
        Dim myHTValue As HTValue
        Dim mySum As System.Int16
        Dim myLottoKombination As LottoKombination
        Dim myCount As System.Int64

        For a As System.Int16 = 1 To 44
            For b As System.Int16 = (a + 1S) To 45
                For c As System.Int16 = (b + 1S) To 46
                    For d As System.Int16 = (c + 1S) To 47
                        For e As System.Int16 = (d + 1S) To 48
                            For f As System.Int16 = (e + 1S) To 49
                                mySum = a + b + c + d + e + f
                                If (myHT.ContainsKey(mySum)) Then
                                    myHTValue = CType(myHT(mySum), HTValue)
                                    myLottoKombination = New LottoKombination
                                    myLottoKombination.A = a
                                    myLottoKombination.B = b
                                    myLottoKombination.C = c
                                    myLottoKombination.D = d
                                    myLottoKombination.E = e
                                    myLottoKombination.F = f
                                    myHTValue.AddALItem(myLottoKombination)
                                    myHT(mySum) = myHTValue
                                Else
                                    myHTValue = New HTValue
                                    myLottoKombination = New LottoKombination
                                    myLottoKombination.A = a
                                    myLottoKombination.B = b
                                    myLottoKombination.C = c
                                    myLottoKombination.D = d
                                    myLottoKombination.E = e
                                    myLottoKombination.F = f
                                    myHTValue.AddALItem(myLottoKombination)
                                    myHT.Add(mySum, myHTValue)
                                End If
                            Next f
                        Next e
                    Next d
                Next c
            Next b
        Next a
        For Each myDE As System.Collections.DictionaryEntry In myHT
            mySum = System.Convert.ToInt16(myDE.Key)
            myHTValue = CType(myDE.Value, HTValue)
            myCount += myHTValue.ALCount
            For i As System.Int32 = 0 To (myHTValue.ALCount - 1)
                myLottoKombination = myHTValue.ALItem(i)
                If ((System.Convert.ToInt64(mySum) * System.Convert.ToInt64(myHTValue.ALCount)) = (System.Convert.ToInt64(myLottoKombination.A) * _
                                                                                                   System.Convert.ToInt64(myLottoKombination.B) * _
                                                                                                   System.Convert.ToInt64(myLottoKombination.C) * _
                                                                                                   System.Convert.ToInt64(myLottoKombination.D) * _
                                                                                                   System.Convert.ToInt64(myLottoKombination.E) * _
                                                                                                   System.Convert.ToInt64(myLottoKombination.F) _
                                                                                                  ) _
                   ) Then System.Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}, Sum: {6}, Count: {7}", myLottoKombination.A.ToString.PadLeft(2), _
                                                                                                         myLottoKombination.B.ToString.PadLeft(2), _
                                                                                                         myLottoKombination.C.ToString.PadLeft(2), _
                                                                                                         myLottoKombination.D.ToString.PadLeft(2), _
                                                                                                         myLottoKombination.E.ToString.PadLeft(2), _
                                                                                                         myLottoKombination.F.ToString.PadLeft(2), _
                                                                                                         mySum.ToString.PadLeft(3), _
                                                                                                         myHTValue.ALCount.ToString.PadLeft(8) _
                                                  )
            Next i
        Next myDE
        System.Console.WriteLine()
        System.Console.WriteLine("Combinations Count: " & myCount)
        System.Console.WriteLine()
        System.Console.WriteLine("The End.")
        System.Console.ReadLine()
    End Sub
End Class

Public Class HTValue
    Private mAL As New System.Collections.ArrayList

    Public ReadOnly Property ALCount() As System.Int32
        Get
            Return Me.mAL.Count
        End Get
    End Property

    Public ReadOnly Property ALItem(ByVal pIndex As System.Int32) As LottoKombination
        Get
            Return CType(Me.mAL(pIndex), LottoKombination)
        End Get
    End Property

    Public Function AddALItem(ByVal pLottoKombination As LottoKombination) As System.Int32
        Return Me.mAL.Add(pLottoKombination)
    End Function
End Class

Public Class LottoKombination
    Private mA As System.Int16
    Private mB As System.Int16
    Private mC As System.Int16
    Private mD As System.Int16
    Private [mE] As System.Int16
    Private mF As System.Int16

    Public Property A() As System.Int16
        Get
            Return Me.mA
        End Get
        Set(ByVal pValue As System.Int16)
            Me.mA = pValue
        End Set
    End Property

    Public Property B() As System.Int16
        Get
            Return Me.mB
        End Get
        Set(ByVal pValue As System.Int16)
            Me.mB = pValue
        End Set
    End Property

    Public Property C() As System.Int16
        Get
            Return Me.mC
        End Get
        Set(ByVal pValue As System.Int16)
            Me.mC = pValue
        End Set
    End Property

    Public Property D() As System.Int16
        Get
            Return Me.mD
        End Get
        Set(ByVal pValue As System.Int16)
            Me.mD = pValue
        End Set
    End Property

    Public Property E() As System.Int16
        Get
            Return Me.mE
        End Get
        Set(ByVal pValue As System.Int16)
            Me.mE = pValue
        End Set
    End Property

    Public Property F() As System.Int16
        Get
            Return Me.mF
        End Get
        Set(ByVal pValue As System.Int16)
            Me.mF = pValue
        End Set
    End Property
End Class
Ergebnis:
Code:
 5,  8, 11, 26, 37, 43, Sum: 130, Count:   140008
 1,  4,  5,  7,  9, 19, Sum:  45, Count:      532
 1,  2,  3,  4, 11, 15, Sum:  36, Count:      110
 2,  8, 11, 14, 19, 22, Sum:  76, Count:    13552

Combinations Count: 13983816

The End.


Hey Doena, ich bin auf dein Code gestossen, ich bin auch gerade dabei etwas ähnliches allerdings für die EuroMillions Lottozahlenzu enwerfen und wollte ganz gerne nachfragen ob ich deinen Code nutzen dürfte?

Danke Sehr!!!!
Jennifer
 
Zurück
Oben