Colorful numbers: Difference between revisions
→{{header|Wren}}: Changed to Phix's approach which is over 100 times faster than I had before.
(→{{header|Wren}}: Changed to Phix's approach which is over 100 times faster than I had before.) |
|||
Line 259:
=={{header|Wren}}==
{{trans|Phix}}
{{libheader|Wren-math}}
{{libheader|Wren-set}}
Line 287 ⟶ 288:
}
var count = List.filled(9, 0)▼
System.print("The colorful numbers less than 100 are:")▼
var used = List.filled(11, false)
var colorful = (0..99).where { |i| isColorful.call(i) }.toList▼
for (chunk in Lst.chunks(colorful, 10)) Fmt.print("$2d", chunk)▼
var largest = 0
System.print("\nThe largest possible colorful number is:")▼
for (i in 1e8-1..0) {▼
if (isColorful.call(i)) {▼
Fmt.print("$,d", i)▼
largest = i▼
break▼
}▼
}▼
var countColorful // recursive
▲var count = List.filled(9, 0)
countColorful = Fn.new { |taken, n|
var dc = 1▼
System.print("\nCount of colorful numbers for each order of magnitude:")▼
var
countColorful.call((digit < 2) ? 9 : 1, String.fromByte(digit + 48))
▲ if (dc > 1) {
if (rem == 0 || rem == 1) {▼
i = i + 2 - rem▼
▲ continue
}
if (isColorful.call(i)) count[dc] = count[dc] + 1▼
var total = (dc == 1) ? 10 : pow * 0.9▼
Fmt.print(" $d digit colorful number count: $,6d - $7.3f\%", dc, count[dc], pc)▼
if (i == largest) break▼
dc = dc + 1▼
▲ i = pow * 0.2 + 2
} else {
var ln = n.count
for (digit in 2..9) {
if (!used[dx]) {
used[dx] = true
countColorful.call(taken + 1, n + String.fromByte(digit + 48))
used[dx] = false
▲ }
}
▲}
▲System.print("The %(cn.count) colorful numbers less than 100 are:")
countColorful.call(0, "")
▲System.print("\nThe largest possible colorful number is:")
▲
}
Line 332 ⟶ 340:
{{out}}
<pre>
The 66 colorful numbers less than 100 are:
0 1 2 3 4 5 6 7 8 9
23 24 25 26 27 28 29 32 34 35
|