36
1
An 'Even string' is any string where the parity of the ASCII values of the characters is always alternating. For example, the string EvenSt-ring$!
is an even-string because the ASCII values of the characters are:
69 118 101 110 83 116 45 114 105 110 103 36 33
And the parities of these numbers are:
Odd Even Odd Even Odd Even Odd Even Odd Even Odd Even Odd
Which is alternating the whole way. However, a string like Hello world!
is not an even string because the ASCII values are:
72 101 108 108 111 32 87 111 114 108 100 33
And the parities are:
Even Odd Even Even Odd Even Odd Odd Even Even Even Odd
Which is clearly not always alternating.
The challenge
You must write either a full program or a function that accepts a string for input and outputs a truthy value if the string is even, and a falsy value otherwise. You can take your input and output in any reasonable format, and you can assume that the input will only have printable ASCII (the 32-127 range). You do not have to handle empty input.
Examples
Here are some examples of even strings:
#define
EvenSt-ring$!
long
abcdABCD
3.141
~
0123456789
C ode - g ol!f
HatchingLobstersVexinglyPopulateJuvenileFoxglove
And all of these examples are not even strings:
Hello World
PPCG
3.1415
babbage
Code-golf
Standard loopholes apply
Shortest answer in bytes wins
Happy golfing!
You may also use this ungolfed solution to test any strings if you're curious about a certain test-case.
this may be slightly more readable – ASCII-only – 2016-10-13T08:56:16.877
1Can the input be length 1? Empty? – xnor – 2016-10-13T08:59:19.923
2@xnor There's a length-1 example in the test cases, but empty input is a good question. – Martin Ender – 2016-10-13T09:04:57.350
Add another uneven string as a test case:
lno
. – adrianmp – 2016-10-13T10:23:21.940@xnor The input may be length 1 (which is always even), but empty inputs may result in undefined behavior. I have added that clarification. – James – 2016-10-13T17:14:32.470
4Any bonus points for program itself being an even string? – Daerdemandt – 2016-10-13T19:14:36.813
@Daerdemandt I thought that's what this challenge was going to be when I first read it – Luigi – 2016-10-14T14:10:12.140