Day 1: Dusty Shed

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

  • morrowind@lemmy.ml
    link
    fedilink
    arrow-up
    3
    ·
    1 day ago

    Roc

    import "input.txt" as input : Str
    
    main! = |_args| {
    	nums = input.split_on("\n").map_try(U64.from_str)?
    
    	tallies = nums.fold(Dict.empty(),	|tally, num| {
    		tally.update(num, |entry| match entry {
    				Ok(count) => Ok(count + 1)
    				Err(_) => Ok(1)
    			}
    		)
    	})
    
    	.to_list().sort_by(|a| a.1)
    
    	dbg tallies.take_last(3) .map(|t| t.0).fold(1, |acc, num| acc * num)
    	dbg tallies.take_first(3).map(|t| t.0).fold(1, |acc, num| acc * num)
    
    	Ok({})
    }