DEV Community

Durga Pokharel
Durga Pokharel

Posted on • Edited on

1

Day 57 Of 100DaysOfCode: Money Change Problem

Today is my day 57th of #100dayofcode and #python. Today also continued to learned more properties of SQL including INNER JOIN,LEFT JOIN, RIGHT JOIN, FULL JOIN, IS LIKE, NOT LIKE, IS NULL, IS NOT NULL etc from Datacamp

Also tried to complete some assignment in coursera regarding to the topic algorithmic toolbox. I tired to solve money change problems, Fractional Knapsack problems, car fueling problem.

Python code

We are going to change Rs.28. In the shop shopkeeper has only Rs.1, Rs.5, Rs.10 as a change. So, possible change for 28 are 10,10,5,1,1,1. For this I tried to write following code.

number = 28
valid_changes = [1, 5, 10]
rem = number
changes=[]

while rem!=0:
#     print(rem)
    if rem%valid_changes[2]==0:
        changes.extend([valid_changes[2]])
        rem -= valid_changes[2]
    elif rem%valid_changes[1]==0:
        changes.extend([valid_changes[1]])
        rem -= valid_changes[1]
    else:
        changes.extend([1])
        rem-=1
print(len(changes))
Enter fullscreen mode Exit fullscreen mode

When above code is run we get,

28
27
26
25
20
10
[1, 1, 1, 5, 10, 10]
Enter fullscreen mode Exit fullscreen mode

Day 57 Of #100DaysOfCode
* More properties of SQL(LEFT JOIN, RIGHT JOIN, FULL JOIN, INNER JOIN)
* More About Algorithm
* Code For Money Change#WomenWhoCode #teachertwitter #DEVCommunity pic.twitter.com/1zuUa1nQ6M

— Durga Pokharel (@mathdurga) February 23, 2021

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay