public
Created

acsl intermediate contest 1 in one line

  • Download Gist
acsl1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
# Taeer Bar-Yam
# Commonweath School
# Division Intermediate - 3
# Tested with Rakudo 2011.12
say
(
( #AVERAGE ANNUAL SALARY
([+] #sum
(my @as = #assign @as(Annual Salary) to the Contract value divied by the contract length
(
my @data= (slurp 'draftdata.txt').split("\n").map({ [.split(' ')] })
#parse text(split by newline then split each by space
).map(->$_ {$_[1]/$_[0]}) #divide each value by length of contract
)
)/@data.elems #divide the sum by the number of elements (average)
)
~
"\n" #newline (~ is concatenation)
~
 
( #LARGEST ANNUAL SALARY & WHICH ONE IT WAS
([max]@as) #Find the greatest Annual Salary
~ " by #" #going to print out which draft had it
~ (
%( #make the following into a hash (each pair of elements is turned into a key-value pair)
(
@as.kv #makes a list with the index followed by the element
).reverse #reverse this list (the values will be the keys and the indices, values
){[max]@as} #value for the greatest Annual Salary(index of the number in the @as array)
+1) #add one(one based indexing for human readablity)
)
~
"\n"
~
 
( #RANGE OF 16-GAME SEASON SALARIES
([max] #greatest salary
(my @g16s = @as.map(*/16)) #salary per game is the salary per year divided by 16
)
- ([min]@g16s) #minus least salary
)
~
"\n"
~
 
( #MIDRANGE OF 18-SEASON SALARIES
(
([max] #greatest salary
(my @g18s = @as.map(*/18)) #salary per game is the salary per year divided by 18
)
+ ([min]@g18s) #plus least salary
)/2 #divide by two (average)
)
~
"\n"
~
 
( #AVERAGE DIFFERENCE BETWEEN 16 SEASON & 18 SEASON
([+] #sum
(@g16s Z- @g18s) #zip with minus (subtracts element from one from element from the other
)/@g16s.elems #divide by number of elements (average)
)
 
).subst(
:g, /('#'? \d+ \.? \d*)/ #find all instances of an optional pound followed by a number
, {!m/'#'/ ?? round($_*1_000_000) !! $_} #If it doesnt have a # X1_000_000(was in millions)
) #if it does have a #, the only instance of this is
#the number of the largest annual salary, and
#that is not in millions, so leave it alone
; #DONE

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.