File tree 5 files changed +5
-17
lines changed
5 files changed +5
-17
lines changed Original file line number Diff line number Diff line change 1
1
pub trait VecExt < T > {
2
- fn fill ( n : usize , t : T ) -> Vec < T > where T : Copy ;
3
2
fn tabulate ( n : usize , f : impl Fn ( usize ) -> T ) -> Vec < T > ;
4
3
}
5
4
6
5
impl < T > VecExt < T > for Vec < T > {
7
- fn fill ( n : usize , t : T ) -> Vec < T > where T : Copy {
8
- let mut vec: Vec < T > = Vec :: with_capacity ( n) ;
9
- ( 0 ..n) . for_each ( |_| vec. push ( t) ) ;
10
- vec
11
- }
12
-
13
6
fn tabulate ( n : usize , f : impl Fn ( usize ) -> T ) -> Vec < T > {
14
7
let mut vec: Vec < T > = Vec :: with_capacity ( n) ;
15
8
( 0 ..n) . for_each ( |i| vec. push ( f ( i) ) ) ;
Original file line number Diff line number Diff line change 1
1
#![ allow( clippy:: needless_range_loop) ]
2
2
3
- use crate :: util:: collection:: * ;
4
-
5
3
type Input = ( usize , Vec < usize > ) ;
6
4
7
5
pub fn parse ( input : & str ) -> Input {
@@ -17,7 +15,7 @@ pub fn parse(input: &str) -> Input {
17
15
18
16
pub fn part1 ( input : & Input ) -> usize {
19
17
let ( width, digits) = input;
20
- let mut visible: Vec < bool > = Vec :: fill ( digits. len ( ) , false ) ;
18
+ let mut visible: Vec < bool > = vec ! [ false ; digits. len( ) ] ;
21
19
22
20
for i in 1 ..( * width - 1 ) {
23
21
let mut left_max = 0 ;
@@ -57,7 +55,7 @@ pub fn part1(input: &Input) -> usize {
57
55
58
56
pub fn part2 ( input : & Input ) -> usize {
59
57
let ( width, digits) = input;
60
- let mut scenic: Vec < usize > = Vec :: fill ( digits. len ( ) , 1 ) ;
58
+ let mut scenic: Vec < usize > = vec ! [ 1 ; digits. len( ) ] ;
61
59
62
60
for i in 1 ..( * width - 1 ) {
63
61
let mut left_max = [ 0 ; 11 ] ;
Original file line number Diff line number Diff line change 1
- use crate :: util:: collection:: * ;
2
1
use crate :: util:: parse:: * ;
3
2
use crate :: util:: point:: * ;
4
3
use std:: collections:: HashSet ;
@@ -33,7 +32,7 @@ pub fn part2(input: &[Point]) -> usize {
33
32
}
34
33
35
34
fn simulate ( input : & [ Point ] , size : usize ) -> usize {
36
- let mut rope: Vec < Point > = Vec :: fill ( size , ORIGIN ) ;
35
+ let mut rope: Vec < Point > = vec ! [ ORIGIN ; size ] ;
37
36
let mut tail: HashSet < Point > = HashSet :: new ( ) ;
38
37
39
38
for step in input {
Original file line number Diff line number Diff line change 1
- use crate :: util:: collection:: * ;
2
1
use crate :: util:: parse:: * ;
3
2
4
3
pub struct Monkey {
@@ -58,7 +57,7 @@ pub fn part2(input: &[Monkey]) -> u64 {
58
57
}
59
58
60
59
fn play ( monkeys : & [ Monkey ] , rounds : u32 , adjust : impl Fn ( u64 ) -> u64 ) -> u64 {
61
- let mut business: Vec < u64 > = Vec :: fill ( monkeys. len ( ) , 0 ) ;
60
+ let mut business: Vec < u64 > = vec ! [ 0 ; monkeys. len( ) ] ;
62
61
63
62
for start_index in 0 ..monkeys. len ( ) {
64
63
for start_item in monkeys[ start_index] . items . iter ( ) {
Original file line number Diff line number Diff line change 1
- use crate :: util:: collection:: * ;
2
1
use crate :: util:: parse:: * ;
3
2
4
3
pub struct Cave {
@@ -40,7 +39,7 @@ pub fn parse(input: &str) -> Cave {
40
39
let width = 2 * max_y + 5 ;
41
40
let height = max_y + 3 ;
42
41
let start = max_y + 2 ;
43
- let mut sand = Vec :: fill ( ( width * height) as usize , false ) ;
42
+ let mut sand = vec ! [ false ; ( width * height) as usize ] ;
44
43
45
44
for row in points {
46
45
for window in row. windows ( 4 ) . step_by ( 2 ) {
You can’t perform that action at this time.
0 commit comments