1
$\begingroup$

I tried this code but it doesn't work. DeleteCases[Tuples[{0, 1, 2}, 3], {_ 1, 1, _}].

$\endgroup$

closed as off-topic by MarcoB, Bob Hanlon, xyz, dr.blochwave, C. E. Jun 12 '15 at 14:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, Bob Hanlon, xyz, dr.blochwave, C. E.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Try replacing _ with ___ (i.e. three underscores rather than one). Also, you have a missing comma. So: {___, 1, 1, ___}. $\endgroup$ – march Jun 11 '15 at 17:24
  • 2
    $\begingroup$ Where the comma is missing? I think it multiples Blank (which is _) by 1, resulting in _. So you were trying to delete all cases that match {_, 1, _}, i.e. all triples with 1 in the center spot. By the way, the three underscores matches any sequence of 0, 1, or more elements. This makes it so that you can match, for instance, {1,1,0}. $\endgroup$ – march Jun 11 '15 at 17:29
  • 2
    $\begingroup$ Errrr ... Not recommended Select[{{##} + 1, #1^#2 #2^#3} & @@@ (Tuples[{0, 1, 2}, 3] - 1) // Quiet, Last@# =!= Indeterminate &][[All, 1]] $\endgroup$ – Dr. belisarius Jun 11 '15 at 17:35
  • 2
    $\begingroup$ Also not recommended, but using pattern matching Cases[{{##} + 1, #1^#2 #2^#3} & @@@ (Tuples[{0, 1, 2}, 3] - 1) // Quiet, {x_, y : Except[Indeterminate]} :> x] $\endgroup$ – Dr. belisarius Jun 11 '15 at 17:38
  • 2
    $\begingroup$ @march A half-witted one ;) (({Abs[Times @@ (1 - Times @@ Partition[#, 2, 1])], #} & /@ Tuples[{0, 1, 2}, 3] // Sort // SplitBy[#, First] &) // Rest)[[All, All, 2]] // Flatten[#, 1] & $\endgroup$ – Dr. belisarius Jun 11 '15 at 18:14
3
$\begingroup$

Given my simple but sane mind (unlike belisarius who has a brilliant but twisted one), I would solve your problem by modifying your code just a bit.

DeleteCases[Tuples[{0, 1, 2}, 3], {1, 1, _} | {_, 1, 1}]
{{0, 0, 0}, {0, 0, 1}, {0, 0, 2}, {0, 1, 0}, {0, 1, 2}, {0, 2, 0}, 
 {0, 2, 1}, {0, 2, 2}, {1, 0, 0}, {1, 0, 1}, {1, 0, 2}, {1, 2, 0}, 
 {1, 2, 1}, {1, 2, 2}, {2, 0, 0}, {2, 0, 1}, {2, 0, 2}, {2, 1, 0}, 
 {2, 1, 2}, {2, 2, 0}, {2, 2, 1}, {2, 2, 2}}

This works because in this problem, for two ones to appear consecutively, they must be in the 1st two slots or (inclusively) the 2nd two slots. I think this should be a little faster than using ___, but it doesn't matter much with your very small alphabet.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.