Sector Five

5.01 - if (s.Length <= 3){
   return "short";
   }
   if (s.Length >= 4 && s.Length <= 7){
   return "average";
   }
   if(s.Length >= 8 && s.Length <= 14){
   return "long";
   }
   return "super long";
5.02 - thx
 if (i % 1111 == 0) return "fancy year";
return "not a fancy year";

5.04 - if (y > 0 && x < 0){
   return (x-y) - 2*(x-y);
   }
   if (x > 0 && y < 0){
   return (x-y);
   }

    if ((x+y) < 0){
return (x+y) - 2*(x+y);
    }
return x + y;
5.05 - return (j == i*i)

3 comments:

  1. There's an easier solution for 5.02:

    public static String Puzzle(int i) {
    if (i % 1111 == 0) return "fancy year";
    return "not a fancy year";
    }

    ReplyDelete
  2. Shorter solution for 5.05:
    return j==i*i;

    ReplyDelete
  3. 5.01 (s.Length <= 3 ? "short" : s.Length <= 7 ? "average" : s.Length <= 14 ? "long" : "super long")
    5.02 (i % 1111 == 0 ? "fancy year" : "not a fancy year")
    5.03 (a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a)
    5.04 Math.Abs(x)+Math.Abs(y)
    5.05 (j == i*i)

    ReplyDelete