Skip to content

Commit

Permalink
Extract params in function
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Dec 29, 2024
1 parent e11d35b commit fa09233
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,44 +115,38 @@ pub fn py_cant_spin_out(prog: &str, depth: Depth) -> BackwardResult {

/***************************************/

#[pyfunction]
pub fn py_segment_cant_halt(prog: &str, segs: usize) -> Option<usize> {
let prog = &CompProg::from_str(prog);
fn get_comp(prog: &str) -> (CompProg, Params) {
let prog = CompProg::from_str(prog);

let (states, colors) = prog
.keys()
.fold((0, 0), |acc, &(a, b)| (acc.0.max(a), acc.1.max(b)));

let params = (1 + states, 1 + colors);

segment_cant_halt(prog, params, segs)
(prog, params)
}

#[pyfunction]
pub fn py_segment_cant_blank(prog: &str, segs: usize) -> Option<usize> {
let prog = &CompProg::from_str(prog);
pub fn py_segment_cant_halt(prog: &str, segs: usize) -> Option<usize> {
let (comp, params) = get_comp(prog);

let (states, colors) = prog
.keys()
.fold((0, 0), |acc, &(a, b)| (acc.0.max(a), acc.1.max(b)));
segment_cant_halt(&comp, params, segs)
}

let params = (1 + states, 1 + colors);
#[pyfunction]
pub fn py_segment_cant_blank(prog: &str, segs: usize) -> Option<usize> {
let (comp, params) = get_comp(prog);

segment_cant_blank(prog, params, segs)
segment_cant_blank(&comp, params, segs)
}

#[pyfunction]
pub fn py_segment_cant_spin_out(
prog: &str,
segs: usize,
) -> Option<usize> {
let prog = &CompProg::from_str(prog);

let (states, colors) = prog
.keys()
.fold((0, 0), |acc, &(a, b)| (acc.0.max(a), acc.1.max(b)));

let params = (1 + states, 1 + colors);
let (comp, params) = get_comp(prog);

segment_cant_spin_out(prog, params, segs)
segment_cant_spin_out(&comp, params, segs)
}

0 comments on commit fa09233

Please sign in to comment.