Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3fce0d3
Showing
7 changed files
with
1,127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import Distribution.Simple | ||
main = defaultMain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module T where | ||
test_true = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Data.Numbers.Primes | ||
import Data.Word | ||
import Data.Binary | ||
import Data.Vector.Binary | ||
import qualified Data.Vector.Unboxed as U | ||
biggest::Integer | ||
biggest = 10^12 | ||
|
||
smallprimes :: [Word] | ||
smallprimes = {-# SCC "smallprimes" #-} takeWhile (<= (ceiling . sqrt $ fromIntegral biggest)) primes | ||
|
||
small_vector = U.fromList smallprimes | ||
|
||
main = encodeFile "primes.dat" small_vector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{-# LANGUAGE BangPatterns #-} | ||
module Logs where | ||
import Data.Word | ||
import Debug.Trace | ||
|
||
|
||
intlog :: Word -> Word -> Word | ||
--intlog 1 _ = error "don't be an idiot" | ||
--intlog _ 1 = 0 | ||
intlog !my_number !my_base = gobble my_number 0 | ||
where | ||
gobble !internal_number !accumulator | ||
| internal_number < my_base = accumulator | ||
| otherwise = gobble (div internal_number my_base) (succ accumulator) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{-# LANGUAGE ScopedTypeVariables, BangPatterns #-} | ||
-- highest is pretty easy to get - we're always going to end up at the LCM of 1..n | ||
-- if you go in in order, then everyone's unhappy up to n | ||
-- but then all bets are off. damn. | ||
|
||
-- so at that point, we need all the common multiples of all our numbers, sorted and uniqed. | ||
|
||
-- can't get to primes > n, because no-one would go there anyway. | ||
-- so: all products of the power set of primes < n, raised to an arbitrary power. | ||
import Data.Numbers.Primes | ||
import Data.List | ||
import Logs | ||
import Debug.Trace | ||
import Data.Array | ||
import Control.Parallel | ||
import Control.Parallel.Strategies | ||
import Data.Word | ||
import qualified Data.Vector.Unboxed as U | ||
import Data.Vector.Binary | ||
import Data.Binary | ||
|
||
solve :: U.Vector Word -> Word -> Word | ||
solve !smallprimes !no = diff small_arr | ||
where diff (!x) = {-# SCC "diff" #-} 1 + U.foldl' (\(!acc) (!x) -> acc + (diff_i x)) 0 x | ||
small_arr = {-# SCC "arr" #-} U.takeWhile (<= (ceiling . sqrt $ fromIntegral no)) smallprimes | ||
diff_i (!x) = {-# SCC "diff_i" #-} (intlog no x ) - 1 | ||
|
||
-- repa stuff | ||
-- small_array = fromFunction (Z :. len) (\(Z :. ix) -> arr ! (Z :. ix)) | ||
-- arr_primes = {-# SCC "arr_primes" #-} fromList (Z :. len :: DIM1) smallerprimes | ||
-- diff = {-# SCC "diff" #-} (+1) . flip (Repa.!) Z . Repa.fold (\acc -> (+acc) . diff_i) 0 | ||
main = do | ||
primes <- {-# SCC "decode" #-} decodeFile "primes.dat" :: IO (U.Vector Word) | ||
l <- getContents | ||
putStr . unlines . format . parMap rseq (solve primes .read) . tail $ lines l | ||
|
||
format n = map (\(num, s) -> "Case #" ++ show num ++ ": " ++ show s ) $ zip [1..] n |
Oops, something went wrong.