From 079c1bfbac4f7d628a241647f87ac87b37b11683 Mon Sep 17 00:00:00 2001 From: Ramaguru Radhakrishnan <7790256+ramagururadhakrishnan@users.noreply.github.com> Date: Mon, 13 May 2024 18:22:19 +0530 Subject: [PATCH] Question 3 Variants Added --- Assets/Solutions/Mid-Term/Q3/V1.hs | 18 ++++++++++++++++++ Assets/Solutions/Mid-Term/Q3/V2.hs | 17 +++++++++++++++++ Assets/Solutions/Mid-Term/Q3/V3.hs | 19 +++++++++++++++++++ Assets/Solutions/Mid-Term/Q3/V4.hs | 18 ++++++++++++++++++ Assets/Solutions/Mid-Term/Q3/V5.hs | 18 ++++++++++++++++++ Assets/Solutions/Mid-Term/Q3/V6.hs | 18 ++++++++++++++++++ Assets/Solutions/Mid-Term/Q3/V7.hs | 18 ++++++++++++++++++ Assets/Solutions/Mid-Term/Q3/V8.hs | 18 ++++++++++++++++++ 8 files changed, 144 insertions(+) create mode 100644 Assets/Solutions/Mid-Term/Q3/V1.hs create mode 100644 Assets/Solutions/Mid-Term/Q3/V2.hs create mode 100644 Assets/Solutions/Mid-Term/Q3/V3.hs create mode 100644 Assets/Solutions/Mid-Term/Q3/V4.hs create mode 100644 Assets/Solutions/Mid-Term/Q3/V5.hs create mode 100644 Assets/Solutions/Mid-Term/Q3/V6.hs create mode 100644 Assets/Solutions/Mid-Term/Q3/V7.hs create mode 100644 Assets/Solutions/Mid-Term/Q3/V8.hs diff --git a/Assets/Solutions/Mid-Term/Q3/V1.hs b/Assets/Solutions/Mid-Term/Q3/V1.hs new file mode 100644 index 0000000..05feda5 --- /dev/null +++ b/Assets/Solutions/Mid-Term/Q3/V1.hs @@ -0,0 +1,18 @@ +pairswap :: [a] -> [a] +pairswap [] = [] +pairswap (x:y:xs) = y : x : pairswap xs + +main :: IO () +main = do + let listInput = [1..6] + stringInput = "ammu" + emptyList = [] + putStrLn $ "Input List:" ++ show listInput + putStrLn $ "Pairwise Swapped List:" ++ show (pairswap listInput) + putStrLn $ "Input String:" ++ stringInput + putStrLn $ "Pairwise Swapped String:" ++ (pairswap stringInput) + putStrLn $ "Input String:" ++ emptyList + putStrLn $ "Pairwise Swapped String:" ++ (pairswap emptyList) + +-- Solved this way by Aishwarya G, Dyanesh S + diff --git a/Assets/Solutions/Mid-Term/Q3/V2.hs b/Assets/Solutions/Mid-Term/Q3/V2.hs new file mode 100644 index 0000000..d2031f1 --- /dev/null +++ b/Assets/Solutions/Mid-Term/Q3/V2.hs @@ -0,0 +1,17 @@ +pairswap :: [a] -> [a] +pairswap [] = [] +pairswap x = [x!!1] ++ [x!!0] ++ pairswap (drop 2 x) + +main :: IO () +main = do + let listInput = [1..6] + stringInput = "ammu" + emptyList = [] + putStrLn $ "Input List:" ++ show listInput + putStrLn $ "Pairwise Swapped List:" ++ show (pairswap listInput) + putStrLn $ "Input String:" ++ stringInput + putStrLn $ "Pairwise Swapped String:" ++ (pairswap stringInput) + putStrLn $ "Input String:" ++ emptyList + putStrLn $ "Pairwise Swapped String:" ++ (pairswap emptyList) + +-- Solved this way by Aravind S, diff --git a/Assets/Solutions/Mid-Term/Q3/V3.hs b/Assets/Solutions/Mid-Term/Q3/V3.hs new file mode 100644 index 0000000..2d77c97 --- /dev/null +++ b/Assets/Solutions/Mid-Term/Q3/V3.hs @@ -0,0 +1,19 @@ +pairswap :: [a] -> [a] +pairswap [] = [] +pairswap x = reverse (take 2 x) ++ pairswap (drop 2 x) + +main :: IO () +main = do + let listInput = [1..6] + stringInput = "ammu" + emptyList = [] + putStrLn $ "Input List:" ++ show listInput + putStrLn $ "Pairwise Swapped List:" ++ show (pairswap listInput) + putStrLn $ "Input String:" ++ stringInput + putStrLn $ "Pairwise Swapped String:" ++ (pairswap stringInput) + putStrLn $ "Input String:" ++ emptyList + putStrLn $ "Pairwise Swapped String:" ++ (pairswap emptyList) + +-- Solved this way by Ashwin Anand, Hemsagar with a mistake (:), +-- Jivan Prasadd with mistake of (+), Dharmik, + diff --git a/Assets/Solutions/Mid-Term/Q3/V4.hs b/Assets/Solutions/Mid-Term/Q3/V4.hs new file mode 100644 index 0000000..d64da45 --- /dev/null +++ b/Assets/Solutions/Mid-Term/Q3/V4.hs @@ -0,0 +1,18 @@ +pairswap :: [a] -> [a] +pairswap [] = [] +pairswap (x:xs) = [head xs, x] ++ pairswap (tail xs) + +main :: IO () +main = do + let listInput = [1..6] + stringInput = "ammu" + emptyList = [] + putStrLn $ "Input List:" ++ show listInput + putStrLn $ "Pairwise Swapped List:" ++ show (pairswap listInput) + putStrLn $ "Input String:" ++ stringInput + putStrLn $ "Pairwise Swapped String:" ++ (pairswap stringInput) + putStrLn $ "Input String:" ++ emptyList + putStrLn $ "Pairwise Swapped String:" ++ (pairswap emptyList) + +-- Solved this way by Gokul, + diff --git a/Assets/Solutions/Mid-Term/Q3/V5.hs b/Assets/Solutions/Mid-Term/Q3/V5.hs new file mode 100644 index 0000000..2b3085c --- /dev/null +++ b/Assets/Solutions/Mid-Term/Q3/V5.hs @@ -0,0 +1,18 @@ +pairswap :: [a] -> [a] +pairswap [] = [] +pairswap (x:y:xs) = [y,x] ++ pairswap xs + +main :: IO () +main = do + let listInput = [1..6] + stringInput = "ammu" + emptyList = [] + putStrLn $ "Input List:" ++ show listInput + putStrLn $ "Pairwise Swapped List:" ++ show (pairswap listInput) + putStrLn $ "Input String:" ++ stringInput + putStrLn $ "Pairwise Swapped String:" ++ (pairswap stringInput) + putStrLn $ "Input String:" ++ emptyList + putStrLn $ "Pairwise Swapped String:" ++ (pairswap emptyList) + +-- Solved this way by Ravi, + diff --git a/Assets/Solutions/Mid-Term/Q3/V6.hs b/Assets/Solutions/Mid-Term/Q3/V6.hs new file mode 100644 index 0000000..4f15372 --- /dev/null +++ b/Assets/Solutions/Mid-Term/Q3/V6.hs @@ -0,0 +1,18 @@ +pairswap :: [a] -> [a] +pairswap [] = [] +pairswap (x:xs) = [head xs] ++ [x] ++ pairswap(drop 1 xs) + +main :: IO () +main = do + let listInput = [1..6] + stringInput = "ammu" + emptyList = [] + putStrLn $ "Input List:" ++ show listInput + putStrLn $ "Pairwise Swapped List:" ++ show (pairswap listInput) + putStrLn $ "Input String:" ++ stringInput + putStrLn $ "Pairwise Swapped String:" ++ (pairswap stringInput) + putStrLn $ "Input String:" ++ emptyList + putStrLn $ "Pairwise Swapped String:" ++ (pairswap emptyList) + +-- Solved this way by Yaswanth, + diff --git a/Assets/Solutions/Mid-Term/Q3/V7.hs b/Assets/Solutions/Mid-Term/Q3/V7.hs new file mode 100644 index 0000000..bf74534 --- /dev/null +++ b/Assets/Solutions/Mid-Term/Q3/V7.hs @@ -0,0 +1,18 @@ +pairswap :: [a] -> [a] +pairswap [] = [] +pairswap (x:y:xs) = [y] ++ [x] ++ pairswap(xs) + +main :: IO () +main = do + let listInput = [1..6] + stringInput = "ammu" + emptyList = [] + putStrLn $ "Input List:" ++ show listInput + putStrLn $ "Pairwise Swapped List:" ++ show (pairswap listInput) + putStrLn $ "Input String:" ++ stringInput + putStrLn $ "Pairwise Swapped String:" ++ (pairswap stringInput) + putStrLn $ "Input String:" ++ emptyList + putStrLn $ "Pairwise Swapped String:" ++ (pairswap emptyList) + +-- Solved this way by Nithin S, Siddharth Krishna, Rakshan K, + diff --git a/Assets/Solutions/Mid-Term/Q3/V8.hs b/Assets/Solutions/Mid-Term/Q3/V8.hs new file mode 100644 index 0000000..57ca796 --- /dev/null +++ b/Assets/Solutions/Mid-Term/Q3/V8.hs @@ -0,0 +1,18 @@ +pairswap :: [a] -> [a] +pairswap [] = [] +pairswap (x:xs) = [head xs] ++ [x] ++ pairswap(tail xs) + +main :: IO () +main = do + let listInput = [1..6] + stringInput = "ammu" + emptyList = [] + putStrLn $ "Input List:" ++ show listInput + putStrLn $ "Pairwise Swapped List:" ++ show (pairswap listInput) + putStrLn $ "Input String:" ++ stringInput + putStrLn $ "Pairwise Swapped String:" ++ (pairswap stringInput) + putStrLn $ "Input String:" ++ emptyList + putStrLn $ "Pairwise Swapped String:" ++ (pairswap emptyList) + +-- Solved this way by Ganasekhar, +