<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi All,<div class=""><br class=""></div><div class="">I’m working through <a href="http://www.seas.upenn.edu/~cis194/hw/02-lists.pdf" class="">http://www.seas.upenn.edu/~cis194/hw/02-lists.pdf</a> - the homework for the CIS 194 Haskell course. </div><div class="">I ‘stuck’ on question 6! </div><div class="">If anyone has done this I’d really appreciate a pointer to solving it.</div><div class=""><br class=""></div><div class="">The problem is, given these colors</div><div class=""><br class=""></div><div class="">colors = [Red, Green, Blue, Yellow, Orange, Purple]</div><div class="">
<div class="page" title="Page 4">
<div class="layoutArea">
<div class="column"><p class=""><font size="4" class=""><span style="font-family: URWPalladioL;" class="">we first need to be able to generate a list of all<br class="">
the codes, ie all length </span><span style="font-family: URWPalladioL; font-style: italic;" class="">n </span><span style="font-family: URWPalladioL;" class="">combinations of the </span><span style="font-family: TeXPalladioL;" class="">6 </span><span style="font-family: URWPalladioL;" class="">colors. In general,
Mastermind games use codes of length </span><span style="font-family: TeXPalladioL;" class="">4</span><span style="font-family: URWPalladioL;" class="">, however in theory the code
could be any length. We have not yet made any assumptions about
the lengths of the codes, so why start now? Your function should
take in a length</span><span style="font-family: TeXPalladioL; vertical-align: 4pt;" class=""> </span><span style="font-family: URWPalladioL;" class="">and return all </span><span style="font-family: BeraSansMono;" class="">Code</span><span style="font-family: URWPalladioL;" class="">s of that length:
</span></font></p>
<pre class=""><span style="font-family: BeraSansMono;" class=""><font size="4" class=""> allCodes :: Int -> [Code]
</font></span></pre><p class=""><font size="4" class=""><span style="font-family: URWPalladioL; font-style: italic;" class="">Hint: </span><span style="font-family: URWPalladioL;" class="">This exercise is a bit tricky. Try using a helper function that
takes in all the codes of length </span><span style="font-family: URWPalladioL; font-style: italic;" class="">n </span><span style="font-family: CMSY10;" class="">− </span><span style="font-family: URWPalladioL;" class="">1 and uses it to produce all codes
of length </span><span style="font-family: URWPalladioL; font-style: italic;" class="">n</span><span style="font-family: URWPalladioL;" class="">. You may find the </span><span style="font-family: BeraSansMono;" class="">concatMap </span><span style="font-family: URWPalladioL;" class="">function helpful. </span></font></p>
</div>
</div>
</div><div class="">Now this </div></div><div class="">[ [a,b,c,d] | a<-colors, b<-colors, c<-colors, d<-colors]</div><div class=""><br class=""></div><div class="">will work for codes of length 4 but clearly doesn’t provide the general solution.</div><div class=""><br class=""></div><div class="">I’m just not seeing it yet!!!!</div><div class=""><br class=""></div><div class="">Thanks</div><div class="">Mike</div></body></html>