Skip to content

Instantly share code, notes, and snippets.

View avanderw's full-sized avatar

Andrew van der Westhuizen avanderw

View GitHub Profile
@avanderw
avanderw / java8-one-liners-for-statistical-properties.md
Created May 14, 2021 08:54 — forked from asela38/java8-one-liners-for-statistical-properties.md
Java 8 One liners for statistical properties : Mean, Mode, Median(Q2), Q1, Q2, Variance, Standard Deviation

While working on a Hacker Rank Problem I wrote few one lines using java stream to find mean, median, mode, Q1, Q3, variance and standard deviation. Thought to share since it's quite interesting.

        // mean
        double mean = list.stream().mapToInt(Integer::intValue).average().getAsDouble();
        System.out.println(mean);
        
        // mode - create count map using group by and sorted with custom comparator to give minimum from competing probable mode values
        Integer mode = list.stream()
                .collect(Collectors.groupingBy(i -> i, () -> new TreeMap<Integer, Long>(), Collectors.counting()))
@avanderw
avanderw / .minttyrc
Last active December 16, 2021 11:18 — forked from inkychris/.minttyrc
Git Bash Theme - Monokai
Font=Consolas
FontHeight=12
FontSmoothing=full
AllowBlinking=yes
Columns=128
Rows=32
PgUpDnScroll=yes
ThemeFile=
Transparency=
BoldAsFont=no