B4A Library A simple permutations and combinations library

This 3-function library simply calculates permutations and combinations for a certain number and given times with or without repetitions. These are useful statistical utilities and can be used in a lot of applications, e.g. counting the number of matches played in a 16-team tournament or the number of combinations for a 4-digit lock or password from 10 possible numbers(0-9)..It also includes a factorial function, e.g. 3!.
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim pclib As Permcomb
End Sub


Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Log(pclib.comb (10,2,False)
End Sub
.
.
 

Attachments

  • pcLibrary.zip
    2 KB · Views: 198

MarcoRome

Expert
Licensed User
Longtime User
Can you do any example with method:

upload_2017-4-2_19-5-12.png


Thank you
 

jkhazraji

Active Member
Licensed User
Longtime User
Here is an example..
B4X:
#Region  Project Attributes 
    #ApplicationLabel: Permutations-Combination
    #VersionCode: 1
    #VersionName: 
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
   
        Dim pclib As Permcomb
End Sub

Sub Globals
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   
            Log(pclib.Perm(10,2,False)) ' Permutations of 10 items for 2 times without repeating an item
            Log(pclib.comb(10,4,True))  'Combinations of 10 items for 4 times, repeating allowed
            Log(pclib.fact(5))          'factorial of 5 (5!)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 
Top