# 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

September 30.

Message 1 of 8
(498 Views)
7 REPLIES 7

## 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 8
(448 Views)

## Re: Code Challenge from Meeting #2

Here is my solution

Message 3 of 8
(435 Views)

One from me...

Message 4 of 8
(406 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 8
(397 Views)

But 1! = 1

Message 6 of 8
(394 Views)

## Re: Code Challenge from Meeting #2

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

Message 7 of 8
(381 Views)
Highlighted

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

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