Sunday, May 7, 2006

Akiba-online Forum Problem

Algoritmo per lo sviluppo di sistemi integrali per il Totocalcio

This is my first blog.
The idea of \u200b\u200bthis post comes from an innate passion for mathematics that I applied to gaming, such as the football pools, the Superenalotto or Lotto.
Here I propose an algorithm designed for the development of a comprehensive system for the pools.
So, let's see how the algorithm described above.
is basically defined the odds, in a direct way to determine what is the i-th column of integral development.
How To?
The idea is to use mathematics on the basic changes: the same that you use when you want to go the decimal number system to the binary, octal, hexadecimal, or any other.
Why this?
To explain this we consider a simple system of three double


1x 1x 1x


The development of this system is as follows:

1111xxxx
11xx11xx
1x1x1x1x

What would happen if we transform the 1 in 0 and x 1?
The development would take the following form:


00001111 00110011 01010101


read in vertical columns such as binary numbers, we see that the decimal system, they coincide with the numbers:

01234567

Quindi, per determinare la i-esima colonna del sistema ci basta trasformare il numero decimale i-1 in binario e modificare gli zeri in uno e gli uno in x.
Quanto detto ci fa comprendere meglio il legame dello sviluppo del sistema (di sole doppie) con l'aritmetica binaria.
Quella illustrata, però, è la situazione più semplice in cui il pronostico è omogeneo e costituito da tutte doppie.
Ma cosa accadrebbe nel caso in cui il pronostico non fosse più costituito da sole doppie? Questa è sicuramente una complicazione in quanto desideriamo passare ad un sistema di numerazione che non è più a base omogenea ma bensì based variable.
That obstacle, however, can easily be overcome by following the algorithm that we describe below.
To better describe this algorithm, we refer again to a concrete example.
To do this, consider the following system: 1



1x 1x 1x2


The development of this system is as follows:

111111111111
111111xxxxxx
11xx2211xx22
1x1x1x1x1x1x


000000000111
123456789012

The numbering system in which we should transform the numbers (from 0 to 11) will have the following basis:


1232 (each position is equal to the lengt of the prediction for that position)

Suppose you want to locate the sixth column (No. 5 numbers from 0 to 11) in such a numbering system.
Then proceed as follows:

dividing the number of column we want to determine the last element of the base:
5:2 = 2 with remainder 1

Divide the result by the penultimate element of the base :
2:3 = 0 with remainder 2

Divide the result by the second element of the base:
0:2 = 0 with remainder 0

dividing the result obtained for the first element of the base:
0:1 = 0 with remainder 0

Considering these ruins in reverse, we get the column:

0021

adding 1 to each position you would:

1132

Hence, by replacing the symbol of their predictions, we obtain the column:

112x

Then we saw that the function performs the following transformation:

5 -> 0021

Equivalent To:

6 -> 112x

Dec2Col Calling this function in C # it can essere scritta nel seguente modo:

string Dec2Col(int NCol, string Base)
{
int NPartite = Base.Length;
string Col="";

NCol--;
for (int i=NPartite-1; i>=0; i--)
{
Col = Pronostico[i].Substring(NCol % Convert.ToInt32(Base.Substring(i,1)), 1) + Col;
NCol /= Convert.ToInt32(Base.Substring(i,1));
}

return Col;
}

Quindi, lo sviluppo completo del sistema può essere effettuato eseguendo un ciclo che ad ogni passo richiama la suddetta funzione e ne stampa il risultato, come mostrato dal seguente codice:

/ / Build the system
for (int i = 1; the <=NCol; i++)
Console.WriteLine (Dec2Col (i, base));



Update

I would like to see that, of the merits of such an algorithm, there is undoubtedly that of its immediate parallelization.
In addition, further to the comment of Claudius, Below is the complete example code, released under GPL 3 License , I wrote in Visual Basic. :

Module Program
Dim Pronostico(13) As String

Sub Main()
Dim NCol As Long
Dim Base As String
Pronostico = new String(){"1", "1", "1x", "x", "1", "1", "1x2", "x", "1x2", "1", "x", "1", "1x", "1x2"}
NCol = 1 : Base = ""
For i=0 To Pronostico.Length - 1
NCol *= Pronostico(i).Length
Base += Pronostico(i).Length.ToString
Next
Console.WriteLine ("Columns to develop:" + NCol.ToString)
For i = 1 To NCol
Console.WriteLine (Dec2Col (i, Base ))
Next
Console.Write ("Press any key to continue...")
Console.ReadKey (True) End Sub
Dec2Col Function (NCol As Long, Base As String) As String Dim
nThis As Integer = Base.Length
Dim Col As String = ""
NCol -= 1
For i = nThis - 1 To 0 Step -1
Col = Mid ( Prediction (i) (Mod NCol Integer.Parse (Mid (Base, i + 1, 1))) + 1, 1) + Col
NCol = Int (NCol / (Integer.Parse (Mid (Base, i + 1, 1), 1)))
Next
Return Col End Function End Module



As well, the one written in C #:

using System;

namespace Totoche
{
class Program
{
static String [] Prediction;
public static void Main (string [] args) {int
NCol;
Base String = "";
Prediction = new String [] {" 1 "," 1 "," 1x "," x "," 1 "," 1 "," 1x2 "," x ", "1x2", "1", "x", "1", "1x", "1x2"};
NCol = 1;
for (int i=0; i
NCol *= Pronostico[i].Length;
Base += Pronostico[i].Length;
}
Console.WriteLine("Colonne da sviluppare: " + NCol);
// Sviluppa il sistema
for (int i=1; i <=NCol; i++)
Console.WriteLine(Dec2Col(i, Base));
Console.Write ("Press any key to continue...");
Console.ReadKey (true);}
public static String Dec2Col ( NCol int, String base) {int nThis
= Base.Length;
With String = "";

NCol -;
for (int i = nThis- 1, i> = 0; i -) {
Prediction = Col [i]. Substring (% NCol Convert.ToInt32 (Base.Substring (i, 1)), 1) + Col;
NCol / = Convert.ToInt32 (Base.Substring (i, 1));}

return Col;
}
}}




And that in Java :

Toto {public class
static String [] Prediction;
public static void main (String [] args) {Int
NCol;
Base String = "";
Prediction = new String [] {"1", "1", "1x", "x", "1", " 1 "," 1x2 "," x "," 1x2 "," 1 "," x "," 1 "," 1x "," 1x2 "};
NCol = 1;
for (int i = 0; the
NCol *= Prediction [i]. length ();
Base + = Prediction [i]. length ();}
System.out.println ("Movie to be developed: + NCol);
// Sviluppa il sistema
for (int i=1; i <=NCol; i++)
System.out.println(Dec2Col(i, Base));
System.out.println("Premi un tasto per continuare . . . ");
}
public static String Dec2Col(int NCol, String Base) {
int NPartite = Base.length();
String Col = "";

NCol--;
for (int i = nThis-1, i> = 0; i -) {
Prediction = Col [i]. Substring (NCol% Integer.parseInt (Base.substring (i , i +1)), (NCol% Integer.parseInt (Base.substring (i, i +1))) +1) + Col;
NCol / = Integer.parseInt (Base.substring (i, i +1));}

return Col;
}}

0 comments:

Post a Comment