| author | plurSKI <black.gavin@gmail.com> | 2010-10-24 03:49:10 (GMT) |
|---|---|---|
| committer | plurSKI <black.gavin@gmail.com> | 2010-10-24 03:49:10 (GMT) |
| commit | 5de9f2b5a45be6ecba9d0153941ccb46a11846b7 (patch) | |
| tree | 44b65f4e97641fc672f7b623a23ce1acd072dfe9 | |
| parent | 39a96eb2da5fa30f9d465c7e056b56ef116a2008 (diff) | |
| download | haskellTidbits-master.zip haskellTidbits-master.tar.gz | |
Added collatz and hdbcmaster
| -rw-r--r-- | collatzConjecture/collatz.gnu | 6 | ||||
| -rw-r--r-- | collatzConjecture/collatz.hs | 15 | ||||
| -rw-r--r-- | hdbcMysql/mysqlTest.hs | 22 | ||||
| -rw-r--r-- | serialIO/serialMonitor.hs (renamed from serialMonitor.hs) | 0 | ||||
| -rw-r--r-- | serialIO/serialServo.pde (renamed from serialServo.pde) | 0 |
5 files changed, 43 insertions, 0 deletions
diff --git a/collatzConjecture/collatz.gnu b/collatzConjecture/collatz.gnu new file mode 100644 index 0000000..a3f4625 --- a/dev/null +++ b/collatzConjecture/collatz.gnu @@ -0,0 +1,6 @@ +set xlabel "Starting Number" +set ylabel "Sequence Length" +set title "Collatz Sequence Lengths" +set terminal png +set output 'collatz.png' +plot 'collatz.dat' with dots diff --git a/collatzConjecture/collatz.hs b/collatzConjecture/collatz.hs new file mode 100644 index 0000000..0920be1 --- a/dev/null +++ b/collatzConjecture/collatz.hs @@ -0,0 +1,15 @@ +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..] + +-- Convert into a table for gnuplot +format x y = show x ++ "\t" ++ show y +table x = unlines (zipWith format [1..] (take x numCollatz)) + +main = writeFile "collatz.dat" (table 100001) diff --git a/hdbcMysql/mysqlTest.hs b/hdbcMysql/mysqlTest.hs new file mode 100644 index 0000000..91e3085 --- a/dev/null +++ b/hdbcMysql/mysqlTest.hs @@ -0,0 +1,22 @@ +import Control.Monad +import Database.HDBC +import Database.HDBC.MySQL + +countString x = "('Count " ++ (sqlValue $ head x) ++ "')" +sqlValue x = show ( fromSql(head x) :: String) + +main = do + conn <- connectMySQL defaultMySQLConnectInfo { + mysqlHost = "localhost", + mysqlPort = 3306, + mysqlUnixSocket = "/var/run/mysqld/mysqld.sock", + mysqlDatabase = "hdbcTest", + mysqlUser = "hdbc", + mysqlPassword = "hdbc" + } + rows <- quickQuery' conn "SELECT count(*) from test" [] + run conn ("insert into test (value) values" ++ + countString rows) [] + rows <- quickQuery' conn "SELECT value from test" [] + forM_ rows $ \row -> putStrLn $ sqlValue row + diff --git a/serialMonitor.hs b/serialIO/serialMonitor.hs index b94c41a..b94c41a 100644 --- a/serialMonitor.hs +++ b/serialIO/serialMonitor.hs diff --git a/serialServo.pde b/serialIO/serialServo.pde index a025048..a025048 100644 --- a/serialServo.pde +++ b/serialIO/serialServo.pde |
