<div dir="ltr">This will double very second digit in list. To do from right, just reverse the list first and then apply doubleEverySecond and then reverse back. <div><br></div><div><br></div><div><br></div><div><div>doubleEveryOther :: [Integer] -> [Integer]</div><div><br></div><div>doubleEveryOther [] = []</div><div>doubleEveryOther (x : []) = [x]</div><div>doubleEveryOther (x : y : []) = x : (2 * y) : []</div><div>doubleEveryOther (x:y:xs) = x : (2 * y) : doubleEveryOther (xs)</div></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 13, 2015 at 10:22 PM, Roelof Wobben <span dir="ltr"><<a href="mailto:r.wobben@home.nl" target="_blank">r.wobben@home.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I try to make make the assignment of CIS194 where I must multiply every second item from the right by 2<br>
<br>
So I thought this could be working :<br>
<br>
-- | Convert a digit to a reversed list for example 123 becomes [3,2,1]<br>
revtoDigits :: Integer -> [Integer]<br>
revtoDigits number<br>
| number <= 0 = []<br>
| number > 0 = number`mod` 10 : revtoDigits (number `div` 10)<br>
<br>
-- | Convert a digit to a list for example 123 becomes [1,2,3]<br>
toDigits :: Integer -> [Integer]<br>
toDigits number<br>
| number <= 0 = []<br>
| number > 0 = toDigitsAcc [] number<br>
<br>
toDigitsAcc:: [Integer] -> Integer -> [Integer]<br>
toDigitsAcc acc number<br>
| number <= 0 = acc<br>
| number > 0 = toDigitsAcc ((number `mod` 10) : acc) (number `div` 10)<br>
<br>
doubleEveryOther :: [Integer] -> [Integer]<br>
doubleEveryOther list = case (length list) `mod` 2 of 0 -> doubleEveryOther [] = []<br>
doubleEveryOther (x:y:xs) = x*2 : y : xs<br>
(length list) `mod` 2 of 0 -> doubleEveryOther [] = []<br>
doubleEveryOther (x:y:xs) = x : y*2 : xs<br>
<br>
<br>
-- | The main entry point.<br>
main = print $ doubleEveryOther [1,2,3]<br>
<br>
<br>
but apperantly you cannot have pattern matching after a case statement because I get a error on the = of a empty list<br>
<br>
Roelof<br>
<br>
<br>
---<br>
Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware.<br>
<a href="http://www.avast.com" target="_blank">http://www.avast.com</a><br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Nishant</div>
</div>