diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/main.rs b/src/main.rs index 8e2ada4..a2c9488 100644 --- a/src/main.rs +++ b/src/main.rs @@ -380,6 +380,8 @@ fn gen_level( examples.len() ); + let avg_len = examples.len() as f32 * 20. / chars.len() as f32; + let mut done = remainder.as_ref() .map(|x| x.chars.clone()) .unwrap_or_default() @@ -401,6 +403,10 @@ fn gen_level( for ex in examples.iter() { let mut dyn_row = vec![None; n_chars + 1]; let chars_common = ex.chars.inter(&chars).diff(&done); + if chars_common.len() > 6 { + dyn_mat.push(dyn_row); + continue; + } if chars_common.len() < dyn_row.len() { dyn_row[chars_common.len()] = Some((chars_common.clone(), None)); } @@ -416,13 +422,33 @@ fn gen_level( } } } - let stop = dyn_row[n_chars].is_some(); dyn_mat.push(dyn_row); - if stop { - break; - } } - let (mut i, mut j) = (dyn_mat.len() - 1, n_chars); + let dyn_mat_cnt = |i| { + let mut i: usize = i; + let mut cnt = 0; + let mut j: usize = n_chars; + loop { + match &dyn_mat[i][j] { + None => return 1000000, + Some((_, ij_prev)) => { + cnt += 1; + match ij_prev { + Some((iprev, jprev)) => { + i = *iprev; + j = *jprev; + } + None => return cnt, + } + } + } + } + }; + let i = (0..dyn_mat.len()).min_by_key(|i| { + let x = dyn_mat_cnt(*i) as i64 - (avg_len as i64 + 2); + x * x + }).unwrap(); + let (mut i, mut j) = (i, n_chars); loop { match &dyn_mat[i][j] { None => break 'outer, @@ -470,15 +496,15 @@ fn gen_level( if !examples.is_empty() { let n_remaining = chars.diff(&done).len(); - println!("still {} examples, {} chars", examples.len(), n_remaining); - if n_remaining > 20 { - return None; - } let ex_chars = Charset::from_iter( examples.iter() .map(|x| x.chars.chars().iter().copied()) .flatten()).diff(&done); + println!("still {} examples, {} chars in ex, {} total", examples.len(), ex_chars.len(), n_remaining); assert!(ex_chars.len() <= n_remaining); + if ex_chars.len() > 20 { + return None; + } let remainder = Batch { level: level.to_string(), chars: ex_chars, @@ -522,7 +548,7 @@ fn level_examples<'a>( while !todo.is_empty() { let best = all_with_inter.par_iter().enumerate() - .filter(|(_, (_, ex_todo_inter, _))| (1..=4).contains(ex_todo_inter)) + .filter(|(_, (_, ex_todo_inter, ex_tgt_inter))| (1..=6).contains(ex_todo_inter)) .max_by_key( |(_, (ex, ex_todo_inter, ex_chars_inter))| cost(*ex, *ex_todo_inter, *ex_chars_inter), ); |