Reputation: 464
I want to generate four digit numbers (from 0000
to 9999
) that look like ABCD
and AABC
.
So for example the pattern ABCD
will have numbers like
0123
,0124
,0125
,0126
,0127
,0128
,0129
so on.
Pattern AABC like:
0012
,0013
,0014
,0015
,0016
etc.
Upvotes: 0
Views: 172
Reputation: 168091
(0..9).to_a.permutation(4).map{|a, b, c, d| [a, b, c, d].join}
(0..9).to_a.permutation(3).map{|a, b, c| [a, a, b, c].join}
Or
(0..9).to_a.permutation(4).map{|a, b, c, d| "#{a}#{b}#{c}#{d}"}
(0..9).to_a.permutation(3).map{|a, b, c| "#{a}#{a}#{b}#{c}"}
Upvotes: 2