Browse Source

initial codewars submission

master
Jim Infield 3 years ago
parent
commit
0f7dd4e424
  1. 38
      src/main.rs

38
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::<String>(),
u32::from_str_radix(
&arg.iter()
.map(|i| i.to_string())
.collect::<String>(),
2
).unwrap(),
binary_slice_to_number(&arg)
);
}
println!();
}
fn func<T>(arg: &T) -> &T {
arg
}
fn binary_slice_to_number(slice: &[u32]) -> u32 {
u32::from_str_radix(
&slice.iter().map(|i| i.to_string()).collect::<String>(),
2
).unwrap()
}
Loading…
Cancel
Save