From 02a7a583f2e54dab52af554dcb9831baa14fad38 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Mon, 16 Oct 2023 14:57:54 +0100 Subject: [PATCH 1/1] Added some basic tasks --- .gitignore | 42 ++++++++++++++ CHANGELOG.md | 5 ++ app/Main.hs | 4 ++ app/cses1068.hs | 18 ++++++ app/cses1069.hs | 8 +++ app/cses1070.hs | 14 +++++ app/cses1083.hs | 12 ++++ app/cses1094.hs | 14 +++++ cses-programming-tasks.cabal | 108 +++++++++++++++++++++++++++++++++++ data/cses1068.txt | 1 + data/cses1069.txt | 1 + data/cses1070a.txt | 1 + data/cses1070b.txt | 1 + data/cses1083.txt | 2 + data/cses1094.txt | 2 + 15 files changed, 233 insertions(+) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 app/Main.hs create mode 100644 app/cses1068.hs create mode 100644 app/cses1069.hs create mode 100644 app/cses1070.hs create mode 100644 app/cses1083.hs create mode 100644 app/cses1094.hs create mode 100644 cses-programming-tasks.cabal create mode 100644 data/cses1068.txt create mode 100644 data/cses1069.txt create mode 100644 data/cses1070a.txt create mode 100644 data/cses1070b.txt create mode 100644 data/cses1083.txt create mode 100644 data/cses1094.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1a0ee39 --- /dev/null +++ b/.gitignore @@ -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 index 0000000..8239595 --- /dev/null +++ b/CHANGELOG.md @@ -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 index 0000000..65ae4a0 --- /dev/null +++ b/app/Main.hs @@ -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 index 0000000..0bc9e41 --- /dev/null +++ b/app/cses1068.hs @@ -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 index 0000000..d91bac9 --- /dev/null +++ b/app/cses1069.hs @@ -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 index 0000000..9144e9e --- /dev/null +++ b/app/cses1070.hs @@ -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 index 0000000..0354890 --- /dev/null +++ b/app/cses1083.hs @@ -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 index 0000000..9fd41ac --- /dev/null +++ b/app/cses1094.hs @@ -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 index 0000000..b8f05a0 --- /dev/null +++ b/cses-programming-tasks.cabal @@ -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 index 0000000..00750ed --- /dev/null +++ b/data/cses1068.txt @@ -0,0 +1 @@ +3 diff --git a/data/cses1069.txt b/data/cses1069.txt new file mode 100644 index 0000000..a6c74b2 --- /dev/null +++ b/data/cses1069.txt @@ -0,0 +1 @@ +ATTCGGGA diff --git a/data/cses1070a.txt b/data/cses1070a.txt new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/data/cses1070a.txt @@ -0,0 +1 @@ +5 diff --git a/data/cses1070b.txt b/data/cses1070b.txt new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/data/cses1070b.txt @@ -0,0 +1 @@ +3 diff --git a/data/cses1083.txt b/data/cses1083.txt new file mode 100644 index 0000000..58c8e41 --- /dev/null +++ b/data/cses1083.txt @@ -0,0 +1,2 @@ +5 +2 3 1 5 diff --git a/data/cses1094.txt b/data/cses1094.txt new file mode 100644 index 0000000..6e41d58 --- /dev/null +++ b/data/cses1094.txt @@ -0,0 +1,2 @@ +5 +3 2 5 1 7 -- 2.34.1