hello Tom !
first of all, thanks for spending time in reading the previous messy post.
Here is the goal for me with this stuff:
I'd like to improve the skill of my pupils in reading integer and decimal
numbers.
Among all the steps used to build this skill :
One of the steps to reach this goal is to make them able to read
factorization of these kind of numbers
and thus find the number itself.
That's why I need several adjustments, to built difficult or easy exercices
according to the abilities of the child.
example : from easy to very hard
Entier seul non mélangé: (1 * 1000) + (2 * 100) + (3 * 10) + (4 * 1)
Entier seul mélangé: (3 * 10) + (4 * 1) + (1 * 1000) + (2 * 100) the child
needs to re-order the factors before finding a solution. So it's more
difficult.
Entier seul shuffle et non mélangé: (12 * 100) + (3 * 10) + (4 * 1)
Entier seul shuffle et mélangé: (34 * 1) + (2 * 100) + (1 * 1000) the
factors are not always the same, so i increase the difficulties.
if i factorize decimal numbers with a decimal part not too long : 3 digits
after the point only... I increase one more time the difficulty.
Décimal non mélangé: (1234 * 1) + (5678 * 0.0001)
Décimal mélangé: (1234 * 1) + (5678 * 0.0001)
Décimal shuffle et non mélangé: (123 * 10) + (4 * 1) + (567 * 0.001) + (8 *
0.0001)
Décimal shuffle et mélangé: (12 * 100) + (56 * 0.01) + (78 * 0.0001) + (34 *
1)
So the software i would like to build looks like this one i did before
http://www.scalpa.net/decomposer.php and I want to improve it by adding
these adjustements and the possibility for me to print a sheet of this kind
of exercices taking account of these adjustements. All that in one shot !
################# I need help here###########################
So to make the soft able to do that : I think some improvements are missing
:
first : when i call the function : TextBox1.Text += ( Utility.Factorize(nb,
array4, True, False)) it works well.
but It could be better if i can build the array according of the lenght of
the number. I believe that the max of this array is equal of the lenght of
the integer part or the decimal part. So if i want to automate the creation
of the sheet of exercices, it's necessary to find a solution in this way.
I tried to find a solution by storing the lenghts of the integeer and of the
decimal part in the same array of Function GenNombre:
TabNbre(2) = tailleEntiere 'storing the length of each part to use it in
genArray
TabNbre(3) = tailleDecimale
but i was'nt able to get them in the code of form1
Thus : how to recover these informations in genArray from the form1 ?
Utility.Factorize(nb, Utility.GenArray(???), True, False))
i think (???) must be an array built with TabNbre(2) and TabNbre(3) . It's
here where i am lost....
#######################################################
Now for the modification of the code :
the purpose of melange method is to mix the array so Children is not always
in front of the same order 10^3*10^2*10^1*10^0 like this :
(1 * 1000) + (2 * 100) + (3 * 10) + (4 * 1) but he can have to read also
this : (3 * 10) + (2 * 100) +(4 * 1) + (1 * 1000) that is more difficult .
So I tried to make it simple and use the utility.factorize function with
some variations as you can see under : I though about using a double for
decimal number but building an array of its factorisation with positive an
negative power of ten, and taking account of the decimal point, did'nt
appear so simple....
It works like that, and i tried to keep it simple ! As you said.
"It looks like you've gone a bit overboard on the ".Net isms" as well. What
is the point of implementing Systems.Collections.IComparer, is there a
collection here somewhere? You can compare things without implementing
IComparer." => I let some pieces of code ..... No needs of it for sure
......Oops..
I add some informations in english and modified some others from yours :
Public Class Utility
Inherits Object
' this is a random number generator and is used by the Shuffle() method
' you can reference it from your code any time you need a random number
' using it in other places will effectively have zero impact on the
Shuffle() method
Public Shared RndGen As System.Random = New System.Random
Public Shared Function GenArray(ByVal max As Integer) As Integer()
' returns an Integer array with max elements
' each element is initialized with a value equal to it's element number()
' so GenArray(3) will return {0, 1, 2}
' obviously you can create such an array without GenArray() but this can be
a bit easier
' the GenArray() method can be called on for any purpose and can
easily(generate)
' a 52-element array representing (for instance) a deck of cards (see:
Shuffle)
Dim Result(max - 1) As Integer
For i As Integer = 0 To (Result.Length - 1)
Result(i) = i
Next
Return Result
End Function
Public Shared Function Shuffle(ByVal order As Integer()) As Integer()
' returns an Integer array passed to it as order after shuffling the
elements()
' the Shuffle() method can shuffle any Integer array (for any purpose) and
can easily
' shuffle a 52-element array representing (for instance) a deck of cards
(see: GenArray)
' please note that Shuffle() need only be called once (an array is shuffled
or it isn't)
' there is nothing to be gained by shuffling twice
Dim rnd As Integer
Dim val As Integer
Dim max As Integer = (order.Length - 1)
For i As Integer = 0 To max
val = order(i)
rnd = RndGen.Next(0, max + 1)
order(i) = order(rnd)
order(rnd) = val
Next
Return order
End Function
Public Shared Function melange(ByVal MonTAb As String()) As String()
'i had this here to have the hability to increase the skill of my pupils in
reading and calculating such factorization
'without that, the factors are always arranged from larger to smaller like
this :
'123456,7689 could be returned as: (123 * 1000) + (456 * 1) + (76 * 0.01)
+( 89 * 0.0001)
'and with that melange we can have : ( 689 * 0.0001) + (6 * 1) + (5 * 10) +
(7 * 0.1) + (1234 * 100)
Dim rnd As Integer
Dim val As String
Dim max As Integer = (MonTAb.Length - 1)
For i As Integer = 0 To max
val = MonTAb(i)
rnd = RndGen.Next(0, max + 1)
MonTAb(i) = MonTAb(rnd)
MonTAb(rnd) = val
Next
Return MonTAb
End Function
Public Shared Function GenNombre(ByVal low As Long, ByVal high As Long) As
Long()
'creates a random decimal number with never more than 3 digits after the
comma
'between low and high and adds 1 so that the upper limit is included.
'split this number in two pieces to handle both the positive and the
negative factorization later because that is not the same "treatment" for
each part
Randomize()
Dim PartieEntiere As Long = 0
Dim PartieDecimale As Long = 0
Dim NbreTire As Double = 0
Do
NbreTire = Math.Round(RndGen.Next(low, high) + RndGen.NextDouble(), 3)
Loop Until NbreTire > 0
PartieEntiere = Int(NbreTire)
PartieDecimale = CLng(Mid$(CStr(NbreTire), InStr(CStr(NbreTire) & ".", ".")
+ 1))
Dim tailleEntiere As Integer = Len(PartieEntiere)
Dim tailleDecimale As Integer = Len(PartieDecimale)
Dim TabNbre(1) As Long 'store the two pieces in an array
TabNbre(0) = PartieEntiere
TabNbre(1) = PartieDecimale
Return TabNbre
End Function
Public Shared Function Factorize(ByVal TabNbre As Long(), ByVal order As
Integer(), Optional ByVal EntierSeul As Boolean = True, Optional ByVal
melanger As Boolean = False) As String
' Factorize returns a string that represents the value passed as TabNbre()
in the form of an
' equation made up of factors of 10 positive or negative
' 123456,7689 could be returned as: (123 * 1000) + (456 * 1) + (76 * 0.01)
+( 89 * 0.0001)
' or 123456 could be returned as: (1234 * 100) + (5 * 10) + (6 * 1) + (7 *
0.1) +( 689 * 0.0001)
' the format is controlled by an integer array named order
Dim LeNbre(1) As Long 'keep the random number in an array of two elements
TabNbre.CopyTo(LeNbre, 0)
Dim Montableau(order.Length - 1) As String 'declaration of an array which
will be used as storage for the possible mixture ("melange")
Dim Result As String = ""
'The integer part is treated
Dim resEnt(order.Length - 1) As Long
order.CopyTo(resEnt, 0)
Dim divEnt(order.Length - 1) As Long
order.CopyTo(divEnt, 0)
Dim balEnt As Long = LeNbre(0) 'the first element is the integer part
For i As Integer = 0 To (order.Length - 1) 'one factorizes with positive
power of ten according to table "order"
Dim val As Integer = order(i)
divEnt(val) = CLng(10 ^ val)
resEnt(val) = (balEnt \ divEnt(val))
balEnt -= (divEnt(val) * resEnt(val))
Next
For i As Integer = (order.Length - 1) To 0 Step -1
If (resEnt(i) > 0) Then
If (Result.Length > 0) Then Result += " + "
Result += "(" + resEnt(i).ToString + " * " + divEnt(i).ToString + ")" 'one
stores for printing on screen
Montableau(i) = "(" + resEnt(i).ToString + " * " + divEnt(i).ToString + ")"
'one stores for "melanging"
End If
Next
'The decimal part is treated if needed...
'I keep the lengh of this array to redim preserve later to keep the
information of the integer part
Dim z As Integer = Montableau.Length
If EntierSeul = False Then
Dim resDeci(order.Length - 1) As Integer
order.CopyTo(resDeci, 0)
Dim div(order.Length - 1) As Single
order.CopyTo(div, 0)
Dim balDeci As Integer = LeNbre(1) 'the second element is the decimal part
For i As Integer = 0 To (order.Length - 1) 'one factorizes with positive
power of ten according to table "order"
Dim val As Integer = order(i)
div(val) = (10 ^ -(order.Length - val)) 'negative power of ten this time
resDeci(val) = (Int(balDeci \ (10 ^ val)))
balDeci -= ((10 ^ val) * resDeci(val))
Next
For i As Integer = (order.Length - 1) To 0 Step -1
If (resDeci(i) > 0) Then
If (Result.Length > 0) Then Result += " + "
Result += "(" + resDeci(i).ToString + " * " + div(i).ToString + ")" 'i store
the result for showing on screen
ReDim Preserve Montableau(z + order.Length - 1)
Montableau(i + z - 1) = "(" + resDeci(i).ToString + " * " + div(i).ToString
+ ")" 'i store the result for mixing before showing on screen
End If
Next
End If ' fin EntierSeul
'Lastly, mix the result if necessary.
If melanger = True Then
Result = "" 'the result is emptied.
melange(Montableau) ' I mix
For i As Integer = (Montableau.Length - 1) To 0 Step -1
If (Montableau(i) <> "") Then Result += Montableau(i) + " + " 'and one
replaces it by the contents of the mixed array
Next
Result = Mid$(Result, 1, Len(Result) - 3) 'I remove the last +, added here
because of the loop, but don't needed
End If
Return Result
End Function
End Class
I will post this from school.
I hope it's clearer.
pascal