grep

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

m and n are 2 integers, where m<=n. "seq m n" outputs exactly n -m +1 integers, one per line, from m to n inclusive.

a. Not having digit '1' in it.
b. Having at least one '1' in it
c. Having one or more 1's, but not consecutive 1's. (No 1's together : ex '11')

  1. Relevant commands, code, scripts, algorithms:

seq/jot (I have a mac). Could output the numbers into a file and search them using grep?

  1. The attempts at a solution (include all code and scripts):

a. terri-brashers-macbook-pro:~ Terri$ for i in $(jot 1000)
> do
> echo "No 1's $(i+2)
> done
>
> q
> for i in $(jot 1000); do echo "No 1's $(i+2)
done

This algorithm won't really work, but am I on the right track?
Or should I go with the grep idea?
No progress either way.. :frowning:

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

University of Alabama at Birmingham, Birmingham (AL), US, Taoqif, cs 333

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

---------- Post updated at 10:41 AM ---------- Previous update was at 10:05 AM ----------

Messing around with it, I ended up sending the output to a new file and then used grep to find and/or exclude numbers.

Not sure i follow the spec as displayed, however something like the following would give you a starting point (identify the number of occuences of '1' per integer)

$ for i in $(seq 100 120) ; do echo $i: $(($(echo $i|grep -o '1'|wc -c)/2)); done
100: 1
101: 2
102: 1
103: 1
104: 1
105: 1
106: 1
107: 1
108: 1
109: 1
110: 2
111: 3
112: 2
113: 2
114: 2
115: 2
116: 2
117: 2
118: 2
119: 2
120: 1

Caveat:depends on the -o option available in Gnu and possibly BSD grep but not portable to, for example Solaris