Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
83
Task/Fraction-reduction/11l/fraction-reduction.11l
Normal file
83
Task/Fraction-reduction/11l/fraction-reduction.11l
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
F indexOf(haystack, needle)
|
||||
V idx = 0
|
||||
L(straw) haystack
|
||||
I straw == needle
|
||||
R idx
|
||||
E
|
||||
idx++
|
||||
R -1
|
||||
|
||||
F getDigits(=n, =le, &digits)
|
||||
L n > 0
|
||||
V r = n % 10
|
||||
I r == 0 | indexOf(digits, r) >= 0
|
||||
R 0B
|
||||
le--
|
||||
digits[le] = r
|
||||
n = Int(n / 10)
|
||||
R 1B
|
||||
|
||||
F removeDigit(digits, le, idx)
|
||||
V pows = [1, 10, 100, 1000, 10000]
|
||||
V sum = 0
|
||||
V pow = pows[le - 2]
|
||||
V i = 0
|
||||
L i < le
|
||||
I i == idx
|
||||
i++
|
||||
L.continue
|
||||
sum = sum + digits[i] * pow
|
||||
pow = Int(pow / 10)
|
||||
i++
|
||||
R sum
|
||||
|
||||
V lims = [ [ 12, 97 ], [ 123, 986 ], [ 1234, 9875 ], [ 12345, 98764 ] ]
|
||||
V count = [0] * 5
|
||||
V omitted = [[0] * 10] * 5
|
||||
|
||||
V i = 0
|
||||
L i < lims.len
|
||||
V n = lims[i][0]
|
||||
L n < lims[i][1]
|
||||
V nDigits = [0] * (i + 2)
|
||||
V nOk = getDigits(n, i + 2, &nDigits)
|
||||
I !nOk
|
||||
n++
|
||||
L.continue
|
||||
V d = n + 1
|
||||
L d <= lims[i][1] + 1
|
||||
V dDigits = [0] * (i + 2)
|
||||
V dOk = getDigits(d, i + 2, &dDigits)
|
||||
I !dOk
|
||||
d++
|
||||
L.continue
|
||||
V nix = 0
|
||||
L nix < nDigits.len
|
||||
V digit = nDigits[nix]
|
||||
V dix = indexOf(dDigits, digit)
|
||||
I dix >= 0
|
||||
V rn = removeDigit(nDigits, i + 2, nix)
|
||||
V rd = removeDigit(dDigits, i + 2, dix)
|
||||
I (1.0 * n / d) == (1.0 * rn / rd)
|
||||
count[i]++
|
||||
omitted[i][digit]++
|
||||
I count[i] <= 12
|
||||
print(‘#./#. = #./#. by omitting #.'s’.format(n, d, rn, rd, digit))
|
||||
nix++
|
||||
d++
|
||||
n++
|
||||
print()
|
||||
i++
|
||||
|
||||
i = 2
|
||||
L i <= 5
|
||||
print(‘There are #. #.-digit fractions of which:’.format(count[i - 2], i))
|
||||
V j = 1
|
||||
L j <= 9
|
||||
I omitted[i - 2][j] == 0
|
||||
j++
|
||||
L.continue
|
||||
print(‘#6 have #.'s omitted’.format(omitted[i - 2][j], j))
|
||||
j++
|
||||
print()
|
||||
i++
|
||||
Loading…
Add table
Add a link
Reference in a new issue