Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  tower hanoi problem (Joel Neely)
   2. Re:  Spec with QuickCheck generationg list of list of the
      same length (Ondrej Nekola)
   3. Re:  tower hanoi problem (Dudley Brooks)
   4. Re:  Getting "Discrete Mathematics Using a Computer" code to
      run (Henk-Jan van Tuyl)
   5. Re:  tower hanoi problem (KC)
   6. Re:  tower hanoi problem (Roelof Wobben)


----------------------------------------------------------------------

Message: 1
Date: Sun, 15 Feb 2015 06:04:11 -0600
From: Joel Neely <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] tower hanoi problem
Message-ID:
        <CAEEzXAiqyhhEREno=8mqcqr+6jr1h6xbbg4xjbjwrraa+ds...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hint:

So each of your has an odd number of lines.
What do all the center lines have in common?
What is common about all of the prefixes (groups of lines before the
center) and suffixes (groups of lines following the center)?


On Sun, Feb 15, 2015 at 2:51 AM, Roelof Wobben <[email protected]> wrote:

> YCH schreef op 15-2-2015 om 9:45:
>
>> How about if I say "Actually target was c not b and here is one more
>> disc. I put it on a. Now you should move all to c"
>>
>>
>>
> Hanoi 1 a b c
>
> A -> C
>
> Hanoi 2 a b c
>
> A -> B
> A -> C
> B -> C
>
> Hanoi 3 a b c
>
> A -> C
> A -> B
> C -> B
> A -> C
> B -> A
> B -> C
> A -> C
>
>
>
> Roelof
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>



-- 
Beauty of style and harmony and grace and good rhythm depend on simplicity.
- Plato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150215/a2d065ff/attachment-0001.html>

------------------------------

Message: 2
Date: Sun, 15 Feb 2015 21:53:32 +0100
From: Ondrej Nekola <[email protected]>
To: [email protected]
Cc: Daniel Bergey <[email protected]>
Subject: Re: [Haskell-beginners] Spec with QuickCheck generationg list
        of list of the same length
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed

Thanks, it sent me to the (higly probably) right direction:

newtype RectList  = RectList [LVector] deriving Show

instance Arbitrary RectList  where
     arbitrary = do
         m <- getPositive <$> arbitrary
         n <- getPositive <$> arbitrary

         RectList <$> replicateM n (vector m)

and the test can look like this:

it "average times number is sum" $
             property (\(RectList x) -> null $ nozeroMembers $ zipWith 
(-) ( map (* (fromIntegral $ length x)) (average x)) (sumVect x) )

Thanks again
    Ondrej
> On 2015-02-15 at 10:52, Ondrej Nekola <[email protected]> wrote:
>> How can I generate list of lists, where all the included lists are of
>> the same length?
> The general approach is to make a newtype, the Arbitrary instance of
> which does what you want.  For example, QucickCheck includes newtypes
> Positive[1] and NonNegative[2], that generate restricted numbers.
>
> For your case, I'd write something like (untested):
>
> ```
> newtype RectList a = RectList [[a]]
>
> instance Arbitrary a => Arbitrary RectList a where
>    arbitrary = do
>      -- length of inner lists
>      m <- getPositive <$> arbitrary
>      -- length of outer list, can be zero
>      n <- getNonNegative <$> arbitrary
>      RectList <$> replicateM n (vector m)
> ```
>
> vector here is another function provided by QuickCheck: [3].
>
> Hope this helps.
>
> bergey
>
>> Link for some tutorial *) can be, I believe, enough but I would be glad
>> for any help.
>>
>> Thanks
>>      Ondra @satai Nekola
>>      [email protected]
>>
>> *) Maybe I have not trained my google good enough yet, but lack of
>> tutorials describing more than the most basic usecase is probably the
>> most problematic point in re-learning Haskell so far.
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> Footnotes:
> [1]  
> http://hackage.haskell.org/package/QuickCheck-2.7.6/docs/Test-QuickCheck.html#t:Positive
>
> [2]  
> http://hackage.haskell.org/package/QuickCheck-2.7.6/docs/Test-QuickCheck.html#t:NonNegative
>
> [3]  
> http://hackage.haskell.org/package/QuickCheck-2.7.6/docs/Test-QuickCheck-Arbitrary.html#v:vector
>
>



