fn walk(
        &self,
        cave: &'a str,
        mut seen: HashSet<&'a str>,
        paths: &mut Vec<Vec<&'a str>>,
        mut path: Vec<&'a str>,
        mut seen_twice: bool,
    ) {
        if seen.contains(cave) {
            if seen_twice {
                return;
            } else {
                seen_twice = true;
            }
        }

        path.push(cave);
        if cave == "end" {
            paths.push(path);
            return;
        }

        // track small caves we've seen
        if cave.starts_with(char::is_lowercase) {
            seen.insert(cave);
        }

        for neighbour in self.caves[cave].iter().filter(|n| **n != "start") {
            self.walk(neighbour, seen.clone(), paths, path.clone(), seen_twice);
        }
    }
// could make this faster by summing completed paths rather than collecting the actual paths.
could make this faster by summing completed paths rather than collecting the actual paths.
could make this faster by summing completed paths rather than collecting the actual paths .
fn walk(
        &self,
        cave: &'a str,
        mut seen: HashSet<&'a str>,
        paths: &mut Vec<Vec<&'a str>>,
        mut path: Vec<&'a str>,
        mut seen_twice: bool,
    ) {
        if seen.contains(cave) {
            if seen_twice {
                return;
            } else {
                seen_twice = true;
            }
        }
        path.push(cave);
        if cave == "end" {
            paths.push(path);
            return;
        }
        // track small caves we've seen
        if cave.starts_with(char::is_lowercase) {
            seen.insert(cave);
        }
        for neighbour in self.caves[cave].iter().filter(|n| **n != "start") {
            self.walk(neighbour, seen.clone(), paths, path.clone(), seen_twice);
        }
    }
fn walk ( & self , cave : & ' a str , mut seen : HashSet < & ' a str > , paths : & mut Vec < Vec < & ' a str > > , mut path : Vec < & ' a str > , mut seen_twice : bool , ) { if seen . contains ( cave ) { if seen_twice { return ; } else { seen_twice = true ; } } path . push ( cave ) ; if cave == " " { paths . push ( path ) ; return ; } // track small caves we've seen if cave . starts_with ( char :: is_lowercase ) { seen . insert ( cave ) ; } for neighbour in self . caves [ cave ] . iter ( ) . filter ( | n | * * n != " " ) { self . walk ( neighbour , seen . clone ( ) , paths , path . clone ( ) , seen_twice ) ; } }
could make this faster by summing completed paths rather than collecting the actual paths.
could make this faster by summing completed paths rather than collecting the actual paths .
&self
cave
&'a str
seen
HashSet<&'a str>
paths
&mut Vec<Vec<&'a str>>
path
Vec<&'a str>
seen_twice
bool
&self
cave
&'a str
seen
HashSet<&'a str>
paths
&mut Vec<Vec<&'a str>>
path
Vec<&'a str>
seen_twice
bool