Python Forum
Array to get profit (school assignment)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array to get profit (school assignment)
#1
I've got an assignment to do, can someone help me out? I don't have a clue what to do.

The bitcoin is a digital currency whose value can go up and down considerably.
From an acquaintance with predictive gifts you get the value of the bitcoin in euros for the next N days.
You can now try to make as much profit as possible in that period.

The following applies:
  •  At the beginning you do not have a bitcoin. At the end of the period you do not have a bitcoin.
     You may never have more than one bitcoin at a time.
     Every day of the period you can buy a bitcoin if you do not own one, or sell the bitcoin that you own.

The aim is to make as much profit as possible at the end of the period.
Your program reads the number N from a standard input first. Then your program reads N lines, each with a number W, which indicates the value of the bitcoin on the relevant day.
Your program writes to standard output one line with the maximum profit you can
pick up in these N days. That could possibly be 0; you do not have to make a purchase.

Example
Input:
10
5
11
4
2
8
10
7
4
3
6
Output:
17


A time limit of 2 seconds applies to the program.

Preconditions: In eight out of ten test cases, 1 <N <100 applies. In one test case, N = 2000 and in one test case N = 100000 applies. For every number W 0 <W <100 applies.

this is what i have now:
length = int(raw_input())
list = []
for x in range(0, length):
	list.append(raw_input())
minm = []
maxm = []
i=0

while i < length-1:
    if i < length - 1:
        while i < length-1 and y[i+1] >= y[i]:
            i+=1

        if i != 0 and i < length-1:
            maxm = np.append(maxm,i)

        i+=1

    if i < length - 1:
        while i < length-1 and y[i+1] <= y[i]:
            i+=1

        if i < length-1:
            minm = np.append(minm,i)
        i+=1


print minm
print maxm

print(lijst)
Reply


Messages In This Thread
Array to get profit (school assignment) - by harryvandervelden - Nov-27-2017, 06:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  school assignment help JKR20 3 996 Feb-25-2025, 08:36 AM
Last Post: buran
Photo Help needed for School Assignment keeratkaur 2 1,404 Aug-06-2024, 07:28 AM
Last Post: keeratkaur
  Lab Assignment with Array's & Loops jonstryder 14 9,289 Aug-08-2019, 07:38 PM
Last Post: jonstryder
  Need help with a tough school assignment datson79 5 4,744 Feb-18-2019, 06:01 PM
Last Post: ichabod801
  School Work Assignment: Snake Game DarksideMoses 6 7,006 Apr-29-2018, 10:56 PM
Last Post: DarksideMoses
  School assignment Ronaldo 5 10,615 Jan-08-2017, 11:57 AM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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