Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7802045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:08:24+00:00 2026-06-02T01:08:24+00:00

I tried to bruteforce euler problem 14 with python without much success. I used

  • 0

I tried to bruteforce euler problem 14 with python without much success.

I used the itertools module but it was too slow. Then I found the formula to solve the problem.

Is there a way to solve the problem using bruteforce?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:08:26+00:00Added an answer on June 2, 2026 at 1:08 am

    You could store the intermediate value in a dictionary and do a kind of a dynamic programming.

    numbers = {1:0}
    max = -1
    startMax = -1
    for i in range(2, 1000 000):
        n = i
        steps = 0
        while n>=i:
            if n&2 == 0:
                n = n/2
            else:
                n = 3*n + 1
            steps = steps + 1
        # n < i, hence it must already be stored in the dictionary
        steps = steps + numbers[n]
        if steps > max:
            max = steps
            startMax = i
        numbers[i] = steps
        return startMax
    

    Another approach may be to store every number you encounter and always check whether the number you are currently on is in the map. But I guess this may take a bit longer with so many dictionary look-ups:

    numbers = {1:0}
    max = -1
    for i in range(2, 1000 000):
        if i in numbers:
            steps = numbers[i]
        else:
            n = i
            steps = 0
            found = False
    
            while not found:
                if n&2 == 0:
                    n = n/2
                else:
                    n = 3*n + 1
                if n in numbers:
                    steps = numbers[n]
                    found = True
                else:
                    newNumbers.append(n)
            # Store all the new numbers into the dictionary
            for num in newNumbers:
                steps = steps + 1
                numbers[num] = steps
        if steps>max:
            max = steps
            startMax = i
    return startMax
    

    You may want to do some testing to find out which one is better, but my bet would be on the first one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I solved Euler problem 14 but the program I used is very slow. I
Tried examples from 'php.net' but don't understand what's the problem. Any suggestions? <?php $_SESSION['test']
For a small project (Problem 10 Project Euler) i tried to sum up all
I tried thinking of an algorithm, but couldn't do it. Here is the problem:
Tried a bunch of things but I can't get it to work consistently amid
tried to find the answer by googling and in MSDN but with no luck.
Tried to install some program, it gives above message requiring 1.1.4322. BUT as the
tried to research on that but sometimes I seem to lack some googling skills...
I tried to research this, but there were still some questions left unanswered. I
Tried with: listPacchetti[2] but it doesnt works at all. In fact I should do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.