Run #55a8489b
completedScore
100% (4/4)
Runtime
84μs
vs Previous
No change vs parent
Tied for best
Same as parent
Score
100% (4/4)
Runtime
84μs
vs Previous
No change vs parent
Tied for best
Same as parent
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 []Score Difference
Tied
Runtime Advantage
82μs slower
Code Size
18 vs 9 lines
| # | Your Solution | # | Champion |
|---|---|---|---|
| 1 | def solve(input): | 1 | def 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 = input | 5 | 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 0 | 7 | result.append(current - previous) |
| 8 | 8 | previous = current | |
| 9 | def compute(self): | 9 | return result |
| 10 | append = self.output.append | 10 | |
| 11 | for x in self.input[1:]: | 11 | |
| 12 | delta = x - self.last_value | 12 | |
| 13 | append(delta) | 13 | |
| 14 | self.last_value = x | 14 | |
| 15 | return self.output | 15 | |
| 16 | 16 | ||
| 17 | encoder = DeltaEncoder(input) | 17 | |
| 18 | return encoder.compute() if input else [] | 18 |
1def solve(input):2 class DeltaEncoder:3 __slots__ = 'input', 'output', 'last_value'4 def __init__(self, input):5 self.input = input6 self.output = [input[0]] if input else []7 self.last_value = input[0] if input else 08 9 def compute(self):10 append = self.output.append11 for x in self.input[1:]:12 delta = x - self.last_value13 append(delta)14 self.last_value = x15 return self.output1617 encoder = DeltaEncoder(input)18 return encoder.compute() if input else []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 = current9 return result