East Sweden LabVIEW User Group

Code Challenge from Meeting #2

The Challenge

Everyone is probably familiar with a factorial. 5 factorial is:

5! -> 5 x 4 x 3 x 2 x 1 = 120

 

For this challenge, reverse it! Write LabVIEW code that tells us if our input number is a factorial or not.

If the number is a factorial it should return 'x!' where x is the factorial number.

E.g. 120 is 5 factorial, return '5!'

 

If the number is not a factorial it should return 'NONE'

 

The code should handle input numbers up to 9,223,372,036,854,775,807 

 

This Thread

This thread is intended as a place to ask questions, discuss the challenge and upload your solutions.

 

Deadline

September 30.

Message 1 of 9
(600 Views)
8 REPLIES 8

Re: Code Challenge from Meeting #2

We briefly discussed measuring execution time for the discussed solutions. However (and this is a little bit of a hint), for this problem, it's not particularly meaningful, as a fast solution won't run long enough to allow for a reliable difference to be detected, at least not on a Windows system.

 

Measuring execution time can be interesting, however, both for debugging and for performance profiling of your application. To this end, I can recommend these custom LabVIEW probes that I found a while back, which you can use to measure the execution time between probes on an error wire, in ms or µs:

 

https://forums.ni.com/t5/LabVIEW/Simple-Sexy-LabVIEW-Timing-Probes/td-p/3484648

Message 2 of 9
(550 Views)

Re: Code Challenge from Meeting #2

Here is my solution Smiley Happy

0 Kudos
Message 3 of 9
(537 Views)

Re: Code Challenge from Meeting #2

One from me...

Skärmklipp.JPG

Message 4 of 9
(508 Views)

Re: Code Challenge from Meeting #2

Here is an arithmetic solution, taking care of the definition 0! = 1 and that x! = 0 has no solution.

Message 5 of 9
(499 Views)

Re: Code Challenge from Meeting #2

But 1! = 1

0 Kudos
Message 6 of 9
(496 Views)

Re: Code Challenge from Meeting #2

Oops, to fast. Wrong input to 'Format into string' should be i+1.

0 Kudos
Message 7 of 9
(483 Views)

Re: Code Challenge from Meeting #2

Hi guys,

Here is what came to my head today. I can't imagine someone trying to do similar staff using script languages. Labview is much more convenient Smiley Happy

Factorial.jpg

0 Kudos
Message 8 of 9
(402 Views)
Highlighted

Re: Code Challenge from Meeting #2

Hi All!

 

The deadline has passed, but anyway... here's a rather readable pattern that could be useful for many similar tasks. The 'First Call?' part might need to be adapted to the particular situation where the VI is called, though.ArraySearchingSolution.pngPer Erik Ruberth,

Prevas AB

Message 9 of 9
(48 Views)
Reply
This is an open group. Sign in and click the "Join Group" button to become a group member and start posting.