<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Once you've made those changes, you
also need<br>
<br>
n `mod` 2^k<br>
<br>
instead of 2^k `mod` n.<br>
<br>
Finally, using e `div` f, and round() in the definitions of e and
f, to give you the largest power of 2 dividing n doesn't work
correctly. For example:<br>
maxexp2 4 = 1 (should be 2)<br>
maxexp2 16 = 3 (should be 4)<br>
maxexp2 18 = 0 (should be 1)<br>
maxexp2 28 = 0 (should be 2)<br>
<br>
But that's not a Haskell error, that's a problem with the
algorithm.<br>
<br>
(Sorry if I've misinterpreted what you're trying to do.)<br>
<br>
Graham<br>
<br>
On 01/12/2013 3:17 AM, mukesh tiwari wrote:<br>
</div>
<blockquote
cite="mid:CAFHZvE9YRH3MTe88bYnY4ac00RaHH=bVqr5Wc_LLjOBPnWmgqA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>Hi Willie, <br>
</div>
Here is the code modified<br>
maxexp2:: Int -> Int<br>
maxexp2 n<br>
|n== 0 || 2^k `mod` n /=0 =0<br>
|otherwise = k<br>
where<br>
k = e `div` f<br>
e = round ( log ( fromIntegral n ) )<br>
f = round ( (log 2.0 ))<br>
<br>
</div>
When you computing k then use backticks (`) [1] not the single
quote ( ' )<br>
<br>
[1] <a moz-do-not-send="true"
href="http://book.realworldhaskell.org/read/functional-programming.html%28">http://book.realworldhaskell.org/read/functional-programming.html(</a>
See Infix function )<br>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Sun, Dec 1, 2013 at 12:52 PM, willie
ekaputra <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:willieekaputra@gmail.com" target="_blank">willieekaputra@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<p dir="ltr">Hi everyone !<br>
I am newbie and I made this code for counting k, so that
2^k divisor of n.Somehow it doesn't work. <br>
Anyone knows what is wrong?</p>
<p dir="ltr">Regards and thanks.<br>
Wili.</p>
<p dir="ltr"> maxexp2:: Int -> Int<br>
maxexp2 n<br>
|n== 0 || 2^k 'mod' n /=0 =0<br>
|otherwise = k<br>
Where <br>
k= e ' div' f<br>
e=round (fromIntegral (log n))<br>
f = round (fromIntegral (log 2))</p>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a moz-do-not-send="true"
href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a moz-do-not-send="true"
href="http://www.haskell.org/mailman/listinfo/beginners"
target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://www.haskell.org/mailman/listinfo/beginners">http://www.haskell.org/mailman/listinfo/beginners</a>
</pre>
</blockquote>
<br>
</body>
</html>