'// Created by Lionello Lunesu and placed in the public domain.' Comment.Single '\n' Text.Whitespace '// This file has been modified from its original version.' Comment.Single '\n' Text.Whitespace '// It has been formatted to fit your screen.' Comment.Single '\n' Text.Whitespace 'module' Keyword ' ' Text.Whitespace 'phoneno' Name ';' Punctuation ' ' Text.Whitespace '// optional' Comment.Single '\n' Text.Whitespace 'import' Keyword ' ' Text.Whitespace 'std' Name '.' Punctuation 'stdio' Name ';' Punctuation ' ' Text.Whitespace '// writefln ' Comment.Single '\n' Text.Whitespace 'import' Keyword ' ' Text.Whitespace 'std' Name '.' Punctuation 'ctype' Name ';' Punctuation ' ' Text.Whitespace '// isdigit ' Comment.Single '\n' Text.Whitespace 'import' Keyword ' ' Text.Whitespace 'std' Name '.' Punctuation 'stream' Name ';' Punctuation ' ' Text.Whitespace '// BufferedFile' Comment.Single '\n' Text.Whitespace '\n' Text.Whitespace '// Just for readability (imagine char[][][char[]]) ' Comment.Single '\n' Text.Whitespace 'alias' Keyword ' ' Text.Whitespace 'char' Keyword.Type '[' Punctuation ']' Punctuation ' ' Text.Whitespace 'string' Name.Builtin ';' Punctuation '\n' Text.Whitespace 'alias' Keyword ' ' Text.Whitespace 'string' Name.Builtin '[' Punctuation ']' Punctuation ' ' Text.Whitespace 'stringarray' Name ';' Punctuation '\n' Text.Whitespace '\n' Text.Whitespace '/// Strips non-digit characters from the string (COW)' Comment.Single '\n' Text.Whitespace 'string' Name.Builtin ' ' Text.Whitespace 'stripNonDigit' Name '(' Punctuation ' ' Text.Whitespace 'in' Keyword ' ' Text.Whitespace 'string' Name.Builtin ' ' Text.Whitespace 'line' Name ' ' Text.Whitespace ')' Punctuation ' \n' Text.Whitespace '{' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'string' Name.Builtin ' ' Text.Whitespace 'ret' Name ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'foreach' Keyword '(' Punctuation 'uint' Keyword.Type ' ' Text.Whitespace 'i' Name ',' Punctuation ' ' Text.Whitespace 'c' Name ';' Punctuation ' ' Text.Whitespace 'line' Name ')' Punctuation ' ' Text.Whitespace '{' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace '// Error: std.ctype.isdigit at C:\\dmd\\src\\phobos\\std\\ctype.d(37) ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '// conflicts with std.stream.isdigit at C:\\dmd\\src\\phobos\\std\\stream.d(2924)' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace 'if' Keyword ' ' Text.Whitespace '(' Punctuation '!' Punctuation 'std' Name '.' Punctuation 'ctype' Name '.' Punctuation 'isdigit' Name '(' Punctuation 'c' Name ')' Punctuation ')' Punctuation ' ' Text.Whitespace '{' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'if' Keyword ' ' Text.Whitespace '(' Punctuation '!' Punctuation 'ret' Name ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'ret' Name ' ' Text.Whitespace '=' Punctuation ' ' Text.Whitespace 'line' Name '[' Punctuation '0.' Literal.Number.Float '.' Punctuation 'i' Name ']' Punctuation ';' Punctuation ' \n ' Text.Whitespace '}' Punctuation ' \n ' Text.Whitespace 'else' Keyword ' ' Text.Whitespace 'if' Keyword ' ' Text.Whitespace '(' Punctuation 'ret' Name ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'ret' Name ' ' Text.Whitespace '~=' Punctuation ' ' Text.Whitespace 'c' Name ';' Punctuation ' \n ' Text.Whitespace '}' Punctuation ' \n ' Text.Whitespace 'return' Keyword ' ' Text.Whitespace 'ret' Name '?' Punctuation 'ret' Name ':' Punctuation 'line' Name ';' Punctuation '\n' Text.Whitespace '}' Punctuation '\n' Text.Whitespace '\n' Text.Whitespace 'unittest' Keyword ' ' Text.Whitespace '{' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'assert' Keyword '(' Punctuation ' ' Text.Whitespace 'stripNonDigit' Name '(' Punctuation '"asdf"' Literal.String ')' Punctuation ' ' Text.Whitespace '==' Punctuation ' ' Text.Whitespace '""' Literal.String ' ' Text.Whitespace ')' Punctuation ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'assert' Keyword '(' Punctuation ' ' Text.Whitespace 'stripNonDigit' Name '(' Punctuation '"\\\'13-=2 4kop"' Literal.String ')' Punctuation ' ' Text.Whitespace '==' Punctuation ' ' Text.Whitespace '"1324"' Literal.String ' ' Text.Whitespace ')' Punctuation ';' Punctuation '\n' Text.Whitespace '}' Punctuation '\n' Text.Whitespace '\n' Text.Whitespace '/// Converts a word into a number, ignoring all non alpha characters ' Comment.Single '\n' Text.Whitespace 'string' Name.Builtin ' ' Text.Whitespace 'wordToNum' Name '(' Punctuation ' ' Text.Whitespace 'in' Keyword ' ' Text.Whitespace 'string' Name.Builtin ' ' Text.Whitespace 'word' Name ' ' Text.Whitespace ')' Punctuation '\n' Text.Whitespace '{' Punctuation '\n' Text.Whitespace '// translation table for the task at hand' Comment.Single '\n' Text.Whitespace 'const' Keyword ' ' Text.Whitespace 'char' Keyword.Type '[' Punctuation '256' Literal.Number.Integer ']' Punctuation ' ' Text.Whitespace 'TRANSLATE' Name ' ' Text.Whitespace '=' Punctuation ' \n ' Text.Whitespace '" "' Literal.String ' ' Text.Whitespace '// 0 ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '" 0123456789 "' Literal.String ' ' Text.Whitespace '// 32 ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '" 57630499617851881234762239 "' Literal.String ' ' Text.Whitespace '// 64 ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '" 57630499617851881234762239 "' Literal.String '\n' Text.Whitespace ' ' Text.Whitespace '" "' Literal.String '\n' Text.Whitespace ' ' Text.Whitespace '" "' Literal.String '\n' Text.Whitespace ' ' Text.Whitespace '" "' Literal.String ' \n ' Text.Whitespace '" "' Literal.String ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'string' Name.Builtin ' ' Text.Whitespace 'ret' Name ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'foreach' Keyword '(' Punctuation 'c' Name ';' Punctuation ' ' Text.Whitespace 'cast' Keyword '(' Punctuation 'ubyte' Keyword.Type '[' Punctuation ']' Punctuation ')' Punctuation 'word' Name ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'if' Keyword ' ' Text.Whitespace '(' Punctuation 'TRANSLATE' Name '[' Punctuation 'c' Name ']' Punctuation ' ' Text.Whitespace '!=' Punctuation ' ' Text.Whitespace "' '" Literal.String.Char ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'ret' Name ' ' Text.Whitespace '~=' Punctuation ' ' Text.Whitespace 'TRANSLATE' Name '[' Punctuation 'c' Name ']' Punctuation ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'return' Keyword ' ' Text.Whitespace 'ret' Name ';' Punctuation '\n' Text.Whitespace '}' Punctuation '\n' Text.Whitespace '\n' Text.Whitespace 'unittest' Keyword ' ' Text.Whitespace '{' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace '// Test wordToNum using the table from the task description.' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace 'assert' Keyword '(' Punctuation ' ' Text.Whitespace '"01112223334455666777888999"' Literal.String ' ' Text.Whitespace '==' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'wordToNum' Name '(' Punctuation '"E | J N Q | R W X | D S Y | F T | A M | C I V | B K U | L O P | G H Z"' Literal.String ')' Punctuation ')' Punctuation ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'assert' Keyword '(' Punctuation ' ' Text.Whitespace '"01112223334455666777888999"' Literal.String ' ' Text.Whitespace '==' Punctuation ' \n ' Text.Whitespace 'wordToNum' Name '(' Punctuation '"e | j n q | r w x | d s y | f t | a m | c i v | b k u | l o p | g h z"' Literal.String ')' Punctuation ')' Punctuation ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'assert' Keyword '(' Punctuation ' ' Text.Whitespace '"0123456789"' Literal.String ' ' Text.Whitespace '==' Punctuation ' \n ' Text.Whitespace 'wordToNum' Name '(' Punctuation '"0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9"' Literal.String ')' Punctuation ')' Punctuation ';' Punctuation '\n' Text.Whitespace '}' Punctuation '\n' Text.Whitespace '\n' Text.Whitespace 'void' Keyword.Type ' ' Text.Whitespace 'main' Name '(' Punctuation ' ' Text.Whitespace 'string' Name.Builtin '[' Punctuation ']' Punctuation ' ' Text.Whitespace 'args' Name ' ' Text.Whitespace ')' Punctuation '\n' Text.Whitespace '{' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace '// This associative array maps a number to an array of words. ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace 'stringarray' Name '[' Punctuation 'string' Name.Builtin ']' Punctuation ' ' Text.Whitespace 'num2words' Name ';' Punctuation '\n' Text.Whitespace '\n' Text.Whitespace ' ' Text.Whitespace 'foreach' Keyword '(' Punctuation 'string' Name.Builtin ' ' Text.Whitespace 'word' Name ';' Punctuation ' ' Text.Whitespace 'new' Keyword ' ' Text.Whitespace 'BufferedFile' Name '(' Punctuation '"dictionary.txt"' Literal.String ' ' Text.Whitespace ')' Punctuation ' ' Text.Whitespace ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'num2words' Name '[' Punctuation ' ' Text.Whitespace 'wordToNum' Name '(' Punctuation 'word' Name ')' Punctuation ' ' Text.Whitespace ']' Punctuation ' ' Text.Whitespace '~=' Punctuation ' ' Text.Whitespace 'word' Name '.' Punctuation 'dup' Name ';' Punctuation ' ' Text.Whitespace '// must dup' Comment.Single '\n' Text.Whitespace '\n' Text.Whitespace ' ' Text.Whitespace '/// Finds all alternatives for the given number' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '/// (should have been stripped from non-digit characters)' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace 'stringarray' Name ' ' Text.Whitespace '_FindWords' Name '(' Punctuation ' ' Text.Whitespace 'string' Name.Builtin ' ' Text.Whitespace 'numbers' Name ',' Punctuation ' ' Text.Whitespace 'bool' Keyword.Type ' ' Text.Whitespace 'digitok' Name ' ' Text.Whitespace ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'in' Keyword ' ' Text.Whitespace '{' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'assert' Keyword '(' Punctuation 'numbers' Name '.' Punctuation 'length' Name ' ' Text.Whitespace '>' Punctuation ' ' Text.Whitespace '0' Literal.Number.Integer ')' Punctuation ';' Punctuation ' \n ' Text.Whitespace '}' Punctuation ' \n ' Text.Whitespace 'out' Keyword '(' Punctuation 'result' Name ')' Punctuation ' ' Text.Whitespace '{' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'foreach' Keyword ' ' Text.Whitespace '(' Punctuation 'a' Name ';' Punctuation ' ' Text.Whitespace 'result' Name ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'assert' Keyword '(' Punctuation ' ' Text.Whitespace 'wordToNum' Name '(' Punctuation 'a' Name ')' Punctuation ' ' Text.Whitespace '==' Punctuation ' ' Text.Whitespace 'numbers' Name ' ' Text.Whitespace ')' Punctuation ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace '}' Punctuation ' \n ' Text.Whitespace 'body' Keyword ' ' Text.Whitespace '{' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'stringarray' Name ' ' Text.Whitespace 'ret' Name ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'bool' Keyword.Type ' ' Text.Whitespace 'foundword' Name ' ' Text.Whitespace '=' Punctuation ' ' Text.Whitespace 'false' Keyword.Constant ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'for' Keyword ' ' Text.Whitespace '(' Punctuation 'uint' Keyword.Type ' ' Text.Whitespace 't' Name '=' Punctuation '1' Literal.Number.Integer ';' Punctuation ' ' Text.Whitespace 't' Name '<=' Punctuation 'numbers' Name '.' Punctuation 'length' Name ';' Punctuation ' ' Text.Whitespace '++' Punctuation 't' Name ')' Punctuation ' ' Text.Whitespace '{' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'auto' Keyword ' ' Text.Whitespace 'alternatives' Name ' ' Text.Whitespace '=' Punctuation ' ' Text.Whitespace 'numbers' Name '[' Punctuation '0.' Literal.Number.Float '.' Punctuation 't' Name ']' Punctuation ' ' Text.Whitespace 'in' Keyword ' ' Text.Whitespace 'num2words' Name ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'if' Keyword ' ' Text.Whitespace '(' Punctuation '!' Punctuation 'alternatives' Name ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'continue' Keyword ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'foundword' Name ' ' Text.Whitespace '=' Punctuation ' ' Text.Whitespace 'true' Keyword.Constant ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'if' Keyword ' ' Text.Whitespace '(' Punctuation 'numbers' Name '.' Punctuation 'length' Name ' ' Text.Whitespace '>' Punctuation ' ' Text.Whitespace 't' Name ')' Punctuation ' ' Text.Whitespace '{' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace '// Combine all current alternatives with all alternatives ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '// of the rest (next piece can start with a digit) ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace 'foreach' Keyword ' ' Text.Whitespace '(' Punctuation 'a2' Name ';' Punctuation ' ' Text.Whitespace '_FindWords' Name '(' Punctuation ' ' Text.Whitespace 'numbers' Name '[' Punctuation 't' Name '..' Punctuation '$' Punctuation ']' Punctuation ',' Punctuation ' ' Text.Whitespace 'true' Keyword.Constant ' ' Text.Whitespace ')' Punctuation ' ' Text.Whitespace ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'foreach' Keyword '(' Punctuation 'a1' Name ';' Punctuation ' ' Text.Whitespace '*' Punctuation 'alternatives' Name ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'ret' Name ' ' Text.Whitespace '~=' Punctuation ' ' Text.Whitespace 'a1' Name ' ' Text.Whitespace '~' Punctuation ' ' Text.Whitespace '" "' Literal.String ' ' Text.Whitespace '~' Punctuation ' ' Text.Whitespace 'a2' Name ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace '}' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'else' Keyword ' \n ' Text.Whitespace 'ret' Name ' ' Text.Whitespace '~=' Punctuation ' ' Text.Whitespace '*' Punctuation 'alternatives' Name ';' Punctuation ' ' Text.Whitespace '// append these alternatives' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '}' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace "// Try to keep 1 digit, only if we're allowed and no other" Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '// alternatives were found' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '// Testing "ret.length" makes more sense than testing "foundword",' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '// but the other implementations seem to do just this.' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace 'if' Keyword ' ' Text.Whitespace '(' Punctuation 'digitok' Name ' ' Text.Whitespace '&&' Punctuation ' ' Text.Whitespace '!' Punctuation 'foundword' Name ')' Punctuation ' ' Text.Whitespace '{' Punctuation ' ' Text.Whitespace '//ret.length == 0 ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace 'if' Keyword '(' Punctuation 'numbers' Name '.' Punctuation 'length' Name ' ' Text.Whitespace '>' Punctuation ' ' Text.Whitespace '1' Literal.Number.Integer ')' Punctuation ' ' Text.Whitespace '{' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace '// Combine 1 digit with all altenatives from the rest ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '// (next piece can not start with a digit) ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace 'foreach' Keyword ' ' Text.Whitespace '(' Punctuation 'a' Name ';' Punctuation ' ' Text.Whitespace '_FindWords' Name '(' Punctuation ' ' Text.Whitespace 'numbers' Name '[' Punctuation '1.' Literal.Number.Float '.' Punctuation '$' Punctuation ']' Punctuation ',' Punctuation ' ' Text.Whitespace 'false' Keyword.Constant ' ' Text.Whitespace ')' Punctuation ' ' Text.Whitespace ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'ret' Name ' ' Text.Whitespace '~=' Punctuation ' ' Text.Whitespace 'numbers' Name '[' Punctuation '0.' Literal.Number.Float '.1' Literal.Number.Float ']' Punctuation ' ' Text.Whitespace '~' Punctuation ' ' Text.Whitespace '" "' Literal.String ' ' Text.Whitespace '~' Punctuation ' ' Text.Whitespace 'a' Name ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace '}' Punctuation ' \n ' Text.Whitespace 'else' Keyword ' \n ' Text.Whitespace 'ret' Name ' ' Text.Whitespace '~=' Punctuation ' ' Text.Whitespace 'numbers' Name '[' Punctuation '0.' Literal.Number.Float '.1' Literal.Number.Float ']' Punctuation ';' Punctuation ' ' Text.Whitespace '// just append this digit ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '}' Punctuation ' \n ' Text.Whitespace 'return' Keyword ' ' Text.Whitespace 'ret' Name ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace '}' Punctuation '\n' Text.Whitespace '\n' Text.Whitespace ' ' Text.Whitespace '/// (This function was inlined in the original program) ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '/// Finds all alternatives for the given phone number ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '/// Returns: array of strings ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace 'stringarray' Name ' ' Text.Whitespace 'FindWords' Name '(' Punctuation ' ' Text.Whitespace 'string' Name.Builtin ' ' Text.Whitespace 'phone_number' Name ' ' Text.Whitespace ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace '{' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'if' Keyword ' ' Text.Whitespace '(' Punctuation '!' Punctuation 'phone_number' Name '.' Punctuation 'length' Name ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'return' Keyword ' ' Text.Whitespace 'null' Keyword.Constant ';' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace '// Strip the non-digit characters from the phone number, and' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace '// pass it to the recursive function (leading digit is allowed)' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace 'return' Keyword ' ' Text.Whitespace '_FindWords' Name '(' Punctuation ' ' Text.Whitespace 'stripNonDigit' Name '(' Punctuation 'phone_number' Name ')' Punctuation ',' Punctuation ' ' Text.Whitespace 'true' Keyword.Constant ' ' Text.Whitespace ')' Punctuation ';' Punctuation ' \n ' Text.Whitespace '}' Punctuation ' \n \n ' Text.Whitespace '// Read the phone numbers ' Comment.Single '\n' Text.Whitespace ' ' Text.Whitespace 'foreach' Keyword '(' Punctuation 'string' Name.Builtin ' ' Text.Whitespace 'phone' Name ';' Punctuation ' ' Text.Whitespace 'new' Keyword ' ' Text.Whitespace 'BufferedFile' Name '(' Punctuation '"input.txt"' Literal.String ' ' Text.Whitespace ')' Punctuation ' ' Text.Whitespace ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'foreach' Keyword '(' Punctuation 'alternative' Name ';' Punctuation ' ' Text.Whitespace 'FindWords' Name '(' Punctuation ' ' Text.Whitespace 'phone' Name ' ' Text.Whitespace ')' Punctuation ' ' Text.Whitespace ')' Punctuation '\n' Text.Whitespace ' ' Text.Whitespace 'writefln' Name '(' Punctuation 'phone' Name ',' Punctuation ' ' Text.Whitespace '": "' Literal.String ',' Punctuation ' ' Text.Whitespace 'alternative' Name ' ' Text.Whitespace ')' Punctuation ';' Punctuation '\n' Text.Whitespace '}' Punctuation '\n' Text.Whitespace