03-03-2012 05:27 PM - edited 03-03-2012 05:36 PM
Problem: Initialize a 2D array of ones with a border of zeroes... (inputs: # of rows, # of columns, border width)
Think about how you would do that, then look here.
Apparently it needs a main VI and four calls to a custom subVI and lots of code. (exception handling, initialzing arrays, transposing arrays, removing parts of arrays, inserting parts of arrays, etc....)
The red insert shows a slightly simpler alternative. 😄
03-05-2012 04:20 AM
Instead, slight simpler...
But eh.... Is there a specific reason to use:
"border*2^n with n=1"
in stead of simply multiplying by 2 ?
03-05-2012 10:11 AM
@Anthony de Vries wrote:
But eh.... Is there a specific reason to use: "border*2^n with n=1" instead of simply multiplying by 2 ?
Yes. "scale by a power of two" on integers is internally achieved by a simple bit shift to the left, which is a significantly more efficient operation than multiplication. For any experienced programmer this is also more intuitive to read. 😄 (In fact, I could have used logical shift as a drop-in replacement to keep it more obscure, but I did not 🐵
You can replace it by a multiplication with two if you like that better, but it won't reduce the number of primitives or simplify the code. 😉
03-05-2012 10:16 AM
@altenbach wrote:
[...] For any experienced programmer [...]Hey!
03-05-2012 11:34 AM
Ah... makes sense.
Although... is the Labview compiler really so dumb??
I remember that the Turbo Pascal 6.0 compiler automatically changed a multiplication by 2 into a logical shift. Same for things like i++ (or pascal inc(i) function) and i:= i+1.
That was >10 years ago. I would have thought that modern compilers would be at least as clever....
03-05-2012 11:54 AM
03-06-2012 04:20 AM
Ok, time to take the plunge - will I post a true Rube piece of code or just show up my own ignorance? Only one way to find out!
To get an array of boolean we could wire the outputs of FP switches to true/flse selctors with 5 and 0 as options (presumably 5V and 0V) and then bundle the signals and then convert that dynamic data back into boolean.
Instead we could simply build an array directly from the switches values.
-CC
03-06-2012 09:13 AM
@ChrissyC87 wrote:
...then bundle the signals and then convert that dynamic data back into boolean.
The amount of dynamic data on the diagram is inversely correlated to the skill level of the programmer. 😄
03-06-2012 11:01 AM
I thought I'd better get this one of mine in before someone else beat me to it!
Although compared to Altenbach's all the code was Rubed!
-CC
03-17-2012 11:00 PM - edited 03-17-2012 11:03 PM
Simple enough, pick 6 nonduplicate integers in the range 0..45.
The orignal is some broken monster code. (This is just part of the code, you can imagine the rest)
The first two solutions are slightly simpler ...
... But all we really need is code the size of a postage stamp. 😄
(Look, no orange wires!)