Hi Elias,
If I understood your solution correctly, it basically boils down to the (correct, as far as I can tell) assumption that, for every block of adjacent facedown pancakes, you need two flips:  one to flip all the pancakes up to the first facedown one  one to flip the whole block of now facedown pancakes back faceup
This seems to always be correct, except if the very top block is facedown, in which case one extra flip is required for that block.
Having understood this, I came up with a slightly different solution: (~↑X)+2×+/2>/X if 0 represents a facedown pancake, and (↑X)+2×+/2</X obviously if 1 represents a facedown one.
Does this seem correct to you? If it does, I hope it helped others understand your solution.
Cheers, Louis
No, actually not. The problem statement says that the final state of the pancake stack should be that they are all facing up. Thus if the final state is 0,there needs to be an extra flip done. Regards,
Elias
On 23 Jun 2016 02:25, "Juergen Sauermann" < address@hidden> wrote:
Hi,
a minor bug below:
+/(X,1)≠(1↑X),X←1 1 1 0 1 1 1 1 1 0 0 0 1 0 0 1 0 0 0 0
8
+/(X,1)≠(1↑X),X←1 1 1 0 1 1 1 1 1 0 0 0 1 0 0 1 0 0
0 1
8
Maybe you meant
+/(X,¯1↑X)≠(1↑X),X←1 1 1 0 1 1 1 1 1 0 0 0 1 0 0 1 0 0 0 0
7
+/(X,¯1↑X)≠(1↑X),X←1 1 1 0 1 1 1 1 1 0 0 0 1 0 0 1 0 0 0
1
8
/// Jürgen
On 06/22/2016 08:27 AM, Elias Mårtenson
wrote:
It's quite simple actually. The idea is simply based on the
observation that what you really want to compute is the number
of transitions 0→1 and 1→0.
The original list is compared to another list that is the
same as the original, but shifted one step to the left. The
last element shifted in is a 1, since you always want the
final stack to be facesideup.
Thus, the comparison is:
1 1 1 0 1 1 1 1 1 0 0 0 1 0 0 1 0
0 0 1
1 1 0 1 1 1 1 1 0 0 0 1 0 0 1 0 0
0 1 1

0 0 1 1 0 0 0 0 1 0 0 1 1 0 1 1 0
0 1 0
Then, all you have to do is
to count the number of ones in the result.
Addendum:
I just thought of a
different way to think of this. If I simply remove any
series of consecutive numbers, all I have to do is to count
the length of the resulting array (subtracting one if the
final element is 1). However, the method of eliminating
duplicates in APL is very similar to the above solution
(comparing with a shifted array) so even if you approach the
problem in this way, the code will be pretty much identical.
Regards,
Elias
