Jump to content

Recommended Posts

Posted

I use 4 Function to calculate this topic,only For Loop got wrong ~

While Loop ✓

$sum = sum(10)
Msgbox(0,"Total","Total:"&$sum)
Func sum($x)
$loop = 1
$y = 10
While $loop
$y = $y - 1
$x = $x * $y
If $y == 1 Then $loop = 0
WEnd
Return $x
EndFunc

Recursion ✓

$sum = sum(10)
Msgbox(0,"Total","Total:"&$sum)
Func sum($x)
If $x = 1 Then
Return 1
Else
Return $x * sum($x - 1)
EndIf
EndFunc

Do Loop ✓

$sum = sum(10)
Msgbox(0,"Total","Total:"&$sum)
Func sum($x)
$y = 10
Do
$y = $y - 1
$x = $x * $y
Until $y == 1
Return $x
EndFunc

For Loop ✖

$sum = sum(10)
Msgbox(0,"Total","Total:"&$sum)
Func sum($x)
$y = 10
For $i = 10 To 1 Step - 1
$y = $y - 1
$x = $x * $y
Next
Return $x
EndFunc
Posted (edited)

Change line

For $i = 10 To 1 Step -1
to
For $i = 10 To 2 Step -1
Because if you go down to 1 and then subtract 1 you multiply with 0. Edited by water

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

$sum = sum(10)
MsgBox(0, "Total", "Total:" & $sum)
Func sum($x)
$y = 10
For $i = 10 To 1 Step -1
$y -= 1
$x += $x * $y
Next
Return $x
EndFunc ;==>sum

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Posted (edited)

#include <Constants.au3>

Local $iValue = Factorial(10)
MsgBox($MB_SYSTEMMODAL, '', 'Total: ' & $iValue)

Func Factorial($x)
    Local $y = $x
    For $i = 1 To $y - 1
        $x *= $i
    Next
    Return $x
EndFunc   ;==>Factorial

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

I think I learnt something too, though I won't let you know what!

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Not to be pedantic, but your function should be called "factorial()", not "sum()".

Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Posted

Why I love 52!

  Quote

So how many ways can you order all the 52 cards in a pack?

The sum is 52x51x50x49x48....x4x3x2x1 and the answer is roughly:

80,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000

That's an 8 with 67 zeros after it.

To put this in perspective, the dinosaurs died out 65,000,000 years ago, and the age of the earth is just 4,500,000,000 years. Now suppose everybody in the world was to arrange packs of cards at the rate of one per second, it would take 600,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 years to get all the combinations! That's why you're VERY unlikely ever to shuffle a pack of cards the same way twice.

Source: http://murderousmaths.co.uk/cardperms.htm

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

52! = 80658175170943878571660636856403766975289505440883277824000000000000

(a LOT more!)

  Reveal hidden contents

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)

Posted

Yeh, I don't know why they didn't post the correct value, as 'roughly' isn't a couple of units here or there.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

True, I'd love 1% of 1‰ of 1‱ of the absolute value of the difference, even in ¥.

  Reveal hidden contents

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)

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
  • Recently Browsing   0 members

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