Python Forum
Maths and python: Compute stress level
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Maths and python: Compute stress level
#1
Hi Expert,

I have a very though question to implement in python. It looks simple but hard. The question is as follow:

A student is preparing for the mid-semester exams and wants to make the least stressful schedule to study. There are 'n' subjects each of which has certain stress-level, and the student has 'days' study days left. The student must study the subjects in order, ie study the ith subject before going on to the (i+1)th subject.

The stress level of any day is defined as the maximum stress level of any subject the student studies on that day. Write a function to find the minimum stress level in which the student can finish studying all subjects, while still studying for at least one subject on each of the study days.

Constraints
1<= n <= 200
1<= days <= n <= 300
1<= stressLevel[i] <= 10^5


If days = 2, the solution is below:

stresslevel = [30, 10, 40, 20, 50]
# stresslevel = [1, 5, 3, 2, 4]

n = len(stresslevel)

days = 2

total_stress = []

for i in range(n-1): 
    x = stresslevel[:i+1]
    y = stresslevel[i+1:]
    
    x_max = max(x)
    y_max = max(y)
    
    temp = x_max + y_max
    total_stress.append(temp)
    
min_stress = min(total_stress)
min_stress
However, if days > 2 ie 5, it becomes difficult because there will be more pointers pointing to the stresslevel list and they will have to count up and down separately.


Thank you for your help
cheerful
Reply
#2
This sounds like the typical knapsack problem which is very well covered by John Guttag in the second lecture of the MIT 'Introduction to Computational Thinking and Data Science' course.
You can watch that video here: https://ocw.mit.edu/courses/electrical-e...-problems/
or download the transcript and lecture materials from the same page.
This one lecture covers greedy, brute-force, and other algorithms to get the best answer.

He used food, your assignment uses stress level. The algorithms are quite similar if not exact.
ndc85430 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compute complex solutions in quadratic equations liam 1 1,878 Feb-09-2020, 04:18 PM
Last Post: Gribouillis
  How to compute conditional unigram probabilities? jbond 2 2,504 Jan-25-2020, 02:58 PM
Last Post: jbond
  why is there an unexpected maths result from a float calculation? maryab 3 2,841 Jun-09-2019, 08:28 PM
Last Post: snippsat
  Finding the Young's Modulues in a curve stress strain AicramM 1 4,442 Nov-03-2018, 09:01 PM
Last Post: Gribouillis
  To extract a specific column from csv file and compute the average vicson 2 8,090 Oct-20-2018, 03:18 AM
Last Post: vicson
  Increasing difficulty of a maths game Maxxy_Gray 1 3,165 Apr-04-2018, 03:00 PM
Last Post: sparkz_alot
  Write a program to compute the sum of the terms of the series: 4 - 8 + 12 - 16 + 20 - chewey777 0 2,800 Mar-24-2018, 12:39 AM
Last Post: chewey777
  Making maths .py program faster Shutcois 1 2,565 Feb-16-2018, 06:39 PM
Last Post: nilamo
  How do you compute tf-idf from a list without using the counter class syntaxkiller 8 5,187 Dec-01-2017, 05:24 PM
Last Post: nilamo
  compute gross pay jamesuzo 1 10,308 Sep-07-2017, 01:47 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020