Skip to content

Latest commit

 

History

History
48 lines (37 loc) · 1.24 KB

2. Find cool numbers.md

File metadata and controls

48 lines (37 loc) · 1.24 KB

Find Cool Numbers

First, clean up your numbers file:

sort -u numbers > tmp; mv tmp numbers
wc -l numbers # how many numbers
cut -b 1-3 numbers | uniq -c # how many numbers per area code

Now, find fun numbers

# repeated strings of digits
egrep "(\d{5}).*\1" numbers #5
egrep "(\d{4}).*\1" numbers #4

# the whole number, with a limited number of unique digits
egrep "^(\d)\1*(\d)\1*\2*\1*\2*\1*\2*\1*\2*(\d)(\1|\2|\3)*$" numbers #3
egrep "^(\d)\1*(\d)(\1|\2)*$" numbers #2

# ex-area code, limited number of unique digits
egrep "^...(\d)\1*(\d)\1*\2*\1*\2*\1*\2*\1*\2*(\d)(\1|\2|\3)*$" numbers #3
egrep "^...(\d)\1*(\d)(\1|\2)*$" numbers #2

# digit runs
egrep '(\d)\1{3}' numbers #4

# sets of triples
egrep "(\d)\1\1.*(\d)\2\2" numbers #2
egrep '(\d)\1{2,}' numbers #1

# sets of doubles
egrep "(\d)\1(\d)\2(\d)\3(\d)\4(\d)\5" numbers #5
egrep "(\d)\1.(\d)\2.(\d)\3.*(\d)\4" numbers #4
egrep "(\d)\1.(\d)\2.(\d)\3" numbers #3

# palindrome
egrep "(\d)(\d)(\d)(\d)(\d)\5\4\3\2\1" numbers #10
egrep "(\d)(\d)(\d)(\d)(\d)\4\3\2\1" numbers #9
egrep "(\d)(\d)(\d)(\d)\4\3\2\1" numbers #8
egrep "(\d)(\d)(\d)(\d)\3\2\1" numbers #7

# toggles
egrep "(\d)(\d)\1\2\1\2\1" numbers #7
egrep "(\d)(\d)\1\2\1\2" numbers #6
egrep "(\d)(\d)\1\2\1" numbers #5