Make your own free website on Tripod.com

MKoD - D Programming Language

Using a static array - code-name SSNutil.d

Very Kool! Discovering information from an SSN example:

/+******************************************************************
 * Program       : SSNutil.exe (needs dmd v0.95+)
 * Source        : SSNutil.d
 * Author        : David L. 'SpottedTiger' Davis
 * Created Date  : 19.Jun.04 (dmd v0.92)
 * Modified Date : 08.Jul.04 Compiled and Tested with dmd v0.95
 *               : 02.Oct.04 Complied and Tested with dmd v0.102
 *               : 04.Jun.06 Complied and Tested with dmd v0.160
 *               : 10.Jan.07 Complied and Tested with dmd v1.0 
 * Requirements  : std.conv, and std.stdio
 * License       : Public Domain 
 *******************************************************************
 *
 * To Compiled: C:\dmd\MKoD>dmd SSNutil.d
 +/

private import std.conv;
private import std.stdio;

struct usrStateIssused
{
    uint   uiB    = 0U; 
    uint   uiE    = 0U;
    char[] sState = "";
}     

/+    
' getIssusingState - Returns the issusing State for a 
'                    valid Social Security Number value.
'
' Author       : David L. 'SpottedTiger' Davis
' Date Created : 19.Jun.04
' Language     : DigitalMars D v0.92 (Compiles with v0.95)
'
' Requirements: struct usrStateIssused{}
'
' --------------------------------
' Based on this information below:
' --------------------------------
'   000     unused   387-399 WI    528-529 UT
'   001-003 NH       400-407 KY    530     NV
'   004-007 ME       408-415 TN    531-539 WA
'   008-009 VT       416-424 AL    540-544 OR
'   010-034 MA       425-428 MS    545-573 CA
'   035-039 RI       429-432 AR    574     AK
'   040-049 CT       433-439 LA    575-576 HI
'   050-134 NY       440-448 OK    577-579 DC
'   135-158 NJ       449-467 TX    580     VI Virgin Islands
'   159-211 PA       468-477 MN    581-584 PR Puerto Rico
'   212-220 MD       478-485 IA    585     NM
'   221-222 DE       486-500 MO    586     PI Pacific Islands*
'   223-231 VA       501-502 ND    587-588 MS
'   232-236 WV       503-504 SD    589-595 FL
'   237-246 NC       505-508 NE    596-599 PR Puerto Rico
'   247-251 SC       509-515 KS    600-601 AZ
'   252-260 GA       516-517 MT    602-626 CA
'   261-267 FL       518-519 ID    627-645 TX
'   268-302 OH       520     WY    646-647 UT 
'   303-317 IN       521-524 CO    648-649 NM 
'   318-361 IL       525     NM    *Guam, American Samoa,
'   362-386 MI       526-527 AZ     Northern Mariana Islands,
'                                   Philippine Islands 
+/       
char[] getIssusingState   
(
    in char[] sSSN
)
{
    uint uiArea = 0U;	
    uint uix    = 0U;

    static usrStateIssused usrSI[ 63 ] =
    [
        {   1U,   3U, "NH" }, {   4U,   7U, "ME" },
        {   8U,   9U, "VT" }, {  10U,  34U, "MA" },
        {  35U,  39U, "RI" }, {  40U,  49U, "CT" },
        {  50U, 134U, "NY" }, { 135U, 158U, "NJ" },
        { 159U, 211U, "PA" }, { 212U, 220U, "MD" }, 
        { 221U, 222U, "DE" }, { 223U, 231U, "VA" }, 
        { 232U, 236U, "WV" }, { 237U, 246U, "NC" }, 
        { 247U, 251U, "SC" }, { 252U, 260U, "GA" }, 
        { 261U, 267U, "FL" }, { 268U, 302U, "OH" }, 
        { 303U, 317U, "IN" }, { 318U, 361U, "IL" }, 
        { 362U, 386U, "MI" }, { 387U, 399U, "WI" },
        { 400U, 407U, "KY" }, { 408U, 415U, "TN" },
        { 416U, 424U, "AL" }, { 425U, 428U, "MS" },
        { 429U, 432U, "AR" }, { 433U, 439U, "LA" },
        { 440U, 448U, "OK" }, { 449U, 467U, "TX" },
        { 468U, 477U, "MN" }, { 478U, 485U, "IA" },
        { 486U, 500U, "MO" }, { 501U, 502U, "ND" },
        { 503U, 504U, "SD" }, { 505U, 508U, "NE" }, 
        { 509U, 515U, "KS" }, { 516U, 517U, "MT" }, 
        { 518U, 519U, "ID" }, { 520U, 520U, "WY" }, 
        { 521U, 524U, "CO" }, { 525U, 525U, "NM" }, 
        { 526U, 527U, "AZ" }, { 528U, 529U, "UT" }, 
        { 530U, 530U, "NV" }, { 531U, 539U, "WA" }, 
        { 540U, 544U, "OR" }, { 545U, 573U, "CA" }, 
        { 574U, 574U, "AK" }, { 575U, 576U, "HI" }, 
        { 577U, 579U, "DC" }, { 580U, 580U, "VI" }, 
        { 581U, 584U, "PR" }, { 585U, 585U, "NM" }, 
        { 586U, 586U, "PI" }, { 587U, 588U, "MS" }, 
        { 589U, 595U, "FL" }, { 596U, 599U, "PR" }, 
        { 600U, 601U, "AZ" }, { 602U, 626U, "CA" }, 
        { 627U, 645U, "TX" }, { 646U, 647U, "UT" }, 
        { 648U, 649U, "NM" }
    ];       
    
    uiArea = toUint( sSSN[ 0 .. 3 ] );
    
    if ( uiArea == 0U || uiArea > 649U ) return "";
    
    for ( uix = 0U; uix < usrSI.length; uix++ )
        if ( uiArea <= usrSI[ uix ].uiE ) break;
        
    if ( uiArea >= usrSI[ uix ].uiB && uiArea <= usrSI[ uix ].uiE )
        return usrSI[ uix ].sState;
    else
        return "";    

} // end char[] getIssusingState( in char[] )

int main()
{
    writefln("getIssusingState( \"267-45-0001\" )=%s ans=\"FL\"", getIssusingState( "267-45-234" ) );
    writefln("getIssusingState( \"267\" )=%s ans=\"FL\"", getIssusingState( "267" ) );
    writefln("getIssusingState( \"625\" )=%s ans=\"CA\"", getIssusingState( "625" ) );
     
    return 0;
    
} // end int main()

C:\dmd\MKoD_ex>..\bin\dmd SSNutil.d
C:\dmd\bin\..\..\dm\bin\link.exe SSNutil,,,user32+kernel32/noi;

C:\dmd\MKoD_ex>SSNutil
getIssusingState( "267-45-0001" )=FL ans="FL"
getIssusingState( "267" )=FL ans="FL"
getIssusingState( "625" )=CA ans="CA"

C:\dmd\MKoD_ex>
Mars: fourth Rock from the Sun.