Looks fat to me ( just kidding :)
Is this any faster? Or does the compiler optimize away the differences?
int l[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 2, 4, 6, 8, 1, 3, 5, 7, 9 };
int
c_luhn2( char *s ) {
return ((
l[ (int)s[ 0] ]
+ s[ 1]
+ l[ (int)s[ 2] ]
+ s[ 3]
+ l[ (int)s[ 4] ]
+ s[ 5]
+ l[ (int)s[ 6] ]
+ s[ 7]
+ l[ (int)s[ 8] ]
+ s[ 9]
+ l[ (int)s[10] ]
+ s[11]
+ l[ (int)s[12] ]
+ s[13]
+ l[ (int)s[14] ] - 7 * '0' ) * 9) % 10;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.