1.tcl 834 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. set fp [open "input"]
  2. gets $fp line
  3. close $fp
  4. proc is_even {x} {
  5. return [expr {$x % 2 == 0}]
  6. }
  7. proc zero_trim {x} {
  8. for {set i 0} {$i < [expr {[string length $x] - 1}]} {incr i} {
  9. if {[string index $x $i] != 0} {
  10. break
  11. }
  12. }
  13. return [string range $x $i end]
  14. }
  15. proc blink {x} {
  16. if {$x == 0} {
  17. return 1
  18. }
  19. if {[is_even [string length $x]]} {
  20. set len [string length $x]
  21. set halflen [expr {$len / 2}]
  22. return [list [zero_trim [string range $x 0 [expr {$halflen - 1}]]] \
  23. [zero_trim [string range $x $halflen end]]]
  24. }
  25. return [expr {$x * 2024}]
  26. }
  27. set lst $line
  28. for {set i 0} {$i < 25} {incr i} {
  29. set new_lst {}
  30. foreach x $lst {
  31. lappend new_lst {*}[blink $x]
  32. }
  33. set lst $new_lst
  34. }
  35. puts [llength $lst]