Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76018

Re: how to get the ordinal number in list

X-Received by 10.182.134.225 with SMTP id pn1mr21116009obb.31.1407731353320; Sun, 10 Aug 2014 21:29:13 -0700 (PDT)
X-Received by 10.50.67.98 with SMTP id m2mr441747igt.15.1407731353223; Sun, 10 Aug 2014 21:29:13 -0700 (PDT)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!h18no11380642igc.0!news-out.google.com!px9ni588igc.0!nntp.google.com!h18no17891476igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Sun, 10 Aug 2014 21:29:12 -0700 (PDT)
In-Reply-To <53e831d1$0$30002$c3e8da3$5496439d@news.astraweb.com>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=59.95.27.212; posting-account=mBpa7woAAAAGLEWUUKpmbxm-Quu5D8ui
NNTP-Posting-Host 59.95.27.212
References <53E658CD.5020904@gmail.com> <CACwCsY7icE7X2upr0auNhe37xh5HdC09Ad4yaetqpo+fcoBRYg@mail.gmail.com> <mailman.12780.1407551775.18130.python-list@python.org> <53e59035$0$29998$c3e8da3$5496439d@news.astraweb.com> <338e8fb0-c9ec-462a-b560-1c1ff77de17e@googlegroups.com> <roy-3060CA.11342209082014@news.panix.com> <b5ac5b12-cda7-464e-9c14-63ef184a7a10@googlegroups.com> <roy-FEFEEE.13102110082014@news.panix.com> <154cc342-7f85-4d16-b636-a1a953913c98@googlegroups.com> <53e831d1$0$30002$c3e8da3$5496439d@news.astraweb.com>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <2768e86c-34cf-4478-ac02-2ea6a4eb9236@googlegroups.com> (permalink)
Subject Re: how to get the ordinal number in list
From Rustom Mody <rustompmody@gmail.com>
Injection-Date Mon, 11 Aug 2014 04:29:13 +0000
Content-Type text/plain; charset=ISO-8859-1
Xref csiph.com comp.lang.python:76018

Show key headers only | View raw


On Monday, August 11, 2014 8:30:32 AM UTC+5:30, Steven D'Aprano wrote:

> You did the same thing in your own course, the only difference being you
> accepted a different set of primitive functions. But ultimately you have to
> introduce *some* amount of concreteness, at some level, otherwise we're
> just engaged in mental masturbation:

> Q: "Write a function to calculate the nth Catalan number."
> A: "Assume that a function Catalan(n) exists and calculates the nth Catalan
> number. Then the solution is Catalan."


You're concocting your own definitions and critiquing/refuting them.

