Commit 4c02157 1 parent cdf6c7c commit 4c02157 Copy full SHA for 4c02157
File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ 4022724 951333 0 21633 5857 97 702 6
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+
4
+ def read_lines () -> list [str ]:
5
+ filename = os .path .join (os .path .dirname (os .path .abspath (__file__ )), 'data.txt' )
6
+ with open (filename , "rb" ) as f :
7
+ return [line .decode ("utf-8" ).strip () for line in f .readlines ()]
8
+
9
+
10
+ def blinking (numbers : list [int ], n : int ) -> list [int ]:
11
+ def split (number : int ) -> list [int ]:
12
+ if number == 0 :
13
+ return [1 ]
14
+
15
+ number_str = str (number )
16
+ if len (number_str ) % 2 == 0 :
17
+ half = len (number_str ) // 2
18
+ return [int (number_str [:half ]), int (number_str [half :])]
19
+
20
+ return [number * 2024 ]
21
+
22
+ if n == 0 :
23
+ return numbers
24
+
25
+ new_numbers = []
26
+ for _ , v in enumerate (numbers ):
27
+ new_numbers .extend (split (v ))
28
+
29
+ return blinking (new_numbers , n - 1 )
30
+
31
+
32
+ lines = read_lines ()
33
+ numbers = [int (num ) for num in lines [0 ].split (' ' )]
34
+
35
+ result = blinking (numbers , 25 )
36
+ print (len (result ))
You can’t perform that action at this time.
0 commit comments