Skip to main content
Commonmark migration
Source Link

#Java 7, 157 153 150 125 117 bytes

Java 7, 157 153 150 125 117 bytes

int c(char[]z){for(int i=2,a,b,c;i<z.length;i++)if(((a=z[i-1])<(c=z[i])&(b=z[i-2])<a)|(a>=c&b>=a))return 0;return 1;}

Ungolfed & test cases:

Try it here.

class M{
  static int c(char[] z){
    for(int i = 2, a, b, c; i < z.length; i++){
      if(((a = z[i-1]) < (c = z[i]) & (b = z[i-2]) < a) | (a >= c & b >= a)){
        return 0; //false
      }
    }
    return 1; //true
  }

  public static void main(String[] a){
    System.out.print(c("ABA".toCharArray()) + ", ");
    System.out.print(c("ABB".toCharArray()) + ", ");
    System.out.print(c("BAB".toCharArray()) + ", ");
    System.out.print(c("BUMP".toCharArray()) + ", ");
    System.out.print(c("BALD".toCharArray()) + ", ");
    System.out.print(c("BALDY".toCharArray()) + ", ");
    System.out.print(c("UPWARD".toCharArray()) + ", ");
    System.out.print(c("EXAMINATION".toCharArray()) + ", ");
    System.out.print(c("AZBYCXDWEVFUGTHSIRJQKPLOMN".toCharArray()) + ", ");

    System.out.print(c("AAA".toCharArray()) + ", ");
    System.out.print(c("ACE".toCharArray()) + ", ");
    System.out.print(c("THE".toCharArray()) + ", ");
    System.out.print(c("BUMPY".toCharArray()) + ", ");
    System.out.print(c("BALDING".toCharArray()) + ", ");
    System.out.print(c("ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()) + ", ");
  }
}

Output:

1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0

#Java 7, 157 153 150 125 117 bytes

int c(char[]z){for(int i=2,a,b,c;i<z.length;i++)if(((a=z[i-1])<(c=z[i])&(b=z[i-2])<a)|(a>=c&b>=a))return 0;return 1;}

Ungolfed & test cases:

Try it here.

class M{
  static int c(char[] z){
    for(int i = 2, a, b, c; i < z.length; i++){
      if(((a = z[i-1]) < (c = z[i]) & (b = z[i-2]) < a) | (a >= c & b >= a)){
        return 0; //false
      }
    }
    return 1; //true
  }

  public static void main(String[] a){
    System.out.print(c("ABA".toCharArray()) + ", ");
    System.out.print(c("ABB".toCharArray()) + ", ");
    System.out.print(c("BAB".toCharArray()) + ", ");
    System.out.print(c("BUMP".toCharArray()) + ", ");
    System.out.print(c("BALD".toCharArray()) + ", ");
    System.out.print(c("BALDY".toCharArray()) + ", ");
    System.out.print(c("UPWARD".toCharArray()) + ", ");
    System.out.print(c("EXAMINATION".toCharArray()) + ", ");
    System.out.print(c("AZBYCXDWEVFUGTHSIRJQKPLOMN".toCharArray()) + ", ");

    System.out.print(c("AAA".toCharArray()) + ", ");
    System.out.print(c("ACE".toCharArray()) + ", ");
    System.out.print(c("THE".toCharArray()) + ", ");
    System.out.print(c("BUMPY".toCharArray()) + ", ");
    System.out.print(c("BALDING".toCharArray()) + ", ");
    System.out.print(c("ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()) + ", ");
  }
}

Output:

1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0

Java 7, 157 153 150 125 117 bytes

int c(char[]z){for(int i=2,a,b,c;i<z.length;i++)if(((a=z[i-1])<(c=z[i])&(b=z[i-2])<a)|(a>=c&b>=a))return 0;return 1;}

Ungolfed & test cases:

Try it here.

class M{
  static int c(char[] z){
    for(int i = 2, a, b, c; i < z.length; i++){
      if(((a = z[i-1]) < (c = z[i]) & (b = z[i-2]) < a) | (a >= c & b >= a)){
        return 0; //false
      }
    }
    return 1; //true
  }

  public static void main(String[] a){
    System.out.print(c("ABA".toCharArray()) + ", ");
    System.out.print(c("ABB".toCharArray()) + ", ");
    System.out.print(c("BAB".toCharArray()) + ", ");
    System.out.print(c("BUMP".toCharArray()) + ", ");
    System.out.print(c("BALD".toCharArray()) + ", ");
    System.out.print(c("BALDY".toCharArray()) + ", ");
    System.out.print(c("UPWARD".toCharArray()) + ", ");
    System.out.print(c("EXAMINATION".toCharArray()) + ", ");
    System.out.print(c("AZBYCXDWEVFUGTHSIRJQKPLOMN".toCharArray()) + ", ");

    System.out.print(c("AAA".toCharArray()) + ", ");
    System.out.print(c("ACE".toCharArray()) + ", ");
    System.out.print(c("THE".toCharArray()) + ", ");
    System.out.print(c("BUMPY".toCharArray()) + ", ");
    System.out.print(c("BALDING".toCharArray()) + ", ");
    System.out.print(c("ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()) + ", ");
  }
}

Output:

1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0
Changed boolean to int to save a couple of bytes
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#Java 7, 157 153 150 125125 117 bytes

booleanint c(char[]z){for(int i=2,a,b,c;i<z.length;i++)if(((a=z[i-1])<(c=z[i])&(b=z[i-2])<a)|(a>=c&b>=a))return 0>1;return0;return 1>0;1;}
class M{
  static booleanint c(char[] z){
    for(int i = 2, a, b, c; i < z.length; i++){
      if(((a = z[i-1]) < (c = z[i]) & (b = z[i-2]) < a) | (a >= c & b >= a)){
        return 0>1;0; //false
      }
    }
    return 1>0;1; //true
  }

  public static void main(String[] a){
    System.out.printlnprint(c("ABA".toCharArray()) + ", ");
    System.out.printlnprint(c("ABB".toCharArray()) + ", ");
    System.out.printlnprint(c("BAB".toCharArray()) + ", ");
    System.out.printlnprint(c("BUMP".toCharArray()) + ", ");
    System.out.printlnprint(c("BALD".toCharArray()) + ", ");
    System.out.printlnprint(c("BALDY".toCharArray()) + ", ");
    System.out.printlnprint(c("UPWARD".toCharArray()) + ", ");
    System.out.printlnprint(c("EXAMINATION".toCharArray()) + ", ");
    System.out.printlnprint(c("AZBYCXDWEVFUGTHSIRJQKPLOMN".toCharArray()) + ", ");

    System.out.printlnprint(c("AAA".toCharArray()) + ", ");
    System.out.printlnprint(c("ACE".toCharArray()) + ", ");
    System.out.printlnprint(c("THE".toCharArray()) + ", ");
    System.out.printlnprint(c("BUMPY".toCharArray()) + ", ");
    System.out.printlnprint(c("BALDING".toCharArray()) + ", ");
    System.out.printlnprint(c("ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()) + ", ");
  }
}
true
true
true
true
true
true
true
true
true
false
false
false
false
false
false1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0

#Java 7, 157 153 150 125 bytes

boolean c(char[]z){for(int i=2,a,b,c;i<z.length;i++)if(((a=z[i-1])<(c=z[i])&(b=z[i-2])<a)|(a>=c&b>=a))return 0>1;return 1>0;}
class M{
  static boolean c(char[] z){
    for(int i = 2, a, b, c; i < z.length; i++){
      if(((a = z[i-1]) < (c = z[i]) & (b = z[i-2]) < a) | (a >= c & b >= a)){
        return 0>1; //false
      }
    }
    return 1>0; //true
  }

  public static void main(String[] a){
    System.out.println(c("ABA".toCharArray()));
    System.out.println(c("ABB".toCharArray()));
    System.out.println(c("BAB".toCharArray()));
    System.out.println(c("BUMP".toCharArray()));
    System.out.println(c("BALD".toCharArray()));
    System.out.println(c("BALDY".toCharArray()));
    System.out.println(c("UPWARD".toCharArray()));
    System.out.println(c("EXAMINATION".toCharArray()));
    System.out.println(c("AZBYCXDWEVFUGTHSIRJQKPLOMN".toCharArray()));

    System.out.println(c("AAA".toCharArray()));
    System.out.println(c("ACE".toCharArray()));
    System.out.println(c("THE".toCharArray()));
    System.out.println(c("BUMPY".toCharArray()));
    System.out.println(c("BALDING".toCharArray()));
    System.out.println(c("ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()));
  }
}
true
true
true
true
true
true
true
true
true
false
false
false
false
false
false

#Java 7, 157 153 150 125 117 bytes

int c(char[]z){for(int i=2,a,b,c;i<z.length;i++)if(((a=z[i-1])<(c=z[i])&(b=z[i-2])<a)|(a>=c&b>=a))return 0;return 1;}
class M{
  static int c(char[] z){
    for(int i = 2, a, b, c; i < z.length; i++){
      if(((a = z[i-1]) < (c = z[i]) & (b = z[i-2]) < a) | (a >= c & b >= a)){
        return 0; //false
      }
    }
    return 1; //true
  }

  public static void main(String[] a){
    System.out.print(c("ABA".toCharArray()) + ", ");
    System.out.print(c("ABB".toCharArray()) + ", ");
    System.out.print(c("BAB".toCharArray()) + ", ");
    System.out.print(c("BUMP".toCharArray()) + ", ");
    System.out.print(c("BALD".toCharArray()) + ", ");
    System.out.print(c("BALDY".toCharArray()) + ", ");
    System.out.print(c("UPWARD".toCharArray()) + ", ");
    System.out.print(c("EXAMINATION".toCharArray()) + ", ");
    System.out.print(c("AZBYCXDWEVFUGTHSIRJQKPLOMN".toCharArray()) + ", ");

    System.out.print(c("AAA".toCharArray()) + ", ");
    System.out.print(c("ACE".toCharArray()) + ", ");
    System.out.print(c("THE".toCharArray()) + ", ");
    System.out.print(c("BUMPY".toCharArray()) + ", ");
    System.out.print(c("BALDING".toCharArray()) + ", ");
    System.out.print(c("ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()) + ", ");
  }
}
1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0
edited body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#Java 7, 157 153 150 125 bytes

boolean c(char[]z){for(int i=2,a,b,c;i<z.length;i++)if(((a=z[i-1])<(c=z[i])&(b=z[i-2])<a)|(a>=c&b>=a))return 0>1;return 1>0;}

Ungolfed & test cases:

Try it here.

class M{
  static boolean c(Stringchar[] sz){
    for(int i = 2, a, b, c; i < z.length; i++){
      if(((a = z[i-1]) < (c = z[i]) & (b = z[i-2]) < a) | (a >= c & b >= a)){
        return 0>1; //false
      }
    }
    return 1>0; //true
  }

  public static void main(String[] a){
    System.out.println(c("ABA".toCharArray()));
    System.out.println(c("ABB".toCharArray()));
    System.out.println(c("BAB".toCharArray()));
    System.out.println(c("BUMP".toCharArray()));
    System.out.println(c("BALD".toCharArray()));
    System.out.println(c("BALDY".toCharArray()));
    System.out.println(c("UPWARD".toCharArray()));
    System.out.println(c("EXAMINATION".toCharArray()));
    System.out.println(c("AZBYCXDWEVFUGTHSIRJQKPLOMN".toCharArray()));

    System.out.println(c("AAA".toCharArray()));
    System.out.println(c("ACE".toCharArray()));
    System.out.println(c("THE".toCharArray()));
    System.out.println(c("BUMPY".toCharArray()));
    System.out.println(c("BALDING".toCharArray()));
    System.out.println(c("ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()));
  }
}

Output:

true
true
true
true
true
true
true
true
true
false
false
false
false
false
false

#Java 7, 157 153 150 125 bytes

boolean c(char[]z){for(int i=2,a,b,c;i<z.length;i++)if(((a=z[i-1])<(c=z[i])&(b=z[i-2])<a)|(a>=c&b>=a))return 0>1;return 1>0;}

Ungolfed & test cases:

Try it here.

class M{
  static boolean c(String s){
    for(int i = 2, a, b, c; i < z.length; i++){
      if(((a = z[i-1]) < (c = z[i]) & (b = z[i-2]) < a) | (a >= c & b >= a)){
        return 0>1; //false
      }
    }
    return 1>0; //true
  }

  public static void main(String[] a){
    System.out.println(c("ABA".toCharArray()));
    System.out.println(c("ABB".toCharArray()));
    System.out.println(c("BAB".toCharArray()));
    System.out.println(c("BUMP".toCharArray()));
    System.out.println(c("BALD".toCharArray()));
    System.out.println(c("BALDY".toCharArray()));
    System.out.println(c("UPWARD".toCharArray()));
    System.out.println(c("EXAMINATION".toCharArray()));
    System.out.println(c("AZBYCXDWEVFUGTHSIRJQKPLOMN".toCharArray()));

    System.out.println(c("AAA".toCharArray()));
    System.out.println(c("ACE".toCharArray()));
    System.out.println(c("THE".toCharArray()));
    System.out.println(c("BUMPY".toCharArray()));
    System.out.println(c("BALDING".toCharArray()));
    System.out.println(c("ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()));
  }
}

Output:

true
true
true
true
true
true
true
true
true
false
false
false
false
false
false

#Java 7, 157 153 150 125 bytes

boolean c(char[]z){for(int i=2,a,b,c;i<z.length;i++)if(((a=z[i-1])<(c=z[i])&(b=z[i-2])<a)|(a>=c&b>=a))return 0>1;return 1>0;}

Ungolfed & test cases:

Try it here.

class M{
  static boolean c(char[] z){
    for(int i = 2, a, b, c; i < z.length; i++){
      if(((a = z[i-1]) < (c = z[i]) & (b = z[i-2]) < a) | (a >= c & b >= a)){
        return 0>1; //false
      }
    }
    return 1>0; //true
  }

  public static void main(String[] a){
    System.out.println(c("ABA".toCharArray()));
    System.out.println(c("ABB".toCharArray()));
    System.out.println(c("BAB".toCharArray()));
    System.out.println(c("BUMP".toCharArray()));
    System.out.println(c("BALD".toCharArray()));
    System.out.println(c("BALDY".toCharArray()));
    System.out.println(c("UPWARD".toCharArray()));
    System.out.println(c("EXAMINATION".toCharArray()));
    System.out.println(c("AZBYCXDWEVFUGTHSIRJQKPLOMN".toCharArray()));

    System.out.println(c("AAA".toCharArray()));
    System.out.println(c("ACE".toCharArray()));
    System.out.println(c("THE".toCharArray()));
    System.out.println(c("BUMPY".toCharArray()));
    System.out.println(c("BALDING".toCharArray()));
    System.out.println(c("ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()));
  }
}

Output:

true
true
true
true
true
true
true
true
true
false
false
false
false
false
false
Changed String input to char[] to save 25 bytes
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading
Fixed with changed rules, resulting in -3 bytes
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading