Skip to content

Instantly share code, notes, and snippets.

@MuzzyDeath
Last active March 2, 2021 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MuzzyDeath/a5dd9d989642aca0d31cd6eb1ba553ec to your computer and use it in GitHub Desktop.
Save MuzzyDeath/a5dd9d989642aca0d31cd6eb1ba553ec to your computer and use it in GitHub Desktop.
The Haskell coding prompt for WellHidden's Skire 2021 Coding Chaos!
Use (http://learnyouahaskell.com/chapters) to learn how to do these problems!
Remember, if you add a function to your .hs file, then you need to load it into your ghci EVERYTIME you make a change.
Do this with `:l <filename>.hs` in your shell.
Question 1:
In the shell, add 3 and 5 together without using functions.
HINT: Use the addition operator `+`.
Question 2:
In the shell, use `div` to divide 17 by 3.
HINT: Your answer should be 5
Question 3:
In main.hs, make function `tripleMe`. This function will take one number and return the tripled value.
NOTE: Use only '+' addition, no multiplication.
HINT: Functions should look something like: `functionName variable1 = logic here`
Question 4:
In main.hs, make function `retHead`. It will accept a list and return the head.
HINT: To test your function, run `retHead [5,8,3,1]` and see if 5 is returned.
Question 5:
In main.hs, make function `least`. It will accept 3 variable and return the smallest variable. You may only use the built-in function `min`, do not use +,-,*,/ or any other operators.
HINT: You will need to use the `min` function two times.
HINT 2: Use the built-in function `head` in your logic. (Yes, this is redundant)
Question 6
In main.hs, make function `ends`. It will accept a list, then return the first and last element in a list.
Question 7
In the shell, use ranges to return a list of multiplicands of 3 that are less than 100
HINT: List should start with 3 and end with 99
Question 8
In the shell, use list comprehension to return a list of multiplicands of 3 that are less than 100
HINT: Use function `mod` in the precondition, do not use answer from Question 7, that is not list comprehension.
Question 9
In main.hs, use list comprehension to make function `divisors` that takes a number and returns a list of that number's divisors. For instance, if the number is 20, then return list [1,2,4,5,10,20].
HINT: Use function `mod` in the precondition.
Question 10
In main.hs, use list comprehension and previously made function `divisors` to make function `commonDivisors` that takes two numbers and returns a list of their common divisors.
HINT: Multiple preconditions will be needed!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment