BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Rube Goldberg Code

Formatting a number as 12 bit binary with leading zeros needs:

  1. A state machine with 5 states.
  2. 36 locals
  3. 12 booleans
  4. 4 variable sized arrays
  5. 3 FOR loops
  6. No autoindexing, but [i] wired to index array.
  7. A manually generated lookup table for all powers of two
  8. ...

Needs to be seen to be appreciated:

 

The last state is classic Rube!

 

Message Edited by altenbach on 10-07-2008 10:45 PM
0 Kudos
Message 321 of 2,635
(13,264 Views)

I like this little bit of code from Christian's example above.

 

Let's split the wire to the case selector and a tunnel.  Compare with 3 and send the result to the "3" boolean (unlabeled, of course), but since it is in the 3 case, if this calculates it is always true!

It also shows what Christian talked about as a way to avoid using those nasty autoindexing tunnels.Smiley Wink

Message Edited by Ravens Fan on 10-08-2008 02:11 AM
Message 322 of 2,635
(13,254 Views)

Ravens Fan wrote:

...

Let's split the wire to the case selector and a tunnel.  Compare with 3 and send the result to the "3" boolean (unlabeled, of course), but since it is in the 3 case, if this calculates it is always true!

 


I think the result is not always true. If your double value is 3.1, the case 3 will be called, but the comparison in the case will be false! In my opinion checking a double value for equality is a bit risky and I always try to avoid it.

 

Uli

Message 323 of 2,635
(13,238 Views)

Some Rube Code from me. 

In an old VI we use, I found the following code which simply calculates the mean of the elements. 

Every Express-VI "Formelxx" calculates (x1+x2+x3)/3, except "Formel41" which calculates (x1+x2+x3+x4+x5+x6+x7+x8)/8.

Uli

 

Message Edited by UliB on 10-08-2008 12:44 PM
Message 324 of 2,635
(13,236 Views)

UliB wrote:

I think the result is not always true. If your double value is 3.1, the case 3 will be called, but the comparison in the case will be false! In my opinion checking a double value for equality is a bit risky and I always try to avoid it.


Good catch.  Smiley Happy  Yes, you are correct in that the double gets rounded to an integer before the case structure makes the comparison, thus case 3 may not actually be a 3 and the comparison would be false.

 

Actually in this case, the way the rest of the code was created, there was no possibility for a 3.1 as the possible numbers to be used were predefined in an array and by the index numbers of that array.  But that code still has the possibility of equality errors when comparing doubles, and that the double representation should not have been used considering the topic was using 12 bit integers.

 

PS:  Thanks for sharing your impressive code as well.

Message Edited by Ravens Fan on 10-08-2008 09:40 AM
0 Kudos
Message 325 of 2,635
(13,218 Views)

I work with good people, so I don't often find Rube's code here.  But I recently found this instance of converting a number to an array of 0s and 1s.

 

Message Edited by tbob on 10-09-2008 12:47 PM
- tbob

Inventor of the WORM Global
Message 326 of 2,635
(13,183 Views)

tbob wrote:


For added effect, the coercion dot simulates the saying: "...and with a cherry on top" 😄

 

By the way, your alternative is not quite equivalent, because you start out with 16 bits, but the loop only runs 8 times. It might need a tweak. 😉

Message Edited by altenbach on 10-09-2008 01:03 PM
Message 327 of 2,635
(13,178 Views)

Another example of the "explicit indexing" and "backwards wires" fan club.

 

The big problem started when he wanted to deal with 100 elements. 😄

 

(Of course you guessed that this code is supposed to be used for frequency (or period) measurements!!! :o!)

 

Message Edited by altenbach on 10-13-2008 01:14 PM
0 Kudos
Message 328 of 2,635
(13,107 Views)

Forgot to post about this one, where some array gymnastics are done. In order to read a file which consists of 2 columns of data into an XY graph we have to do all of this:

 

instead of just this:

 

 

from here: http://forums.ni.com/ni/board/message?board.id=170&view=by_date_ascending&message.id=361078#M361078

Message Edited by smercurio_fc on 10-13-2008 04:19 PM
Download All
Message 329 of 2,635
(13,099 Views)

Can't show the code for this one... It's WAY to wide...

 

http://forums.ni.com/ni/attachments/ni/170/362300/1/controller_BP.png

 

From this thread:

http://forums.ni.com/ni/board/message?board.id=170&thread.id=362300

 

 

You have to see it...

0 Kudos
Message 330 of 2,635
(13,008 Views)