2
$\begingroup$

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}]
$\endgroup$

3 Answers 3

2
$\begingroup$

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, ___}]
$\endgroup$
3
  • $\begingroup$ yeah but i have a lot to delete isn't there any function to delete them all at once ? $\endgroup$
    – Vlatko
    May 13, 2015 at 14:22
  • $\begingroup$ @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. $\endgroup$ May 13, 2015 at 15:08
  • $\begingroup$ Sry i didn't wrote the function at first the right way it works perfectly thank you very much ::)) $\endgroup$
    – Vlatko
    May 13, 2015 at 20:50
2
$\begingroup$

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} *)
$\endgroup$
1
  • $\begingroup$ Thanks man it worked perfectly :)) $\endgroup$
    – Vlatko
    May 13, 2015 at 20:51
0
$\begingroup$

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}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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