Here is the Haskell definition [Ive modernized my '93 code].
It corresponds to the 4th interpretation from 
http://en.wikipedia.org/wiki/Catalan_number#Applications_in_combinatorics
-- applications of a bin op to a 'full' binary tree

All of 3 lines!

data Tree a = I (Tree a) (Tree a) | L a deriving Show
c [x]= [L x]
c ls = [I x y | i<-[1..length ls -1], let (l,r) = splitAt i ls, x <- c l, y <- c r]

Read 'L' as Leaf Node
     'I' as Internal Node
     'c' as the catalan enumerator

splitAt splits a list at a position:

*Main> splitAt 3 [3,4,5,6,7]
([3,4,5],[6,7])


And some example runs

*Main> c []
[]
*Main> c [1]
[L 1]
*Main> c [1,2]
[I (L 1) (L 2)]
*Main> c [1,2,3]
[I (L 1) (I (L 2) (L 3)),I (I (L 1) (L 2)) (L 3)]
*Main> c [1,2,3,4]
[I (L 1) (I (L 2) (I (L 3) (L 4))),I (L 1) (I (I (L 2) (L 3)) (L 4)),I (I (L 1) (L 2)) (I (L 3) (L 4)),I (I (L 1) (I (L 2) (L 3))) (L 4),I (I (I (L 1) (L 2)) (L 3)) (L 4)]
*Main> 

Opening up the last eg into separate lines:

[I (L 1) (I (L 2) (I (L 3) (L 4))),
 I (L 1) (I (I (L 2) (L 3)) (L 4)),
 I (I (L 1) (L 2)) (I (L 3) (L 4)),
 I (I (L 1) (I (L 2) (L 3))) (L 4),
 I (I (I (L 1) (L 2)) (L 3)) (L 4)]

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: how to get the ordinal number in list luofeiyu <elearn2014@gmail.com> - 2014-08-09 10:35 -0700
  Re: how to get the ordinal number in list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-09 13:06 +1000
    Re: how to get the ordinal number in list Rustom Mody <rustompmody@gmail.com> - 2014-08-08 20:48 -0700
      Re: how to get the ordinal number in list Roy Smith <roy@panix.com> - 2014-08-09 11:34 -0400
        Re: how to get the ordinal number in list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-10 09:43 +1000
        Re: how to get the ordinal number in list Rustom Mody <rustompmody@gmail.com> - 2014-08-10 09:28 -0700
          Re: how to get the ordinal number in list Roy Smith <roy@panix.com> - 2014-08-10 13:10 -0400
            Re: how to get the ordinal number in list Rustom Mody <rustompmody@gmail.com> - 2014-08-10 10:34 -0700
              Re: how to get the ordinal number in list Roy Smith <roy@panix.com> - 2014-08-10 14:14 -0400
                Re: how to get the ordinal number in list Rustom Mody <rustompmody@gmail.com> - 2014-08-10 11:26 -0700
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-11 05:03 +1000
                Re: how to get the ordinal number in list Marko Rauhamaa <marko@pacujo.net> - 2014-08-10 22:14 +0300
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-11 05:20 +1000
                Re: how to get the ordinal number in list Rustom Mody <rustompmody@gmail.com> - 2014-08-10 22:23 -0700
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-11 15:46 +1000
                Re: how to get the ordinal number in list Rustom Mody <rustompmody@gmail.com> - 2014-08-10 23:22 -0700
                Re: how to get the ordinal number in list Steven D'Aprano <steve@pearwood.info> - 2014-08-11 08:55 +0000
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-11 19:15 +1000
                Re: how to get the ordinal number in list Marko Rauhamaa <marko@pacujo.net> - 2014-08-11 12:35 +0300
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-11 19:51 +1000
                Re: how to get the ordinal number in list Marko Rauhamaa <marko@pacujo.net> - 2014-08-11 13:46 +0300
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-11 21:06 +1000
                Re: how to get the ordinal number in list Steven D'Aprano <steve@pearwood.info> - 2014-08-11 09:44 +0000
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-11 19:53 +1000
                Re: how to get the ordinal number in list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-11 21:30 +1000
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-11 20:07 +1000
                Re: how to get the ordinal number in list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-13 10:47 +1000
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-13 11:31 +1000
                Re: how to get the ordinal number in list Roy Smith <roy@panix.com> - 2014-08-12 21:45 -0400
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-13 12:06 +1000
                Re: how to get the ordinal number in list Roy Smith <roy@panix.com> - 2014-08-11 07:55 -0400
                Re: how to get the ordinal number in list Tim Chase <python.list@tim.thechases.com> - 2014-08-11 07:30 -0500
                Re: how to get the ordinal number in list Marko Rauhamaa <marko@pacujo.net> - 2014-08-11 15:41 +0300
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-11 22:53 +1000
                Re: how to get the ordinal number in list Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-11 14:57 +0100
                Re: how to get the ordinal number in list Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-10 21:32 +0100
                Re: how to get the ordinal number in list Roy Smith <roy@panix.com> - 2014-08-10 18:01 -0400
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-11 08:43 +1000
                Re: how to get the ordinal number in list Rustom Mody <rustompmody@gmail.com> - 2014-08-10 20:35 -0700
                Re: how to get the ordinal number in list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-11 12:04 +1000
                Re: how to get the ordinal number in list Robert Kern <robert.kern@gmail.com> - 2014-08-11 12:56 +0100
                Re: how to get the ordinal number in list Rustom Mody <rustompmody@gmail.com> - 2014-08-11 05:11 -0700
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-11 22:45 +1000
                Re: how to get the ordinal number in list Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-11 15:01 +0100
                Re: how to get the ordinal number in list alister <alister.nospam.ware@ntlworld.com> - 2014-08-11 12:30 +0000
                Re: how to get the ordinal number in list Marko Rauhamaa <marko@pacujo.net> - 2014-08-11 15:41 +0300
                Re: how to get the ordinal number in list Robin Becker <robin@reportlab.com> - 2014-08-11 15:32 +0100
                Re: how to get the ordinal number in list Terry Reedy <tjreedy@udel.edu> - 2014-08-11 18:01 -0400
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-12 09:27 +1000
                Re: how to get the ordinal number in list wxjmfauth@gmail.com - 2014-08-12 00:21 -0700
                Re: how to get the ordinal number in list alister <alister.nospam.ware@ntlworld.com> - 2014-08-12 10:40 +0000
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-12 23:39 +1000
                Re: how to get the ordinal number in list alister <alister.nospam.ware@ntlworld.com> - 2014-08-12 18:45 +0000
                Re: how to get the ordinal number in list Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-12 20:16 +0100
                Re: how to get the ordinal number in list "Neil D. Cerutti" <neilc@norwich.edu> - 2014-08-12 13:40 -0400
                Re: how to get the ordinal number in list Rustom Mody <rustompmody@gmail.com> - 2014-08-12 11:20 -0700
                Re: how to get the ordinal number in list "Neil D. Cerutti" <neilc@norwich.edu> - 2014-08-12 15:29 -0400
                Re: how to get the ordinal number in list Rustom Mody <rustompmody@gmail.com> - 2014-08-12 20:49 -0700
                Re: how to get the ordinal number in list Terry Reedy <tjreedy@udel.edu> - 2014-08-12 18:01 -0400
              Re: how to get the ordinal number in list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-11 13:00 +1000
                Re: how to get the ordinal number in list Rustom Mody <rustompmody@gmail.com> - 2014-08-10 21:29 -0700
                Re: how to get the ordinal number in list Steven D'Aprano <steve@pearwood.info> - 2014-08-11 10:28 +0000
                Re: how to get the ordinal number in list Rustom Mody <rustompmody@gmail.com> - 2014-08-11 04:49 -0700
                Re: how to get the ordinal number in list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-13 12:11 +1000
                Re: how to get the ordinal number in list Chris Angelico <rosuav@gmail.com> - 2014-08-13 12:18 +1000
                Re: how to get the ordinal number in list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-13 13:11 +1000
          Re: how to get the ordinal number in list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-11 03:17 +1000

csiph-web