Skip to content

Latest commit

 

History

History
78 lines (61 loc) · 2.82 KB

File metadata and controls

78 lines (61 loc) · 2.82 KB

ARC Task 09629e4f - Code Golf Evolution

Task Description

Pattern: Fill grid segments (Medium)

The 11x11 grid is divided into a 3x3 grid of 3x3 segments by separator lines (rows 3, 7 and columns 3, 7 filled with value 5). One segment is the "key" segment containing exactly 5 unique values (including 0). The key segment acts as a template: for each non-zero value at position (r,c) in the key, fill segment (r,c) with that value. Segments not mapped in the key are filled with 0.

Champion Solution

170 bytes | Score: 2330

solve=lambda g,R=range:[[(5,[y for a in R(9)if 6>len({*(y:=[g[a//3*4+i][a%3*4+j]for i in R(3)for j in R(3)])})][0][i//4*3+j//4])[i%4<3>j%4]for j in R(11)]for i in R(11)]

Evolution Log

Generation 0 (Initial)

1137 bytes | Score: 1363

  • Basic implementation with explicit loops and comments
  • Full variable names, verbose structure

Generation 1

526 bytes | Score: 1974

  • Removed comments, shortened variable names
  • Combined nested loops where possible

Generation 2

400 bytes | Score: 2100

  • Used single index with //3 and %3 for segment iteration
  • Flattened segment value collection

Generation 3

333 bytes | Score: 2167

  • Used set unpacking {*s} instead of set(x for x in s if x)
  • Simplified key segment storage to flat list

Generation 4

235 bytes | Score: 2265

  • Combined output generation into single list comprehension
  • Used conditional expression for separator handling

Generation 5

208 bytes | Score: 2292

  • Reduced indentation (1 space)
  • Removed unnecessary variable assignments

Generation 6

204 bytes | Score: 2296

  • Used tuples (0,1,2) instead of range(3) for inner loops

Generation 7

202 bytes | Score: 2298

  • Changed condition to 5>len({*s}-{0}) format

Generation 8

199 bytes | Score: 2301

  • Used tuple indexing [s[...],5][condition] instead of ternary

Generation 9

195 bytes | Score: 2305

  • Discovered chained comparison i%4<3>j%4 for condition

Generation 10

170 bytes | Score: 2330

  • Key insight: key segment has 5 unique values total (4 non-zero + 0)
  • Changed condition to 6>len({*y}) (simpler than -{0})
  • Converted to single lambda expression
  • Used default argument R=range for repeated range calls
  • Inlined key segment detection into list comprehension

Key Golf Techniques Used

  1. Lambda conversion: def solve(g): -> solve=lambda g:
  2. Default arg aliasing: R=range saves bytes on repeated calls
  3. Chained comparisons: i%4<3>j%4 is shorter than i%4<3 and j%4<3
  4. Tuple indexing: (a,b)[condition] instead of b if condition else a
  5. Walrus operator: := to capture values in comprehensions
  6. Set unpacking: {*list} instead of set(list)
  7. Condition simplification: Counting total unique values (6) instead of non-zero unique values (5)