Libraryless. Click here for Pure Java version (9244L/51K).
1 | // you should not overflow in the sum... |
2 | static long longAverage(long... a) {
|
3 | long sum = 0; |
4 | for i over a: |
5 | sum += a[i]; |
6 | ret ldiv_round(sum, l(a)); |
7 | } |
8 | |
9 | static long longAverage(Iterable<Long> l) {
|
10 | long sum = 0; |
11 | long n = 0; |
12 | fOr (Long i : l) |
13 | if (i != null) { sum += i; ++n; }
|
14 | ret ldiv_round(sum, n); |
15 | } |
Began life as a copy of #1010188
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1036051 |
| Snippet name: | longAverage |
| Eternal ID of this version: | #1036051/2 |
| Text MD5: | e859b6c2c599d9e7fd9e8db235a404e5 |
| Transpilation MD5: | f598d78d6ed1a842c2273e90f980ab0c |
| Author: | stefan |
| Category: | javax / maths |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-09-03 02:06:49 |
| Source code size: | 331 bytes / 15 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 420 / 547 |
| Version history: | 1 change(s) |
| Referenced in: | [show references] |