Luhn test of credit card numbers: Difference between revisions

Content added Content deleted
(Luhn test for Octave and Matlab)
(→‎{{header|MATLAB}}: simpler solution is available)
Line 1,008: Line 1,008:


=={{header|MATLAB}}==
=={{header|MATLAB}}==
The solution for [http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Octave[Octave]] will also work with Matlab.

{{improve|MATLAB|The example for Octave works with all versions of matlab, contradicts the following statements, and is much simpler than all solutions shown here.}}

There is no easy way to perform digit level manipulation of a number. In order to perform these digit level manipulations, many of the operations have to be performed on strings and char arrays. Using the built-in MATLAB string and numeral manipulation and conversion functions, it is possible to reduce the Luhn Algorithm to two lines of code. Unfortunately, because of the number of type conversions necessary to do this, these two lines of code are extremely obfuscated. The first example is the unobfuscated code. The second example is the vectorized version.
There is no easy way to perform digit level manipulation of a number. In order to perform these digit level manipulations, many of the operations have to be performed on strings and char arrays. Using the built-in MATLAB string and numeral manipulation and conversion functions, it is possible to reduce the Luhn Algorithm to two lines of code. Unfortunately, because of the number of type conversions necessary to do this, these two lines of code are extremely obfuscated. The first example is the unobfuscated code. The second example is the vectorized version.