Skip to content

Commit

Permalink
Question 3 Variants Added
Browse files Browse the repository at this point in the history
  • Loading branch information
ramagururadhakrishnan authored May 13, 2024
1 parent e207ee6 commit 079c1bf
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Assets/Solutions/Mid-Term/Q3/V1.hs
Original file line number Diff line number Diff line change
@@ -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

17 changes: 17 additions & 0 deletions Assets/Solutions/Mid-Term/Q3/V2.hs
Original file line number Diff line number Diff line change
@@ -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,
19 changes: 19 additions & 0 deletions Assets/Solutions/Mid-Term/Q3/V3.hs
Original file line number Diff line number Diff line change
@@ -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,

18 changes: 18 additions & 0 deletions Assets/Solutions/Mid-Term/Q3/V4.hs
Original file line number Diff line number Diff line change
@@ -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,

18 changes: 18 additions & 0 deletions Assets/Solutions/Mid-Term/Q3/V5.hs
Original file line number Diff line number Diff line change
@@ -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,

18 changes: 18 additions & 0 deletions Assets/Solutions/Mid-Term/Q3/V6.hs
Original file line number Diff line number Diff line change
@@ -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,

18 changes: 18 additions & 0 deletions Assets/Solutions/Mid-Term/Q3/V7.hs
Original file line number Diff line number Diff line change
@@ -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,

18 changes: 18 additions & 0 deletions Assets/Solutions/Mid-Term/Q3/V8.hs
Original file line number Diff line number Diff line change
@@ -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,

0 comments on commit 079c1bf

Please sign in to comment.