Ad

A simple regex solution

Code
Diff
  • function testPassword(password) {
      return /(?=.{8,})(?=.*[A-Z])(?=.*[0-9])(?=.*[!"#\$%&'\(\)\*\+'\-./;:<>=\?])/.test(password);
    }
    
    • function testPassword(password){
    • var cap = false;
    • var spec = false;
    • var number = false;
    • var temp;
    • for(i=0;i<password.length;i++){
    • temp = password[i].charCodeAt();
    • if(temp > 32 && temp < 48){
    • spec = true;
    • } else if(temp > 57 && temp < 64){
    • spec = true;
    • }
    • }
    • //check each digit and see if any are capital letters
    • for(i=0;i<password.length;i++){
    • if(password.charCodeAt(i) > 64 && password.charCodeAt(i) < 91){
    • cap = true;
    • }
    • function testPassword(password) {
    • return /(?=.{8,})(?=.*[A-Z])(?=.*[0-9])(?=.*[!"#\$%&'\(\)\*\+'\-./;:<>=\?])/.test(password);
    • }
    • //see if the password is over 8 digits long
    • if(password.length > 7){
    • number = true;
    • }
    • //provide final answer
    • if(cap && number && spec){
    • return true;
    • } else {
    • return false;
    • }
    • }
Code
Diff
  • #include <cmath>
    
    static bool willTheyMeet(
      int startHour1, 
      int endHour1, 
      int startHour2,
      int endHour2)
    {
      return !(
        fmax(startHour1, endHour1) < fmin(startHour2, endHour2) ||
        fmin(startHour1, endHour1) > fmax(startHour2, endHour2)
      );
    };
    • #include <cmath>
    • static float hourToRad(int hour)
    • {
    • return (float) hour * (M_PI / 12.0);
    • };
    • static bool willTheyMeet(
    • int startHour1,
    • int endHour1,
    • int startHour2,
    • int endHour2)
    • {
    • auto a1 = hourToRad(startHour1);
    • auto a2 = hourToRad(endHour1);
    • auto b1 = hourToRad(startHour2);
    • auto b2 = hourToRad(endHour2);
    • if (a1 == b2 || a2 == b1)
    • return false;
    • float da = (a2 - a1) / 2.0;
    • float db = (b2 - b1) / 2.0;
    • float ma = (a2 + a1) / 2.0;
    • float mb = (b2 + b1) / 2.0;
    • float cda = cos(da);
    • float cdb = cos(db);
    • return cos(ma - b1) >= cda ||
    • cos(ma - b2) >= cda ||
    • cos(mb - a1) >= cdb ||
    • cos(mb - a2) >= cdb;
    • return !(
    • fmax(startHour1, endHour1) < fmin(startHour2, endHour2) ||
    • fmin(startHour1, endHour1) > fmax(startHour2, endHour2)
    • );
    • };