File tree 2 files changed +35
-0
lines changed 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " day19"
3
+ version = " 0.1.0"
4
+ authors = [" Denys Levchenko <denis.levtchenko@gmail.com>" ]
5
+
6
+ [dependencies ]
Original file line number Diff line number Diff line change
1
+ use std:: io:: prelude:: * ;
2
+ use std:: fs:: File ;
3
+
4
+ fn main ( ) {
5
+
6
+ fn get_new_molecules ( init_molecule : String , from : & str , to : & str ) -> Vec < String > {
7
+ let splited_molecule: Vec < & str > = init_molecule. split ( from) . collect ( ) ;
8
+ let molecule_len = splited_molecule. len ( ) ;
9
+ ( 0 ..molecule_len - 1 ) . map ( |i| splited_molecule. iter ( )
10
+ . enumerate ( )
11
+ . map ( |( splited_index, & splited_val) | {
12
+ if splited_index == i {
13
+ splited_val. to_string ( ) + to
14
+ } else if splited_index != molecule_len - 1 {
15
+ splited_val. to_string ( ) + from
16
+ } else {
17
+ splited_val. to_string ( )
18
+ }
19
+ } ) . collect :: < Vec < String > > ( ) . concat ( ) )
20
+ . collect ( )
21
+
22
+
23
+ }
24
+
25
+ let replaced_molecule = get_new_molecules ( "HOHOH" . to_string ( ) , "H" , "OO" ) ;
26
+
27
+
28
+ println ! ( "{:?}" , replaced_molecule) ;
29
+ }
You can’t perform that action at this time.
0 commit comments