[COLOR=Blue] #include[/COLOR][COLOR=Sienna]<iostream>[/COLOR]
[COLOR=Blue] void[/COLOR] main()
{
[COLOR=Blue]int[/COLOR] number=0,tmp1=0, tmp2=0, x =0;
std::cout<<[COLOR=Sienna]"Enter the number: "[/COLOR];
std::cin>>number;
x=number; //the original number
[COLOR=Blue]for[/COLOR](;number>0;)
{
tmp1=number%10;
number /=10;
tmp2=number%10;
[COLOR=Blue] if[/COLOR](tmp1 > 5 && tmp2 >6)//Check the conditions here.
{
std::cout<<x<<" [COLOR=Sienna]IS GOOD\n[/COLOR]";
[COLOR=Blue]break[/COLOR];
}
[COLOR=Blue]if [/COLOR](number ==0)//At the end now.
{
std::cout<<x<<" [COLOR=Sienna]IS NOT GOOD\n[/COLOR]";
}
}
std::cin>>tmp1;//stops the console from closing too quickly
}
Enter the number: 3765
3765 IS GOOD
Enter the number: 1567
1567 IS NOT GOOD
java:~ $echo "1234" | egrep -i '.*[6-9][5-9].*'
java:~ $echo "12347" | egrep -i '.*[6-9][5-9].*'
java:~ $echo "123475" | egrep -i '.*[6-9][5-9].*'
123475
java:~ $echo "123474" | egrep -i '.*[6-9][5-9].*'
java:~ $echo "123479" | egrep -i '.*[6-9][5-9].*'
123479
java:~ $echo "123479343" | egrep -i '.*[6-9][5-9].*'
123479343
java:~ $
; Consume a list of single digits, subtract 6 from each item, and filter out the negative values
(define (reduce-list list)
(cond
[(and (>= (- (first list) 6) 0) (empty? (rest list))) (- (first list) 6)]
[(>= (- (first list) 6) 0) (cons (- (first list) 6) (reduce-list (rest list)))]
[else (reduce-list (rest list))]))
; Go through the list and find if two successive numbers have the first number greater than the second one.
(define (compute list)
(cond
[(or (empty? (rest list)) (empty? (first list))) false]
[(> (first list) (first (rest list))) true]
[else (compute (rest list))]))
; Test it
(compute (reduce-list '(3 7 6 5)))
(define list '(3 7 6 5))
(foldr (lambda (a b) (cond [(> a b) true]
[(equal? b true) true]
[else a]))
10
(filter (lambda (a) (>= a 0)) (map (lambda (a) (- a 6)) list)))