Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
- #AutoIt3Wrapper_Compression=4
- #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
- #NoTrayIcon
- #include <IE.au3>
- #include <ButtonConstants.au3>
- #include <EditConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <WindowsConstants.au3>
- $IE = _IECreateEmbedded()
- If $IE = 0 Then
- MsgBox(16, "Errore", "Impossibile inizializzare IE.")
- Exit 1
- EndIf
- $FormTitle = "Scompositore - GianluTB"
- $Form1 = GUICreate($FormTitle, 465, 97, 192, 124)
- $Form_NumberInput = GUICtrlCreateInput("", 8, 8, 449, 21, BitOR($ES_CENTER, $ES_NUMBER))
- $Form_Scomponi = GUICtrlCreateButton("Scomponi", 8, 40, 75, 25)
- $Form_IEObject = GUICtrlCreateObj($IE, 90, 35, 350, 50)
- GUISetState(@SW_SHOW)
- $ScomponiStato = True
- While 1
- If Int(GUICtrlRead($Form_NumberInput)) > 0 And $ScomponiStato = False Then
- GUICtrlSetState($Form_Scomponi, $GUI_ENABLE)
- $ScomponiStato = True
- ElseIf Int(GUICtrlRead($Form_NumberInput)) < 1 And $ScomponiStato = True Then
- GUICtrlSetState($Form_Scomponi, $GUI_DISABLE)
- $ScomponiStato = False
- EndIf
- $nMsg = GUIGetMsg()
- Switch $nMsg
- Case $GUI_EVENT_CLOSE
- Exit
- Case $Form_NumberInput
- Case $Form_Scomponi
- $n = GUICtrlRead($Form_NumberInput)
- If $n > 0 Then
- ; Salvo in $NS l'array con il numero scomposto..
- $ns = Scomponi($n)
- ; elimino la vecchia scomposizione
- FileDelete(@TempDir & "\r.htm")
- ; la scrivo in r.htm
- FileWrite(@TempDir & "\r.htm", MakeString($ns))
- ; la visualizzo con iexplore..
- _IENavigate($IE, @TempDir & "\r.htm", 0)
- ; setto il focus sull'input per velocizzare :)
- ControlFocus($FormTitle, "", $Form_NumberInput)
- Else
- MsgBox(48, "Errore", "Inserisci un numero valido!")
- EndIf
- EndSwitch
- WEnd
- Func MakeString($numeroscomposto)
- ; da un array bidimensionale, prepara una stringa
- ; in html per visualizzare la scomposizione..
- $string = ""
- For $i = 0 To UBound($numeroscomposto) - 1
- $string &= $numeroscomposto[$i][0] & "<sup>" & $numeroscomposto[$i][1] & "</sup>"
- If $i < UBound($numeroscomposto) - 1 Then $string &= " * "
- Next
- Return $string
- EndFunc ;==>MakeString
- Func Scomponi($n)
- Dim $r[1][2]
- $numero = $n
- $divisore = 2
- While True
- If Mod($numero, $divisore) == 0 Then
- $added = False
- For $i = 0 To UBound($r)-1
- If $r[$i][0] = $divisore Then
- $r[$i][1] += 1
- $added = True
- EndIf
- Next
- If $added = False Then
- ReDim $r[UBound($r)+1][2]
- $r[UBound($r)-1][0] = $divisore
- $r[UBound($r)-1][1] = 1
- EndIf
- $numero /= $divisore
- Else
- $divisore = nextPrime($divisore)
- EndIf
- If $numero = 1 Then
- ExitLoop
- EndIf
- WEnd
- _ArrayDelete($r,0)
- Return $r
- EndFunc
- Func isPrime($n)
- For $i = 1 To $n
- If Mod($n,$i) == 0 Then
- If $i <> 1 And $i <> $n Then
- Return False
- EndIf
- EndIf
- Next
- Return True
- EndFunc
- Func nextPrime($n)
- $i = $n
- While True
- $i += 1
- If isPrime($i) Then
- Return $i
- EndIf
- WEnd
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement