| Bytes | Lang | Time | Link |
|---|---|---|---|
| 041 | AWK | 250401T190239Z | xrs |
| 040 | Arturo | 230121T163523Z | chunes |
| 036 | Factor + math.unicode | 230121T155857Z | chunes |
| 010 | Japt | 180502T182044Z | Shaggy |
| 027 | Julia 0.6 | 180702T143435Z | Sundar R |
| 033 | Excel | 180503T110112Z | Wernisch |
| 065 | Ruby | 180509T235648Z | lfvt |
| 010 | MATL | 180503T180239Z | DJMcMayh |
| 033 | Excel | 180503T145000Z | dissemin |
| 025 | TIBasic | 180503T130521Z | Timtech |
| 046 | Clojure | 180503T072437Z | NikoNyrh |
| 016 | J | 180503T082820Z | Galen Iv |
| 057 | Java 8 | 180503T070537Z | Kevin Cr |
| 014 | K4 / K oK | 180502T202452Z | mkst |
| 014 | Charcoal | 180502T203829Z | Neil |
| 033 | Octave | 180502T195310Z | Luis Men |
| 013 | APL+WIN | 180502T171125Z | Graham |
| 008 | Stax | 180502T172708Z | wastl |
| 028 | R+pryr | 180502T165247Z | JayCe |
| 028 | Perl 5 pa | 180502T173604Z | Xcali |
| 006 | Stax | 180502T172905Z | Khuldrae |
| 049 | Triangularity | 180502T171602Z | Mr. Xcod |
| 049 | JavaScript Node.js | 180502T164245Z | DanielIn |
| 035 | Haskell | 180502T165127Z | Angs |
| 038 | Python 3 | 180502T170843Z | Dennis |
| 007 | 05AB1E | 180502T164340Z | Emigna |
| 006 | Husk | 180502T170641Z | Mr. Xcod |
| 007 | Jelly | 180502T165757Z | Dennis |
| 009 | Jelly | 180502T164044Z | Mr. Xcod |
AWK, 41 bytes
{for(i=0;i++<NF;)x+=$i*NR}END{print x/70}
{ # run each line
for(i=0; # reset to zero each row
i++<NF;) # each element of row
x+=$i*NR # number times row number added to sum
} # at end of line
END{ # when no more rows
print x/70}
Japt, 11 10 bytes
xÈ/#F*ÒYz7
Explanation
È :Pass each element at index Y through a function
/#F : Divide by 70
Yz7 : Floor divide Y by 7
Ò : Negate the bitwise NOT of that to add 1
* : Multiply both results
x :Reduce by addition
Julia 0.6, 27 bytes
p->repeat(1:4,inner=7)'p/70
The repeat call forms a column matrix of 28 values, containing seven 1's, then seven 2's, etc. We then transpose it with ', then do a matrix multiplication with the input (mutiplication is implicit here). Since it's a matrix multiplication of a 1x28 matrix with a 28x1 matrix, we end up with a single value, which is the weighted sum we need. Divide that by 70 to get our weighted mean.
Excel, 36 33 bytes
-3 bytes thanks to @tsh.
=SUM(1:1,H1:AB1,O1:AB1,V1:AB1)/70
Input in first row (A1 to AB1).
MATL, 10 bytes
7es4:*s70/
I haven't posted a MATL answer in ages! Figured I might participate as part of LOTM May 2018!
Explanation:
7e % Reshape the array into 7 rows (each week is one column)
s % Sum each column
4: % Push [1 2 3 4]
* % Multiply each columnar sum by the corresponding element in [1 2 3 4]
s % Sum this array
70/ % Divide by 70
Excel: 33 bytes
(3 bytes saved from @wernisch's answer by running data on 2 lines from A1:N1 and A2:N2)
=AVERAGE(A1:N2,H1:N2,A2:N2,H2:N2)
Apologies for not including this as a comment. I don't have enough reputation to do so.
TI-Basic, 25 bytes
mean(Ansseq(sum(I>{0,7,21,42}),I,1,70
Alternate solution, 39 bytes
Input L1
For(I,1,70
Ans+L1(I)sum(I>{0,7,21,42
End
Ans/70
Clojure, 48 46 bytes
#(/(apply +(for[i[0 7 14 21]v(drop i %)]v))70)
This ended up being shorter than mapcat + subvec combination.
J, 16 bytes
70%~1#.]*7#4{.#\
Explanation:
#\ finds the lengths of all successive prefixes (1 2 3 4 ... 28)
4{. takes the first 4 items (1 2 3 4)
7# creates 7 copies of each element of the above list
]* multiplies the input by the above
1#. sum
70%~ divide by 70
Java 8, 57 bytes
a->{int r=0,i=35;for(;i-->7;)r+=i/7*a[i-7];return r/70d;}
Explanation:
a->{ // Method with integer-array parameter and double return-type
int r=0, // Result-sum, starting at 0
i=35; // Index-integer, starting at 35
for(;i-->7;) // Loop `i` downwards in the range (35,7]
r+= // Add the following to the result-sum:
i/7 // `i` integer-divided by 7,
*a[i-7]; // multiplied by the item at index `i-7`
return r/70d;} // Return the result-sum, divided by 70.0
K4 / K (oK), 19 16 14 bytes
Solution:
+/(1+&4#7)%70%
Example:
+/(1+&4#7)%70%50 50 50 50 50 50 50 10 10 10 10 10 10 10 50 50 50 50 50 50 50 50 50 50 50 50 50 50
42
Explanation:
Evaluation is perform right-to-left. Divide 7 1s, 7 2s, 7 3s and 7 4s by 70 divided by the input; then sum up.
+/(1+&4#7)%70% / the solution
70% / 70 divided by the input
( )% / the stuff in brackets divided by this...
4#7 / draw from 7, 4 times => 7 7 7 7
& / 'where' builds 7 0s, 7 1s, 7 2s, 7 3s
1+ / add one
+/ / sum (+) over (/) to get the total
Charcoal, 14 bytes
I∕ΣE⪪A⁷×Σι⊕κ⁷⁰
Try it online! Link is to verbose version of code. Explanation:
A Input array
⪪ ⁷ Split into subarrays of length 7
E Loop over each subarray
ι Subarray
Σ Sum
κ Loop index
⊕ Incremented
× Product
Σ Sum results
⁷⁰ Literal 70
∕ Divide
I Cast to string
Implicitly print
APL+WIN, 13 bytes
Prompts for array as a vector of integers:
(+/⎕×7/⍳4)÷70
Explanation:
7/⍳4) create a vector comprising 7 1s, 7 2s, 7 3s and 7 4s
+/⎕× prompt for input, multiply by the vector above and sum result
(....)÷70 divide the above sum by 70
Stax, 10 8 bytes
äΔ6◙█µøΓ
Explanation (unpacked):
7/4R:B$:V Full program, implicit input
7/ Split into parts of length 7
4R Push [1, 2, 3, 4]
:B Repeat each element the corresponding number of times
$ Flatten
:V Average
R+pryr, 32 28 bytes
and the same average score week over week would result in equality of the means.
pryr::f(s%*%rep(1:4,e=7)/70)
Saved 4 bytes by using dot product thanks to Giuseppe.
Pure R would have two more bytes using function
Perl 5 -pa, 28 bytes
$\+=$_/70*int$i++/7+1for@F}{
Input is space separated rather than comma separated.
Stax, 6 bytes
ñI"%"╟
Run and debug it at staxlang.xyz!
Unpacked (7 bytes) and explanation:
7/|]$:V
7/ Split into groups of seven.
|] Suffixes
$:V Flatten and average. Implicit print as fraction.
Triangularity, 49 bytes
....)....
...D7)...
..14)21..
.WM)IEtu.
}u)70s/..
Explanation
)D7)14)21WM)IEtu}u)70s/ – Full program.
)D7)14)21 – Push the literals 0, 7, 14, 21 onto the stack.
WM } – Wrap the stack to a list and run each element on a separate
stack, collecting the results in a list.
)IEt – Crop the elements of the input before those indices.
u – Sum that list.
u – Then sum the list of sums.
)70 – Push the literal 70 onto the stack.
s/ – Swap and divide.
JavaScript (Node.js), 49 bytes
a=>a.map((x,i)=>(I+=d=-~(i/7),s+=x*d),s=I=0)&&s/I
Non generics solution
JavaScript (Node.js), 39 36 bytes
a=>a.reduce((s,x,i)=>s+x*-~(i/7))/70
Haskell, 35 bytes
(/70).sum.zipWith(*)([1..]<*[1..7])
Bonus: if a,b,c,d are the weekly sums, normal average is the same as weighted average iff:
(a + b + c + d)/4 = (a + 2b + 3c + 4d)/10 <=>
10(a + b + c + d) = 4(a + 2b + 3c + 4d) <=>
5(a + b + c + d) = 2(a + 2b + 3c + 4d) <=>
5a + 5b + 5c + 5d = 2a + 4b + 6c + 8d <=>
3a + b - c - 3d = 0
One solution is when first and last week have same sums, and likewise second and third weeks have the same sum, but there are infinitely many solutions if your biceps are up to it. Example: [15,10,10,10,10,10,5,20,20,20,25,25,20,20,30,20,20,20,20,20,20,10,10,20,0,10,10,10]
05AB1E, 8 7 bytes
Saved 1 byte thanks to Mr. Xcoder
7ô.s˜ÅA
Explanation
7ô # split list into groups of 7
.s # push suffixes
˜ # flatten
ÅA # arithmetic mean
Husk, 6 bytes
AΣΣṫC7
Uses the trick Dennis used to outgolf my Jelly submission. Instead of repeating each chunk N times, it retrieves the suffixes of the list of chunks, which after flattening will yield the same result, except for the order.
Jelly, 7 bytes
s7ṫJFÆm
How it works
s7ṫJFÆm Main link. Argument: A (array of length 28)
s7 Split the array into chunks of length 7.
J Indices; yield [1, ..., 28].
ṫ Tail; yield the 1st, ..., 28th suffix of the result to the left.
Starting with the 5th, the suffixes are empty arrays.
F Flatten the resulting 2D array.
Æm Take the arithmetic mean.
Jelly, 9 bytes
s7x"J$FÆm
How it works
s7x"J$FÆm – Takes input from the first command line argument and outputs to STDOUT.
s7 – Split into groups of 7.
" – Apply vectorised (zipwith):
x J$ – Repeat the elements of each list a number of times equal to the list's index.
F – Flatten.
Æm – Arithmetic mean.