Distinct palindromes within decimal numbers: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 810: Line 810:
gather {
gather {
for a in (0..arr.end), b in (a .. arr.end) {
for a in (0..arr.end), b in (a .. arr.end) {
var sublist = arr.ft(a, b)
var sublist = arr.items(a..b -> ...)
take(sublist) if (sublist == sublist.flip)
take(sublist) if (sublist == sublist.flip)
}
}
Line 823: Line 823:
123456832098769, 12345679432098769, 1234567905432098769, 123456790165432098769,
123456832098769, 12345679432098769, 1234567905432098769, 123456790165432098769,
83071934127905179083, 1320267947849490361205695, "amanaplanacanalpanama"].each {|n|
83071934127905179083, 1320267947849490361205695, "amanaplanacanalpanama"].each {|n|
var p = palindromes(n.kind_of(Number) ? n.digits : n.chars).grep { .len >= 2}
var p = palindromes(n.kind_of(Number) ? n.digits : n.chars).grep { .len >= 2}
say ("#{'%25s' % n} has #{'%2d' % p.len} palindromes of length 2 or more: ",
say ("#{'%25s' % n} has #{'%2d' % p.len} palindromes of length 2 or more: ",
p.sort.map{.join}.sort_by{.len}.join(' '))
p.sort.map{.join}.sort_by{.len}.join(' '))
}</syntaxhighlight>
}</syntaxhighlight>