Jump to content

Most efficient way to get prime factorization with autoit


Recommended Posts

It has to be with exponents, so for 20 I would need

2^2,5

rather than

2,2,5

any ideas?

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

It has to be with exponents, so for 20 I would need

2^2,5

What is the bit size of the numbers you want to factorize and how fast do you need it to be?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

_Factor()

Returns an array and is fairly fast (for AutoIt). You would have to manipulate the array to get your exponential notation, but that's trivial. Also note that [1] is either 1 or -1 based on the sign of the input. One is not considered prime and is not usually listed as a factor, it is only included to deal with negative numbers consistently. If [0] = 2 then the input was prime.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • 6 years later...

Here is the code for Prime Factorization

 

$divisor = 0
$str =""
$contd = "Y"
$divided =1
$divident =1
While $contd<>"N" or $contd<>"n"
   $divisor = InputBox("To find Prime Factor", "Please give number for which prime Factor has to be found ?")
      While $divisor > 1
         While $divided =1
            $divident +=1
               if isPrime($divident) then
                  if Mod($divisor,$divident) = 0 Then
                     ConsoleWrite (stringformat("%03d",String($divident)) & "|" & String($divisor)& @CRLF)
                     $str = $str & stringformat("% 3d",String($divident)) & "," & String($divisor)& @CRLF
                     ;ConsoleWrite ("---|----------"& @CRLF)
                     $divisor=$divisor/$divident
                     $divided =0
                     ;ConsoleWrite (String($divident) & "," & String($divisor)& @CRLF)
                  EndIf
                  ConsoleWrite(String($divident)& @CRLF)
               EndIf
         WEnd
         $divided =1
         $divident=1
      WEnd
      MsgBox(1,"Answer " ,$str)
      $str =""
   $contd =InputBox("Want to continue ... ","Y/N?")
WEnd

Func IsPrime($io_number)
    Local $Num
    $Num = Abs($io_number)
    if $io_number = 2 then Return 1
    If $Num < 2 And $Num > -2 Then Return 1
    For $a = 2 To Int(($Num / 2) + 1)
        If Mod($Num, $a) = 0 Then Return 0
    Next
    Return 1
EndFunc   ;==>IsPrime

PrimeFactor.exe

Link to comment
Share on other sites

  • Moderators

@HemantMalve Did you not notice that this thread is almost 7 years old? Please don't resurrect old threads. If you have a script or snippet you would like to share, we have an Examples forum.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Dear Sir,@JLogan3o13

I was searching for code for the same and Google take me here so i updated the same so that in future if anyone reaches here one can find it easily. That's the only objective for updating here. I could have updated in there but Not sure if Google could had find that.

Sorry for inconvenience caused, Will take care next time. 

Hemant Malve

Edited by HemantMalve
typo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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