From 0f7dd4e424a2b9486767688332d55fe427469b02 Mon Sep 17 00:00:00 2001 From: Jim Infield Date: Mon, 2 Aug 2021 21:32:37 -0500 Subject: [PATCH] initial codewars submission --- src/main.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index e7a11a9..2561486 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,39 @@ fn main() { - println!("Hello, world!"); + + let args = vec![ + [0,0,0,1], + [0,1,1,0], + [1,1,1,1] + ]; + + println!(); + + for arg in args { + println!("{:?} {:12?}{:4?}{:4?}", + arg, + arg.iter() + .map(|i| i.to_string()) + .collect::(), + u32::from_str_radix( + &arg.iter() + .map(|i| i.to_string()) + .collect::(), + 2 + ).unwrap(), + binary_slice_to_number(&arg) + ); + } + + println!(); +} + +fn func(arg: &T) -> &T { + arg +} + +fn binary_slice_to_number(slice: &[u32]) -> u32 { + u32::from_str_radix( + &slice.iter().map(|i| i.to_string()).collect::(), + 2 + ).unwrap() }