-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumbers_with_non_decimal_digits.sf
More file actions
34 lines (24 loc) · 979 Bytes
/
numbers_with_non_decimal_digits.sf
File metadata and controls
34 lines (24 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/ruby
# Daniel "Trizen" Șuteu
# Date: 06 July 2021
# https://github.com/trizen
# Generate numbers such that when represented in a given base > 10, all digits are >= 10.
# See also:
# https://rosettacode.org/wiki/Numbers_in_base-16_representation_that_cannot_be_written_with_decimal_digits
func generate_from_prefix(limit, p, base, digits) {
var seq = [p]
digits.each {|d|
var num = (p*base + d)
num <= limit || return seq
seq << __FUNC__(limit, num, base, digits)...
}
return seq
}
func numbers_with_non_decimal_digits(limit, base = 10) {
var digits = @(10..^base)
digits.map {|p| generate_from_prefix(limit, p, base, digits)... }\
.sort
}
say numbers_with_non_decimal_digits(500, 16)
__END__
[10, 11, 12, 13, 14, 15, 170, 171, 172, 173, 174, 175, 186, 187, 188, 189, 190, 191, 202, 203, 204, 205, 206, 207, 218, 219, 220, 221, 222, 223, 234, 235, 236, 237, 238, 239, 250, 251, 252, 253, 254, 255]