@@ -44,26 +44,12 @@ class Digits {
44
44
var count: array (array (i64 , 75 ), 10 );
45
45
}
46
46
47
- // TODO: Add a builtin to perform integer conversion / truncation.
48
- fn I64DigitToI32 (a: i64 ) - > i32 {
49
- if (a == 0 ) { return 0 ; }
50
- if (a == 1 ) { return 1 ; }
51
- if (a == 2 ) { return 2 ; }
52
- if (a == 3 ) { return 3 ; }
53
- if (a == 4 ) { return 4 ; }
54
- if (a == 5 ) { return 5 ; }
55
- if (a == 6 ) { return 6 ; }
56
- if (a == 7 ) { return 7 ; }
57
- if (a == 8 ) { return 8 ; }
58
- return 9 ;
59
- }
60
-
61
47
fn ReduceToDigits (n: i64 , depth: i32 , multiplicity: i64 , digits: Digits* ) - > i64 {
62
48
if (n == - 1 ) { return 0 ; }
63
49
if (depth == 0 ) { return multiplicity; }
64
50
if (n < 10 ) {
65
- let count: i64 * = & digits- > count[I64DigitToI32 (n) ][depth - 1 ];
66
- * count = * count + multiplicity;
51
+ let count: i64 * = & digits- > count[n as i32 ][depth - 1 ];
52
+ * count + = multiplicity;
67
53
return 0 ;
68
54
}
69
55
let next: (i64 , i64 ) = Next (n);
@@ -78,7 +64,7 @@ fn Run() {
78
64
79
65
var n: i64 ;
80
66
while (ReadInt64 (& n)) {
81
- total = total + ReduceToDigits (n, max_depth, 1 , & digits);
67
+ total + = ReduceToDigits (n, max_depth, 1 , & digits);
82
68
PrintInt64 (total);
83
69
digits.Print (max_depth - 1 );
84
70
SkipSpaces ();
@@ -90,14 +76,13 @@ fn Run() {
90
76
digits.Print (depth);
91
77
var digit: i64 = 0 ;
92
78
while (digit < 10 ) {
93
- let m: i64 = digits.count[I64DigitToI32 ( digit) ][depth];
79
+ let m: i64 = digits.count[digit as i32 ][depth];
94
80
if (m > 0 ) {
95
81
let next: (i64 , i64 ) = Next (digit);
96
- total = total +
97
- ReduceToDigits (next.0 , depth, m, & digits) +
98
- ReduceToDigits (next.1 , depth, m, & digits);
82
+ total + = ReduceToDigits (next.0 , depth, m, & digits) +
83
+ ReduceToDigits (next.1 , depth, m, & digits);
99
84
}
100
- digit = digit + 1 ;
85
+ ++ digit ;
101
86
}
102
87
-- depth;
103
88
}
0 commit comments