Unless I missed something, the function in question is:

sqrt (a * a + 2 + 2 * num) - fromIntegral a
where num = 10

1 -> sqrt (1 * 1 + 2 + 2 * 10) - 1 -> sqrt (1 + 2 + 20) - 1 -> sqrt
(23) - 1 -> 3.79xxxxx

the fractional will only ever come from the sqrt function.  Do any of
the following actually look like square values to you?

26
31
38
47
58
71
86
103
122

IMO, the code works and your expectations are a bit off.

Thomas

On Mon, Sep 28, 2009 at 11:54 PM, Magicloud Magiclouds
<magicloud.magiclo...@gmail.com> wrote:
> The original code is
> givenSum num = map (\a ->
>                      let l = (sqrt $ fromIntegral (a * a + 2 + 2 *
> num)) - (fromIntegral a) in
>                      case properFraction l of
>                        (_, 0) ->
>                          True
>                        _ ->
>                          False
>                   ) $ take num [1..]
> :t l is (Floating a) => a
> Well, in ghci
> *Main> givenSum 10
> [False,False,False,False,False,False,False,False,False,False]
>
> On Tue, Sep 29, 2009 at 2:45 PM, Thomas DuBuisson
> <thomas.dubuis...@gmail.com> wrote:
>> On Mon, Sep 28, 2009 at 11:35 PM, Magicloud Magiclouds
>> <magicloud.magiclo...@gmail.com> wrote:
>>> It never matches to (_, 0.0)....
>>> I mean
>>> case properFraction l of
>>>  (_, 0) -> l
>>>  _ -> 0 -- always goes here.
>>
>> Odd, it works fine for me.
>>
>> f x =
>>        case properFraction x of
>>                (_,0) -> True
>>                _     -> False
>>
>>
>> *Main> f 5
>> True
>> *Main> f 5.5
>> False
>> *Main> f 4.0
>> True
>> *Main> f 4.00000001
>> False
>>
>>
>> Thomas
>>
>
>
>
> --
> 竹密岂妨流水过
> 山高哪阻野云飞
>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to