Re: Solve a Debate

2008-03-09 Thread castironpi
> days_in_month 12: > 31 > 30 > 28 > 31 > ... > 30 > 31 > assign $days days_in_month[$month] > > This program consists of 2 operations (table jump and assignment) > and 12 values. This makes a memory consumption of 12+2 = 14 Along the same lines, you could populate the table somewhat sparsely, and

Re: Solve a Debate

2008-02-19 Thread castironpi
> Past a "many-small" certain point on numbers of hash-tables, if that's > the right word, in a program, and intepreter process on a machine, is > it be more time-efficient to allocate a 2**32-byte table?  Are > 'modulo' and 'doublesize' the only steps of the lookup process that it > would eliminat

Re: Solve a Debate

2008-02-18 Thread castironpi
On Feb 17, 11:23 pm, greg <[EMAIL PROTECTED]> wrote: > Wolfgang Draxinger wrote: > > Somehow you seem to think, that a lookup table will require more > > resources (memory I guess you thought) than a sequence of > > comparisons. However you didn't take into account, that the > > program code itself

Re: Solve a Debate

2008-02-17 Thread greg
Wolfgang Draxinger wrote: > Somehow you seem to think, that a lookup table will require more > resources (memory I guess you thought) than a sequence of > comparisons. However you didn't take into account, that the > program code itself requires memory, too (for the operation > codes). In Python,

Re: Solve a Debate

2008-02-17 Thread castironpi
> What shall there be missing? breaks? You noticed, that I defined > some artificial architecture on purpose. "days_in_month 12:" > tells it, that the next 12 blurps are tabular data, that can be > indexed. If the "interpreter" hits the line "days_in_month 12:" > it will unconditionally jump 12 ins

Re: Solve a Debate

2008-02-17 Thread Wolfgang Draxinger
[EMAIL PROTECTED] wrote: >> days_in_month 12: >> 31 >> 30 >> 28 >> 31 >> ... >> 30 >> 31 >> assign $days days_in_month[$month] > > This is missing > days_in_month 12: > 31 > break > 30 > break What shall there be missing? breaks? You noticed, that I defined some artificial architecture on purpos

Re: Solve a Debate

2008-02-17 Thread castironpi
> days_in_month 12: > 31 > 30 > 28 > 31 > ... > 30 > 31 > assign $days days_in_month[$month] This is missing days_in_month 12: 31 break 30 break Or the addition add $x' $x offset store $r0 $x' assign $days $r0 Is that 4 ticks or 5; or 24 blips? -- http://mail.python.org/mailman/listinfo/python-

Re: Solve a Debate

2008-02-17 Thread castironpi
On Feb 17, 7:05 am, Wolfgang Draxinger <[EMAIL PROTECTED]> wrote: > nexes wrote: > > there is more data that needed to be assigned(i.e. a couple > > megs of data) it would be simpler (and more efficient) to > > do a compare rather then assigning all that data to an array, > > since you are only goi

Re: Solve a Debate

2008-02-17 Thread Wolfgang Draxinger
nexes wrote: > there is more data that needed to be assigned(i.e. a couple > megs of data) it would be simpler (and more efficient) to > do a compare rather then assigning all that data to an array, > since you are only going to be using 1 value and the rest > of the data in the array is useless.

Re: Solve a Debate

2008-02-16 Thread Steve Holden
John Machin wrote: > On Feb 17, 11:11 am, "Gabriel Genellina" <[EMAIL PROTECTED]> > wrote: >> En Sat, 16 Feb 2008 19:43:37 -0200, John Machin <[EMAIL PROTECTED]> >> escribi�: >> >>> On Feb 16, 3:48 pm, Dan Bishop <[EMAIL PROTECTED]> wrote: days_in_month = lambda m: m - 2 and 30 + bool(1 << m &

Re: Solve a Debate

2008-02-16 Thread John Machin
On Feb 17, 11:11 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Sat, 16 Feb 2008 19:43:37 -0200, John Machin <[EMAIL PROTECTED]> > escribi�: > > > On Feb 16, 3:48 pm, Dan Bishop <[EMAIL PROTECTED]> wrote: > > >> days_in_month = lambda m: m - 2 and 30 + bool(1 << m & 5546) or 28 > > > Alter

Re: Solve a Debate

2008-02-16 Thread Gabriel Genellina
En Sat, 16 Feb 2008 19:43:37 -0200, John Machin <[EMAIL PROTECTED]> escribi�: > On Feb 16, 3:48 pm, Dan Bishop <[EMAIL PROTECTED]> wrote: >> >> days_in_month = lambda m: m - 2 and 30 + bool(1 << m & 5546) or 28 > > Alternatively: > > days_in_month = lambda m: m - 2 and 31 - ((m + 9) % 12 % 5 % 2)

Re: Solve a Debate

2008-02-16 Thread John Machin
On Feb 17, 9:57 am, [EMAIL PROTECTED] wrote: > > days_in_month = lambda m: m - 2 and 31 - ((m + 9) % 12 % 5 % 2) or 28 > > > the guts of which is slightly more elegant than the ancient writing > > from which it was derived: > > Lacks citation. Maxima mea culpa. Pages 294-295 (in particular formul

Re: Solve a Debate

2008-02-16 Thread castironpi
> days_in_month = lambda m: m - 2 and 31 - ((m + 9) % 12 % 5 % 2) or 28 > > the guts of which is slightly more elegant than the ancient writing > from which it was derived: Lacks citation. -- http://mail.python.org/mailman/listinfo/python-list

Re: Solve a Debate

2008-02-16 Thread Steve Holden
[EMAIL PROTECTED] wrote: > On Feb 15, 11:50 pm, Steve Holden <[EMAIL PROTECTED]> wrote: >> Dan Bishop wrote: >>> On Feb 15, 10:24 am, nexes <[EMAIL PROTECTED]> wrote: [...] What are everyone else's thoughts on this? >>> days_in_month = lambda m: m - 2 and 30 + bool(1 << m & 5546) or 28 >> Eleg

Re: Solve a Debate

2008-02-16 Thread John Machin
On Feb 16, 3:48 pm, Dan Bishop <[EMAIL PROTECTED]> wrote: > On Feb 15, 10:24 am, nexes <[EMAIL PROTECTED]> wrote: > > > > > Alright so me and my friend are having argument. > > > Ok the problem we had been asked a while back, to do a programming > > exercise (in college) > > That would tell you how

Re: Solve a Debate

2008-02-16 Thread castironpi
On Feb 15, 11:50 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > Dan Bishop wrote: > > On Feb 15, 10:24 am, nexes <[EMAIL PROTECTED]> wrote: > >> Alright so me and my friend are having argument. > > >> Ok the problem we had been asked a while back, to do a programming > >> exercise (in college) > >>

Re: Solve a Debate

2008-02-15 Thread Steve Holden
Dan Bishop wrote: > On Feb 15, 10:24 am, nexes <[EMAIL PROTECTED]> wrote: >> Alright so me and my friend are having argument. >> >> Ok the problem we had been asked a while back, to do a programming >> exercise (in college) >> That would tell you how many days there are in a month given a >> specif

Re: Solve a Debate

2008-02-15 Thread Dan Bishop
On Feb 15, 10:24 am, nexes <[EMAIL PROTECTED]> wrote: > Alright so me and my friend are having argument. > > Ok the problem we had been asked a while back, to do a programming > exercise (in college) > That would tell you how many days there are in a month given a > specific month. > > Ok I did my

Re: Solve a Debate

2008-02-15 Thread castironpi
On Feb 15, 12:32 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2008-02-15, Ivan Van Laningham <[EMAIL PROTECTED]> wrote: > > > Lookup tables are always significantly faster than a bunch of > > ifs. > > Mostly always.  It depends on what you mean by "lookup table", > and it depends on how the la

Re: Solve a Debate

2008-02-15 Thread Quentin Gallet-Gilles
If the data becomes much bigger, change your way of storing it, not the code. You don't want to code hundreds of "if - elif - else" because you have hundreds of different data, right ? TheDailyWTF is full of horror stories like this, by the way ;-) Data growth shouldn't result in modification in lo

Re: Solve a Debate

2008-02-15 Thread Grant Edwards
On 2008-02-15, Ivan Van Laningham <[EMAIL PROTECTED]> wrote: > Lookup tables are always significantly faster than a bunch of > ifs. Mostly always. It depends on what you mean by "lookup table", and it depends on how the language implements things. If you by "lookup table" you mean a linearly in

Re: Solve a Debate

2008-02-15 Thread Ivan Van Laningham
Hi All-- Lookup tables are always significantly faster than a bunch of ifs. Metta, Ivan On Fri, Feb 15, 2008 at 10:10 AM, Tim Chase <[EMAIL PROTECTED]> wrote: > > Ok the problem we had been asked a while back, to do a programming > > exercise (in college) > > That would tell you how many days t

RE: Solve a Debate

2008-02-15 Thread Reedick, Andrew
> -Original Message- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of nexes > Sent: Friday, February 15, 2008 11:25 AM > To: python-list@python.org > Subject: Solve a Debate > > Alright so me and my friend are having argument. > > Ok the problem we had been asked

Re: Solve a Debate

2008-02-15 Thread Tim Chase
> Ok the problem we had been asked a while back, to do a programming > exercise (in college) > That would tell you how many days there are in a month given a > specific month. > > Ok I did my like this (just pseudo): > > If month = 1 or 3 or etc > noDays = 31 > Elseif month = 4 or 6