Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int min, max
- bool failEVEN, failODD = false // init both sequence checks with false so we can check them each cycle
- vector = array of ints
- foreach (var i in vector)
- {
- // did both sequences fail already?
- if (failEVEN && failODD)
- {
- // stop the loop as there is no point checking further...
- break;
- }
- // check if i is an EVEN number (using MODULO it will return 0 when it is an EVEN number (no failsafe used here as no mega numbers are expected!))
- if (i % 2 == 0 && !failEVEN)
- {
- // is our current number bigger or the same as our last one?
- if (i >= max)
- {
- // yeah we got a valid number.. now store it to check against the next one...
- max = i;
- }
- else
- {
- // don't tell mom that we failed on our EVEN sequence... but tell our boss!
- failEVEN = true;
- }
- }
- else if (!failODD)
- {
- // is our current number smaller or the same as our last one?
- if (i <= min)
- {
- // yeah we got a valid number.. now store it to check against the next one...
- min = i;
- }
- else
- {
- // tell our superiors that we failed on the ODD sequence...
- failODD = true;
- }
- }
- }
- if (!failEVEN)
- {
- print "EVEN sequence is valid!";
- }
- else
- {
- print "EVEN sequence is NOT valid!";
- }
- if (!failODD)
- {
- print "ODD sequence is valid!";
- }
- else
- {
- print "ODD sequence is NOT valid!";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement