From 49d4f20b18e24003e64c71a81b558f86cc1cda0e Mon Sep 17 00:00:00 2001 From: Bill Ewanick Date: Tue, 5 Aug 2025 09:18:33 -0400 Subject: [PATCH] Make computation parallel --- flake.nix | 1 + src/3n+1/Main.hs | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index b696281..0f1a197 100644 --- a/flake.nix +++ b/flake.nix @@ -51,6 +51,7 @@ # maths primes arithmoi + parallel # graphing libraries! # Chart diff --git a/src/3n+1/Main.hs b/src/3n+1/Main.hs index e896518..e69c59c 100644 --- a/src/3n+1/Main.hs +++ b/src/3n+1/Main.hs @@ -3,13 +3,21 @@ The Simplest Math Problem No One Can Solve - Collatz Conjecture https://youtu.be/094y1Z2wpJg -} -import Data.Set (fromList) -import Debug.Trace (trace) +import Control.Parallel.Strategies +import Data.Containers.ListUtils +import Debug.Trace (trace) main :: IO () main = do - let results = map f [10^1_000..10^1_000+100] :: [Integer] - print (fromList results) + let start = 2^1_000_000 + let end = 100 + -- let message = "Starting at " <> show start <> ", and computing " <> show end <> " values." + let message = "Starting at 2^1_000_000, and computing " <> show end <> " values." + let results = parMap rpar f [start..start+end] :: [Integer] + putStrLn "======================================" + putStrLn message + print $ nubOrd results + putStrLn "======================================" lst :: [Integer] lst = take 300 [2^100_000..]