Silly Stock Market

APL (Dyalog Extended), 34 32 bytes

⌊{⍺,2⍕+/-⍵}⌸××50ׯ1×\⍤↓1,1+.05××
Monadic × in Dyalog extended for letters corresponds to the casing
¯1 1 ≡ ×'aA'

1+.05×× - 1 + 0.05 times the sign (either 1.05 or 0.95)
1,      - concat 1 to the front
¯1×\⍤↓  - cumulative product and drop the last element
50×     - multiply by 50
××50... - the sign times that
⌊{⍺,2⍕+/-⍵}⌸ - group (dyadic ⌸) by the lowercased input (⌊)
 {⍺,2⍕+/-⍵}  - return the left item (the person) concat their rounded total

-2 thanks to Adám

Try it online!


Java, 277 bytes

class c{public static void main(String[]a){double[]m=new double[26];double s=50;for(byte b:a[0].getBytes()){if(b>=97){m[b-97]+=s;s*=.95;}else{m[b-65]-=s;s*=1.05;}}char g=65;for(double k:m){if(k!=0){System.out.println(g+String.format(java.util.Locale.ENGLISH,"%.2f",k));}g++;}}}

Ungolfed:

class c {
    public static void main(String[]a) {
        double[] m = new double[26];
        double s = 50;
        for(byte b : a[0].getBytes()) {
            if(b>=97) {
                m[b-97]+=s;  
                s*=.95;
            } else {
                m[b-65]-=s;
                s*=1.05;
            }
        }
        char g=65;
        for(double k:m) {
            if(k!=0) {
                System.out.println(g+String.format(java.util.Locale.ENGLISH,"%.2f",k));
            }
            g++;
        }
    }
}

JavaScript (ES7), 145 142 bytes

I can't find a shorter way to round out the results...

x=>[for(c of(i=50,a={},x))(a[d=c.toUpperCase()]=a[d]||0,c<"["?(a[d]-=i,i*=1.05):(a[d]+=i,i*=.95))]&&Object.keys(a).map(k=>[k,a[k].toFixed(2)])

Fun fact: this would only be 101 bytes if not for the rounding requirement:

x=>[for(c of(i=50,a={},x))(a[d=c.toUpperCase()]=a[d]||0,c<"["?(a[d]-=i,i*=1.05):(a[d]+=i,i*=.95))]&&a

Tags:

Code Golf