Skip to main content
added 95 characters in body
Source Link
Ezhik
  • 793
  • 3
  • 3

Rust, 239239 234 bytes

|i:&str||i|{let mut r=vec![];for l in 1..i.len(){let(mut s,mut v)=(vec![0;l*2],vec![(0,0)]);for c in i.bytes(){s[c as usize%3&1]+=1-(c as i64%5&2);v.push((s[0],s[1]));s.rotate_left(2);}v.sort();v.dedup();r.push((!v.len(),l));}r.sort();r[0].1}

Try it online!Try it online!

Ungolfed:

    |i: &str||i| {
        let mut r = vec![];
        for l in 1..i.len() {
            let (mut s, mut v) = (vec![0; l * 2], vec![(0, 0)]);
            for c in i.bytes() {
                s[c as usize % 3 & 1] += // %3 - bit 1 flips, s[0] or s[1]
                    1 - (c as i64 % 5 & 2); // %5 - bit 2 flips, 0 or 2
                v.push((s[0], s[1]));
                s.rotate_left(2);
            }
            v.sort();
            v.dedup();
            r.push((!v.len(), l)); // dirty negation to reverse tuple sort order
        }
        r.sort();
        r[0].1
    };

History:

  • -5 by removing the type annotation for i (thanks @Aiden4)

Rust, 239 bytes

|i:&str|{let mut r=vec![];for l in 1..i.len(){let(mut s,mut v)=(vec![0;l*2],vec![(0,0)]);for c in i.bytes(){s[c as usize%3&1]+=1-(c as i64%5&2);v.push((s[0],s[1]));s.rotate_left(2);}v.sort();v.dedup();r.push((!v.len(),l));}r.sort();r[0].1}

Try it online!

Ungolfed:

    |i: &str| {
        let mut r = vec![];
        for l in 1..i.len() {
            let (mut s, mut v) = (vec![0; l * 2], vec![(0, 0)]);
            for c in i.bytes() {
                s[c as usize % 3 & 1] += // %3 - bit 1 flips, s[0] or s[1]
                    1 - (c as i64 % 5 & 2); // %5 - bit 2 flips, 0 or 2
                v.push((s[0], s[1]));
                s.rotate_left(2);
            }
            v.sort();
            v.dedup();
            r.push((!v.len(), l)); // dirty negation to reverse tuple sort order
        }
        r.sort();
        r[0].1
    };

Rust, 239 234 bytes

|i|{let mut r=vec![];for l in 1..i.len(){let(mut s,mut v)=(vec![0;l*2],vec![(0,0)]);for c in i.bytes(){s[c as usize%3&1]+=1-(c as i64%5&2);v.push((s[0],s[1]));s.rotate_left(2);}v.sort();v.dedup();r.push((!v.len(),l));}r.sort();r[0].1}

Try it online!

Ungolfed:

    |i| {
        let mut r = vec![];
        for l in 1..i.len() {
            let (mut s, mut v) = (vec![0; l * 2], vec![(0, 0)]);
            for c in i.bytes() {
                s[c as usize % 3 & 1] += // %3 - bit 1 flips, s[0] or s[1]
                    1 - (c as i64 % 5 & 2); // %5 - bit 2 flips, 0 or 2
                v.push((s[0], s[1]));
                s.rotate_left(2);
            }
            v.sort();
            v.dedup();
            r.push((!v.len(), l)); // dirty negation to reverse tuple sort order
        }
        r.sort();
        r[0].1
    };

History:

  • -5 by removing the type annotation for i (thanks @Aiden4)
Source Link
Ezhik
  • 793
  • 3
  • 3

Rust, 239 bytes

|i:&str|{let mut r=vec![];for l in 1..i.len(){let(mut s,mut v)=(vec![0;l*2],vec![(0,0)]);for c in i.bytes(){s[c as usize%3&1]+=1-(c as i64%5&2);v.push((s[0],s[1]));s.rotate_left(2);}v.sort();v.dedup();r.push((!v.len(),l));}r.sort();r[0].1}

Try it online!

Ungolfed:

    |i: &str| {
        let mut r = vec![];
        for l in 1..i.len() {
            let (mut s, mut v) = (vec![0; l * 2], vec![(0, 0)]);
            for c in i.bytes() {
                s[c as usize % 3 & 1] += // %3 - bit 1 flips, s[0] or s[1]
                    1 - (c as i64 % 5 & 2); // %5 - bit 2 flips, 0 or 2
                v.push((s[0], s[1]));
                s.rotate_left(2);
            }
            v.sort();
            v.dedup();
            r.push((!v.len(), l)); // dirty negation to reverse tuple sort order
        }
        r.sort();
        r[0].1
    };