Tag Info

New answers tagged

1

This may be a bit un-mathematicaesque, but it turns out to be convenient to store the board as a flat vector: (larger board for illustration) n = 12; board0 = Flatten[ Table[0, {n^2}], 1]; v[icol_, jrow_] = icol + n (jrow - 1); Now we can create lists of indices representing structures such as rows,columns, and diagonals. Here the function diag ...


2

EDIT Making this code runnable with Java reloader. Load the Java reloader (run the code from that post. For Mac OS X, see the comments below the post for a link to the Mac version) Compile the class: - JCompileLoad @ "package javaapplicationsim; /** * @author developer */ public class JavaApplicationSIM { final byte E = 0; // EDGE final byte _ = ...


3

Here is my own rough answer - it turns out that asking a question on SE helps clarifying one's thinking! I would still appreciate if some of the experts can weigh in. First, we'll store the board as a square matrix of symbols B, W and ".": m = Partition[RandomChoice[{B, W, "."}, 25], 5] // MatrixForm $\left( \begin{array}{ccccc} W & . & B & ...


8

One function comes to mind that already implements matching of multidimensonal rules: CellularAutomaton. Allow me to represent your board data like this: board = SparseArray[ a /. h_[x_, y_] :> ({-y - 1, x + 1} -> h) /. {black -> \[FilledCircle], white -> \[EmptyCircle]}, {7, 7}, " "]; For my example I shall show a generic 3x3 rule ...


2

ClearAll[f]; n = 10; Evaluate[f @@ Table[With[{s = Symbol["x" <> ToString[i]]}, Pattern[s, Blank[]]], {i, n}]] := Evaluate[Plus @@ (Sin@Table[s = Symbol["x" <> ToString[i]], {i, n}])] ?f


1

kAwayWordsF[str_, dist_, alph_, strlen_] := Module[{len = StringLength[str], dict}, dict = StringJoin /@ Tuples[alph, strlen]; With[{nf = Nearest[dict]}, Complement[nf[str, {Infinity, dist}], nf[str, {Infinity, dist - 1}]]]] kAwayWordsF["00000000",1,{"0","1","Q"},8] (* {"00000001", "0000000Q", "00000010", "000000Q0", "00000100", ...


3

Original Bresenham I guess I can come of with a somewhat shorter implementation without using Reap and Sow. If someone is interested, it follows almost exactly the pseudo-code here bresenham[p0_, p1_] := Module[{dx, dy, sx, sy, err, newp}, {dx, dy} = Abs[p1 - p0]; {sx, sy} = Sign[p1 - p0]; err = dx - dy; newp[{x_, y_}] := With[{e2 = 2 err}, ...


3

HanningFilter[signal_List] := With[{len = Length[signal]}, 2 signal Sin[Pi Range[len]/len]^2] Sin, Times,Power are Listable,that means Attributes /@ {Sin, Times, Power} Sin[{a, b}] {a, b}^2 {a, b} {c, d} (*{{Listable,NumericFunction,Protected},{Flat,Listable, NumericFunction,OneIdentity,Orderless,Protected}, {Listable, NumericFunction, ...



Top 50 recent answers are included