Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE ONLY DO QUESTION 2 IN PYTHON in grading homework 5 I noticed a variety of solutions to question 1 0 ( print all numbers
PLEASE ONLY DO QUESTION IN PYTHON in grading homework I noticed a variety of solutions to question print all numbers between
and inclusive, where each digit is even I appreciate questions like this for it allows me to see a
range of thinking on how to solve a problem. Here are two solutions that were given:
printn for n in range if allintc for c in strn sep
for i in range:
iseven true
for j in stri:
if intj:
iseven false
if iseven:
numbers.appendi
printnumbers
The second solution takes more coding but essentially does the same thing. Part of writing software
or doing analysis, at least is identifying patterns of what needs to be done. Making a problem
generic can sometimes help in this regard find numbers between x and y etc. Looking at a
problem in a different way thinking outside of the box can provide a unique solution as well. One
thing to always remember is that just because something is a number doesn't mean it has to be
treated as a number. Think of phone numbers or social security numbers. While they contain only
digits, one almost never performs mathematical operations against them so they could just as easily
be strings, and probably should be
The two solutions above are more efficient than examining every number between or x and
or y but they could be more efficient yet. Think about what problem we're trying to solve. The
first solution is probably a good one, but is there a better one? If the s position contains an odd
number, does it matter what the digit is in the one's position? No so we should move to the next s
position value. The same holds true for s and s positions.
Q pts Determine how to time programs in Python. Run tests of each of the first two solutions
given above and average the results. Come up with a solution that is more efficient faster Run
CIS
tests on it and record the average. Supply your faster algorithm and the average result of all three
algorithms.
Q Deep dive into logically cutting corners in a solution through analysis. Find a solution to this
problem that executes in under second can it be even faster? without hardcoding the
answer. Displaying values takes a long time so remove most output statements once youre getting
close. I'll spare you the long version of the question. Simply do this: find the price of four items who's
sum and who's product both equal So abcd abcd There may be more than
one answer. I originally solved this problem years ago in C My initial algorithm ran for over
hours. My deep dive analysis produced one that solved it in about second. Supply your final
algorithm and how long it takes to solve the problem using the average of three runs
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started