LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CLD-R Exam 1, Question 19


@Mitch_Peplow wrote:

So when I asked the question of if you take the value of 6 and decrement by 2 every time, is that not possible with a Factorial?


You can decrement by 2, but it will not meet the definition of a factorial.


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
Message 11 of 21
(1,260 Views)

wiebe@CARYA wrote:

Note that the implementation is old-school (=OBSOLETE).

 

Nowadays we can simply put the VI (as a sub VI) on the diagram. Much, much, better.


Ah, yes, many recursive functions can be written iteratively, but for others, the recursive method is quicker, "neater", and easier to understand.  For example, the formula for Binomial Coefficients (or the number of ways to choose k things from n objects) involves lots of multiplication and division when done without recursion, but only addition with recursion.  It is also remarkably fast -- the number of 5 card poker hands (2.6 million) takes about half a second, 6-card hands (20 million) takes 4.6 seconds, and 7-card hands (134 million) takes under 29 seconds.  I don't have the patience to compute the number of bridge hands (13 cards) ...

 

Bob Schor

0 Kudos
Message 12 of 21
(1,243 Views)

@Bob_Schor wrote:

wiebe@CARYA wrote:

Note that the implementation is old-school (=OBSOLETE).

 

Nowadays we can simply put the VI (as a sub VI) on the diagram. Much, much, better.


Ah, yes, many recursive functions can be written iteratively, but for others, the recursive method is quicker, "neater", and easier to understand.  For example, the formula for Binomial Coefficients (or the number of ways to choose k things from n objects) involves lots of multiplication and division when done without recursion, but only addition with recursion.  It is also remarkably fast -- the number of 5 card poker hands (2.6 million) takes about half a second, 6-card hands (20 million) takes 4.6 seconds, and 7-card hands (134 million) takes under 29 seconds.  I don't have the patience to compute the number of bridge hands (13 cards) ...

 

Bob Schor


How about double-pinochle with 20 cards and four decks of face cards plus 10 and A?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 13 of 21
(1,238 Views)

@Bob_Schor wrote:

wiebe@CARYA wrote:

Note that the implementation is old-school (=OBSOLETE).

 

Nowadays we can simply put the VI (as a sub VI) on the diagram. Much, much, better.


Ah, yes, many recursive functions can be written iteratively, but for others, the recursive method is quicker, "neater", and easier to understand.  For example, the formula for Binomial Coefficients (or the number of ways to choose k things from n objects) involves lots of multiplication and division when done without recursion, but only addition with recursion.  It is also remarkably fast -- the number of 5 card poker hands (2.6 million) takes about half a second, 6-card hands (20 million) takes 4.6 seconds, and 7-card hands (134 million) takes under 29 seconds.  I don't have the patience to compute the number of bridge hands (13 cards) ...

 

Bob Schor


I'm not talking about iterative recursion ("fake" recursion). That has always been an option, but can result in more complex vs. more complex concept. I usually prefer recursive VI's as well.

 

I was saying the dynamic call by reference can be replaced with a call to the same VI:

Factor X.png

 

 

0 Kudos
Message 14 of 21
(1,222 Views)

@Wiebe -- I completely mis-interpreted your remark ("OBSOLETE").  I was thinking "recursion" (= reentrant VI) and didn't realize I hadn't mentioned the word earlier, and thought that you were saying that the recursive method was obsolete!

 

This may be due to a similar post around the same time asking about Fibonacci Numbers, which also have a Recursive Definition, and I had "recursion" on the brain (or what passes for a brain).  I completely agree with your FactorX method of computing X!, though I might have made the Default case return "1" and the other case be 1.. (to foil being called with negative numbers).

 

Bob Schor

0 Kudos
Message 15 of 21
(1,207 Views)

@Bob_Schor wrote:

@Wiebe -- I completely mis-interpreted your remark ("OBSOLETE").  I was thinking "recursion" (= reentrant VI) and didn't realize I hadn't mentioned the word earlier, and thought that you were saying that the recursive method was obsolete!


That happens. It was clear to me it was just miscommunication. Just made the example so others can learn. We really don't want people to take those exam questions as an example.

 


@Bob_Schor wrote:

This may be due to a similar post around the same time asking about Fibonacci Numbers, which also have a Recursive Definition, and I had "recursion" on the brain (or what passes for a brain).  I completely agree with your FactorX method of computing X!, though I might have made the Default case return "1" and the other case be 1.. (to foil being called with negative numbers).


The default and 1.. cases makes good sense.

 

Didn't think the factor vi through, I did not even run it before posting! Just remade the VI from the image.

0 Kudos
Message 16 of 21
(1,197 Views)

What would be the output if the VI was not re entrant? Would it be 12?

0 Kudos
Message 17 of 21
(1,155 Views)

@proph wrote:

What would be the output if the VI was not re entrant? Would it be 12?


If it wasn't reentrant, it wouldn't compile (or run)… A non-reentrant VI can't call itself.

0 Kudos
Message 18 of 21
(1,126 Views)

@Mitch_Peplow wrote:

So when I asked the question of if you take the value of 6 and decrement by 2 every time, is that not possible with a Factorial? So basically is it always a decrement of one every time, so it will always be 6x5x4x3x2x1 and nothing else?


Wouldn't that be 3!*2?

6*4*2 = 3*2 * 2*2 * 1*2 = (3*2*1)*2 = 3!*2

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 19 of 21
(1,117 Views)

Wouldn't that be 3!*2?

6*4*2 = 3*2 * 2*2 * 1*2 = (3*2*1)*2 = 3!*2

Oops, nope.

6*4*2 = 48

(3!) * 2 = 12

 

Looks like you were applying the Distributive law to multiplication by accident....

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 20 of 21
(1,110 Views)