------------------------------

Message: 3
Date: Sun, 15 Feb 2015 12:54:36 -0800
From: Dudley Brooks <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] tower hanoi problem
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed

In my opinion, advising Mr Wobben to watch the pattern of moves will 
*not* lead him to the recursive solution, since the pattern of moves is 
really iterative.

My hint would be to remember the very nature of recursion itself (for 
*any* problem):  Do the first step.  Then (to put it very dramatically) 
do *everything else* in *a single step*!  (Realizing that "everything 
else" is really the same problem, just made slightly smaller.)

Note:  "A single step" might itself have more than one step.  My point 
is that recursion consists of (to put it humorously):  To do 
ABCDEFGHIJKLMNOPQRSTUVWXYZ, first you do A, then you do 
BCDEFGHIJKLMNOPQRSTUVWXYZ.  And, of course, "first" might actually be 
"last"!  And remembering the story of the Gordian Knot might help too.  
(I apologize that trying not to be too explicit in the hint possibly 
makes it even more obscure.)

Here's another hint that's useful for all kinds of programming problems, 
not just recursion:  Most problems consist of not only what you're 
trying to solve, but also what the restrictions are on what you're 
allowed to do to solve it.  Often some good insights come from imagining 
how you could solve the problem if you could ignore one or more of the 
restrictions (that's what I meant by the Gordian Knot reference).  So 
for the Towers of Hanoi, think about what the restrictions are on what 
kind of moves you're allowed to make.  Remove one of those restrictions.

(Speaking of the iterative solution, the fun thing about actually 
physically doing the Towers of Hanoi is that, even though you're doing 
it by remembering the steps of the iterative pattern, as you watch the 
towers grow and shrink you can kind of "see" the recursion.)

On 2/15/15 12:51 AM, Roelof Wobben wrote:
> YCH schreef op 15-2-2015 om 9:45:
>> How about if I say "Actually target was c not b and here is one more
>> disc. I put it on a. Now you should move all to c"
>>
>>
>
> Hanoi 1 a b c
>
> A -> C
>
> Hanoi 2 a b c
>
> A -> B
> A -> C
> B -> C
>
> Hanoi 3 a b c
>
> A -> C
> A -> B
> C -> B
> A -> C
> B -> A
> B -> C
> A -> C
>
>
> Roelof
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



------------------------------

Message: 4
Date: Mon, 16 Feb 2015 00:45:15 +0100
From: "Henk-Jan van Tuyl" <[email protected]>
To: "Lawrence Bottorff" <[email protected]>, "[email protected]"
        <[email protected]>
Subject: Re: [Haskell-beginners] Getting "Discrete Mathematics Using a
        Computer" code to run
Message-ID: <op.xt4hlps4pz0j5l@alquantor>
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes


There are several types of exceptions that could be caught here, but the  
compiler does not know which one to choose. You could specify a type, but  
it is easier to use 'onException' (also in Control.Exception) instead of  
'catch', if you want to treat all exceptions the same way, without any  
info about the kind of exception.


On Sun, 15 Feb 2015 17:49:21 +0100, Lawrence Bottorff <[email protected]>  
wrote:

> Thanks for the tip. Yes, I had tried that, but never got it right. Here's
> my change:
:
> Stdm02142015.lhs:1037:40-46:
>     No instance for (Exception e1) arising from a use of `catch'
>     The type variable `e1' is ambiguous
>     Possible fix: add a type signature that fixes these type variable(s)
>     Note: there are several potential instances:
>       instance Exception NestedAtomically
>         -- Defined in `Control.Exception.Base'
>       instance Exception NoMethodError
>         -- Defined in `Control.Exception.Base'
>       instance Exception NonTermination
>         -- Defined in `Control.Exception.Base'
>       ...plus 7 others
>     In a stmt of a 'do' block:
>       filedata <- (readFile filename) `catch` (\ _ -> return "")
:
> et cetera, et cetera. Any idea where this import Control.Exception should
> go. Or is there something else amiss?
>
> On Sun, Feb 15, 2015 at 5:06 AM, Henk-Jan van Tuyl <[email protected]>
> wrote:
>
>> On Sat, 14 Feb 2015 23:30:13 +0100, Lawrence Bottorff  
>> <[email protected]>
>> wrote:
>>
>>  .../Discrete/Stdm02142015.lhs:1036:40-46:
>>>     Not in scope: `catch'
>>>
>>> .../Discrete/Stdm02142015.lhs:1048:40-46:
>>>     Not in scope: `catch'
>>> Failed, modules loaded: none.
>>>
>>> This is on ghci 7.6.3
>>>
>>
>> The function "catch" is removed from Prelude, you need to add the line:
>>   import Control.Exception
>>
>> Regards,
>> Henk-Jan van Tuyl

-- 
Folding@home
What if you could share your unused computer power to help find a cure? In  
just 5 minutes you can join the world's biggest networked computer and get  
us closer sooner. Watch the video.
http://folding.stanford.edu/


------------------------------

Message: 5
Date: Sun, 15 Feb 2015 19:10:14 -0800
From: KC <[email protected]>
To: [email protected], Haskell Beginners
        <[email protected]>
Subject: Re: [Haskell-beginners] tower hanoi problem
Message-ID:
        <camlkxykwgrr7h_de68b5s8weus8cjkkkm5yjx2qz9tmcusr...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

The interesting way is to view the pegs not in a straight line but in
another conic section ...

--
--

Sent from an expensive device which will be obsolete in a few months! :D

Casey

On Feb 15, 2015 12:54 PM, "Dudley Brooks" <[email protected]>
wrote:

> In my opinion, advising Mr Wobben to watch the pattern of moves will *not*
> lead him to the recursive solution, since the pattern of moves is really
> iterative.
>
> My hint would be to remember the very nature of recursion itself (for
> *any* problem):  Do the first step.  Then (to put it very dramatically) do
> *everything else* in *a single step*!  (Realizing that "everything else" is
> really the same problem, just made slightly smaller.)
>
> Note:  "A single step" might itself have more than one step.  My point is
> that recursion consists of (to put it humorously):  To do
> ABCDEFGHIJKLMNOPQRSTUVWXYZ, first you do A, then you do
> BCDEFGHIJKLMNOPQRSTUVWXYZ.  And, of course, "first" might actually be
> "last"!  And remembering the story of the Gordian Knot might help too.  (I
> apologize that trying not to be too explicit in the hint possibly makes it
> even more obscure.)
>
> Here's another hint that's useful for all kinds of programming problems,
> not just recursion:  Most problems consist of not only what you're trying
> to solve, but also what the restrictions are on what you're allowed to do
> to solve it.  Often some good insights come from imagining how you could
> solve the problem if you could ignore one or more of the restrictions
> (that's what I meant by the Gordian Knot reference).  So for the Towers of
> Hanoi, think about what the restrictions are on what kind of moves you're
> allowed to make.  Remove one of those restrictions.
>
> (Speaking of the iterative solution, the fun thing about actually
> physically doing the Towers of Hanoi is that, even though you're doing it
> by remembering the steps of the iterative pattern, as you watch the towers
> grow and shrink you can kind of "see" the recursion.)
>
> On 2/15/15 12:51 AM, Roelof Wobben wrote:
>
>> YCH schreef op 15-2-2015 om 9:45:
>>
>>> How about if I say "Actually target was c not b and here is one more
>>> disc. I put it on a. Now you should move all to c"
>>>
>>>
>>>
>> Hanoi 1 a b c
>>
>> A -> C
>>
>> Hanoi 2 a b c
>>
>> A -> B
>> A -> C
>> B -> C
>>
>> Hanoi 3 a b c
>>
>> A -> C
>> A -> B
>> C -> B
>> A -> C
>> B -> A
>> B -> C
>> A -> C
>>
>>
>> Roelof
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150215/94b16774/attachment-0001.html>

------------------------------

Message: 6
Date: Mon, 16 Feb 2015 08:58:03 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] tower hanoi problem
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150216/e7f4f933/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 80, Issue 30
*****************************************

Reply via email to