From: John Benediktsson Date: Thu, 18 Nov 2021 23:11:27 +0000 (-0800) Subject: vin: adding a VIN decoding tool. X-Git-Tag: 0.99~2242 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=b3fe2b626ac66922da47d11767c822996581a997 vin: adding a VIN decoding tool. --- diff --git a/extra/vin/authors.txt b/extra/vin/authors.txt new file mode 100644 index 0000000000..e091bb8164 --- /dev/null +++ b/extra/vin/authors.txt @@ -0,0 +1 @@ +John Benediktsson diff --git a/extra/vin/summary.txt b/extra/vin/summary.txt new file mode 100644 index 0000000000..79c502ab8c --- /dev/null +++ b/extra/vin/summary.txt @@ -0,0 +1 @@ +VIN (Vehicle Identification Number) diff --git a/extra/vin/vin.factor b/extra/vin/vin.factor new file mode 100644 index 0000000000..c4397f7e15 --- /dev/null +++ b/extra/vin/vin.factor @@ -0,0 +1,405 @@ +! Copyright (C) 2021 John Benediktsson +! See http://factorcode.org/license.txt for BSD license + +USING: assocs combinators combinators.short-circuit kernel make +math sequences strings ; + +IN: vin + + + +: valid-vin? ( vin -- ? ) + { + [ length 17 = ] + [ [ "ABCDEFGHJKLMNPRSTUVWXYZ0123456789" member? ] all? ] + [ + [ 8 swap nth ] + [ WEIGHTS swap 0 [ TRANSLITERATION at * + ] 2reduce 11 mod ] bi + dup 10 = [ drop CHAR: X = ] [ CHAR: 0 + = ] if + ] + } 1&& ; + + + +: parse-vin ( vin -- details ) + [ + { + [ [ 0 3 ] dip subseq wmi% ] + [ [ 3 9 ] dip subseq vds% ] + [ [ 9 17 ] dip subseq vis% ] + } cleave + ] H{ } make ;