Fix bugs (switch naive and cyclic) and add timing output for series calculation

This commit is contained in:
hal8174 2025-04-06 20:35:08 +02:00
parent be3697a749
commit 46907f8752
3 changed files with 10 additions and 9 deletions

View file

@ -2,7 +2,8 @@ fn main() {
for length in 2.. { for length in 2.. {
let mut count = 0; let mut count = 0;
let mut state = vec![0, 1]; let mut state = vec![0, 1];
let start = std::time::Instant::now();
stamp_folding::cyclic::stamp_folding(&mut state, 1, length - 2, &mut count, &mut |_, _| {}); stamp_folding::cyclic::stamp_folding(&mut state, 1, length - 2, &mut count, &mut |_, _| {});
println!("{length:02}: {count} {}", count * 2); println!("{length:02}: {count} {} {:?}", count * 2, start.elapsed());
} }
} }

View file

@ -9,7 +9,7 @@ pub fn stamp_folding(
// dbg!(&current, depth, last_inserted_index); // dbg!(&current, depth, last_inserted_index);
if remaining == 0 { if remaining == 0 {
callback(*count, current); callback(*count, current);
*count = count.checked_add(1).unwrap(); *count = count.checked_add(depth as u128).unwrap();
return; return;
} }
@ -37,12 +37,6 @@ pub fn stamp_folding(
} }
} }
if last.is_none() {
current.insert(0, depth);
stamp_folding(current, 0, remaining - 1, count, callback);
current.remove(0);
}
let mut last = None; let mut last = None;
for i in (last_inserted_index + 1)..current.len() { for i in (last_inserted_index + 1)..current.len() {
if let Some(l) = last { if let Some(l) = last {

View file

@ -9,7 +9,7 @@ pub fn stamp_folding(
// dbg!(&current, depth, last_inserted_index); // dbg!(&current, depth, last_inserted_index);
if remaining == 0 { if remaining == 0 {
callback(*count, current); callback(*count, current);
*count = count.checked_add(depth as u128).unwrap(); *count = count.checked_add(1).unwrap();
return; return;
} }
@ -37,6 +37,12 @@ pub fn stamp_folding(
} }
} }
if last.is_none() {
current.insert(0, depth);
stamp_folding(current, 0, remaining - 1, count, callback);
current.remove(0);
}
let mut last = None; let mut last = None;
for i in (last_inserted_index + 1)..current.len() { for i in (last_inserted_index + 1)..current.len() {
if let Some(l) = last { if let Some(l) = last {