# Permutations and recurrence equation

First problem: I need to show all Permutations with length 4 of this elements {x, y, z, w, t} but with this condition: the element z mustn't be after element t. I tryed this :

A = {x, y, z, w, t}
Permutations[A, {4 }]


But don't know how to remove those permutations in which z is after t.

Second problem: I have a recurrence equation in which i have to print the first 11 member of the sequence a which are the answers of the equation but they don't have the digit 3 in their number.

RecurrenceTable[{a[n + 1] == 11*a[n], a[1] == 7}, a[n], {n, 1, 11}]


For a reasonable number of items, make them all and delete the ones you don't want.

A = {x, y, z, w, t};
DeleteCases[Permutations[A, {4}], {___, t, ___, z, ___}]

• yeah but i have a lot to delete isn't there any function to delete them all at once ? May 13, 2015 at 14:22
• @Vlatko I don't understand. How can you "have a lot to delete"? There are only 84 cases and it takes (on a Mac Pro) just 0.000157 seconds to compute them all. May 13, 2015 at 15:08
• Sry i didn't wrote the function at first the right way it works perfectly thank you very much ::)) May 13, 2015 at 20:50

For your second problem, use IntegerDigits, MemberQ and Select to find elements of the sequence that do not (!MemberQ[...,3]) have a 3 digit ...

Select[RecurrenceTable[{a[n+1]==11*a[n],a[1]==7},
a[n], {n,1,11}],!MemberQ[IntegerDigits@#,3]&]

(* results {7, 77, 847, 102487, 12400927, 1500512167, 181561972207} *)

• Thanks man it worked perfectly :)) May 13, 2015 at 20:51

Just for variety (for second part):

f[n_] := Nest[11 # &, 7, n - 1]
q[n_] := Times @@ Unitize[IntegerDigits[n] - 3];
lst = f /@ Range[11];


Approaches:

Reap[Sow[f@#, q@(f@#)] & /@ Range[11], 1, #2 &][[2, 1]]
Pick[lst, q /@ lst, 1]
1 /. GroupBy[lst, q]


All yield:

{7, 77, 847, 102487, 12400927, 1500512167, 181561972207}