Monday, March 9, 2015

Monday, March 9th

Regular class today. It was our first class out of two this week; we won't be having class Friday as it is parent teacher conferences.

As I said last time, I advanced on a lot of problems but didn't complete that many of them. Today, what I tried to work on a lot was completing those problems. Mr. Daly helped me with three of them. For a lot of them, it was just small, simple things missing. Other times, it was the logic that I needed to rethink - I need to start sometimes to think of flagging, and solving problems with that. There was one problem however, that is called haveThree, which I was very confused about. I solved it, and all of the tests were correct, except the bottom one which says other test. This usually only happens when whoever codes writes lines of code that are created especially and only for the tests and not to solve the actual problem; but that is not what I did. So I am confused as to what I did wrong and I have no clue what I can fix now.

For good new, however, I am now more than halfway complete with Array 2.
----------------------------------------------------------------------------------------------------------------------------------

Here is today's problem, one that I did on my own:

----------------------------------------------------------------------------------------------------------------------------------
Given an array of ints, return true if the array contains either 3 even or 3 odd values all next to each other. 

modThree({2, 1, 3, 5}) → true
modThree({2, 1, 2, 5}) → false
modThree({2, 4, 2, 5}) → true


public boolean modThree(int[] nums) {
  
  for (int i=0;i<nums.length-2;i++)
// since we need to look 2 places further of each integer, stop 2 before the end so that it does 
// not become out of bounds.
  {
  
  if (!(nums[i]%2==0) && !(nums[i+1]%2==0) && !(nums[i+2]%2==0))
  {
    return true;
// an odd number will not return 0 as a remainder when divided by two. if the percent mod by 2 //of a number isn't 0 then it is an odd number. if that number and the next two numbers are //odd, then return true.
  }
  
  if ((nums[i]%2==0) && (nums[i+1]%2==0) && (nums[i+2]%2==0))
  {
    return true;
// an even number will return 0 as a remainder when it it divided by two. if a number is even, 
// and the following two digits are also even, then return true.
  }
  
  }
  
  return false;
// if none of the above conditions are true, then return false.
}


Next class, I will continue with Array 2. The problems are getting harder and harder as we approach the end, but I'm sure I can do it. I will also solve those problems that I haven't finished completely yet.








No comments:

Post a Comment