Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
90
Task/Fraction-reduction/FreeBASIC/fraction-reduction.basic
Normal file
90
Task/Fraction-reduction/FreeBASIC/fraction-reduction.basic
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
Type Result
|
||||
n As Integer
|
||||
nine(8) As Integer
|
||||
End Type
|
||||
|
||||
Function indexOf(n As Integer, s() As Integer) As Integer
|
||||
For i As Integer = 0 To Ubound(s)
|
||||
If s(i) = n Then Return i
|
||||
Next
|
||||
Return -1
|
||||
End Function
|
||||
|
||||
Function getDigits(n As Integer, le As Integer, digits() As Integer) As Boolean
|
||||
While n > 0
|
||||
Dim r As Integer = n Mod 10
|
||||
If r = 0 Or indexOf(r, digits()) >= 0 Then Return False
|
||||
le -= 1
|
||||
digits(le) = r
|
||||
n \= 10
|
||||
Wend
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Function removeDigit(digits() As Integer, le As Integer, idx As Integer) As Integer
|
||||
Dim pows(4) As Integer = {1, 10, 100, 1000, 10000}
|
||||
Dim sum As Integer = 0
|
||||
Dim pow As Integer = pows(le - 2)
|
||||
For i As Integer = 0 To le - 1
|
||||
If i = idx Then Continue For
|
||||
sum += digits(i) * pow
|
||||
pow \= 10
|
||||
Next
|
||||
Return sum
|
||||
End Function
|
||||
|
||||
Sub main()
|
||||
Dim As Integer lims(3, 1) = {{12, 97}, {123, 986}, {1234, 9875}, {12345, 98764}}
|
||||
Dim As Integer count(4)
|
||||
Dim As Integer omitted(4, 9)
|
||||
Dim As Integer upperBound = Ubound(lims, 1)
|
||||
Dim As Integer i, n, j, d
|
||||
For i = 0 To upperBound
|
||||
Dim As Integer nDigits(i + 1)
|
||||
Dim As Integer dDigits(i + 1)
|
||||
Dim As Integer blank(i + 1)
|
||||
For n = lims(i, 0) To lims(i, 1)
|
||||
For j = 0 To Ubound(blank)
|
||||
nDigits(j) = blank(j)
|
||||
Next
|
||||
Dim As Boolean nOk = getDigits(n, i + 2, nDigits())
|
||||
If Not nOk Then Continue For
|
||||
For d = n + 1 To lims(i, 1) + 1
|
||||
For j = 0 To Ubound(blank)
|
||||
dDigits(j) = blank(j)
|
||||
Next
|
||||
Dim As Boolean dOk = getDigits(d, i + 2, dDigits())
|
||||
If Not dOk Then Continue For
|
||||
For nix As Integer = 0 To Ubound(nDigits)
|
||||
Dim As Integer digit = nDigits(nix)
|
||||
Dim As Integer dix = indexOf(digit, dDigits())
|
||||
If dix >= 0 Then
|
||||
Dim As Integer rn = removeDigit(nDigits(), i + 2, nix)
|
||||
Dim As Integer rd = removeDigit(dDigits(), i + 2, dix)
|
||||
If (n / d) = (rn / rd) Then
|
||||
count(i) += 1
|
||||
omitted(i, digit) += 1
|
||||
If count(i) <= 12 Then
|
||||
Print n & "/" & d & " = " & rn & "/" & rd & " by omitting " & digit & "'s"
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
Next
|
||||
Print
|
||||
Next
|
||||
|
||||
For i = 2 To 5
|
||||
Print "There are " & count(i - 2) & " " & i & "-digit fractions of which:"
|
||||
For j = 1 To 9
|
||||
If omitted(i - 2, j) = 0 Then Continue For
|
||||
Print Using "###### have #'s omitted"; omitted(i - 2, j); j
|
||||
Next
|
||||
Print
|
||||
Next
|
||||
End Sub
|
||||
|
||||
main()
|
||||
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue