NumPy Project Euler Problem 5

This entry is part 5 of 6 in the series NumPy Project Euler

Project Euler Problem 5is one of those problems that seem hard, but turn out to be trivial after you think about them. In this case it is very important to use the information given to you in the problem. This means using the fact that 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. We can therefore limit our search to multiples of 2520.

1. Create a divisors array

First we will create a divisors array. We only need to divide by the numbers 11 – 20.

divisors = numpy.arange(11, 21)

2. Check for 0 remainder

Second make sure that all the divisions of a number by the divisors produce a 0 remainder. We can check for that with the NumPy all function.

numpy.all((i % divisors) == 0)

3. Test the solution

Eventually we will get an answer. We need to check whether this is the correct answer. Use the assert_equal function from the numpy.testing module to confirm the result.

numpy.testing.assert_equal(numpy.zeros(19), i % numpy.arange(2, 21))

Below is the complete code solution.

import numpy
 
#2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
 
#What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
 
# 1. Create a divisors array
divisors = numpy.arange(11, 21)
 
for i in xrange(2520, 10 ** 9, 2520):
        # 2. Check for 0 remainder
        if numpy.all((i % divisors) == 0):
                print i
                # 3. Test the solution
                numpy.testing.assert_equal(numpy.zeros(19), i % numpy.arange(2, 21))
                break

 

If you liked this post and are interested in NumPy check out NumPy Beginner’s Guide by yours truly. The NumPy Christmas Book Giveaway has officially ended. Winners will be contacted by the publisher. A new review of the book was added on Amazon.

Share
Posted in programming | Tagged , , | Leave a comment

Technical Career Navigator Review

In these hard economic times The Technical Career Navigator by Ray Weiss is the perfect book to help you find a job, keep your job and advance your career. The book is written for programmers, hardware engineers, technical managers and documentation writers. It consists of two alphabetically sorted lists of one to three page articles. Each article starts with one or more relevant quotes. The first list contains general tips for the intended audience. The second list contains job search tips.

Technical Navigator
Author Ray Weiss
ISBN-10 013148396X

I tried dividing the first list in some sublists for the purpose of this review.

Career

As expected the book contains a number of general career insights.

  • Be Noticed – do your work and make sure you’re noticed.
  • Consulting – tips on avoiding doing grunt work, setting your rates, growing your skillset and finding new projects.
  • Decisions – we make so many decisions in our working life, that we need to review where we are heading at least once a year.
  • Hairy Arm – leave an obvious flaw in your design or proposal. People want to have something to fix before accepting your idea.
  • I don’t Know – it’s hard to say that you don’t know something, but it is the best thing to do.
  • Lateral Thinking – a different way to solve problems.
  • Line Versus Service – work where the money is, line organizations.

Product Marketing

Surprisingly, the book also has advice on product marketing.

  • Betting On Instinct – most companies do extensive market analysis, however eventually decisions are made not based on numbers, but intuition.
  • By The You-Know-Whats – this one doesn’t require any explanation.

Technical Management

Technical management pitfalls are also discussed in the book.

  • Breaking Owsie Chains – owsie chains are bad. You need to find a way to break them.
  • Consent of the Governed – managers do not have a Divine Right to rule.
  • Credit Theory of Management – this theory compares management to credit banking.
  • Fear – you cannot innovate if you live in fear.
  • Gearing up – shifting from mediocrity to superiority.
  • Hiring – a list of hiring techniques is given.
  • It’s not What you do – do not expect other people to work in the same way or at the same level as you do.

Writing and Documentation

The author is a former technical editor with years of experience writing documentation.

  • Conceptual Maps – needed for documentation. I wonder if mind maps are meant here.
  • Learn to Write – writing can be learned. You need to read and practice a lot. There are two stages. First, aim for simplicity. In the last stage you try to perfect your style. For a technical writer content is more important than style.
  • Writing Memos, Letters – use a pyramidlike approach, put concepts at the top and details at the bottom. Use contractions and keep the text simple.

Programmer or Engineer

The writer seems to make a distinction between programmers and hardware engineers.

  • Design Reviews – reviews are needed to find errors early.
  • Engineering Notebook – you should have one, preferably a paper notebook.
  • Expecting Too Much – you don’t expect your code to work the first time you run it, do you? Why would it be different in real life?
  • Invest 30 minutes a Day – set time aside each day to keep current.
  • Pat Yourself on the Back – as you become more senior you will get less and less kudos from management. Know your worth.
  • Product Track Record – make sure you have some successes.

Job Search Tips

At the end of the book we find hints and observations about job hunting.

  • Catching a Horse – finding a job is easier, while you have one.
  • Contacting People – hints on contacting managers and recruiters.
  • Do It In Parallel – search in parallel fashion.

Technical Career Navigator contains many hidden gems. It’s a book you will be reading again and again. I give this book 5 stars out of 5.

Share
Posted in books | Leave a comment