DEV Community

Durga Pokharel
Durga Pokharel

Posted on • Edited on

1

Day 58 Of 100DaysOfcode: More About Algorithm

Todays I completed 58th day of #100daysOfCode and #python learning. Like yesterday today also continued to learned more about SQL properties(CROSS JOIN, UNION, UNION ALL, INTERSECT, EXCEPT) from Datacamp

Tired to complete some assignment from Coursera. Learned more types of algorithms from algorithmic toolbox. I tried to solve car fueling problem which is given below.

Python code

def compute_min_refills(distance, tank, stops):

    numrefill, currentrefill= 0,0
    stops = [0] + stops + [distance] #include the start and end points in the stops list   
    if distance <= tank:
        return 0
    else:
        while currentrefill < len(stops)-1:
            lastrefill = currentrefill
            #print(currentrefill, lastrefill, len(stops))
            while currentrefill < len(stops)-1 and stops[currentrefill+1] - stops[lastrefill]<=tank:

                currentrefill += 1

            if currentrefill == lastrefill:
                return -1
            if currentrefill < len(stops)-1:
                numrefill +=1

        #print(numrefill)

        return numrefill
if __name__ == '__main__':
    d, m, _, *stops = map(int, sys.stdin.read().split())
    print(compute_min_refills(d, m, stops))
Enter fullscreen mode Exit fullscreen mode

Day 58 Of #100DaysOfCode and #Python
* SQL (CROSS JOIN, UNION, UNION ALL, INTERSECT, EXCEPT) From Datacamp
* More about Algorithm
* Car Fueling #womenintech #CodeNewbie #DEVCommunity pic.twitter.com/m6S9iYETX1

— Durga Pokharel (@mathdurga) February 24, 2021

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (2)

Collapse
 
otumianempire profile image
Michael Otu

Indent the last line under the if block

Collapse
 
iamdurga profile image
Durga Pokharel

Thank you for pointing out.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay