BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Rube Goldberg Code

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. 😄

 

 

Message 1091 of 2,571
(11,907 Views)

Instead, slight simpler...  Smiley LOL

 

 

But eh....  Is there a specific reason to use: 

 

"border*2^n with n=1"  

 

in stead of simply multiplying by 2 ?   Smiley Wink

0 Kudos
Message 1092 of 2,571
(11,863 Views)

@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 ?   Smiley Wink


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. 😉

Message 1093 of 2,571
(11,831 Views)

@altenbach wrote:
[...] For any experienced programmer [...]
Hey!
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 1094 of 2,571
(11,824 Views)

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.... 

0 Kudos
Message 1095 of 2,571
(11,798 Views)
No, the LabVIEW compiler is very smart, but I still believe that the programmer should code as close to the intended result as possible. 🙂 (I don't know the specifics for this particular case, so why risk it?)
0 Kudos
Message 1096 of 2,571
(11,801 Views)

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! Smiley Very Happy

 

Rube 1.JPG

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 

----------------------------------------------------------------------------------------------------------------------------
"If anyone needs me, I'll be in the Angry Dome!"


Message 1097 of 2,571
(11,763 Views)

@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. 😄

Message 1098 of 2,571
(11,737 Views)

I thought I'd better get this one of mine in before someone else beat me to it!  

 

Seen here

 

Rubed Fizzbuzz.JPG

Although compared to Altenbach's all the code was Rubed! Smiley Wink

 

-CC 

----------------------------------------------------------------------------------------------------------------------------
"If anyone needs me, I'll be in the Angry Dome!"


0 Kudos
Message 1099 of 2,571
(11,715 Views)

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!)

 

(seen here)

 

 

0 Kudos
Message 1100 of 2,571
(11,574 Views)