All of these problems are stolen from CodingBat. Write function signatures as well as the actual function.
Make sure to write a list of test cases so you have thought through what every part of the problem description means before you start coding.
(makeLast
): Given a list of Int
, return a new list twice the
length of the original. The last element of the result is
the same as the last element of the original list, and every
other element is 0.
(swapEnds
) Given a list, return a new list with the first and last elements
exchanged.
(unluckyOne
) Say that a 1 immediately followed by a 3 in a list
is an “unlucky” 1. Return true if the given list contains an
unlucky 1 in the first 2 or last 2 positions in the list.
withoutDoubles:: Int -> Int -> Bool -> Int
. The first two inputs
represent rolls of six-sided dice ([1..6]). Return the sum of the
inputs. If the boolean is true, if the dice show the same value,
increment one die to the next value, wrapping around to a 1 if the
value was a six.
(teenSum
) Given 2 ints, return their sum. However, “teen” values
in the range 13..19 inclusive, are extra lucky. So if either value
is a teen, just return 19.
(teaParty
) We are having a party with amounts of tea and
candy. Return the int outcome of the party encoded as 0=bad,
1=good, or 2=great. A party is good (1) if both tea and candy are
at least 5. However, if either tea or candy is at least double the
amount of the other one, the party is great (2). However, in all
cases, if either tea or candy is less than 5, the party is always
bad (0).
(xyBalance
) We’ll say that a String is xy-balanced if for all the ‘x’ chars in the string, there exists a ‘y’ char somewhere later in the string. So “xxy” is balanced, but “xyx” is not. One ‘y’ can balance multiple ‘x’s. Return true if the given string is xy-balanced.
(unluckyOne2
) Continuing the unluckyOne
problem, return true if a
list contains an unlucky 1 in any position.