Run #55a8489b

completed

Score

100% (4/4)

Runtime

84μs

vs Previous

No change vs parent

Tied for best

Same as parent

Solution Lineage

Current100%Same as parent
14f29bb0100%Same as parent
1fa01a21100%Same as parent
5ebb440a100%Same as parent
0d4c6e1a100%Same as parent
fc388e08100%Same as parent
9a85cf4c100%Same as parent
2247f12d100%Same as parent
e4ad5402100%Same as parent
55eba166100%Same as parent
3262d2b3100%Same as parent
bdddb255100%Same as parent
847619c7100%Same as parent
2719fc90100%Same as parent
1e36bda9100%Same as parent
380ea5f5100%Same as parent
22f02144100%Same as parent
97e89d33100%Same as parent
7aa61938100%Same as parent
bf3cc7cb100%Same as parent
1b0022fa100%Same as parent
a0476361100%Same as parent
63d9b382100%Same as parent
ade5d889100%Same as parent
67a62c16100%Same as parent
a8d34455100%Same as parent
66bab92d100%Same as parent
f7e21609100%Same as parent
037f37f8100%Same as parent
a6d896e8100%Same as parent
fc7ff349100%Same as parent
24759bcd100%Same as parent
1cf986ba100%Same as parent
0d24334d100%Same as parent
c804fcd2100%Same as parent
d0345072100%Same as parent
3a42fee5100%Same as parent
6da7503c100%Same as parent
a7c4355f100%Same as parent
6160708a100%Same as parent
a7a1adf7100%Same as parent
c262f05a100%Same as parent
f487bb71100%Same as parent
98562a4d100%Same as parent
77eb4eed100%Same as parent
b98ae242100%Same as parent
38172ecc100%Same as parent
e69a69b3100%Same as parent
0faf3ad8100%Same as parent
6fcaaa43100%Same as parent
ff05f018100%Same as parent
b1c7402a100%Same as parent
c771a435100%Same as parent
a26ef9a4100%Same as parent
2402e846100%Same as parent
fd4d992d100%Improved from parent
43aa7f6425%Regression from parent
8526c232100%Same as parent
bbb94a82100%Same as parent
1aeefd0e100%Same as parent
7b1e508d100%Same as parent
3933d6fd100%Same as parent
ab373fe2100%Same as parent
72e0a3dd100%Same as parent
ef8ec475100%Same as parent
7774af03100%Same as parent
1906c4f0100%Same as parent
a881520b100%Same as parent
ff533f20100%Improved from parent
c07852e925%Regression from parent
6c4e319f100%Same as parent
0139cffd100%Same as parent
5fd7278e100%Same as parent
2fac06cd100%First in chain

Code

def solve(input):
    class DeltaEncoder:
        __slots__ = 'input', 'output', 'last_value'
        def __init__(self, input):
            self.input = input
            self.output = [input[0]] if input else []
            self.last_value = input[0] if input else 0
        
        def compute(self):
            append = self.output.append
            for x in self.input[1:]:
                delta = x - self.last_value
                append(delta)
                self.last_value = x
            return self.output

    encoder = DeltaEncoder(input)
    return encoder.compute() if input else []

Compare with Champion

Score Difference

Tied

Runtime Advantage

82μs slower

Code Size

18 vs 9 lines

#Your Solution#Champion
1def solve(input):1def solve(input):
2 class DeltaEncoder:2 if not input:
3 __slots__ = 'input', 'output', 'last_value'3 return []
4 def __init__(self, input):4 result = [input[0]]
5 self.input = input5 previous = input[0]
6 self.output = [input[0]] if input else []6 for current in input[1:]:
7 self.last_value = input[0] if input else 07 result.append(current - previous)
8 8 previous = current
9 def compute(self):9 return result
10 append = self.output.append10
11 for x in self.input[1:]:11
12 delta = x - self.last_value12
13 append(delta)13
14 self.last_value = x14
15 return self.output15
1616
17 encoder = DeltaEncoder(input)17
18 return encoder.compute() if input else []18
Your Solution
100% (4/4)84μs
1def solve(input):
2 class DeltaEncoder:
3 __slots__ = 'input', 'output', 'last_value'
4 def __init__(self, input):
5 self.input = input
6 self.output = [input[0]] if input else []
7 self.last_value = input[0] if input else 0
8
9 def compute(self):
10 append = self.output.append
11 for x in self.input[1:]:
12 delta = x - self.last_value
13 append(delta)
14 self.last_value = x
15 return self.output
16
17 encoder = DeltaEncoder(input)
18 return encoder.compute() if input else []
Champion
100% (4/4)2μs
1def solve(input):
2 if not input:
3 return []
4 result = [input[0]]
5 previous = input[0]
6 for current in input[1:]:
7 result.append(current - previous)
8 previous = current
9 return result