Created
December 22, 2017 09:24
-
-
Save minstrel271/72e5c22f1ad461a8ef132422e51334f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn func(seq: &[u8]) -> u64 { | |
let n = seq.len(); | |
let mut sum = 0u64; | |
for i in 0..n { | |
let j = (i + 1) % n; | |
if seq[i] == seq[j] { | |
sum += seq[i] as u64 | |
} | |
} | |
sum | |
} | |
fn parse_seq(string: &str) -> Vec<u8> { | |
string | |
.chars() | |
.filter_map(|c| c.to_digit(10)) | |
.map(|d| d as u8) | |
.collect() | |
} | |
fn main() { | |
static INPUT: &str = &"68376334795224855827459835293967497295464175589881588256882344699473595413912688278647235862566123233983921662578792917453912795352746426512649965615919588512125567186837411371179875287621488759761429629174886972298349197722423458299323141529413191327622485249495864168181327197661454464926326248274999448373741839963155646828842752761293142356422964355349521987483211496361289666375779728345952231649453711684539164893151811849653331845998998597991146881361717234517911759893792348815818755262456378627116779495435596139617246571678531183335956244163871445674244765586446362529159854137535962117184875192273872222899887357292312978286182636232921252574738118347521187637829623831872437381979223955675634257889137823684924127338433248519515211796732599314921611399736571277222546332369461136277417419794865524123989722492356536832313937597437717873787593849468836733642529378547151146397532997237439387663769334722979172954835154486382983716698212694357398153392926255272961384626131829678171219569288685597141132355322788254163923888378155573948753185423158997877718687642446457446643422536541238979761725496426292359382168535641216124211741896552562128941824172241913873537828976172738276983915232241451589421911121567228899853934667954786256223614621554618294467191255153395256524786159758429643756586457639177183891162214163549688595416893383194995824534247841414247526268212761954913719452114876764745799982792594753759626334319631191917894368116738893548797661111899664138398354818931135486984944719992393148681724116616741428937687985152658296679845474766477741553632712968679175356452987459761126437216758171182395219393289199148996813762849991484678429793578629331215796996751484375784895561682156658579887518746862371751372692472765217374791324656745291574784495299477362964676351148183676897122366838656342745944945275263617729359831466565694983217252594237828187612857523344265418227883219383138893873384775659548637662867572687198263688597865118173921615178165442133987362382721444844952715592955744739873677838847693982379696776"; | |
println!("{}", func(&parse_seq(INPUT))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment