(#1) What am I doing wrong?

For questions about problems on the Project Euler web site. No spoilers. Please include the question number in the subject line of your post.

(#1) What am I doing wrong?

Postby E3x3 » Fri Jul 10, 2015 3:39 am

It yields 266,333, which is the wrong answer.
(BTW, I just started coding, so I'm sorry if it's not advanced)

Code: Select all
factor = 0
product = 0
SumOfProducts = 0

while True:
    if product == 999:
        ThreeProductTotal = SumOfProducts
        break
    else:
        factor += 1
        product = 3 * factor
        SumOfProducts += product
       
factor = 0
product = 0
SumOfProducts = 0

while True:
    if product == 995:
        FiveProductTotal = SumOfProducts
        break
    else:
        factor += 1
        product = 5 * factor
        SumOfProducts += product
       
print(ThreeProductTotal + FiveProductTotal)
Last edited by metulburr on Fri Jul 10, 2015 4:03 am, edited 1 time in total.
Reason: added code tags
E3x3
 
Posts: 2
Joined: Tue Jul 07, 2015 10:34 pm

Re: (#1) What am I doing wrong?

Postby Mekire » Fri Jul 10, 2015 4:29 am

You are double counting numbers.
Multiples of 3 or 5.

So currently you are counting numbers like 15 twice.
Also, there is a simpler way.
New Users, Read This
  • Use code tags when posting code.
  • Include any errors with your post (in code tags).
  • Describe your problem; not your chosen solution.
  • Make examples the minimum length to demonstrate your issue.
User avatar
Mekire
 
Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

Re: (#1) What am I doing wrong?

Postby E3x3 » Sat Jul 11, 2015 6:40 pm

Please explain how I can fix it?
E3x3
 
Posts: 2
Joined: Tue Jul 07, 2015 10:34 pm

Re: (#1) What am I doing wrong?

Postby micseydel » Sat Jul 11, 2015 9:03 pm

The two things that come to mind are to (1) not double count or (2) after double counting, remove those double counted numbers from your sum.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: (#1) What am I doing wrong?

Postby Kebap » Sat Jul 11, 2015 11:47 pm

A picture sometimes says more than 1000 words could:
Image
Due to the reasons discussed here we are moving to python-forum.net on October 1, 2016.

This forum will be closed. Please create an account at the new site to continue discussion.

IRC://irc.freenode.net/python-forum
Kebap
 
Posts: 689
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe


Return to Project Euler

Who is online

Users browsing this forum: No registered users and 1 guest