#include "library.h" /* after seeing that some starting points produce very long Collatz sequences while neighbouring ones produce very short ones, this presents the information graphically. The horizontal axis is N The vertical axis is the length of the Collatz sequence that starts with N horizontal axis compressed to allow N to go up to 5000 */ int length_collatz_from(const int n) { if (n == 1) return 1; else if (n % 2 == 1) { const int rest = length_collatz_from(3*n+1); return 1 + rest; } else { const int rest = length_collatz_from(n/2); return 1 + rest; } } void plot(const int a, const int b) { const int len = length_collatz_from(a); draw_point(a/10, 500 - len); if (a < b) plot(a+1, b); } void main() { make_window(500, 500); set_pen_width(3); set_pen_color(color::red); plot(1, 5000); }