Monday, February 27, 2012

Can I sleep in?

So the term "Program" in "Program a day" is a little bit misleading. It can refer to yes, a program, or just a class, a method, a function, or just implementing an example of a technique.


A little simple, but here's the idea. Time starts as I finish reading this: "The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in."

public boolean sleepIn(boolean weekday, boolean vacation) {
     if(!weekday && vacation){
          return true;
     }
     else if(weekday && vacation){
          return true;
     }
     else if(!weekday && !vacation){
          return true;
     }
     else
          return false;
}
Total time: 2:19


In a lot of my coding, I have a lot of the if else's, so there's a way to cut back on making it so wordy. Rereading what to do, "Sleep in if not weekday, or on vacation". This one if statement fills both requirements, instead of making all statements for all requirements. The actual answer was:
  
{
     if(!weekday || vacation)
          return true;
     else 
          return false; 
}

Just know it for next time! 
 

Saturday, February 25, 2012

For science!

     Hey guys! This is a simple blog meant to help me as a computer science major. Hope to be a programmer for a living one day, so it's best to keep practicing. The hope is to keep practicing with small little programs, be it "once a day", as this blog is aimed towards. The probability of getting one in every day is unlikely, but I think the name sounds better than "ProgramSometimes" or "ProgramEveryFewDays". 

      Currently working in Java, and I took C last semester, so that's probably what my posts will consist of until I get a more firm grasp in others. 

     I'll probably end up timing them, as well. This is for reference- if I am out of new ideas, go back and create the same (or similar) program, then compare times. Maybe set handicaps on some logic problems. I can't use this method, or only limited to this. Who knows, it's an adventure into computer science!