6

Is it allowed to ask a question if you've already have an solution/answer?

This could be done to get alternative options/solutions for algorithms. But on the other hand may distract from people who are actually struggling with a real problem.

Also, for algorithms/improvements, you have programming or programming puzzle stackexchange which may be better suited. And when talking about algorithms/programming it's not really specific to Arduino anymore, as at this point it's usually C/C++.


My example: I have an LED matrix of 12x12, but they are connected in an "S" way. Like for example:

 1  2  3  4
 8  7  6  5
 9 10 11 12
16 15 14 13

Now I would have to map these LED nr's to X-Y coordinates (which is not just x+y*width because it's in an S pattern).

I feel it's not really Arduino specific and I already have (2 actually) answers for it, but I'm really curious to see if there's another simpler solution to it (to the logic to my own solution).


Also, I'm curious if as in code-golf you're allowed to state that the answer with least bytes / fastest execution time (or something like that) will 'win'?

  • 1
    In general, yes, you're allowed. However, the question and the self-answer should be judged on its own just like normal Q&A, meaning they should be on-topic, standalone, self-contained, etc. For code-golf, there's already a site dedicated for it: Code Golf – Andrew T. Mar 17 at 14:56
  • @AndrewT. thanks for the link to the article about answering your own question, I now see that can also be used to encourage others to come up with a 'better' or alternative solution. – Paul Mar 18 at 17:51
5

You're kind of in a borderland area there :)

I would say:

  • If you are looking for other ways to implement something, or
  • Your code uses the Arduino API or Arduino libraries, or
  • You have something that "works" but you don't know if it's the "right" way of doing it

then sure, go for it. While it could apply to other environments, if you're doing on Adruino with Arduino libraries (like the FastLED library for example) then I for one have no problem with it.

I wouldn't go for the "code golf" thing though. What the "best" answer is would be very subjective. Readability could be more beneficial than shaving one clock cycle off the execution - especially when the Arduino API itself is not that efficient in the first place.

As far as your example goes, I would submit an answer. It would contain something like:

int ledNumber = (y * width) + ((y & 1) ? (width - x - 1) : x);
  • Good one. I could ask it on Arduino.SE to get a solution (and possible multiple), or potentially ask help to improve the execution speed if required. But if I would be interested in the more theoretical/mathematical solution, there is other SE's that are better fit. (In that case one could/would strip the "algorithm" from it's implementation, which also makes it not about Arduino) – Paul Mar 18 at 17:45
  • Also I found a few other LED strip table projects which do have different solutions (such as putting the whole list in PROGMEM) and I myself had the same solution as you (except I used modulo to check for odd/even), but I figure your bitwise-& would be more efficient. – Paul Mar 18 at 17:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .