Mars Exploration

  • + 0 comments

    My answer in Typescript, simple, not minimized

    const SOS = (l: number) => 'SOS'.repeat(l);
    const SBD = (l: number, cb: (i: number) => string) => Array(l).fill('').map((_, i) => cb(i)).join('');
    function marsExploration(s: string): number {
        let recieved_signal = s;
        let expected_signal = SOS(s.length / 3);
        let differen_signal = SBD(s.length, i => recieved_signal[i] != expected_signal[i] ? 'X' : ' ');
    
        console.log('Expected signal:', expected_signal)
        console.log('Recieved signal:', recieved_signal)
        console.log('Difference:     ', differen_signal)
    
        return differen_signal.split('').reduce((p, c) => c == 'X' ? p + 1 : p, 0)
    }