This ARC task involves ranking vertical columns of 5s by their height. The input grid contains columns of 5s that extend from different starting rows to the bottom. The output replaces each 5 with a color (1-4) based on the column's height rank:
- Color 1: Tallest column (most 5s)
- Color 2: Second tallest
- Color 3: Third tallest
- Color 4: Shortest column
| Generation | Bytes | Score | Key Changes |
|---|---|---|---|
| 0 (initial) | 529 | 1971 | Verbose working solution with comments |
| 1 | 223 | 2277 | Remove comments, single-char variables, compress whitespace |
| 2 | 198 | 2302 | Use zip(*g) to iterate columns, sum for counting |
| 3 | 195 | 2305 | Use c.get instead of lambda for sort key |
| 4 | 189 | 2311 | Merge statements with semicolons |
| 5 | 184 | 2316 | Use (v>0) multiplication trick |
| 6 | 178 | 2322 | Use m[x] instead of m.get(x,0) |
| 7 | 157 | 2343 | Use .index() instead of dict lookup |
| 8 | 156 | 2344 | Use -~ instead of +1 |
| 9 | 150 | 2350 | Remove unnecessary filter (if sum(c)) |
| 10 | 142 | 2358 | Use [*map(sum,zip(*g))] instead of list comprehension |
def solve(g):
c=[*map(sum,zip(*g))];s=sorted(range(len(c)),key=lambda i:-c[i])
return[[v and-~s.index(x)for x,v in enumerate(r)]for r in g]-
[*map(sum,zip(*g))]- Transpose grid and sum columns in one expression (saves bytes over list comprehension) -
-~xinstead ofx+1- Bitwise NOT followed by negation equals increment, saves 1 byte -
v and expr- Short-circuit evaluation returns 0 (falsy) when v=0, otherwise evaluates expr -
sorted(range(len(c)),key=lambda i:-c[i])- Sort indices by column sum descending -
.index(x)+1- Get 1-based rank directly from sorted list position -
Single-character variables -
g,c,s,r,v,xfor maximum compression -
Semicolons - Chain statements on one line to minimize newline overhead
- Transpose the grid using
zip(*g)to get columns - Sum each column (counting 5s, since 0s contribute nothing)
- Sort column indices by their sums in descending order
- For each cell: if value is non-zero, look up its column's rank (index+1)