Tag Info

New answers tagged

3

Your operation using the v10 operator form for MemberQ, along with Alternatives: uno = RandomSample[Range @ 52] ~Partition~ 13; And @@ MemberQ[1 | 14 | 27 | 40] /@ uno Or using modular arithmetic as already provided by others: x = RandomSample @ Range @ 52; Sign[x ~Mod~ 13] ~Partition~ 4 // Total {12, 11, 13, 12} This is the number of non-ace ...


3

Just for fun: You can count number of "aces" (obviously arbitrary choice) 4 sets of 13 cards: Total /@ Partition[ Boole[Mod[#, 13] == 1] & /@ RandomSample[Range@52, 52], 13] For simulation: tab[n_] := Table[Total /@ Partition[Boole[Mod[#, 13] == 1] & /@ RandomSample[Range@52, 52], 13], {n}]; Now cheating by just testing ...


3

Just write simpler code! Here's an example... first, the setup: cards = 52; uno = Partition[RandomSample[Range[cards], cards], cards/4]; aces = 1 + {0, 1, 2, 3} cards/4; (it's a bit easier to test if you set cards = 12). FreeQ[ Intersection[aces, #] & /@ uno, {}] Enjoy.


4

Uuuh, that's like a breeze.... ace= {1, 14, 27, 40}; uno = Partition[RandomSample[Range[52], 52], 13]; Intersection[#, ace] & /@ uno This returns the Aces returned in each hand let's go gambling....hi,hi,hi


1

Here's one way... g[1][x_] := 1; g[2][x_] := x; g[3][x_] := x^2; norm[r_, s_] := Integrate[r[x]*s[x] + r'[x]*s'[x], {x, 0, 1}]; gram=Array[norm[g[#1], g[#2]] &, {3, 3}] or... gram=Table[norm[a, b], {a, {g1, g2, g3}}, {b, {g1, g2, g3}}]; or... gram=Outer[norm, {g1, g2, g3}, {g1, g2, g3}]


2

Use this instead: FindInstance[#, {a, b}]& /@ {a + b > 1 && a + b < 2, a + b > 2 && a + b < 3} or, in fact, this: FindInstance[#, {a, b}]& /@ {{a + b > 1, a + b < 2}, {a + b > 2, a + b < 3}}


7

MovingMap is doing, what it is supposed to do. Evaluating AbsoluteTime /@ (Data[[1 ;; 5]][[All, 1]]) {3439843200, 3440102400, 3440188800, 3440275200, 3440361600} gives the timestamps for the first five data points in absolute time. The output of MovingMap[foo[#] &, Data, 5] or simpler MovingMap[foo[#] &, Data[[1 ;; 5]], 5] ...


0

f[##, c] & @@@ (Transpose[{{a1, a2}, {b1, b2}}]) (*{f[a1, b1, c], f[a2, b2, c]}*)


3

Thread[f[{a1, a2}, {b1, b2}, c]] (* {f[a1, b1, c], f[a2, b2, c]} *) Thread[f[{a1, a2}, {b1, b2}, c1 -> c11]] (* {f[a1, b1, c1 -> c11], f[a2, b2, c1 -> c11]} *)


5

Since c is common to all the entries, I would do this: MapThread[f[##, c] &, {{a1, a2}, {b1, b2}}] (* ==> {f[a1, b1, c] , f[a2, b2, c]} *) Here the ## stands for SlotSequence and accepts the pair of arguments fed into it by Inner, taken from the two Lists. This is based on constructing a pure function (identified by the & at the end) that is ...


3

lst = {a1, a2, a3, a4, a5}; Transpose[{Cos[lst], Sin[lst]}]


3

lst = {a1, a2, a3, a4, a5}; {Cos@#, Sin@#} & /@ lst (* {{Cos[a1], Sin[a1]}, {Cos[a2], Sin[a2]}, {Cos[a3], Sin[a3]}, {Cos[a4], Sin[a4]}, {Cos[a5], Sin[a5]}} *) Or Through@{Cos, Sin}@# & /@ lst (* same result *)


3

If you can't use Listable to your code is probably to use: ClearAll[f] (*first definition handles cases when you use list:={x,y};f[list]*) f[listof_Symbol] := f @@ (Hold[listof] /. OwnValues[listof]); (*general definition handles list of symbols*) f[vars_ : {(_) ..}] := ReleaseHold @ Map[ValueQ, Hold[vars], {2}]; (*as in kugler's answer the line ...


0

you can change the attribute of Map: Clear[f] f[var_] := ValueQ[var] SetAttributes[f, HoldAll] SetAttributes[Map, HoldAll] {x, y, z} = {1, 2, 3}; Map[f, {x, y, z, k}] (*{True, True, True, False}*)


2

The two standard approaches to this problem, Unevaluated and Listable, have already been posted. If you need a different kind of evaluation control please consider my original method:(1),(2),(3),(4) Load step How do I evaluate only one step of an expression? then: SetAttributes[f2, HoldAll] f2[s_Symbol] := step[s] /. {_[x_List] :> f2 /@ ...


4

Or set another attribute, Listable and be done with Map: SetAttributes[f,{HoldAll,Listable}]; x=10; y=.; z=.; f[{x,y,z}] (* {True, False, False} *)


5

Map[f, Unevaluated@{x, y, z}] (* {True, True, True} *) Update: ClearAll[f, x, y, z, q, w, e, r, t] f[vars : {(_) ..}] := Map[ValueQ, Unevaluated@vars]; SetAttributes[f, HoldAllComplete]; f[{x}] (* {False} *) x = 10; f[{x}] (* {True} *) f[{x, y}] (* {True, False} *) f[{x, y, z, q, w, e, r, t}] (* {True, False, False, False, False, False, False, False} ...


1

Your answers are correct. The first two solutions occur "at infinity" but your last two (after Chop) are {x->-4, y->0} and {x->0, y->0}, as is correct.


0

Following your comment to my original answer I now understand what you mean by "Apply is only parallelized at the top level." Since Parallelize is an automatic process and since the Method option does not seem to have the desired effect I can only suggest a possible workaround, clumsy as it may be. exp = Array[f, {1, 3, 2, 4}]; Parallelize[g[##, ...



Top 50 recent answers are included