How to resolve the algorithm Find the missing permutation step by step in the FreeBASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Find the missing permutation step by step in the FreeBASIC programming language

Table of Contents

Problem Statement

Listed above are   all-but-one   of the permutations of the symbols   A,   B,   C,   and   D,   except   for one permutation that's   not   listed.

Find that missing permutation.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Find the missing permutation step by step in the FreeBASIC programming language

Source code in the freebasic programming language

' version 30-03-2017
' compile with: fbc -s console

Data "ABCD", "CABD", "ACDB", "DACB", "BCDA", "ACBD"
Data "ADCB", "CDAB", "DABC", "BCAD", "CADB", "CDBA"
Data "CBAD", "ABDC", "ADBC", "BDCA", "DCBA", "BACD"
Data "BADC", "BDAC", "CBDA", "DBCA", "DCAB"

' ------=< MAIN >=------

Dim As ulong total(3, Asc("A") To Asc("D"))  ' total(0 to 3, 65 to 68)
Dim As ULong i, j, n = 24 \ 4   ' n! \ n
Dim As String tmp

For i = 1 To 23
    Read tmp
    For j = 0 To 3
        total(j, tmp[j]) += 1
    Next
Next

tmp = Space(4)
For i = 0 To 3
    For j = Asc("A") To Asc("D")
        If total(i, j) <> n Then
         tmp[i] = j
        End If
    Next
Next

Print "The missing permutation is : "; tmp

' empty keyboard buffer
While InKey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End

' version 30-03-2017
' compile with: fbc -s console

Data "ABCD", "CABD", "ACDB", "DACB", "BCDA", "ACBD"
Data "ADCB", "CDAB", "DABC", "BCAD", "CADB", "CDBA"
Data "CBAD", "ABDC", "ADBC", "BDCA", "DCBA", "BACD"
Data "BADC", "BDAC", "CBDA", "DBCA", "DCAB"

' ------=< MAIN >=------

Dim As ULong total(3)  ' total(0 to 3)
Dim As ULong i, j, n = 24 \ 4   ' n! \ n
Dim As ULong total_val = (Asc("A") + Asc("B") + Asc("C") + Asc("D")) * n
Dim As String tmp

For i = 1 To 23
    Read tmp
    For j = 0 To 3
        total(j) += tmp[j]
    Next
Next

tmp = Space(4)
For i = 0 To 3
    tmp[i] = total_val - total(i)
Next

Print "The missing permutation is : "; tmp

' empty keyboard buffer
While Inkey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End

' version 30-03-2017
' compile with: fbc -s console

Data "ABCD", "CABD", "ACDB", "DACB", "BCDA", "ACBD"
Data "ADCB", "CDAB", "DABC", "BCAD", "CADB", "CDBA"
Data "CBAD", "ABDC", "ADBC", "BDCA", "DCBA", "BACD"
Data "BADC", "BDAC", "CBDA", "DBCA", "DCAB"

' ------=< MAIN >=------

Dim As ULong i,j 
Dim As String tmp, missing = chr(0, 0, 0, 0) ' or string(4, 0)

For i = 1 To 23
    Read tmp
    For j = 0 To 3
        missing[j] Xor= tmp[j]
    Next
Next

Print "The missing permutation is : "; missing

' empty keyboard buffer
While Inkey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End

  

You may also check:How to resolve the algorithm Hello world/Web server step by step in the Ruby programming language
You may also check:How to resolve the algorithm Loops/While step by step in the NewLISP programming language
You may also check:How to resolve the algorithm Truncatable primes step by step in the Phix programming language
You may also check:How to resolve the algorithm Rot-13 step by step in the VBScript programming language
You may also check:How to resolve the algorithm Chinese zodiac step by step in the Groovy programming language