Giter VIP home page Giter VIP logo

Comments (1)

diegochillo avatar diegochillo commented on August 27, 2024
def select_activities(set_of_activities):
    activities=list(set_of_activities)
    activities.sort()
    activities=list(enumerate(activities))
    lastend=0
    for index, activity in activities:
        if activity[0]<activity[1]:
            if activity[0]<lastend:
                activities[index]=(index,"DEL")
            else:
                lastend=activity[1]
        else:
            activities[index] = (index, "DEL")

    result=[activity for index, activity in activities if activity!='DEL']
    return result


def test_select_activities(set_of_activities, expected):
    result=select_activities(set_of_activities)
    return result==expected


# TEST CASES:

activities={(6, 8), (7, 9), (9, 13), (14, 18), (15, 17), (18, 20), (20, 24), (21, 23), (20, 23), (23,24)}
expected=[(6, 8), (9, 13), (14, 18), (18, 20), (20, 23), (23, 24)]
print (test_select_activities(activities, expected))

activities={(1, 4), (3, 5), (4, 6), (6, 9), (9, 12), (11, 13), (16, 18), (17, 19), (18, 22), (21,24)}
expected=[(1, 4), (4, 6), (6, 9), (9, 12), (16, 18), (18, 22)]
print (test_select_activities(activities, expected))

activities={(22, 24), (7, 9), (16, 20), (16, 22), (13, 17), (11, 14), (20, 22)}
expected=[(7, 9), (11, 14), (16, 20), (20, 22), (22, 24)]
print (test_select_activities(activities, expected))

activities={(24, 22), (7, 9), (16, 20), (16, 22), (13, 17), (11, 14), (20, 22)}
expected=[(7, 9), (11, 14), (16, 20), (20, 22)]
print (test_select_activities(activities, expected))

from 2020-2021.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.