53,452 reputation
5149244
bio website mathprogramming-intro.org
location St. Petersburg, Russia
age 37
visits member for 2 years, 3 months
seen 1 hour ago

Ok, an obligatory note: opinions expressed here are mine and not those of my employer.


3h
comment MapIndexed stops at levelspec 1 if only the index is passed?
@Kuba May be you're right. If we anyway replace the element with position, we probably lose this info either way.
3h
comment MapIndexed stops at levelspec 1 if only the index is passed?
@Kuba I think it's not so simple. We could imagine a different action, where all parts are simply replaced by their positions, while heads are preserved. I think, they key point is that MapIndexed acts depth-first, leaves before branches. No idea why this one was down voted.
6h
comment How to create list of delayed rules?
I think, the easiest is to use injector pattern: Range[Length[myHand]] /. i_Integer :> (ToString[myHand[[i, 1]]] <> " of " <> ToString[myHand[[i, 2]]]) :> Print[myHand[[i]]].
1d
revised Detecting patterns of black and white stones on a 2D board
Corrected stringification
1d
revised Detecting patterns of black and white stones on a 2D board
Edited per Mr.Wizard's suggestion, added instructions how to use with Java reloader
1d
comment StringReplace, ReplaceAll and Rule interact in a bizarre way
@Pillsy [2/2] Then, it does renamings for all variables inside patterns on the l.h.s. of the rule, which, in my simpler example, is Replace[x, {l_Integer, u_Integer} :> l + u]. And it does not care about the non-pattern occurences of l and u (r.h.s. of inner RuleDelayed here), inside the l.h.s. of Rule, because, as I said, it thinks that l_ and u_ patterns belong to Rule. So, it messes up the bindings of inner RuleDelayed. Perhaps, this may be called a bug. Also, not that it is only happens when outer and inner rules are "lexically coupled" by some common variable.
1d
comment StringReplace, ReplaceAll and Rule interact in a bizarre way
@Pillsy [1/2] Thanks for the accept! Yep, I did not see this one before either. But it is clear that it would rename the variables inside patterns for l.h.s. of either inner Rule or RuleDelayed, as long as they are syntactically coupled via some common variable (as in the last example of yours). The problem here is that the external RuleDelayed does not recognize the correct localization of land U variables - it thinks they belong to Rule.
1d
awarded  Enlightened
1d
awarded  Nice Answer
2d
comment Scan vs Map vs Apply
+1, nice answer. I'd perhaps emphasize more strongly that because Scan does not produce an output, it can be significantly more memory-efficient than Map, particularly when such an output is not needed and in discarded in any case. I've seen cases where this made a real difference.
2d
revised StringReplace, ReplaceAll and Rule interact in a bizarre way
added 128 characters in body
2d
revised StringReplace, ReplaceAll and Rule interact in a bizarre way
Added some more hints at what't happening
2d
revised StringReplace, ReplaceAll and Rule interact in a bizarre way
Added some more hints at what't happening
2d
revised StringReplace, ReplaceAll and Rule interact in a bizarre way
Added a link to our co-authored answer with Mr. Wizard
2d
comment StringReplace, ReplaceAll and Rule interact in a bizarre way
@Mr.Wizard Thanks! Indeed, very relevant.
2d
revised StringReplace, ReplaceAll and Rule interact in a bizarre way
added 898 characters in body
2d
answered StringReplace, ReplaceAll and Rule interact in a bizarre way
2d
comment speeding up a function
Without a complete, working, minimal self-contained example illustrating the problem, the chances to get an answer are much lower. Surely, you should provide all the functions needed to run your code and reproduce your results. Also, the questions get a fairly short lifespan here, particularly if there are many of them. So, my suggestion is that you reformulate the question, provide a minimal fully working code, delete this one and ask a new one - because a new question has a higher chance to be answered.
Apr
20
awarded  Enlightened
Apr
20
awarded  Nice Answer