Example Code

MI » MU Puzzle

Code and Documents

Attachment

Overview

The MI » MU puzzle is based on the similarly-named puzzle found in Douglas Hofstadter's Gödel Escher Bach.  In this puzzle, the aim is to begin with MI and end with MU.  The only permissible symbols in this puzzle are M, I and U.

Description

Starting with the initial string "MI", can you create the string "MU" while abiding by the following rules:

  1. If the string ends with I, you may add a U to the end.  (MI » MIU)
  2. You may always double the string after M.  (MIUIU » MIUIUIUIU)
  3. You may replace the string III with a U.  (MIUIIIU » MIUUU)
  4. You may remove the string UU.  (MIUUU » MIU)

The aim of this program is to demonstrate how string manipulation functions may be used to control program flow, and to have some fun with LabVIEW.

Steps to Implement or Execute Code

  1. Download the code.
  2. Run the program.
  3. Try, try and try again.

Requirements

Software

  • LabVIEW 2012

VI Snippet

MAIN_snippet.png

Screenshot of Main VI

subVI_snippet.png

Screenshot of sub VI

Matthew H.
Applications Engineer
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
crossrulz
Knight of NI Knight of NI
Knight of NI
on

Just some tweaks here:

You don't need the timeouts for the event structures.  All that does is create a polling situation.

With that, your Breakout control terminal should be inside of the Apply Value Change event case.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
mudson
NI Employee (retired)
on

You're absolutely right on both counts.  🙂

Paranoia surrounding hung event structures induces me to add time-outs to nearly every event structure I use.  I'll make those changes on the next revision.

Thanks for the heads up!

Matthew H.
Applications Engineer
National Instruments
crossrulz
Knight of NI Knight of NI
Knight of NI
on

I found a bug when trying to do Rule 4.  I was finding that I couldn't apply rule 4 at the end of the string.  Then I found that you have an extra comparison!  I'm pretty sure it was because you copied the Rule 3 case.  When testing the selections of Rule 4, your shift register should only be giving the immediately previous iteration, not previous 2 iterations.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Contributors