some fun alternatives (not meant to be improvements):
firstdigit =: 9
consecutive =: 10&(^ + * * ([ ^ <:@]))@(6&-)
NB. number of items
noi =: firstdigit * (consecutive 3) - (consecutive 4) + 10-1
now that we know what we want, let’s do it:
d3a =: }.@(":"0) 1000+i.1000
tripsa =: 3 $"0 '0123456789'
NB. the DRY principle
rtbl =: 2 : ',/@:(u"n/)'
exp2 =: (i.4) |. rtbl 0 1 , rtbl 1
clean2 =: ~.@: #~ %~@i.&'0'"1
and finally, check if everything worked out fine:
(noi,6) -: $ clean2 d3a exp2 tripsa
Am 07.07.21 um 12:15 schrieb 'Mike Day' via Programming:
Here’s one implementation of what I’d suggested for construction from all
3-digit representations of 0-999, working in characters rather than numerals.
Staying in characters saves time and space, not shown here, compared to
evaluating the representations. Also, I’m pre-evaluating the 3-digit
representations, so timing and sizing the calculation, below, might be
misleading, compared, say, to sd3, which includes the calculation of all
numbers from 1000 to 9999.
Alignment ok in fixed font!
d3 =: }."1 ":,.1000+i.1000 NB. 3 digit strings,
'000','001'...'999'
trips =: |: 3 10$'0123456789' NB. identical triples:
'000','111'....
exp =: ,/@:(0 1 2 3(|."0 1/)(,/@:(,"1/)))NB. Expand 3dig nums with triples
clean =: ~.@: #~'0'~:{."1 NB. Unique elements of required 6dig
nums
$clean d3 exp trips
33219 6
({~5?# )clean d3 exp trips
691777
722254
780009
575999
588854
It’s apparently agreed that we’re happy to accept 4-,5-,6-tuples of repeated
digits.
Cheers,
Mike
Sent from my iPad
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
--
----------------------
mail written using NEO
neo-layout.org
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm