Quick question about creating 'chains', the chain is valid if all adjacent elements fulfill a condition. E.g. reorder a list of triplets where neighbours share exactly 2 elements. (assuming it is possible)
Is there a more idiomatic way to 'chain' elements by condition other than creating adjacency graph and finding hamiltonian path?
Intro
Let's say there was a question on Mathematica.SE we migrated to Math.SE or somewhere.
I could bet that the original topic marked [migrated] visible on the main in Mathematica.SE would automatically redirect to migrated on Math.SE.
It does not seem to be the case anymore.
More explanatio...
What would be the best way to make a function that had a return that alternates between 1 and -1? So the first time it was called f[] gave 1, second time -1, the third 1 and so on..
You will find a lot of information in this answer. I will add a few personal notes.
Module
Use Module when you want to localize variables inside your function's body, and those variables will potentially acquire and/or change their values during the computation.
Basic use
For example:
f[x_]:...
@JasonB Your backticks should come through... f[] := (notGlobalContext`c++; (-1)^notGlobalContext`c)