Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* PADDING
- ******************************************************************************************************************************************************************************************
- */
- #[memoize::memoize]
- pub fn first_star_solve(
- stones: Vec<String>,
- n: u64
- ) -> u64 {
- if n == 0 {
- return stones.len() as u64
- }
- let mut new_stones = Vec::with_capacity(stones.len()*2);
- for stone in stones {
- match stone.as_str() {
- "0" => {
- new_stones.push("1".to_string());
- }
- s if s.len() % 2 == 0 => {
- let s1 = s[..s.len()/2].parse::<u64>().unwrap().to_string();
- let s2 = s[s.len()/2..].parse::<u64>().unwrap().to_string();
- new_stones.push(s1);
- new_stones.push(s2);
- }
- s => {
- let s1 = (s.parse::<u64>().unwrap()*2024).to_string();
- new_stones.push(s1)
- }
- }
- }
- new_stones.iter().map(|x| {
- first_star_solve(vec![x.to_string()], n-1)
- }).collect::<Vec<u64>>().iter().sum()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement