diff --git a/.gitignore b/.gitignore index c6e4cb2..ebf22f7 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ billiard_words *.pnm *.png *.hi +gmon.out diff --git a/billiard_words.hs b/billiard_words.hs index 92ef72c..80c8d5a 100644 --- a/billiard_words.hs +++ b/billiard_words.hs @@ -11,18 +11,13 @@ wordlist = nub $ sortBy (comparing sl) [((p `div` gcd p q, q `div` gcd p q), slo -- only allows slopes 0 <= p/q <= 1 slopeWord :: Int -> Int -> String -slopeWord p q = - concat $ map word $ zipWith step list (tail list) +slopeWord p q = concat $ map word $ zipWith step list (tail list) where p_ = p `div` gcd p q q_ = q `div` gcd p q - xmax = if (p_ - q_) `mod` 3 == 0 then q_ else 3*q_ - list = [(x,y) | x <- ([0..xmax] :: [Int]), let y = floor (fromIntegral x*fromIntegral p/fromIntegral q)] - - step :: (Int,Int) -> (Int,Int) -> (Int,Int) - step (x1,y1) (x2,y2) = ((x1-y1) `mod` 3, y2 - y1) - - word :: (Int,Int) -> String + xmax = if (p_-q_) `mod` 3 == 0 then q_ else 3*q_ :: Int + list = [(x,(x*p) `div` q) | x <- [0..xmax]] + step (x1,y1) (x2,y2) = ((x1-y1) `mod` 3, y2-y1) word (0,0) = "bc" word (1,0) = "ab" word (2,0) = "ca" diff --git a/max_slope_picture_billiards/generate.hs b/max_slope_picture_billiards/generate.hs index 011f38f..d53e0a8 100644 --- a/max_slope_picture_billiards/generate.hs +++ b/max_slope_picture_billiards/generate.hs @@ -9,6 +9,6 @@ col = map (\(r,g,b) -> (round $ r*255, round $ g*255, round $ b*255)) colors :: main = do foo <- readFile "max_slopes_billiard" let dat = map (read.(!!2).words) $ lines foo :: [Int] - writeFile "max_slope_billiards.pnm" $ header ++ unlines [printf "%d %d %d" r g b | p <- dat, let (r,g,b) = col !! (p `mod` 10)] + writeFile "max_slope_billiards.pnm" $ header ++ unlines [printf "%d %d %d" r g b | p <- dat, let (r,g,b) = col !! (p `mod` 14)] where header = "P3\n300\n123\n255\n"