Skip to content

Instantly share code, notes, and snippets.

@Rotwang
Created May 14, 2020 21:42
Show Gist options
  • Save Rotwang/62a6740280bc844b19e583ee9abdbcac to your computer and use it in GitHub Desktop.
Save Rotwang/62a6740280bc844b19e583ee9abdbcac to your computer and use it in GitHub Desktop.
let x = 1930;
let len = (x as f64).log10().floor() as u32 + 1;
let mut digits = (0..len)
.map(|i| (x / 10u64.pow(i)) % 10)
.collect::<Vec<u64>>();
digits.sort_unstable();
let mut answer: u64 = 0;
for (i, v) in digits.iter().enumerate() {
answer += v * 10u64.pow(i as u32);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment