English cardinal anagrams: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (New draft task and Raku example) |
(Added Wren) |
||
Line 62: | Line 62: | ||
5679 5697 5769 5796 5967 5976 6579 6597 6795 6975 7569 7596 7695 7965 9567 9576 9675 9765 |
5679 5697 5769 5796 5967 5976 6579 6597 6795 6975 7569 7596 7695 7965 9567 9576 9675 9765 |
||
6798 6879 6897 6978 7698 7869 7896 7968 8679 8697 8769 8796 8967 8976 9678 9768 9867 9876</pre> |
6798 6879 6897 6978 7698 7869 7896 7968 8679 8697 8769 8796 8967 8976 9678 9768 9867 9876</pre> |
||
=={{header|Wren}}== |
|||
{{libheader|Wren-sort}} |
|||
{{libheader|Wren-fmt}} |
|||
I've reused the code for determining the number names from the related task. |
|||
<syntaxhighlight lang="ecmascript">import "./sort" for Sort |
|||
import "./fmt" for Fmt |
|||
var small = [ |
|||
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", |
|||
"twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" |
|||
] |
|||
var tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"] |
|||
var illions = ["", " thousand", " million", " billion"," trillion", " quadrillion", " quintillion"] |
|||
var say |
|||
say = Fn.new { |n| |
|||
var t = "" |
|||
if (n < 0) { |
|||
t = "negative " |
|||
n = -n |
|||
} |
|||
if (n < 20) { |
|||
t = t + small[n] |
|||
} else if (n < 100) { |
|||
t = t + tens[(n/10).floor] |
|||
var s = n % 10 |
|||
if (s > 0) t = t + "-" + small[s] |
|||
} else if (n < 1000) { |
|||
t = t + small[(n/100).floor] + " hundred" |
|||
var s = n % 100 |
|||
if (s > 0) t = t + " " + say.call(s) |
|||
} else { |
|||
var sx = "" |
|||
var i = 0 |
|||
while (n > 0) { |
|||
var p = n % 1000 |
|||
n = (n/1000).floor |
|||
if (p > 0) { |
|||
var ix = say.call(p) + illions[i] |
|||
if (sx != "") ix = ix + " " + sx |
|||
sx = ix |
|||
} |
|||
i = i + 1 |
|||
} |
|||
t = t + sx |
|||
} |
|||
return t |
|||
} |
|||
for (limit in [1000, 10000]) { |
|||
var ana = {} |
|||
for (i in 0..limit) { |
|||
var key = Sort.quick(say.call(i).toList).join("") |
|||
if (ana.containsKey(key)) { |
|||
ana[key].add(i) |
|||
} else { |
|||
ana[key] = [i] |
|||
} |
|||
} |
|||
if (limit == 1000) { |
|||
var all = [] |
|||
for (v in ana.values) { |
|||
if (v.count > 1) all.addAll(v) |
|||
} |
|||
System.print("First 30 English cardinal anagrams:") |
|||
Fmt.tprint("$3d", all.sort().take(30), 10) |
|||
System.print() |
|||
} |
|||
var count = ana.count { |me| me.value.count > 1 } |
|||
Fmt.print("Count of English cardinals up to $,d: $,d", limit, count) |
|||
var max = 0 |
|||
var largest |
|||
for (v in ana.values) { |
|||
if (v.count > max) { |
|||
max = v.count |
|||
largest = v |
|||
} else if (v.count == max) { |
|||
largest.addAll(v) |
|||
} |
|||
} |
|||
var n = limit == 1000 ? 3 : 4 |
|||
Fmt.print("\nLargest group(s) of English cardinal anagrams up to $,d:", limit) |
|||
Fmt.tprint("$%(n)d", largest.sort(), 12) |
|||
if (limit == 1000) System.print() |
|||
}</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
First 30 English cardinal anagrams: |
|||
67 69 76 79 96 97 102 103 104 105 |
|||
106 107 108 109 112 122 123 124 125 126 |
|||
127 128 129 132 133 134 135 136 137 138 |
|||
Count of English cardinals up to 1,000: 317 |
|||
Largest group(s) of English cardinal anagrams up to 1,000: |
|||
679 697 769 796 967 976 |
|||
Count of English cardinals up to 10,000: 2,534 |
|||
Largest group(s) of English cardinal anagrams up to 10,000: |
|||
1679 1697 1769 1796 1967 1976 2679 2697 2769 2796 2967 2976 |
|||
3679 3697 3769 3796 3967 3976 4679 4697 4769 4796 4967 4976 |
|||
5679 5697 5769 5796 5967 5976 6179 6197 6279 6297 6379 6397 |
|||
6479 6497 6579 6597 6791 6792 6793 6794 6795 6798 6879 6897 |
|||
6971 6972 6973 6974 6975 6978 7169 7196 7269 7296 7369 7396 |
|||
7469 7496 7569 7596 7691 7692 7693 7694 7695 7698 7869 7896 |
|||
7961 7962 7963 7964 7965 7968 8679 8697 8769 8796 8967 8976 |
|||
9167 9176 9267 9276 9367 9376 9467 9476 9567 9576 9671 9672 |
|||
9673 9674 9675 9678 9761 9762 9763 9764 9765 9768 9867 9876 |
|||
</pre> |