Problem 158

A place to air possible concerns or difficulties in understanding ProjectEuler problems. This forum is not meant to publish solutions. This forum is NOT meant to discuss solution methods or giving hints how a problem can be solved.
Forum rules
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.

This forum is NOT meant to discuss solution methods for a problem.

In particular don't post any code fragments or results.

Don't start begging others to give partial answers to problems

Don't ask for hints how to solve a problem

Don't start a new topic for a problem if there already exists one


See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
Post Reply
quilan
Posts: 182
Joined: Fri Aug 03, 2007 11:08 pm

Problem 158

Post by quilan »

I've got a nice algorithm all written out for problem 158, but it appears one of my assumptions about the nature of lexographical sorting is incorrect. The example says that of strings of length 3, there are 10400 which have only 1 character greater than its left neighbor.

Yet, running this naive brute force on 3 letters, I get a result of 11700.

Python:

Code: Select all

total=0;
for a in range(ord("a"),ord("z")+1):
    for b in range(ord("a"),ord("z")+1):
        for c in range(ord("a"),ord("z")+1):
            t=0;
            if(b>a): t+=1;
            if(c>b): t+=1;
            if(t==1): total+=1;
            #st=chr(a)+chr(b)+chr(c);

print "Total: %d"%total;
What simple rule/example am I missing?
ex ~100%'er... until the gf came along.
Image
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Confirmation on Problem 158 example

Post by daniel.is.fischer »

You've simply overlooked the word 'different' in the problem text. Or maybe not, it's not in that sentence, so technically we have a mistake in the example :oops: It's in the more important sentences, though :)
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
quilan
Posts: 182
Joined: Fri Aug 03, 2007 11:08 pm

Re: Confirmation on Problem 158 example

Post by quilan »

Ahhhh, many thanks. Now just to modify the algorithm...
ex ~100%'er... until the gf came along.
Image
sleepintegrity
Posts: 1
Joined: Sat Nov 13, 2010 5:56 pm

Re: Problem 158

Post by sleepintegrity »

Just a clarification to help people who might struggle with this problem, like I did, in order to save them some frustration: as the problem is worded, it is ambiguous and redundant. First off, of course a string of n characters that are all different will be of length n. So, saying p(n) counts strings with n characters of length n sounds like it's adding an extra requirement, some kind of diagonalisation requirement, which is confusing.

The ambiguity is that it's unclear whether we are considering alphabets with n <= 26 characters, or whether we are choosing n <= 26 characters from the standard alphabet. It turns out that the correct answer requires you to assume the latter. But the wording "We now consider" implies that we're doing something that puts a twist on what was stated in the first paragraph, whereas it's actually exactly the same as the example in the first paragraph. Also, the redundancy in specifying the string length contributes to interpretation that what was being specified was the size of the alphabet, rather than the number of characters chosen from it, which does not need to be specified. Hope this helps someone.
User avatar
PurpleBlu3s
Posts: 75
Joined: Mon Sep 19, 2011 6:49 pm

Re: Problem 158

Post by PurpleBlu3s »

I'm trying to get 10400 for n=3, but I'm getting 9800. Am I missing any cases by thinking like this, or am I just calculating it wrong?

Get all possible strings where the first two letters are not lexicographically ordered, and append a lexicographically ordered character to the end, i.e. zx.y, zw.(x+y), ..., za.(b+...+y), yw.(x+z), yv.(w+x+z), ..., ca.(b+d+e+...+z).
Then get all possible strings where the first two letters are lexicographically ordered, and append a non-lexicographically correct character, i.e. yz.(a+...+x), xz.(a+...+w+y), ..., ac.b.

Thanks for any help.
Image
User avatar
jaap
Posts: 588
Joined: Tue Mar 25, 2008 3:57 pm
Contact:

Re: Problem 158

Post by jaap »

PurpleBlu3s wrote:I'm trying to get 10400 for n=3, but I'm getting 9800. Am I missing any cases by thinking like this, or am I just calculating it wrong?
That should give the right answer for the 3 letter example. Note that there are the same number of each type (so 5200 each). Can you see why?
User avatar
PurpleBlu3s
Posts: 75
Joined: Mon Sep 19, 2011 6:49 pm

Re: Problem 158

Post by PurpleBlu3s »

jaap wrote:
PurpleBlu3s wrote:I'm trying to get 10400 for n=3, but I'm getting 9800. Am I missing any cases by thinking like this, or am I just calculating it wrong?
That should give the right answer for the 3 letter example. Note that there are the same number of each type (so 5200 each). Can you see why?
Thanks, I saw the problem with my calculation.
Image
User avatar
PurpleBlu3s
Posts: 75
Joined: Mon Sep 19, 2011 6:49 pm

Re: Problem 158

Post by PurpleBlu3s »

So I've returned to this problem after a while, and I wanted to check if anyone could confirm my value for n=4, 164450?

Thanks.
Image
User avatar
thedoctar
Posts: 128
Joined: Fri Apr 15, 2011 11:57 am
Location: Sydney, Australia

Re: Problem 158

Post by thedoctar »

PurpleBlu3s wrote:So I've returned to this problem after a while, and I wanted to check if anyone could confirm my value for n=4, 164450?

Thanks.
That value is correct,I believe.
Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
Image
fabas indulcet fames
itteerde
Posts: 8
Joined: Wed Dec 31, 2014 6:59 am

Re: Problem 158

Post by itteerde »

p(26)=25, right?

missing something, just want to check if I even understand the problem correct
v6ph1
Posts: 134
Joined: Mon Aug 25, 2014 7:14 pm

Re: Problem 158

Post by v6ph1 »

itteerde wrote:p(26)=25, right?
No - These 4 are also valid:
zyx...olnmk...cba
zyx...omnlk...cba
zyx...omlnk...cba
zyx...onlmk...cba
Image
itteerde
Posts: 8
Joined: Wed Dec 31, 2014 6:59 am

Re: Problem 158

Post by itteerde »

v6ph1 wrote:
itteerde wrote:p(26)=25, right?
No - These 4 are also valid:
zyx...olnmk...cba
zyx...omnlk...cba
zyx...omlnk...cba
zyx...onlmk...cba
I see, thx a lot - think that will do it for me
Post Reply