Re: [Haskell-cafe] Re: All binary strings of a given length

2010-10-15 Thread rgowka1
Thanks Daniel.

But genbin 32 gives an empty list.. works till 31.

On Fri, Oct 15, 2010 at 9:05 AM, Daniel Gorín  wrote:
> I expect this one to run in constant space:
>
> import Data.Bits
>
> genbin :: Int -> [String]
> genbin n = map (showFixed n) [0..2^n-1::Int]
>    where showFixed n i = map (bool '1' '0' . testBit i) [n-1,n-2..0]
>          bool t f b = if b then t else f
>
> Daniel
>
> On Oct 15, 2010, at 9:43 AM, Eugene Kirpichov wrote:
>
>> Actually my ghci doesn't crash for genbin 25 (haven't tried further),
>> though it eats quite a bit of memory.
>> How are you going to use these bit strings? Do you need all of them at once?
>>
>> 2010/10/15 Aleksandar Dimitrov :
>>> On Fri, 15 Oct 2010 14:34:42 +0200, rgowka1  wrote:
>>>
>>>> Amazing, will never find this in any other languagw. But ghci crashes
>>>> for bigger input. Like genbin 20. How to scale this function?
>>>
>>> Well, "scaling" this isn't really possible, because of its complexity. It
>>> generates all permutations of a given string with two states for each
>>> position. In regular languages, this is the language {1,0}^n, n being the
>>> length of the string. This means that there are 2^n different strings in the
>>> language. For 20, that's already 1048576 different Strings! Strings are
>>> furthermore not really the best way to encode your output. Numbers (i.e.
>>> bytes) would be much better. You could generate them, and only translate
>>> into strings when needed.
>>>
>>> HTH,
>>> Aleks
>>> ___
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe@haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>
>>
>>
>> --
>> Eugene Kirpichov
>> Senior Software Engineer,
>> Grid Dynamics http://www.griddynamics.com/
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: All binary strings of a given length

2010-10-15 Thread rgowka1
Amazing, will never find this in any other languagw. But ghci crashes
for bigger input. Like genbin 20. How to scale this function?

On 10/15/10, Eugene Kirpichov  wrote:
> Here's why it works:
>
> genbin 3 = replicateM 3 "01" = (unfold replicateM) do x1 <- "01"; x2
> <- "01" ; x3 <- "01"; return [x1,x2,x3] = your desired result
> (enumerate all combinations of x1,x2,x3 with each being 0 or 1).
>
> 2010/10/15 Eugene Kirpichov :
>> genbin = flip replicateM "01"
>>
>> 2010/10/15 rgowka1 :
>>> Hi -
>>>
>>> How can I generate all binary string of a given length? The type
>>> signature would something like -
>>>
>>> genbin :: Int -> [String]
>>>
>>> For example genbin 2 would give ["00","11","01","10"] and genbin 3
>>> would give ["000","001","010","011","100","101","110","111"] etc..
>>>
>>> thanks..
>>> ___
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe@haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>
>>
>>
>> --
>> Eugene Kirpichov
>> Senior Software Engineer,
>> Grid Dynamics http://www.griddynamics.com/
>>
>
>
>
> --
> Eugene Kirpichov
> Senior Software Engineer,
> Grid Dynamics http://www.griddynamics.com/
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] All binary strings of a given length

2010-10-15 Thread rgowka1
Hi -

How can I generate all binary string of a given length? The type
signature would something like -

genbin :: Int -> [String]

For example genbin 2 would give ["00","11","01","10"] and genbin 3
would give ["000","001","010","011","100","101","110","111"] etc..

thanks..
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Help to create a function to calculate a n element moving average ??

2010-09-26 Thread rgowka1
Type signature would be Int -> [Double] -> [(Double,Double)]

Any thoughts or ideas on how to calculate a n-element moving average
of a list of Doubles?

Let's say [1..10]::[Double]

what is the function to calculate the average of the 3 elements?

[(1,0),(2,0),(3,2),(4,3)] :: [(Double,Double)]

(1,0) the average is zero as the length is less than 3

(2,0) the average is zero as the length is less than 3

(3,2) the average is (1+2+3)/3 = 2

(4,3) the average is (2+3+4)/3 = 9
..
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Candlestick charts

2010-09-25 Thread rgowka1
I am trying to compile demo.hs, but keep getting the error that
Paths_gnuplot could not be found. What/where is paths_gnuplot?? Sorry,
I am still a beginner..

On Sat, Sep 25, 2010 at 8:48 AM, Henning Thielemann
 wrote:
>
> On Sat, 25 Sep 2010, rgowka1 wrote:
>
>> Can I just do cabal install gnuplot or should I use darcs to get the
>> candles version..
>
> The Hackage version should be up to date now.
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Candlestick charts

2010-09-25 Thread rgowka1
Can I just do cabal install gnuplot or should I use darcs to get the
candles version..

On Sat, Sep 25, 2010 at 8:03 AM, Henning Thielemann
 wrote:
>
> On Sat, 25 Sep 2010, rgowka1 wrote:
>
>> Hi -
>>
>> What are the libraries to use in Haskell to generate a stock
>> candlestick chart like
>> http://stockcharts.com/h-sc/ui?s=SPY&p=D&b=5&g=5&id=p05007254056
>>
>> I will use Finance-Quote-Yahoo to get the quote data from Yahoo.
>
> You might try the gnuplot package as interface to the gnuplot program.
>
> There was already someone who wanted to plot candle sticks:
>  http://projects.haskell.org/pipermail/gnuplot/2010-April/09.html
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Candlestick charts

2010-09-25 Thread rgowka1
Hi -

What are the libraries to use in Haskell to generate a stock
candlestick chart like
http://stockcharts.com/h-sc/ui?s=SPY&p=D&b=5&g=5&id=p05007254056

I will use Finance-Quote-Yahoo to get the quote data from Yahoo.

thanks for all your help.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] xemacs newbie question - haskell mode

2010-08-15 Thread rgowka1
HI -

I have been struggling to get the Xemacs recognize hs file. I have installed
the Haskell-mode.. However I keep getting the message "File mode
specification error: (wrong-number-of-arguments require 3)".. How do I go
about fixing this??

Many thanks
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe