square / luhnybin

Apache License 2.0
231 stars 171 forks source link

Java solution to the Luhny Bin #1

Closed bdurette closed 8 years ago

bdurette commented 12 years ago

Here's my Java solution to the Luhny Bin problem. It memoizes the "Luhny Sums" (odd and even) of potential credit card numbers at each character offset in the input stream. It uses the lookup table to compute the check values for 14 through 16 digit numbers ending at any given character and masks accordingly.

Some potential improvements:

  1. Store information in the mask step to eliminate the need to remask overlapping regions.
  2. Save memory by not storing the entire lookup table in memory. Each time a non-credit-card character is encountered, the table can be cleared. This is only necessary if long inputs are expected.

All in all, a fun problem. Thanks!

bdurette commented 12 years ago

Pull request now includes some additional tests:

  1. Don't assume CC #'s will be in 4 digit segments (if delimited).
  2. Don't assume that delimiters will only be one character long.