Is it a Bumpy Word?
MATL, 4 bytes
d0>d
Explanation:
d % Implicitly take input. Take difference between each element
0> % Check whether diff's are positive. Should result in [0 1 0 1 ...] pattern.
d % Again take the difference. Any consecutive rises or falls results in a
% difference of 0, which is a falsy value in MATL
This is my first MATL entry, so I wonder how much improvement there can be from this naive port from my MATLAB/Octave attempt (which would be @(a)all(diff(diff(a)>0))
). Note that the all
is not necessary because any zero makes an array false, so there's no A
in the MATL port.
JavaScript (ES6), 75 69 63 46 43 bytes
Saved 3 bytes thanks to Neil:
f=([c,...s])=>s[1]?c<s[0]^s[0]<s[1]&&f(s):1
Destructuring the string parameter instead of s.slice(1)
.
Previous solution:
Saved 17 bytes thanks to ETHproductions:
f=s=>s[2]?s[0]<s[1]^s[1]<s[2]&&f(s.slice(1)):1
What happened from the previous solution step by step:
f=(s,i=0,a=s[i++]<s[i])=>s[i+1]&&(b=a^(a=s[i]<s[i+1]))?f(s,i):b // (63) Original
f=(s,i=0,a=s[i++]<s[i])=>s[i+1]&&(b=a^(s[i]<s[i+1]))?f(s,i):b // (61) No point in reassigning `a`, it's not used again
f=(s,i=0,a=s[i++]<s[i])=>s[i+1]&&(b=a^s[i]<s[i+1])?f(s,i):b // (59) Remove unnecessary parentheses
f=(s,i=0)=>s[i+2]&&(b=s[i++]<s[i]^s[i]<s[i+1])?f(s,i):b // (55) `a` is now just a waste of bytes
f=(s,i=0)=>s[i+2]?(b=s[i++]<s[i]^s[i]<s[i+1])?f(s,i):b:1 // (56) Rearrange conditional expressions to allow for more golfing
f=(s,i=0)=>s[i+2]?(b=s[i++]<s[i]^s[i]<s[i+1])&&f(s,i):1 // (55) Rearrange conditional expression
f=(s,i=0)=>s[i+2]?(s[i++]<s[i]^s[i]<s[i+1])&&f(s,i):1 // (53) `b` is now also a waste of bytes
f=(s,i=0)=>s[i+2]?s[i++]<s[i]^s[i]<s[i+1]&&f(s,i):1 // (51) Remove unnecessary parentheses
f=s=>s[2]?s[0]<s[1]^s[1]<s[2]&&f(s.slice(1)):1 // (46) Use `s.slice(1)` instead of `i`
Previous solutions:
63 bytes thanks to ETHproductions:
f=(s,i=0,a=s[i++]<s[i])=>s[i+1]&&(b=a^(a=s[i]<s[i+1]))?f(s,i):b
69 bytes:
f=(s,i=0,a=s[i++]<s[i])=>i+1<s.length&&(b=a^(a=s[i]<s[i+1]))?f(s,i):b
75 bytes:
f=(s,a=s[0]<s[1])=>{for(i=1;i+1<s.length&&(b=a^(a=s[i++]<s[i])););return b}
All letters in a word must have the same case.
LabVIEW, 36 equivalent bytes
Golfed down using logical equivalences:
Ungolfed:
First we convert to lowercase, then to byte array. Trim off the first element of the byte array as it has no precedent. Then, for each element in the array, check if it's greater than the previous one (U8 char maps to ASCII as you expect) and store the result for the next iteration, as well as in an array for viewing overall bumpiness. If the current and prior boolean check are equal, we terminate the loop and it's not bumpy. Else, it's bumpy!