Skip to content

Instantly share code, notes, and snippets.

@Radvendii
Created March 5, 2012 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Radvendii/1976316 to your computer and use it in GitHub Desktop.
Save Radvendii/1976316 to your computer and use it in GitHub Desktop.
acsl intermediate contest 1 in one line
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment