User:Inthar/Code: Difference between revisions

Inthar (talk | contribs)
Inthar (talk | contribs)
Line 767: Line 767:
}
}
result
result
}
// Is the scale word s = s(x, y, z) pairwise well-formed (pwf)?
pub fn is_pwf(s: &str) -> bool {
let s1 = s.replace("z", "y");
let s2 = s.replace("z", "x");
let s3 = s.replace("y", "x").replace("z", "y");
return is_sv2(&s1)&&is_sv2(&s2)&&is_sv2(&s3);
}
// Is the scale word s = s(a,b,c) pairwise well-formed (pwf)?
pub fn is_pmos(s: &str) -> bool {
let s1 = s.replace("z", "y");
let s2 = s.replace("z", "x");
let s3 = s.replace("y", "x").replace("z", "y");
maximum_variety(&s1) == 2 && maximum_variety(&s2) == 2  && maximum_variety(&s3) == 2
}
// Is the scale word s = s(x, y, z), x > y > z > 0, monotone-mos?
pub fn is_mmos(scale: &str) -> bool {
let s1 = scale.replace("y", "x").replace("z", "y"); // m = L
let s2 = scale.replace("z", "y"); // m = s
let s3 = scale.replace("z", "");  // s = 0
maximum_variety(&s1) == 2 && maximum_variety(&s2) == 2  && maximum_variety(&s3) == 2
}
// Is the scale s = s(x, y) a single period mos (aka well-formed, wf)?
pub fn is_sv2(scale: &str) -> bool {
if scale.len() <= 1{
return false;
}
let floor_half : usize = scale.len()/2;
for slice_length in 1..(floor_half+1) {
let mut sizes: BTreeSet<(usize, usize)> = BTreeSet::new();
for basepoint in 0..(scale.len()) {
let mut size: (usize, usize) = (0, 0);
let sl = &slice_cyclic_string(scale, basepoint, slice_length);
let chars_in_sl = sl.chars();
for c in chars_in_sl {
match c {
'x' => {size.0 += 1;},
'y' => {size.1 += 1;},
_ => {panic!()},
}
}
sizes.insert(size);
}
if sizes.len() != 2 {
return false;
}
}
return true;
}
}