Jump to content

Yellowstone sequence: Difference between revisions

Rust solution extended to plot the first 100 numbers in the sequence
m (Minor edit to C++ code)
(Rust solution extended to plot the first 100 numbers in the sequence)
Line 1,150:
<lang rust>// [dependencies]
// num = "0.3"
// plotters = "^0.2.15"
 
use num::integer::gcd;
use std::collections::HashSet;
use plotters::prelude::*;
 
fn yellowstone_sequence() -> impl std::iter::Iterator<Item = u32> {
Line 1,158 ⟶ 1,160:
let mut min = 1;
let mut n = 0;
let mut n1 = 10;
let mut n2 = 0;
std::iter::from_fn(move || {
Line 1,178 ⟶ 1,180:
Some(n)
})
}
 
// Based on the example in the "Quick Start" section of the README file for
// the plotters library.
fn plot_yellowstone(filename: &str) -> Result<(), Box<dyn std::error::Error>> {
let root = BitMapBackend::new(filename, (800, 600)).into_drawing_area();
root.fill(&WHITE)?;
let mut chart = ChartBuilder::on(&root)
.caption("Yellowstone Sequence", ("sans-serif", 24).into_font())
.margin(10)
.x_label_area_size(20)
.y_label_area_size(20)
.build_ranged(0usize..100usize, 0u32..180u32)?;
chart.configure_mesh().draw()?;
chart.draw_series(LineSeries::new(
yellowstone_sequence().take(100).enumerate(),
&BLUE))?;
Ok(())
}
 
Line 1,186 ⟶ 1,206:
}
println!();
match plot_yellowstone("yellowstone.png") {
Ok(()) => {}
Err(error) => eprintln!("Error: {}", error)
}
}</lang>
 
{{out}}
A plot of the first 100 Yellowstone numbers is saved to the file "yellowstone.png".
<pre>
First 30 Yellowstone numbers:
1,777

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.