Added some basic tasks
authorNeil Smith <NeilNjae@users.noreply.github.com>
Mon, 16 Oct 2023 13:57:54 +0000 (14:57 +0100)
committerNeil Smith <NeilNjae@users.noreply.github.com>
Mon, 16 Oct 2023 13:57:54 +0000 (14:57 +0100)
15 files changed:
.gitignore [new file with mode: 0644]
CHANGELOG.md [new file with mode: 0644]
app/Main.hs [new file with mode: 0644]
app/cses1068.hs [new file with mode: 0644]
app/cses1069.hs [new file with mode: 0644]
app/cses1070.hs [new file with mode: 0644]
app/cses1083.hs [new file with mode: 0644]
app/cses1094.hs [new file with mode: 0644]
cses-programming-tasks.cabal [new file with mode: 0644]
data/cses1068.txt [new file with mode: 0644]
data/cses1069.txt [new file with mode: 0644]
data/cses1070a.txt [new file with mode: 0644]
data/cses1070b.txt [new file with mode: 0644]
data/cses1083.txt [new file with mode: 0644]
data/cses1094.txt [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..1a0ee39
--- /dev/null
@@ -0,0 +1,42 @@
+# Extensionless files
+*
+!/**/
+!*.*
+
+# Haskell bits
+dist
+dist-*
+cabal-dev
+*.o
+*.hi
+*.chi
+*.chs.h
+*.dyn_o
+*.dyn_hi
+.hpc
+.hsenv
+.cabal-sandbox/
+cabal.sandbox.config
+*.prof
+*.aux
+*.hp
+*.eventlog
+cabal.project.local
+.HTF/
+
+
+# IPython / IHaskell notebook checkpoints
+.ipynb*
+
+# Sublime text
+*.sublime-workspace
+
+# Logs
+*.log
+
+# Profile exports
+*.ps
+
+# KDE
+.directory
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644 (file)
index 0000000..8239595
--- /dev/null
@@ -0,0 +1,5 @@
+# Revision history for cses-programming-tasks
+
+## 0.1.0.0 -- YYYY-mm-dd
+
+* First version. Released on an unsuspecting world.
diff --git a/app/Main.hs b/app/Main.hs
new file mode 100644 (file)
index 0000000..65ae4a0
--- /dev/null
@@ -0,0 +1,4 @@
+module Main where
+
+main :: IO ()
+main = putStrLn "Hello, Haskell!"
diff --git a/app/cses1068.hs b/app/cses1068.hs
new file mode 100644 (file)
index 0000000..0bc9e41
--- /dev/null
@@ -0,0 +1,18 @@
+import Data.List
+collatz :: Int -> Int
+collatz n | even n = n `div` 2
+collatz n | otherwise = 3 * n + 1
+
+collatzStep :: Int -> Maybe (Int, Int)
+collatzStep 0 = Nothing
+collatzStep 1 = Just (1, 0)
+collatzStep n = Just (n, collatz n)
+main :: IO ()
+main = do
+  line <- getLine
+  let n = read line
+  let nums = unfoldr collatzStep n
+  let outStr = intercalate " " $ map show nums
+  putStrLn outStr
diff --git a/app/cses1069.hs b/app/cses1069.hs
new file mode 100644 (file)
index 0000000..d91bac9
--- /dev/null
@@ -0,0 +1,8 @@
+import Data.List 
+main :: IO ()
+main = do
+  line <- getLine
+  print $ maximum $ map length $ group line
+          
\ No newline at end of file
diff --git a/app/cses1070.hs b/app/cses1070.hs
new file mode 100644 (file)
index 0000000..9144e9e
--- /dev/null
@@ -0,0 +1,14 @@
+import Data.List 
+main :: IO ()
+main = do
+  line1 <- getLine
+  let nums = read line1
+  putStrLn $ solve nums
+solve :: Int -> String
+solve nums | nums == 1 = "1"
+solve nums | nums <= 3 = "NO SOLUTION"
+solve nums | otherwise = intercalate " " $ map show $ evens ++ odds
+  where (evens, odds) = partition (\n -> (n `mod` 2) == 0) [1..nums]
+  
\ No newline at end of file
diff --git a/app/cses1083.hs b/app/cses1083.hs
new file mode 100644 (file)
index 0000000..0354890
--- /dev/null
@@ -0,0 +1,12 @@
+main :: IO ()
+main = do
+  line1 <- getLine
+  let numCount = read line1
+  line2 <- getLine
+  let nums = map read $ words line2
+  print $ solve numCount nums
+solve :: Int -> [Int] -> Int
+solve numCount nums = expected - actual
+  where expected = (numCount * (numCount + 1)) `div` 2
+        actual = sum nums
diff --git a/app/cses1094.hs b/app/cses1094.hs
new file mode 100644 (file)
index 0000000..9fd41ac
--- /dev/null
@@ -0,0 +1,14 @@
+main :: IO ()
+main = do
+  line1 <- getLine
+  line2 <- getLine
+--   let numLen = read line1
+  let nums = map read $ words line2
+  print $ solve nums
+
+solve :: [Int] -> Int
+solve (n:nums) = moves
+  where (_, moves) = foldl makeMove (n, 0) nums
+        makeMove (current, moves) n
+          | n >= current = (n, moves)
+          | otherwise = (current, moves + current - n)
diff --git a/cses-programming-tasks.cabal b/cses-programming-tasks.cabal
new file mode 100644 (file)
index 0000000..b8f05a0
--- /dev/null
@@ -0,0 +1,108 @@
+cabal-version:      3.4
+-- The cabal-version field refers to the version of the .cabal specification,
+-- and can be different from the cabal-install (the tool) version and the
+-- Cabal (the library) version you are using. As such, the Cabal (the library)
+-- version used must be equal or greater than the version stated in this field.
+-- Starting from the specification version 2.2, the cabal-version field must be
+-- the first thing in the cabal file.
+
+-- Initial package description 'cses-programming-tasks' generated by
+-- 'cabal init'. For further documentation, see:
+--   http://haskell.org/cabal/users-guide/
+--
+-- The name of the package.
+name:               cses-programming-tasks
+
+-- The package version.
+-- See the Haskell package versioning policy (PVP) for standards
+-- guiding when and how versions should be incremented.
+-- https://pvp.haskell.org
+-- PVP summary:     +-+------- breaking API changes
+--                  | | +----- non-breaking API additions
+--                  | | | +--- code changes with no API change
+version:            0.1.0.0
+
+-- A short (one-line) description of the package.
+-- synopsis:
+
+-- A longer description of the package.
+-- description:
+
+-- The license under which the package is released.
+license:            MPL-2.0
+
+-- The file containing the license text.
+license-file:       LICENSE
+
+-- The package author(s).
+author:             Neil Smith
+
+-- An email address to which users can send suggestions, bug reports, and patches.
+maintainer:         NeilNjae@users.noreply.github.com
+
+-- A copyright notice.
+-- copyright:
+category:           Game
+build-type:         Simple
+
+-- Extra doc files to be distributed with the package, such as a CHANGELOG or a README.
+extra-doc-files:    CHANGELOG.md
+
+-- Extra source files to be distributed with the package, such as examples, or a tutorial module.
+-- extra-source-files:
+
+common warnings
+    ghc-options: -Wall
+
+executable cses-programming-tasks
+    -- Import common warning flags.
+    import:           warnings
+
+    -- .hs or .lhs file containing the Main module.
+    main-is:          Main.hs
+
+    -- Modules included in this executable, other than Main.
+    -- other-modules:
+
+    -- LANGUAGE extensions used by modules in this package.
+    -- other-extensions:
+
+    -- Other library packages from which modules are imported.
+    build-depends:    base ^>=4.18.0.0
+
+    -- Directories containing source files.
+    hs-source-dirs:   app
+
+    -- Base language which the package is written in.
+    default-language: GHC2021
+
+
+common build-directives
+  build-depends:       base >=4.16
+  default-language:    GHC2021
+  hs-source-dirs:      ., app
+  ghc-options:         -O2 
+                       -Wall 
+                       -threaded 
+                       -rtsopts "-with-rtsopts=-N"
+
+executable cses1068
+  import: build-directives
+  main-is: cses1068.hs
+
+executable cses1083
+  import: build-directives
+  main-is: cses1083.hs
+
+executable cses1069
+  import: build-directives
+  main-is: cses1069.hs
+
+executable cses1094
+  import: build-directives
+  main-is: cses1094.hs
+
+executable cses1070
+  import: build-directives
+  main-is: cses1070.hs
+  
\ No newline at end of file
diff --git a/data/cses1068.txt b/data/cses1068.txt
new file mode 100644 (file)
index 0000000..00750ed
--- /dev/null
@@ -0,0 +1 @@
+3
diff --git a/data/cses1069.txt b/data/cses1069.txt
new file mode 100644 (file)
index 0000000..a6c74b2
--- /dev/null
@@ -0,0 +1 @@
+ATTCGGGA
diff --git a/data/cses1070a.txt b/data/cses1070a.txt
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/data/cses1070b.txt b/data/cses1070b.txt
new file mode 100644 (file)
index 0000000..00750ed
--- /dev/null
@@ -0,0 +1 @@
+3
diff --git a/data/cses1083.txt b/data/cses1083.txt
new file mode 100644 (file)
index 0000000..58c8e41
--- /dev/null
@@ -0,0 +1,2 @@
+5
+2 3 1 5
diff --git a/data/cses1094.txt b/data/cses1094.txt
new file mode 100644 (file)
index 0000000..6e41d58
--- /dev/null
@@ -0,0 +1,2 @@
+5
+3 2 5 1 7