32
1
Almost six years ago, fellow PPCG member steenslag posted the following challenge:
In a standard dice (die) the numbers are arranged so that opposite faces add to seven. Write the shortest possible program in your preferred language which outputs a random throw followed by 9 random tippings. A tipping is a quarter turn of the dice, e.g. if the dice is facing 5, all possible tippings are 1,3,4 and 6.
Example of desired output:
1532131356
So, now that everybody has completely forgotten about it and the winning answer has long since been accepted, we'll be writing a program to validate the die tipping sequences generated by the submitted solutions. (This makes sense. Just pretend it does.)
Challenge
Your program or function is given a sequence such as 1532131356
. Validate that each consecutive digit is:
- Not equal to the previous digit
- Not equal to 7 minus the previous digit
(You don't have to validate the first digit.)
Rules
- Your program must return a truthy value if the input is valid and a falsey value otherwise.
- You can assume that the input consists of only the digits 1-6 and is at least 1 character long. Sequences won't have a fixed length like in steenslag's challenge.
- You can take the input as a string (
"324324"
), an array or array-like datastructure ([1,3,5]
) or as multiple arguments (yourFunction(1,2,4)
).
Standard I/O and loophole rules apply.
Test cases
Truthy
1353531414
3132124215
4142124136
46
4264626313135414154
6
2642156451212623232354621262412315654626212421451351563264123656353126413154124151545145146535351323
5414142
Falsey
Repeated digit
11 3132124225 6423126354214136312144245354241324231415135454535141512135141323542451231236354513265426114231536245 553141454631 14265411
Opposing side of die
16 42123523545426464236231321 61362462636351 62362462636361
4Welcome to PPCG, This is a really nice first answer. – Post Rock Garf Hunter – 2016-12-21T14:53:11.867
1This doesn't work for about half of the false cases. E.g.
3132124225
returns5
. – Jake Cobb – 2016-12-21T15:37:24.357You can fix it using
n and p*(7-p!=n!=p)
. – Jake Cobb – 2016-12-21T15:45:35.387@JakeCobb It should work with all the test cases now. Unfortunately it's now 2 bytes longer :( – notjagan – 2016-12-21T17:46:30.873
What a clever use of reduce, passing each value to the next step. – xnor – 2016-12-22T04:38:21.360