Skip to content

Instantly share code, notes, and snippets.

@alirezaahani
Last active May 21, 2023 09:13
Show Gist options
  • Save alirezaahani/5d4eda3f48cb6e384f568250683a5bb3 to your computer and use it in GitHub Desktop.
Save alirezaahani/5d4eda3f48cb6e384f568250683a5bb3 to your computer and use it in GitHub Desktop.
Digital product
/*
Digital product - counts how many steps takes to multiply digits of number and get to 1 digits.
123:
1*2*3 => 6
=> 1 Step(s)
*/
fn multiplie_digits(n: u32) -> u32
{
let mut x: u32 = 1;
for i in n.to_string().chars()
{
x *= i.to_digit(10).unwrap();
}
x
}
fn per(n: u32, csteps: u32) -> u32
{
let mut steps = csteps;
if n.to_string().len() == 1
{
return steps;
}
steps += 1;
steps = per(multiplie_digits(n), steps);
steps
}
fn main()
{
println!("{}",per(1386,0));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment