75
75
//! [grows rather large]: https://oeis.org/A017763/b017763.txt
76
76
//! [Lucas's theorem]: https://en.wikipedia.org/wiki/Lucas%27s_theorem
77
77
//! [Chinese remainder theorem]: https://en.wikipedia.org/wiki/Chinese_remainder_theorem
78
- use crate :: util:: integer:: * ;
79
78
use crate :: util:: parse:: * ;
79
+ use crate :: util:: slice:: * ;
80
80
81
81
/// Lookup table for first five rows of
82
82
/// [Pascal's triangle](https://en.wikipedia.org/wiki/Pascal%27s_triangle).
@@ -135,12 +135,12 @@ pub fn part1(input: &[u8]) -> i32 {
135
135
( current, next) = ( next, current) ;
136
136
}
137
137
138
- fold_number ( & current[ ..8 ] )
138
+ current[ ..8 ] . fold_decimal ( )
139
139
}
140
140
141
141
pub fn part2 ( input : & [ u8 ] ) -> usize {
142
142
let digits: Vec < _ > = input. iter ( ) . copied ( ) . map ( usize:: from) . collect ( ) ;
143
- let start = fold_number ( & digits[ ..7 ] ) ;
143
+ let start = digits[ ..7 ] . fold_decimal ( ) ;
144
144
145
145
// This approach will only work if the index is in the second half of the input.
146
146
let size = digits. len ( ) ;
@@ -160,7 +160,7 @@ pub fn part2(input: &[u8]) -> usize {
160
160
}
161
161
162
162
result. iter_mut ( ) . for_each ( |r| * r %= 10 ) ;
163
- fold_number ( & result)
163
+ result. fold_decimal ( )
164
164
}
165
165
166
166
/// Computes C(n, k) % 2
@@ -215,9 +215,3 @@ fn bimonial_mod_5(mut n: usize, mut k: usize) -> usize {
215
215
fn binomial_mod_10 ( n : usize , k : usize ) -> usize {
216
216
5 * binomial_mod_2 ( n, k) + 6 * bimonial_mod_5 ( n, k)
217
217
}
218
-
219
- /// Folds a slice of digits into an integer.
220
- #[ inline]
221
- fn fold_number < T : Integer < T > > ( slice : & [ T ] ) -> T {
222
- slice. iter ( ) . fold ( T :: ZERO , |acc, & b| T :: TEN * acc + b)
223
- }
0 commit comments