Jump to content

Geting the Radical of a number?


mmavipc
 Share

Recommended Posts

I know how to do this with a pencil and paper but how do I do it in autoit?

http://en.wikipedia.org/wiki/Radical_of_an_integer

for example

504 = 2^3 * 3^2 * 7

and Rad(504) = 2 * 3 * 7 = 42

[size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N

Link to comment
Share on other sites

try this

MsgBox(0, '', Radical(504))

Func Radical($Rad)
    Local $ToMul, $Splitted
    Local $Start = 1
    If $Rad = 0 Then
        Return 0
    EndIf
    
    For $x = 2 To 11
        Do
            If Not IsFloat(Execute('$Rad / $x')) Then
                $Rad = Execute('$Rad / $x')
                If Not StringInStr($ToMul, $x) Then
                    $ToMul = $ToMul & $x
                EndIf
            EndIf
        Until IsFloat(Execute('$Rad / $x'))
    Next
    $Splitted = StringSplit($ToMul, '')

    For $i = 1 To UBound($Splitted) - 1
        $Start = Number($Start) * Number($Splitted[$i])
    Next
    Return $Start
EndFunc  ;==>Radical
Link to comment
Share on other sites

try this

MsgBox(0, '', Radical(504))

Func Radical($Rad)
    Local $ToMul, $Splitted
    Local $Start = 1
    If $Rad = 0 Then
        Return 0
    EndIf
    
    For $x = 2 To 11
        Do
            If Not IsFloat(Execute('$Rad / $x')) Then
                $Rad = Execute('$Rad / $x')
                If Not StringInStr($ToMul, $x) Then
                    $ToMul = $ToMul & $x
                EndIf
            EndIf
        Until IsFloat(Execute('$Rad / $x'))
    Next
    $Splitted = StringSplit($ToMul, '')

    For $i = 1 To UBound($Splitted) - 1
        $Start = Number($Start) * Number($Splitted[$i])
    Next
    Return $Start
EndFunc ;==>Radical
thank you. With a few modifications to your code it now works great

my code

Func R($Rad)
    if isprime($rad) Then
        return $rad
    EndIf
    Local $ToMul, $Splitted
    Local $Start = 1
    If $Rad = 0 Then
        Return 0
    EndIf
    
    For $x = 2 To 11
        Do
            If Not IsFloat(Execute('$Rad / $x')) Then
                $Rad = Execute('$Rad / $x')
                If Not StringInStr($ToMul, $x) Then
                    $ToMul = $ToMul & $x
                EndIf
            EndIf
        Until IsFloat(Execute('$Rad / $x'))
    Next
    $Splitted = StringSplit($ToMul, '')

    For $i = 1 To UBound($Splitted) - 1
        $Start = Number($Start) * Number($Splitted[$i])
    Next
    Return $Start
EndFunc  ;==>Radical
func isprime($int)
    dim $np = True
    for $i = 2 to 9
        $d = $int / $i
        if $i <> $int and IsInt($d) Then
            $np = False
            ExitLoop
        EndIf
    Next
    return $np
EndFunc

[size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N

Link to comment
Share on other sites

this version should not has problem:

MsgBox(0, '', Radical(7))

Func Radical($Rad)
    Local $ToMul, $Splitted
    Local $Start = 1
    If $Rad = 0 Or 11 Or 13 Or 15 Or 17 Or 19 Then
            Return $Rad
    EndIf

    For $x = 2 To 19
        Do
            If Not IsFloat(Execute('$Rad / $x')) Then
                $Rad = Execute('$Rad / $x')
                If Not StringInStr($ToMul, $x) Then
                    $ToMul = $ToMul & $x
                EndIf
            EndIf
        Until IsFloat(Execute('$Rad / $x'))
    Next
    $Splitted = StringSplit($ToMul, '')

    For $i = 1 To UBound($Splitted) - 1
        $Start = Number($Start) * Number($Splitted[$i])
    Next
    Return $Start
EndFunc  ;==>Radical
Link to comment
Share on other sites

this version should not has problem:

MsgBox(0, '', Radical(7))

Func Radical($Rad)
    Local $ToMul, $Splitted
    Local $Start = 1
    If $Rad = 0 Or 11 Or 13 Or 15 Or 17 Or 19 Then
            Return $Rad
    EndIf

    For $x = 2 To 19
        Do
            If Not IsFloat(Execute('$Rad / $x')) Then
                $Rad = Execute('$Rad / $x')
                If Not StringInStr($ToMul, $x) Then
                    $ToMul = $ToMul & $x
                EndIf
            EndIf
        Until IsFloat(Execute('$Rad / $x'))
    Next
    $Splitted = StringSplit($ToMul, '')

    For $i = 1 To UBound($Splitted) - 1
        $Start = Number($Start) * Number($Splitted[$i])
    Next
    Return $Start
EndFunc ;==>Radical
try running this

MsgBox(0, '', Radical(4))

Func Radical($Rad)
    Local $ToMul, $Splitted
    Local $Start = 1
    If $Rad = 0 Or 11 Or 13 Or 15 Or 17 Or 19 Then
            Return $Rad
    EndIf

    For $x = 2 To 19
        Do
            If Not IsFloat(Execute('$Rad / $x')) Then
                $Rad = Execute('$Rad / $x')
                If Not StringInStr($ToMul, $x) Then
                    $ToMul = $ToMul & $x
                EndIf
            EndIf
        Until IsFloat(Execute('$Rad / $x'))
    Next
    $Splitted = StringSplit($ToMul, '')

    For $i = 1 To UBound($Splitted) - 1
        $Start = Number($Start) * Number($Splitted[$i])
    Next
    Return $Start
EndFunc  ;==>Radical
i get 4 i shoudl get 2

and running my previous code for getting the radical of 39 instead of getting 39(3*13) as expected i get 3

[size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N

Link to comment
Share on other sites

Func Radical($Rad)
    Local $ToMul, $Splitted
    Local $Start = 1
    If $Rad = 0 Or $Rad = 11 Or $Rad = 13 Or $Rad = 15 Or $Rad = 17 Or $Rad = 19 Then
            Return $Rad
    EndIf

    For $x = 2 To 19
        Do
            If Not IsFloat(Execute('$Rad / $x')) Then
                $Rad = Execute('$Rad / $x')
                If Not StringInStr($ToMul, $x) Then
                    $ToMul = $ToMul & $x
                EndIf
            EndIf
        Until IsFloat(Execute('$Rad / $x'))
    Next
    $Splitted = StringSplit($ToMul, '')

    For $i = 1 To UBound($Splitted) - 1
        $Start = Number($Start) * Number($Splitted[$i])
    Next
    Return $Start
EndFunc

Link to comment
Share on other sites

Func Radical($Rad)
    Local $ToMul, $Splitted
    Local $Start = 1
    If $Rad = 0 Or $Rad = 11 Or $Rad = 13 Or $Rad = 15 Or $Rad = 17 Or $Rad = 19 Then
            Return $Rad
    EndIf

    For $x = 2 To 19
        Do
            If Not IsFloat(Execute('$Rad / $x')) Then
                $Rad = Execute('$Rad / $x')
                If Not StringInStr($ToMul, $x) Then
                    $ToMul = $ToMul & $x
                EndIf
            EndIf
        Until IsFloat(Execute('$Rad / $x'))
    Next
    $Splitted = StringSplit($ToMul, '')

    For $i = 1 To UBound($Splitted) - 1
        $Start = Number($Start) * Number($Splitted[$i])
    Next
    Return $Start
EndFunc
your code doesn't work either

try MsgBox(0, '', radical(39)) expected 39(13*3) got 9

[size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N

Link to comment
Share on other sites

Hi,

here my solution to get radical:

Note: The algorithm based by Klaus Merkert, Hohenstaufen-Gymnasium Kaiserslautern, http://www.hsg-kl.de

Func _Radical($n)
    Local $F = ObjCreate("System.Collections.ArrayList")
    While Mod($n,2) == 0
        If Not $F.Contains(2) Then $F.add(2)
        $n = $n/2
    WEnd
    While Mod($n,3) == 0
        If Not $F.Contains(3) Then $F.add(3)
        $n = $n/3
    WEnd
    Local $t = 5
    Local $diff = 2
    While $t*$t <= $n
        While Mod($n,$t) == 0
            If Not $F.Contains($t) Then $F.add($t)
            $n = $n/$t
        WEnd
        $t = $t + $diff
        $diff = 6 - $diff
    WEnd
    If $n > 1 And Not $F.Contains($n) Then $F.add($n)
    Local $out = 1
    For $element In $F
        $out *= $element
    Next
    Return $out
EndFunc

; If someone need: a function to get prime factors
Func _GetPrimeFactors($n)
    Local $F = ObjCreate("System.Collections.ArrayList")
    While Mod($n,2) == 0
        $F.add(2)
        $n = $n/2
    WEnd
    While Mod($n,3) == 0
        $F.add(3)
        $n = $n/3
    WEnd
    Local $t = 5
    Local $diff = 2
    While $t*$t <= $n
        While Mod($n,$t) == 0
            $F.add($t)
            $n = $n/$t
        WEnd
        $t = $t + $diff
        $diff = 6 - $diff
    WEnd
    If $n > 1 Then $F.add($n)
    Local $out = ''
    For $element In $F
        $out &= $element & ','
    Next
    Return StringTrimRight($out, 1)
EndFunc
Edited by BugFix

Best Regards BugFix  

Link to comment
Share on other sites

Hi,

here my solution to get radicand:

Func _Radical($n)
    Local $F = ObjCreate("System.Collections.ArrayList")
    While Mod($n,2) == 0
        If Not $F.Contains(2) Then $F.add(2)
        $n = $n/2
    WEnd
    While Mod($n,3) == 0
        If Not $F.Contains(3) Then $F.add(3)
        $n = $n/3
    WEnd
    Local $t = 5
    Local $diff = 2
    While $t*$t <= $n
        While Mod($n,$t) == 0
            If Not $F.Contains($t) Then $F.add($t)
            $n = $n/$t
        WEnd
        $t = $t + $diff
        $diff = 6 - $diff
    WEnd
    If $n > 1 And Not $F.Contains($n) Then $F.add($n)
    Local $out = 1
    For $element In $F
        $out *= $element
    Next
    Return $out
EndFuncoÝ÷ Ø Ýû(ê'zwu¬ÊÚ zÚkgiËh®Êjx§µè­«­¢+ÙÕ¹}ÑAÉ¥µÑ½ÉÌ ÀÌØí¸¤(1½°ÀÌØíô=©
ÉÑ ÅÕ½ÐíMåÍÑ´¹
½±±Ñ¥½¹Ì¹ÉÉå1¥ÍÐÅÕ½Ðì¤(]¡¥±5½ ÀÌØí¸°È¤ôôÀ(ÀÌØí¹ È¤(ÀÌØí¸ôÀÌØí¸¼È(%]¹(]¡¥±5½ ÀÌØí¸°Ì¤ôôÀ(ÀÌØí¹ Ì¤(ÀÌØí¸ôÀÌØí¸¼Ì(%]¹(1½°ÀÌØíÐôÔ(1½°ÀÌØí¥ôÈ(]¡¥±ÀÌØíШÀÌØíбÐìôÀÌØí¸(]¡¥±5½ ÀÌØí¸°ÀÌØíФôôÀ(ÀÌØí¹ ÀÌØíФ(ÀÌØí¸ôÀÌØí¸¼ÀÌØíÐ($%]¹(ÀÌØíÐôÀÌØíЬÀÌØí¥(ÀÌØí¥ôØ´ÀÌØí¥(%]¹(%ÀÌØí¸ÐìÄQ¡¸ÀÌØí¹ ÀÌØí¸¤(%1½°ÀÌØí½ÕÐôÌäìÌäì(%½ÈÀÌØí±µ¹Ð%¸ÀÌØí($$ÀÌØí½ÕеÀìôÀÌØí±µ¹ÐµÀìÌäì°Ìäì(%9áÐ(%IÑÕɸMÑÉ¥¹QÉ¥µI¥¡Ð ÀÌØí½ÕаĤ)¹Õ¹
THANK YOU

[size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N

Link to comment
Share on other sites

  • 7 years later...
  • Moderators

danyel,

Welcome to the AutoIt forums.

But in future please do not reply to 7 year old threads....

M23

P.S. And certainly do not hijack them - start your own thread.

 

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...