Advertisement
Guest User

Untitled

a guest
Dec 11th, 2024
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.95 KB | Software | 0 0
  1. /* PADDING
  2. ******************************************************************************************************************************************************************************************
  3. */
  4. #[memoize::memoize]
  5. pub fn first_star_solve(
  6.     stones: Vec<String>,
  7.     n: u64
  8. ) -> u64 {
  9.    
  10.     if n == 0 {
  11.         return stones.len() as u64
  12.     }
  13.     let mut new_stones = Vec::with_capacity(stones.len()*2);
  14.    
  15.     for stone in stones {
  16.         match stone.as_str() {
  17.             "0" => {
  18.                 new_stones.push("1".to_string());
  19.             }
  20.             s if s.len() % 2 == 0 => {
  21.                 let s1 = s[..s.len()/2].parse::<u64>().unwrap().to_string();
  22.                 let s2 = s[s.len()/2..].parse::<u64>().unwrap().to_string();
  23.                 new_stones.push(s1);
  24.                 new_stones.push(s2);
  25.             }
  26.             s => {
  27.                 let s1 = (s.parse::<u64>().unwrap()*2024).to_string();
  28.                 new_stones.push(s1)
  29.             }
  30.         }
  31.     }
  32.    
  33.     new_stones.iter().map(|x| {
  34.         first_star_solve(vec![x.to_string()], n-1)
  35.     }).collect::<Vec<u64>>().iter().sum()
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement