dn writes:
[...]
> Further, if you look at the OP's original solution, it only publishes
> the last pair, ie the match, without mention of the list of non-matches.
> Was it perhaps only a means of testing the solution?
It was a means of showing the student that indeed they obtained a match.
If
On 11/09/2021 10:09, dn via Python-list wrote:
The stated requirement is: "I'd like to get the number of times I
tried". Given such: why bother with returning any of the pairs of values?
Indeed, if that's the requirement, then you can do even better, noting
that the probability of getting a
On 2021-09-08 13:07:47 +1200, Greg Ewing wrote:
> On 8/09/21 2:53 am, Grant Edwards wrote:
> >#define IF if (
> >#define THEN ) {
> >#define ELSE } else {
> >#define ENDIF }
>
> I gather that early versions of some of the Unix utilities were
> written by someone who liked using mac
On 11/09/2021 18.03, Chris Angelico wrote:
> On Sat, Sep 11, 2021 at 3:26 PM dn via Python-list
> wrote:
>>
>> On 31/08/2021 01.50, Chris Angelico wrote:
>>> On Mon, Aug 30, 2021 at 11:13 PM David Raymond
>>> wrote:
> def how_many_times():
> x, y = 0, 1
> c = 0
> wh
On Sat, Sep 11, 2021 at 3:26 PM dn via Python-list
wrote:
>
> On 31/08/2021 01.50, Chris Angelico wrote:
> > On Mon, Aug 30, 2021 at 11:13 PM David Raymond
> > wrote:
> >>
> >>> def how_many_times():
> >>> x, y = 0, 1
> >>> c = 0
> >>> while x != y:
> >>> c = c + 1
> >>> x, y = rol
On 31/08/2021 01.50, Chris Angelico wrote:
> On Mon, Aug 30, 2021 at 11:13 PM David Raymond
> wrote:
>>
>>> def how_many_times():
>>> x, y = 0, 1
>>> c = 0
>>> while x != y:
>>> c = c + 1
>>> x, y = roll()
>>> return c, (x, y)
>>
>> Since I haven't seen it used in answers yet, her
On Wed, 8 Sep 2021 16:32:45 - (UTC), Grant Edwards
declaimed the following:
>On 2021-09-08, Dennis Lee Bieber wrote:
>
>> I spent close to 20 years (80s-90s) maintaining the /output/ of such
>> a preprocessor.
>
>Ouch. I hope it paid well. ;)
Only if one ignores the bloody cost of a
On Wed, 8 Sep 2021 14:46:28 - (UTC), Grant Edwards
declaimed the following:
>On 2021-09-08, charles hottel wrote:
>
>> So what do yoy think or feel about a language like RATFOR (Rational
>> FORTRAN) which was implemented as macros? Should they instead have
>> simply adapted themselves to
On 2021-09-08, Dennis Lee Bieber wrote:
> I spent close to 20 years (80s-90s) maintaining the /output/ of such
> a preprocessor.
Ouch. I hope it paid well. ;)
Back when I did a lot of TeX/LaTeX stuff on VMS, I used to make
occasional fixes and add (very minor) features to one of the dvi
handlin
t On
Behalf Of charles hottel
Sent: Tuesday, September 7, 2021 11:31 PM
To: python-list@python.org
Subject: Re: on writing a while loop for rolling two dice
So what do yoy think or feel about a language like RATFOR (Rational
FORTRAN) which was implemented as macros? Should they instead have simply
ad
On Wed, 8 Sep 2021 00:24:44 +0100, Alan Gauld via Python-list
declaimed the following:
>
>That was quite common in C before it became popular(early/mid 80s).
>I've seen Pascal, Algol and Coral macro sets in use.
>You could even download pre-written ones from various
>bulletin boards (remember the
On 2021-09-08, charles hottel wrote:
> So what do yoy think or feel about a language like RATFOR (Rational
> FORTRAN) which was implemented as macros?
The RATFOR implementations I've seen weren't done using macros. It was
a preprocessor, yes. But it generates code for the various structured
sta
On 2021-09-08, charles hottel wrote:
> So what do yoy think or feel about a language like RATFOR (Rational
> FORTRAN) which was implemented as macros? Should they instead have
> simply adapted themselves to FORTRAN?
That's an interesting question. If the langauge is complete,
well-defined, an
7, 2021 9:08 PM
To: python-list@python.org
Subject: Re: on writing a while loop for rolling two dice
On 8/09/21 2:53 am, Grant Edwards wrote:
#define IF if (
#define THEN ) {
#define ELSE } else {
#define ENDIF }
...
I gather that early versions of some of the Unix utilities
another object means you over-rode the meaning of
+= for instance.
-Original Message-
From: Python-list On
Behalf Of Richard Damon
Sent: Tuesday, September 7, 2021 10:09 PM
To: python-list@python.org
Subject: Re: on writing a while loop for rolling two dice
On 9/7/21 3:51 PM, Avi Gross via
On 9/7/21 3:51 PM, Avi Gross via Python-list wrote:
> and similarly changes any function imported directly
> to also be fully qualified.
One danger with this is that it can actual change the behavior of the
program. Maybe more likely with global objects than functions, but still
an issue.
Remembe
@python.org
Subject: Re: on writing a while loop for rolling two dice
On 8/09/21 2:53 am, Grant Edwards wrote:
>#define IF if (
>#define THEN ) {
>#define ELSE } else {
>#define ENDIF }
>...
I gather that early versions of some of the Unix utilities were written by
so
On 8/09/21 2:53 am, Grant Edwards wrote:
#define IF if (
#define THEN ) {
#define ELSE } else {
#define ENDIF }
...
I gather that early versions of some of the Unix utilities were
written by someone who liked using macros to make C resemble Algol.
I guess you can get away with t
On 07/09/2021 15:53, Grant Edwards wrote:
> I remember engineering manager I worked with about 35 years ago who
> used a set of C macros to try to make his code look as much like BASIC
> as possible:
>
> #define IF if (
> #define THEN ) {
> #define ELSE } else {
> #define ENDIF }
> ...
alister via Python-list
Sent: Tuesday, September 7, 2021 2:58 PM
To: python-list@python.org
Subject: Re: on writing a while loop for rolling two dice
On Tue, 07 Sep 2021 14:53:29 +, Grant Edwards wrote:
> On 2021-09-06, Stefan Ram wrote:
>> "Avi Gross" writes:
>&g
On Tue, 7 Sep 2021 16:08:04 +1200, Greg Ewing
declaimed the following:
>On 7/09/21 11:38 am, Avi Gross wrote:
>
>> #define INDEFINITELY_LOOP while (true)
>>
>> So, how to do something like that in python, is a challenge left to the user
>> ?
>
>def hell_frozen_over():
> return False
>
>whil
Grant Edwards writes:
> On 2021-09-06, Stefan Ram wrote:
>> "Avi Gross" writes:
>>> In languages like C/C++ there are people who make up macros like:
>>>#define INDEFINITELY_LOOP while (true)
>>>Or something like that and then allow the preprocessor to replace
>>>INDEFINITELY_LOOP with valid C
On Tue, 07 Sep 2021 14:53:29 +, Grant Edwards wrote:
> On 2021-09-06, Stefan Ram wrote:
>> "Avi Gross" writes:
>>> In languages like C/C++ there are people who make up macros like:
>>>#define INDEFINITELY_LOOP while (true)
>>>Or something like that and then allow the preprocessor to replace
On 2021-09-06, Stefan Ram wrote:
> "Avi Gross" writes:
>> In languages like C/C++ there are people who make up macros like:
>>#define INDEFINITELY_LOOP while (true)
>>Or something like that and then allow the preprocessor to replace
>>INDEFINITELY_LOOP with valid C code.
>
> Those usually are
On 7/09/21 11:38 am, Avi Gross wrote:
#define INDEFINITELY_LOOP while (true)
So, how to do something like that in python, is a challenge left to the user 😉
def hell_frozen_over():
return False
while not hell_frozen_over():
--
Greg
--
https://mail.python.org/mailman/listinfo/py
ython-list@python.org
Subject: Re: on writing a while loop for rolling two dice
"Avi Gross" writes:
> In languages like C/C++ there are people who make up macros like:
>#define INDEFINITELY_LOOP while (true)
>Or something like that and then allow the preprocessor to replace
>IND
python-list@python.org
Subject: Re: on writing a while loop for rolling two dice
On 2021-09-06 at 20:11:41 -0400,
Avi Gross via Python-list wrote:
> And in the python version, has anyone made a generator that returned
> NULL or the like so you can say uselessly:
>
> for ( _ in forever(
On 2021-09-06 at 20:11:41 -0400,
Avi Gross via Python-list wrote:
> And in the python version, has anyone made a generator that returned
> NULL or the like so you can say uselessly:
>
> for ( _ in forever() ) ...
while "forever":
...
--
https://mail.python.org/mailman/listinfo/pyth
in the python version, has anyone made a generator that returned NULL or
the like so you can say uselessly:
for ( _ in forever() ) ...
-Original Message-
From: Python-list On
Behalf Of Stefan Ram
Sent: Monday, September 6, 2021 12:34 PM
To: python-list@python.org
Subject: Re: on wri
:50 PM
To: python-list@python.org
Subject: Re: on writing a while loop for rolling two dice
On Sat, 4 Sep 2021 12:27:55 -0500, "Michael F. Stemper"
declaimed the following:
>
>Kernighan and Ritchie agree(d) with you. Per _The C Programming
>Language__:
> Experience shows
On Sat, 4 Sep 2021 12:27:55 -0500, "Michael F. Stemper"
declaimed the following:
>
>Kernighan and Ritchie agree(d) with you. Per _The C Programming
>Language__:
> Experience shows that do-while is much less used that while
> and for.
>
And just for confusion, consider languages with
essage-
From: Python-list On
Behalf Of Hope Rouselle
Sent: Thursday, September 2, 2021 10:42 AM
To: python-list@python.org
Subject: Re: on writing a while loop for rolling two dice
David Raymond writes:
>> def how_many_times():
>> x, y = 0, 1
>> c = 0
>> while x
"Michael F. Stemper" writes:
> On 04/09/2021 08.53, Hope Rouselle wrote:
>> Chris Angelico writes:
>
>>> And at this point, it's looking pretty much identical to the for loop
>>> version. Ultimately, they're all the same and you can pick and choose
>>> elements from each of them.
>> I see. That
"Peter J. Holzer" writes:
> On 2021-09-02 11:28:21 -0300, Hope Rouselle wrote:
>> dn writes:
>> > On 29/08/2021 08.46, Hope Rouselle wrote:
>> >> Here's my solution:
>> >>
>> >> --8<---cut here---start->8---
>> >> def how_many_times():
>> >> x, y = 0, 1
>>
Chris Angelico writes:
> On Fri, Sep 3, 2021 at 4:33 AM Hope Rouselle wrote:
>> Yeah. Here's a little context. I came across this by processing a list
>> of exercises. (I'm teaching a course --- you know that by now, I
>> guess.) So the first thing I observed was the equal volume of work
>>
On 04/09/2021 08.53, Hope Rouselle wrote:
Chris Angelico writes:
And at this point, it's looking pretty much identical to the for loop
version. Ultimately, they're all the same and you can pick and choose
elements from each of them.
I see. That's why C must have added the do-while, but yea
On 2021-09-02 11:28:21 -0300, Hope Rouselle wrote:
> dn writes:
> > On 29/08/2021 08.46, Hope Rouselle wrote:
> >> Here's my solution:
> >>
> >> --8<---cut here---start->8---
> >> def how_many_times():
> >> x, y = 0, 1
> >> c = 0
> >> while x != y:
> >>
def how_many_times():
x, y = 0, 1
c = 0
while x != y:
c = c + 1
x, y = roll()
return c, (x, y)
Since I haven't seen it used in answers yet, here's another option using our
new walrus operator
def how_many_times():
roll_count = 1
while (rolls := roll())[0] != rol
On Fri, Sep 3, 2021 at 4:51 AM Hope Rouselle wrote:
>
> Chris Angelico writes:
>
> > On Mon, Aug 30, 2021 at 11:13 PM David Raymond
> > wrote:
> >>
> >> > def how_many_times():
> >> > x, y = 0, 1
> >> > c = 0
> >> > while x != y:
> >> > c = c + 1
> >> > x, y = roll()
> >> > retu
On Fri, Sep 3, 2021 at 4:33 AM Hope Rouselle wrote:
> Yeah. Here's a little context. I came across this by processing a list
> of exercises. (I'm teaching a course --- you know that by now, I
> guess.) So the first thing I observed was the equal volume of work
> dedicated to while loops and fo
Chris Angelico writes:
> On Mon, Aug 30, 2021 at 11:13 PM David Raymond
> wrote:
>>
>> > def how_many_times():
>> > x, y = 0, 1
>> > c = 0
>> > while x != y:
>> > c = c + 1
>> > x, y = roll()
>> > return c, (x, y)
>>
>> Since I haven't seen it used in answers yet, here's another
David Raymond writes:
>> def how_many_times():
>> x, y = 0, 1
>> c = 0
>> while x != y:
>> c = c + 1
>> x, y = roll()
>> return c, (x, y)
>
> Since I haven't seen it used in answers yet, here's another option using our
> new walrus operator
>
> def how_many_times():
> roll_co
dn writes:
> On 29/08/2021 08.46, Hope Rouselle wrote:
>> Here's my solution:
>>
>> --8<---cut here---start->8---
>> def how_many_times():
>> x, y = 0, 1
>> c = 0
>> while x != y:
>> c = c + 1
>> x, y = roll()
>> return c, (x, y)
>
>>
>> Why a
On 30/08/2021 06:17, dn via Python-list wrote:
OTOH the simulation of rolling n-number of dice, as would happen in the
real-world, would be broken by making the computer's algorithm more
efficient (rolling until the first non-equal value is 'found'). Does
that mean the realism of the model dies?
On Tue, Aug 31, 2021 at 12:28 AM Peter Otten <__pete...@web.de> wrote:
>
> On 30/08/2021 15:50, Chris Angelico wrote:
>
> > def how_many_times():
> > return next((count, rolls) for count, rolls in
> > enumerate(iter(roll, None)) if len(Counter(rolls)) == 1)
>
>
> That's certainly the most Coun
On 30/08/2021 15:50, Chris Angelico wrote:
def how_many_times():
return next((count, rolls) for count, rolls in
enumerate(iter(roll, None)) if len(Counter(rolls)) == 1)
That's certainly the most Counter-intuitive version so far;)
Do I get bonus points for it being a one-liner that doe
On Mon, Aug 30, 2021 at 11:13 PM David Raymond wrote:
>
> > def how_many_times():
> > x, y = 0, 1
> > c = 0
> > while x != y:
> > c = c + 1
> > x, y = roll()
> > return c, (x, y)
>
> Since I haven't seen it used in answers yet, here's another option using our
> new walrus operator
> def how_many_times():
> x, y = 0, 1
> c = 0
> while x != y:
> c = c + 1
> x, y = roll()
> return c, (x, y)
Since I haven't seen it used in answers yet, here's another option using our
new walrus operator
def how_many_times():
roll_count = 1
while (rolls := roll())[0] !=
On 30/08/2021 00.47, Peter Otten wrote:
> On 29/08/2021 12:13, dn via Python-list wrote:
>> On 29/08/2021 20.06, Peter Otten wrote:
>> ...
>>> OK, maybe a bit complicated... but does it pay off if you want to
>>> generalize?
>>>
>> def roll_die(faces):
>>> Â while True: yield random.randrang
On Mon, Aug 30, 2021 at 9:53 AM dn via Python-list
wrote:
>
> On 29/08/2021 22.24, Chris Angelico wrote:
> > On Sun, Aug 29, 2021 at 8:14 PM dn via Python-list
> > wrote:
> >> Efficiency:
> >> - wonder how max( d ) == min( d ) compares for speed with the set() type
> >> constructor?
> >
> > That
On 29/08/2021 22.24, Chris Angelico wrote:
> On Sun, Aug 29, 2021 at 8:14 PM dn via Python-list
> wrote:
>> Efficiency:
>> - wonder how max( d ) == min( d ) compares for speed with the set() type
>> constructor?
>
> That may or may not be an improvement.
>
>> - alternately len( d ) < 2?
>> - or
On 29/08/2021 12:13, dn via Python-list wrote:
On 29/08/2021 20.06, Peter Otten wrote:
...
OK, maybe a bit complicated... but does it pay off if you want to
generalize?
def roll_die(faces):
while True: yield random.randrange(1, 1 + faces)
def hmt(faces, dies):
for c, d in enumera
On Sun, Aug 29, 2021 at 8:14 PM dn via Python-list
wrote:
> Efficiency:
> - wonder how max( d ) == min( d ) compares for speed with the set() type
> constructor?
That may or may not be an improvement.
> - alternately len( d ) < 2?
> - or len( d ) - 1 coerced to a boolean by the if?
Neither of t
On 29/08/2021 20.06, Peter Otten wrote:
...
> OK, maybe a bit complicated... but does it pay off if you want to
> generalize?
>
def roll_die(faces):
> while True: yield random.randrange(1, 1 + faces)
>
def hmt(faces, dies):
> for c, d in enumerate(zip(*[roll_die(faces)]*dies), 1
On 28/08/2021 14:00, Hope Rouselle wrote:
def how_many_times():
x, y = 0, 1
c = 0
while x != y:
c = c + 1
x, y = roll()
return c, (x, y)
--8<---cut here---end--->8---
Why am I unhappy? I'm wish I could confine x, y to the while loop. T
[1, 3, 1, 13, 11, 4, 3, 5, 2, 4]
And the code can be a tad shorter, LOL!
But obviously then you have more overhead than an iterative solution or one
using a generator ...
-Original Message-
From: Python-list On
Behalf Of Alan Gauld via Python-list
Sent: Saturday, August 28, 2021 6:52 PM
To:
On 28/08/2021 21:50, Hope Rouselle wrote:
>>> roll_count = 0
>>> while True:
>>> outcome = roll_two_dice()
>>> roll_count += 1
>>> if outcome[ 0 ]== outcome[ 1 ]: break
>>> return roll_count, outcome[ 0 ]
>>
>
> Wait, I'm surprised ``outcome'' is still a valid name at the
> return-sta
On 8/28/2021 8:00 AM, Hope Rouselle wrote:
How should I write this? I'd like to roll two six-sided dice until I
get the same number on both. I'd like to get the number of times I
tried. Here's a primitive I'm using:
--8<---cut here---start->8---
x, y = rol
On 29/08/2021 08.46, Hope Rouselle wrote:
> Here's my solution:
>
> --8<---cut here---start->8---
> def how_many_times():
> x, y = 0, 1
> c = 0
> while x != y:
> c = c + 1
> x, y = roll()
> return c, (x, y)
>
> Why am I unhappy? I'm wish I cou
Hope Rouselle writes:
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>
>> Hope Rouselle writes:
>>>How would you write this?
>>
>> """Rolls two dice until both yield the same value.
>> Returns the number of times the two dice were rolled
>> and the final value yielded."""
>> roll_count = 0
>> wh
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Hope Rouselle writes:
>>How would you write this?
>
> """Rolls two dice until both yield the same value.
> Returns the number of times the two dice were rolled
> and the final value yielded."""
> roll_count = 0
> while True:
> outcome = roll_two_
On Sun, Aug 29, 2021 at 7:37 AM Hope Rouselle wrote:
>
> How should I write this? I'd like to roll two six-sided dice until I
> get the same number on both. I'd like to get the number of times I
> tried. Here's a primitive I'm using:
>
> --8<---cut here---start--
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Hope Rouselle writes:
>>Wait, I'm surprised ``outcome'' is still a valid name at the
>>return-statement. Wasn't it defined inside the while? Shouldn't its
>>scope be restricted to the while block? I had no idea. I should learn
>>some Python.
>
>
63 matches
Mail list logo