Tag Info

New answers tagged

4

f1[{a_, b_, ___}] := {a, f[a, b], b}; g1[{a_, B_, b_}] := {g[a, B, b], B, b}; NestList[g1[f1[#]] &, {a, b}, 2][[All, 1 ;; 2]] // TableForm (* a b g[a,f[a,b],b] f[a,b] g[g[a,f[a,b],b],f[g[a,f[a,b],b],f[a,b]],f[a,b]] f[g[a,f[a,b],b],f[a,b]] *) To get your nomenclature ...


1

This does what you want: With[{count = 3, start = {a, b}}, Most /@ NestList[Composition[Prepend[Rest@#, g@@#]&, {#[[1]], f[#[[1]], #[[2]]], #[[2]]}&], Append[start, 0], count]] Explanation: ...& defines an anonymous function. # accesses its argument, which is the list. [[n]] just ...


2

These are marginally faster than yours: mySet = RandomChoice[CharacterRange["a", "z"], 10000]; Times @@ Last /@ Tally@mySet or: Times @@ Tally@mySet // Last


2

Version 10: Times @@ Counts @ mySet (* 12 *) Other versions: Times @@ Length /@ Gather @ mySet (* 12 *) Times @@ Length /@ Split @ Sort @ mySet (* 12 *) Some timings: testdata=RandomChoice[CharacterRange["a","z"],{10000}]; Times @@ Transpose[Tally[testdata]][[2]]//AbsoluteTiming//First (* 0.00170 *) Times@@Counts@testdata//AbsoluteTiming//First (* ...


2

Here is how you can do it using NestList and some code vectorization mat1[[1 ;; 2]] = Module[{ct = 1}, NestList[({{const1, const2}, {const3, const4}}.#) mat2[[1 ;; 2, ++ct]] &, mat1[[1 ;; 2, 1]], n - 1] //Transpose]; Assuming that the variables const1 to const4 have numerical values close enough to 1, e.g. const1 = 1.0; const2 = 0.9; const3 = ...



Top 50 recent answers are included