Collatz Conjecture in Haskell
Overview
The Collatz Conjecture is based on sequences from the following formulas:
n/2 for even n 3*n + 1 for odd n
Collatz Sequence Code
Code to generate sequences and find the lengths of the sequences:
test :: Int -> Int
test x | even x = x `div` 2
| otherwise = 3*x + 1
collatz :: Int -> [Int]
collatz 1 = [1]
collatz x = x : collatz (test x)
numCollatz = map (length . collatz) [1..]
Output Code
Generates a table that gnuplot can handle.
format x y = show x ++ "t" ++ show y table x = unlines (zipWith format [1..] (take x numCollatz)) main = writeFile "collatz.dat" (table 100000)
Images
1000, 10000, and 100000 numbers respectively



Video
Click the image below for a video of the behavior as we go to higher numbers (Pretty obvious from the above pictures :p).

Code
- collatz.hs --Haskell code described above
- collatz.gnu -- The gnuplot code to generate a graph
Comments(0)
2010-02-28 23:24:35
Add your comment:
Hardware
Software
- TAIM (Alpha Version): GHCI integration with vim
- CheaTorrent -- An evil BitTorrent client
- Self Modifying 2D Turing Automata
- Competing Conway Life Automata
- X11 Timelapse Desktop Video
- Colored Wolfram Automata With Sound Input
- Pseudo Video Feedback in Processing
- Haskell Cipher Saber
- Illegal FIlenames -- Windows and *nix
- Simple Perl SDL Music Keyboard (Updated)
- Image to Spectrogram
- Pastebin Hell
- OMGWTFRNG (OWR)
- OTP Enhancement : Failure Report
- Java Network File Transfer Tool
- AES Encrypted Filesystem Speeds
- Dual Message Encryption
- PHP Website
- Mp3 Splitting Script
- Random Obfuscation Tool
- Filesystem Speed Comparisons
- Java Based Web Server GUI