Inconsummate numbers in base 10: Difference between revisions
Content added Content deleted
(→{{header|Free Pascal}}: Faster version checking Digitalsum, testing for max used factor.) |
(Inconsummate numbers in base 10 in FreeBASIC) |
||
Line 200: | Line 200: | ||
Inconsummate number 100000: 536081 |
Inconsummate number 100000: 536081 |
||
</pre> |
</pre> |
||
=={{header|FreeBASIC}}== |
|||
{{trans|Action!}} |
|||
<syntaxhighlight lang="freebasic">Dim As Boolean consummate(0 To 999999) |
|||
For j As Integer = Lbound(consummate) To Ubound(consummate) |
|||
consummate(j) = False |
|||
Next j |
|||
consummate(1) = True |
|||
Dim As Integer maxSum = 9 |
|||
Dim As Integer ub = Ubound(consummate) |
|||
While ub > 10 |
|||
maxSum += 9 |
|||
ub /= 10 |
|||
Wend |
|||
Dim As Integer maxNumber = Ubound(consummate) * maxSum |
|||
Dim As Integer tn = 1, hn = 0, th = 0, tt = 0, ht = 0, mi = 0, tm = 0 |
|||
Dim As Integer sumD, n, d, dRatio |
|||
For n = 10 To maxNumber Step 10 |
|||
sumD = tm + mi + ht + tt + th + hn + tn |
|||
For d = n To n + 9 |
|||
If d Mod sumD = 0 Then ' d is comsummate |
|||
dRatio = d / sumD |
|||
If dRatio <= Ubound(consummate) Then consummate(dRatio) = True |
|||
End If |
|||
sumD += 1 |
|||
Next d |
|||
tn += 1 |
|||
If tn > 9 Then |
|||
tn = 0 |
|||
hn += 1 |
|||
If hn > 9 Then |
|||
hn = 0 |
|||
th += 1 |
|||
If th > 9 Then |
|||
th = 0 |
|||
tt += 1 |
|||
If tt > 9 Then |
|||
tt = 0 |
|||
ht += 1 |
|||
If ht > 9 Then |
|||
ht = 0 |
|||
mi += 1 |
|||
If mi > 9 Then |
|||
mi = 0 |
|||
tm += 1 |
|||
End If |
|||
End If |
|||
End If |
|||
End If |
|||
End If |
|||
End If |
|||
Next n |
|||
Dim As Integer i = 0, count = 0 |
|||
Print "The first 50 inconsummate numbers:" |
|||
While i < Ubound(consummate) And count < 100000 |
|||
i += 1 |
|||
If Not consummate(i) Then |
|||
count += 1 |
|||
If count < 51 Then |
|||
Print Using "######"; i; |
|||
If count Mod 10 = 0 Then Print |
|||
Elseif count = 1000 Or count = 10000 Or count = 100000 Then |
|||
Print Using !"\nInconsummate number ######: ######"; count; i; |
|||
End If |
|||
End If |
|||
Wend |
|||
Sleep</syntaxhighlight> |
|||
{{out}} |
|||
<pre>The first 50 inconsummate numbers: |
|||
62 63 65 75 84 95 161 173 195 216 |
|||
261 266 272 276 326 371 372 377 381 383 |
|||
386 387 395 411 416 422 426 431 432 438 |
|||
441 443 461 466 471 476 482 483 486 488 |
|||
491 492 493 494 497 498 516 521 522 527 |
|||
Inconsummate number 1000: 6996 |
|||
Inconsummate number 10000: 59853 |
|||
Inconsummate number 100000: 536081</pre> |
|||
=={{header|J}}== |
=={{header|J}}== |