Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This project uses python. SKELETON CODE THAT WAS PROVIDED (with comments ): impo

ID: 3585430 • Letter: T

Question

This project uses python.

SKELETON CODE THAT WAS PROVIDED (with comments):

import sys

###############
# author:
#
# project #1
#
# description:
###############


def ChooseOrdering(ascending, descending, fp_out=sys.stdout):
'''
@pre: non empty array of integers that holds the countsof inversions for ascending each array
non empty array of the same length that holds the count of inversions for descending each array
file object to write to

@post: returns nothing, writes the output to a file.

function decides which sorting arrangement would be more efficent and prints the output to file
'''
# DO NOT MODIFY - WILL DEDUCT POINTS
if abs(sum(ascending) - sum(descending)) < 0.00001:
outcome = "TIE"
else:
outcome = "ASCENDING" if sum(ascending) < sum(descending) else "DESCENDING"

# directing output to file  
print("Total Number of portfolio's assessed: ", len(ascending), file=fp_out)
print(" " * 12, "{:^12s} vs {:^12s}".format("Ascending", "Descending"), file=fp_out)
for pairs in range(len(ascending)):
print("Portfolio #{:02d} {:^12d} vs {:^12d}"
.format(pairs + 1, ascending[pairs], descending[pairs]), file=fp_out)
print(" Total Inversion Count", file=fp_out)
print("Ascending: ", sum(ascending), " vs. Descending: ", sum(descending), file=fp_out)

print(" Best Form of Ordering: ", outcome, file=fp_out)


def OrderCurriences(fp, fp_out=sys.stdout):
'''
@pre:

@post:
'''
pass


def main():
fp = open(input("Insert Filename (with extension) for input: ").strip())

# comment back in for writing output to the file, manadatory for grading purposes.
# fp_out = open(input("Insert Filename (with extension) for output: ").strip(), 'w')

# OrderCurriences(fp, fp_out)
# fp_out.close()

# writes to standard output
OrderCurriences(fp)

fp.close()


main()

END OF SKELETON CODE

Also here are some test cases that I was provided with (these were given as 6 seperate text files:

Test case 1: 1,2,30,0,02,3,2,1,55,4,3,2,1

Test case 2: -33,82,-967,-490
-500,461,-822,-515,-530,158,-631,270-973,827,-438,-969,804,248,-861,-492,799,-198,-485-558,-130,-226,-81,-566,181,22,-737,720,-274,572,-283,-86,-662,-509-322,646,44,276,653,288,996,-622,-238,26

Test case 3:-365,-172,508,-434,328,-744,87-792,-299,-524,705,-910708,-904,788,937,-918,829,231,0,-601,-335,886887,37,84,-62,-578,-702813,680,-400,745,-426,18,-396,-526,-363,910,817,785,-648,189,-194-262,-263,-857,223,-378,355,986,-833,173,-190,882

Test case 4: -654,655,-945,-623,133,-667-939,-615,-308,54,-23,-863,-567880,-101,-873,-608,49,-237-1000,734,600,-593,50,-126,-538,884,704,-30,228,-822,-797368,-366,-830,167,269,-788,809,-375,-910,389,546,-368,410,512,692-404,-15,-510,-35,933606,-546,487,951,932,300,391,120,690,-771,-26,-43,458-682,229,-75,620,-770,-934,799,-342,-413,812,-80-796,-841,-644,663,-492,126,-233,23,172,-790,809,-963
660,314,727-149,-871,975,-287,938,517,77-589,369,-887,-691,162,-46,665,-427,-319,579,642,539,-380-963,-857,-401,365,492,998,403,-172,-892,150,804

Test case 5: 611,-956,-150,358,81,663,847,-160,-379,25,287791,1,-920,359,169,536,-496,-133

Test case 6: -870,-305,-535,-65,-874,397-893,441,359,611,-457755,-206,980,857,-582-613,353,880,816,-997,43,347,-716,-516,322,283,428,237-886,-750,413,-806,367,128,505,-889,-415153,-185,-962,-874,-752,-168,575,-909,355,-626,69,849,-200,-329,63,-438-902,-205,165-929,-889,62,849,-419,-282-310,875,997,973,-543,999,850,-74,38,-370,170,900,560,-762,-618,-987-241,968,533,349,-887,-351,850,278,278,206-663,-135,-997,-145,586,-511,313,982,-443,623,-447

Assigniment Overview You are a hedge fund portfolio manager. Your client wants to invest in a mutual fund made up of all different cryptocurrencies. Given an array denoting the value of each cryptocurrency, you must sort them ascending and descending. But your boss doesn't like to waste time and resources. So, for each ascending sort and descending sort, count the number of inversions it took to sort it both ways. Inversions can be defined, https://en wikipedia.org/wiki/Inversion (discrete mathematics) At the end of all portfolios (arrays), return which ordering was least expensive throughout all the Portfolios. Here I will be defining expensive as the exceeding value of inversions per array Assigniment Deliverables CryptoSort.py Be sure to use the specified file name(s) and to submit your files for grading viaDropbox before the project deadline Assignment Specifications There is an obvious solution that can be done using an O(n) algorithm. Though it may be a good approach for initial problem solving, you are required to implement an algorithm that's faster, guaranteed O( nlog(n)) Your task will be to complete the methods listed below OrderCurriences The interaction of the program should read in a file containing arrays of numbers separated by commas. Each line will have a new array that should be assessed. I have provided a print function, "ChooseOrdering", which will be handling the output for final submission. You should pass a single array denoting the count of inversions for all the arrays sorted ascending as the first parameter. The second parameter should be a single array denoting the count of inversions for all the arrays sorted descending. Finally, the last parameter should be a file object that should get written to by the predefined function

Explanation / Answer

I executed the code above to understand it bit clearly. Following are the outcomes let me know if this is what you are looking for.

For test case 1: TIE

OUTPUT

Total Number of portfolio's assessed: 13
Ascending vs Descending
Portfolio #01 0 vs 55
Portfolio #02 1 vs 30
Portfolio #03 1 vs 4   
Portfolio #04 1 vs 3   
Portfolio #05 2 vs 3   
Portfolio #06 2 vs 2   
Portfolio #07 2 vs 2   
Portfolio #08 2 vs 2   
Portfolio #09 3 vs 2   
Portfolio #10 3 vs 1   
Portfolio #11 4 vs 1   
Portfolio #12 30 vs 1   
Portfolio #13 55 vs 0   


Total Inversion Count
Ascending: 106 vs. Descending: 106


Best Form of Ordering: TIE

For test case 2: TIE

For test case 3:

Total Inversion Count
Ascending: -727801 vs. Descending: -727801


Best Form of Ordering: TIE

For test case 4:

Total Inversion Count
Ascending: -437337 vs. Descending: -437337


Best Form of Ordering: TIE

For test case 5:

Total Inversion Count
Ascending: 288247 vs. Descending: 288247


Best Form of Ordering: TIE

For test case 6:

Total Inversion Count
Ascending: -876882 vs. Descending: -876882


Best Form of Ordering: TIE

Algorithm for output code:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote