#Java 8, (削除) 231 (削除ここまで)(削除) 193 (削除ここまで)(削除) 185 (削除ここまで)(削除) 122 (削除ここまで)(削除) 103 (削除ここまで) 78 bytes
Java 8, (削除) 231 (削除ここまで)(削除) 193 (削除ここまで)(削除) 185 (削除ここまで)(削除) 122 (削除ここまで)(削除) 103 (削除ここまで) 78 bytes
s->s.length==5&&(s[1]-s[0])*(s[3]-s[2])<0&(s[2]-s[1])*(s[4]-s[3])<0&s[4]==s[0]
-38 bytes thanks to @dpa97 for reminding me to use char[] instead of String.
-63 bytes thanks to @KarlNapf's derived formula.
-25 bytes by converting it from Java 7 to Java 8 (and now returning a boolean instead of integer).
193 bytes answer:
int c(char[]s){if(s.length!=5)return 0;int a=s[0],b=s[1],c=s[2],d=s[3],e=s[4],z=b-a,y=c-b,x=d-c,w=e-d;return e!=a?0:(z>0&y>0&x<0&w<0)|(z<0&y>0&x>0&w<0)|(z>0&y<0&x<0&w>0)|(z<0&y<0&x>0&w>0)?1:0;}
Explanation:
- If the length of the string isn't 5, we return
false - If the first character doesn't equal the last character, we return
false - Then we check the four valid cases one by one (let's indicate the five characters as 1 through 5), and return
trueif it complies to any of them (andfalseotherwise):- If the five characters are distributed like:
1<2<3>4>5(i.e.ALPHA) - If the five characters are distributed like:
1>2<3<4>5(i.e.EAGLE,HARSH,NINON,PINUP) - If the five characters are distributed like:
1<2>3>4<5(i.e.RULER) - If the five characters are distributed like:
1>2>3<4<5(i.e.THEFT,WIDOW)
- If the five characters are distributed like:
These four rules can be simplified to 1*3<0 and 2*4<0 (thanks to @KarlNapf's Python 2 answer).
#Java 8, (削除) 231 (削除ここまで)(削除) 193 (削除ここまで)(削除) 185 (削除ここまで)(削除) 122 (削除ここまで)(削除) 103 (削除ここまで) 78 bytes
s->s.length==5&&(s[1]-s[0])*(s[3]-s[2])<0&(s[2]-s[1])*(s[4]-s[3])<0&s[4]==s[0]
-38 bytes thanks to @dpa97 for reminding me to use char[] instead of String.
-63 bytes thanks to @KarlNapf's derived formula.
-25 bytes by converting it from Java 7 to Java 8 (and now returning a boolean instead of integer).
193 bytes answer:
int c(char[]s){if(s.length!=5)return 0;int a=s[0],b=s[1],c=s[2],d=s[3],e=s[4],z=b-a,y=c-b,x=d-c,w=e-d;return e!=a?0:(z>0&y>0&x<0&w<0)|(z<0&y>0&x>0&w<0)|(z>0&y<0&x<0&w>0)|(z<0&y<0&x>0&w>0)?1:0;}
Explanation:
- If the length of the string isn't 5, we return
false - If the first character doesn't equal the last character, we return
false - Then we check the four valid cases one by one (let's indicate the five characters as 1 through 5), and return
trueif it complies to any of them (andfalseotherwise):- If the five characters are distributed like:
1<2<3>4>5(i.e.ALPHA) - If the five characters are distributed like:
1>2<3<4>5(i.e.EAGLE,HARSH,NINON,PINUP) - If the five characters are distributed like:
1<2>3>4<5(i.e.RULER) - If the five characters are distributed like:
1>2>3<4<5(i.e.THEFT,WIDOW)
- If the five characters are distributed like:
These four rules can be simplified to 1*3<0 and 2*4<0 (thanks to @KarlNapf's Python 2 answer).
Java 8, (削除) 231 (削除ここまで)(削除) 193 (削除ここまで)(削除) 185 (削除ここまで)(削除) 122 (削除ここまで)(削除) 103 (削除ここまで) 78 bytes
s->s.length==5&&(s[1]-s[0])*(s[3]-s[2])<0&(s[2]-s[1])*(s[4]-s[3])<0&s[4]==s[0]
-38 bytes thanks to @dpa97 for reminding me to use char[] instead of String.
-63 bytes thanks to @KarlNapf's derived formula.
-25 bytes by converting it from Java 7 to Java 8 (and now returning a boolean instead of integer).
193 bytes answer:
int c(char[]s){if(s.length!=5)return 0;int a=s[0],b=s[1],c=s[2],d=s[3],e=s[4],z=b-a,y=c-b,x=d-c,w=e-d;return e!=a?0:(z>0&y>0&x<0&w<0)|(z<0&y>0&x>0&w<0)|(z>0&y<0&x<0&w>0)|(z<0&y<0&x>0&w>0)?1:0;}
Explanation:
- If the length of the string isn't 5, we return
false - If the first character doesn't equal the last character, we return
false - Then we check the four valid cases one by one (let's indicate the five characters as 1 through 5), and return
trueif it complies to any of them (andfalseotherwise):- If the five characters are distributed like:
1<2<3>4>5(i.e.ALPHA) - If the five characters are distributed like:
1>2<3<4>5(i.e.EAGLE,HARSH,NINON,PINUP) - If the five characters are distributed like:
1<2>3>4<5(i.e.RULER) - If the five characters are distributed like:
1>2>3<4<5(i.e.THEFT,WIDOW)
- If the five characters are distributed like:
These four rules can be simplified to 1*3<0 and 2*4<0 (thanks to @KarlNapf's Python 2 answer).
- 136.2k
- 14
- 154
- 394
#Java 78, (削除) 231 (削除ここまで) (削除) 193 (削除ここまで) (削除) 185 (削除ここまで) (削除) 122 (削除ここまで) 103(削除) 103 (削除ここまで) 78 bytes
int c(char[]s){return s->s.length==5&&(s[1]-s[0])*(s[3]-s[2])<0&(s[2]-s[1])*(s[4]-s[3])<0&s[4]==s[0]?1:0;}
-38 bytes thanks to @dpa97 for reminding me to use char[] instead of String.
-63 bytes thanks to @KarlNapf's derived formula.
-25 bytes by converting it from Java 7 to Java 8 (and now returning a boolean instead of integer).
It returns an int (0 or 1) instead of a boolean, because OP didn't explicit asked for a truthy/falsey return-type, but "The output can be true/false, 1/0, 1/Null, etc." instead.
Explanation:
- If the length of the string isn't 5, we return
0false(false) - If the first character doesn't equal the last character, we return
0false(false) - Then we check the four valid cases one by one (let's indicate the five characters as 1 through 5), and return
1true(true) if it complies to any of them (and0false(false) otherwise):- If the five characters are distributed like:
1<2<3>4>5(i.e.ALPHA) - If the five characters are distributed like:
1>2<3<4>5(i.e.EAGLE,HARSH,NINON,PINUP) - If the five characters are distributed like:
1<2>3>4<5(i.e.RULER) - If the five characters are distributed like:
1>2>3<4<5(i.e.THEFT,WIDOW)
- If the five characters are distributed like:
These four rules can be simplified to 1*3<0 and 2*4<0 (thanks to @KarlNapf's Python 2 answer).
Ungolfed & test code:
class M{
static int c(char[]s){
return s.length == 5
&& (s[1]-s[0])*(s[3]-s[2]) < 0 & (s[2]-s[1])*(s[4]-s[3]) < 0
& s[4]==s[0]
? 1
: 0;
}
public static void main(String[] a){
System.out.print(c("ALPHA".toCharArray()) + ",");
System.out.print(c("EAGLE".toCharArray()) + ",");
System.out.print(c("HARSH".toCharArray()) + ",");
System.out.print(c("NINON".toCharArray()) + ",");
System.out.print(c("PINUP".toCharArray()) + ",");
System.out.print(c("RULER".toCharArray()) + ",");
System.out.print(c("THEFT".toCharArray()) + ",");
System.out.println(c("WIDOW".toCharArray()));
System.out.print(c("CUBIC".toCharArray()) + ",");
System.out.print(c("ERASE".toCharArray()) + ",");
System.out.print(c("FLUFF".toCharArray()) + ",");
System.out.print(c("LABEL".toCharArray()) + ",");
System.out.print(c("MODEM".toCharArray()) + ",");
System.out.print(c("RADAR".toCharArray()) + ",");
System.out.print(c("RIVER".toCharArray()) + ",");
System.out.print(c("SWISS".toCharArray()) + ",");
System.out.print(c("TRUST".toCharArray()) + ",");
System.out.print(c("KNEES".toCharArray()) + ",");
System.out.print(c("QUEEN".toCharArray()) + ",");
System.out.print(c("GROOVE".toCharArray()) + ",");
System.out.print(c("ONLY".toCharArray()) + ",");
System.out.print(c("CHARACTER".toCharArray()) + ",");
System.out.print(c("OFF".toCharArray()) + ",");
System.out.print(c("IT".toCharArray()) + ",");
System.out.print(c("ORTHO".toCharArray()) + ",");
System.out.print(c("RULES".toCharArray()) + ",");
System.out.print(c("".toCharArray()));
}
}
Output:
1,1,1,1,1,1,1,1
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
#Java 7, (削除) 231 (削除ここまで) (削除) 193 (削除ここまで) (削除) 185 (削除ここまで) (削除) 122 (削除ここまで) 103 bytes
int c(char[]s){return s.length==5&&(s[1]-s[0])*(s[3]-s[2])<0&(s[2]-s[1])*(s[4]-s[3])<0&s[4]==s[0]?1:0;}
-38 bytes thanks to @dpa97 for reminding me to use char[] instead of String.
-63 bytes thanks to @KarlNapf's derived formula.
It returns an int (0 or 1) instead of a boolean, because OP didn't explicit asked for a truthy/falsey return-type, but "The output can be true/false, 1/0, 1/Null, etc." instead.
Explanation:
- If the length of the string isn't 5, we return
0(false) - If the first character doesn't equal the last character, we return
0(false) - Then we check the four valid cases one by one (let's indicate the five characters as 1 through 5), and return
1(true) if it complies to any of them (and0(false) otherwise):- If the five characters are distributed like:
1<2<3>4>5(i.e.ALPHA) - If the five characters are distributed like:
1>2<3<4>5(i.e.EAGLE,HARSH,NINON,PINUP) - If the five characters are distributed like:
1<2>3>4<5(i.e.RULER) - If the five characters are distributed like:
1>2>3<4<5(i.e.THEFT,WIDOW)
- If the five characters are distributed like:
These four rules can be simplified to 1*3<0 and 2*4<0 (thanks to @KarlNapf's Python 2 answer).
Ungolfed & test code:
class M{
static int c(char[]s){
return s.length == 5
&& (s[1]-s[0])*(s[3]-s[2]) < 0 & (s[2]-s[1])*(s[4]-s[3]) < 0
& s[4]==s[0]
? 1
: 0;
}
public static void main(String[] a){
System.out.print(c("ALPHA".toCharArray()) + ",");
System.out.print(c("EAGLE".toCharArray()) + ",");
System.out.print(c("HARSH".toCharArray()) + ",");
System.out.print(c("NINON".toCharArray()) + ",");
System.out.print(c("PINUP".toCharArray()) + ",");
System.out.print(c("RULER".toCharArray()) + ",");
System.out.print(c("THEFT".toCharArray()) + ",");
System.out.println(c("WIDOW".toCharArray()));
System.out.print(c("CUBIC".toCharArray()) + ",");
System.out.print(c("ERASE".toCharArray()) + ",");
System.out.print(c("FLUFF".toCharArray()) + ",");
System.out.print(c("LABEL".toCharArray()) + ",");
System.out.print(c("MODEM".toCharArray()) + ",");
System.out.print(c("RADAR".toCharArray()) + ",");
System.out.print(c("RIVER".toCharArray()) + ",");
System.out.print(c("SWISS".toCharArray()) + ",");
System.out.print(c("TRUST".toCharArray()) + ",");
System.out.print(c("KNEES".toCharArray()) + ",");
System.out.print(c("QUEEN".toCharArray()) + ",");
System.out.print(c("GROOVE".toCharArray()) + ",");
System.out.print(c("ONLY".toCharArray()) + ",");
System.out.print(c("CHARACTER".toCharArray()) + ",");
System.out.print(c("OFF".toCharArray()) + ",");
System.out.print(c("IT".toCharArray()) + ",");
System.out.print(c("ORTHO".toCharArray()) + ",");
System.out.print(c("RULES".toCharArray()) + ",");
System.out.print(c("".toCharArray()));
}
}
Output:
1,1,1,1,1,1,1,1
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
#Java 8, (削除) 231 (削除ここまで) (削除) 193 (削除ここまで) (削除) 185 (削除ここまで) (削除) 122 (削除ここまで) (削除) 103 (削除ここまで) 78 bytes
s->s.length==5&&(s[1]-s[0])*(s[3]-s[2])<0&(s[2]-s[1])*(s[4]-s[3])<0&s[4]==s[0]
-38 bytes thanks to @dpa97 for reminding me to use char[] instead of String.
-63 bytes thanks to @KarlNapf's derived formula.
-25 bytes by converting it from Java 7 to Java 8 (and now returning a boolean instead of integer).
Explanation:
- If the length of the string isn't 5, we return
false - If the first character doesn't equal the last character, we return
false - Then we check the four valid cases one by one (let's indicate the five characters as 1 through 5), and return
trueif it complies to any of them (andfalseotherwise):- If the five characters are distributed like:
1<2<3>4>5(i.e.ALPHA) - If the five characters are distributed like:
1>2<3<4>5(i.e.EAGLE,HARSH,NINON,PINUP) - If the five characters are distributed like:
1<2>3>4<5(i.e.RULER) - If the five characters are distributed like:
1>2>3<4<5(i.e.THEFT,WIDOW)
- If the five characters are distributed like:
These four rules can be simplified to 1*3<0 and 2*4<0 (thanks to @KarlNapf's Python 2 answer).
These four rules can be simplified to 1*3<0 and 2*4<0 (thanks to @KarlNapf's Python 2 answer @KarlNapf's Python 2 answer).
These four rules can be simplified to 1*3<0 and 2*4<0 (thanks to @KarlNapf's Python 2 answer).
These four rules can be simplified to 1*3<0 and 2*4<0 (thanks to @KarlNapf's Python 2 answer).
- 136.2k
- 14
- 154
- 394
- 136.2k
- 14
- 154
- 394
- 136.2k
- 14
- 154
- 394
- 136.2k
- 14
- 154
- 394
- 136.2k
- 14
- 154
- 394