To be concrete, I think you're looking at Problem 31, right?
http://projecteuler.net/problem=31
in which case, we have a few choices for denomination:
1p, 2p, 5p, 10p, 20p, 50p, 100p, 200p
and we're trying to _count_ how many ways to make 200p.
Here's a sketch of how I'd attack this
Thanks everyone, things to chew on. I'll look at the other itertools
functions mentioned. I did solve Proj. Euler 15 & 18 (and it's
corresponding 67), one more elegantly than the other, and I have given
some thought to how to break this one down, but haven't figured it out
yet. I think I might not
Keith Winston Wrote in message:
> I'm working through some of the Project Euler problems, and the
> following might spoil one of the problems, so perhaps you don't want
> to read further...
>
>
> The problem relates to finding all possible combinations of coins that
> equal a given total. I'm b
This sounds very much like a problem that demands trying to break the
problems down into subproblems, and then applying a
"dynamic-programming approach" to make it fairly easy to get an
efficient solution. Such problems that are amendable to this approach
have a "substructure" to them so that the
Hi Keith,
On 12 January 2014 23:12, Keith Winston wrote:
> I'm working through some of the Project Euler problems, and the
> following might spoil one of the problems, so perhaps you don't want
> to read further...
>
>
> The problem relates to finding all possible combinations of coins that
> eq
I'm working through some of the Project Euler problems, and the
following might spoil one of the problems, so perhaps you don't want
to read further...
The problem relates to finding all possible combinations of coins that
equal a given total. I'm basically brute-forcing it, which is probably
not
On Sun, Jan 12, 2014 at 2:22 PM, Keith Winston wrote:
> There's another approach, I think, that's quite easy if order IS important.
Alas, there's one further problem with my script, relating to testing
multiple sequential letters in product... but I'm not going to say
more, I'll leave it as a pro
Emile van Sebille wrote:
> On 01/12/2014 12:21 PM, Peter Otten wrote:
>
> test("axbxc", "abc")
>> True
> test("abbxc", "abc")
>> False
>>
>> Is the second result desired?
>
> No -- the second should match -- you found a test case I didn't...
>
> def test(a,b):
>for ii in a:
> i
On 01/12/2014 12:21 PM, Peter Otten wrote:
test("axbxc", "abc")
True
test("abbxc", "abc")
False
Is the second result desired?
No -- the second should match -- you found a test case I didn't...
def test(a,b):
for ii in a:
if ii not in b: a=a.replace(ii,"")
while ii+ii in a: a=a.r
Emile van Sebille wrote:
> On 01/12/2014 06:43 AM, Dave Angel wrote:
>> Roelof Wobben Wrote in message:
>>
>> That documentation says nothing about order. And the test cases
>> specifically contradict it.
>>
>> so try
>>
>> if set (b) <= set (a):
>
> or, as the OP specified, if order is rel
On 01/12/2014 06:43 AM, Dave Angel wrote:
Roelof Wobben Wrote in message:
That documentation says nothing about order. And the test cases
specifically contradict it.
so try
if set (b) <= set (a):
or, as the OP specified, if order is relevant,
def test(a,b):
for ii in a:
if ii no
On Sun, Jan 12, 2014 at 2:38 PM, Keith Winston wrote:
> Sigh and this line needs to read (if it's going to do what I said):
As Alan pointed out, the examples provided do NOT account for order,
so if one uses my (corrected) algorithm, you get different results
from the examples. Without the f
On Sun, Jan 12, 2014 at 2:38 PM, Keith Winston wrote:
> On Sun, Jan 12, 2014 at 2:22 PM, Keith Winston wrote:
>> if test:
>
> Sigh and this line needs to read (if it's going to do what I said):
>
> if test != -1:
Consider the case of `product == "letter"`. Do you want to doub
On Sun, Jan 12, 2014 at 2:22 PM, Keith Winston wrote:
> if test:
Sigh and this line needs to read (if it's going to do what I said):
if test != -1:
--
Keith
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscr
OOps, I never used the "success" boolean in my code, but forgot to
remove it. Sorry.
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
On 12/01/2014 19:22, Keith Winston wrote:
On Sun, Jan 12, 2014 at 7:44 AM, Alan Gauld wrote:
OK< So there is nothing here about the orders being the same.
That makes it much easier.
There's another approach, I think, that's quite easy if order IS important.
Iterate through the letters of pr
On Sun, Jan 12, 2014 at 7:44 AM, Alan Gauld wrote:
> OK< So there is nothing here about the orders being the same.
> That makes it much easier.
There's another approach, I think, that's quite easy if order IS important.
Iterate through the letters of product, find() them initially from the
begi
Thanks Dave, that looks like a good idea, I've played a little with
one-line generators (? the things similar to list comprehensions), but
I'm still wrapping my head around how to use them. Meanwhile I'm
reorganizing my code because I now understand better how to use
iterators (i.e. the combination
On 12/01/14 14:43, Dave Angel wrote:
so try
if set (b) <= set (a):
Ooh, nice! For some reason I've never thought of
applying set to a string before.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
_
On Sun, Jan 12, 2014 at 8:21 AM, Peter Otten <__pete...@web.de> wrote:
>
> OP: You'll get bonus points (from me, so they're pointless points, but
> still) if you can solve this (including the fifth apocryphal test case)
> using the collections.Counter class.
Hint:
>>> print(Counter.__sub__.__
Roelof Wobben Wrote in message:
That documentation says nothing about order. And the test cases
specifically contradict it.
so try
if set (b) <= set (a):
--
DaveA
Android NewsGroup Reader
http://www.piaohong.tk/newsgroup
___
Tutor ma
Keith Winston Wrote in message:
> I've got this line:
>
> for k in range(len(tcombo)):
> tcombo_ep.append(list(combinations(tcombo, k+1)))
>
> generating every possible length combination of tcombo. I then test
> them, and throw most of them away. I need to do this differently, it
> gets wa
Alan Gauld wrote:
> On 12/01/14 08:12, Roelof Wobben wrote:
>
>> # Write a Python procedure fix_machine to take 2 string inputs
>> # and returns the 2nd input string as the output if all of its
>> # characters can be found in the 1st input string and "Give me
>> # something that's not useless nex
On 12/01/14 08:12, Roelof Wobben wrote:
# Write a Python procedure fix_machine to take 2 string inputs
# and returns the 2nd input string as the output if all of its
# characters can be found in the 1st input string and "Give me
# something that's not useless next time." if it's impossible.
OK
On Sun, Jan 12, 2014 at 4:19 AM, Alan Gauld wrote:
> lambdas are just a shortcut for single expression functions.
> You never need them, they just tidy up the code a bit by
> avoiding lots of use-once short functions.
Thanks, I figured out how to iterate the combinations function. I'll
play with
Hello,
Here is the whole exercise with examples.
# By Sam the Great from forums
# That freaking superhero has been frequenting Udacity
# as his favorite boss battle fight stage. The 'Udacity'
# banner keeps breaking, and money is being wasted on
# repairs. This time, we need you to procedural
On 12/01/14 09:04, Keith Winston wrote:
I'm partially asking in order to clarify the question in my mind, but
any help will be appreciated. I don't really understand lambda
functions yet, but I can sort of imagine they might work here
somehow... or not.
lambdas are just a shortcut for single e
I've got this line:
for k in range(len(tcombo)):
tcombo_ep.append(list(combinations(tcombo, k+1)))
generating every possible length combination of tcombo. I then test
them, and throw most of them away. I need to do this differently, it
gets way too big (crashes my computer).
I'm going to pla
28 matches
Mail list logo