@@ -12,6 +12,55 @@ error(message: string) → thrown error
12
12
13
13
export { } ;
14
14
15
- const practice = `` ;
15
+ const practice = `
16
+ 00100
17
+ 11110
18
+ 10110
19
+ 10111
20
+ 10101
21
+ 01111
22
+ 00111
23
+ 11100
24
+ 10000
25
+ 11001
26
+ 00010
27
+ 01010
28
+ ` ;
29
+ // input = practice;
16
30
17
- // input = practice;
31
+
32
+ const itms = input . trim ( ) . split ( '\n' ) ;
33
+
34
+ const num0 = itms [ 0 ] . length . dwth ( log ) ; // 12
35
+ const num1 = ( itms . length ) / 2 ; // 500
36
+
37
+ const codegolf = m => ( q = a => parseInt ( a . join `` , 2 ) , v1 = new Array ( m [ 0 ] . length ) . fill `` . map ( ( _ , i ) => + ( m . reduce ( ( t , a ) => t + ( a [ i ] == 0 ) , 0 ) < m . length / 2 ) ) , v2 = v1 . map ( w => 1 - w ) , q ( v1 ) * q ( v2 ) ) ;
38
+ // const codegolf = m=>(q=a=>parseInt(a.join``,2),v1=new Array(m[0].length).fill``.map((_,i)=>+(m.reduce((t,a)=>t+(a[i]==0),0)<m.length/2)),v2=v1.map(w=>1-w),q(v1)*q(v2));
39
+ // const codegolf = v=>(q=a=>parseInt(a.join``,2),m=v.trim().split`\n`,v1=new Array(m[0].length).fill``.map((_,i)=>+(m.reduce((t,a)=>t+(a[i]==0),0)<m.length/2)),v2=v1.map(w=>1-w),q(v1)*q(v2));
40
+ // const codegolf = v=>(q=a=>parseInt(a.join``,2),m=v.trim().split`\n`,v1=new Array(m[0].length).fill``.map((_,i)=>+(m.reduce((t,a)=>t+(a[i]=="0"),0)<m.length/2)),v2=v1.map(w=>1-w),q(v1)*q(v2));
41
+ // const codegolf = v=>(q=a=>parseInt(a.join``,2),m=v.trim().split`\n`,v1=new Array(m[0].length).fill(0).map((_,i)=>+(m.reduce((t,a)=>t+(a[i]=="0"),0)<m.length/2)),v2=v1.map(w=>1-w),q(v1)*q(v2));
42
+ // const codegolf = v=>(q=a=>parseInt(a.join``,2),m=v.trim().split`\n`,v1=range(m[0].length).map(i=>+(m.reduce((t,a)=>t+(a[i]=="0"),0)<m.length/2)),v2=v1.map(w=>1-w),q(v1)*q(v2));
43
+ // const codegolf = v=>(q=parseInt,m=v.trim().split`\n`,v1=range(m[0].length).map(i=>+(m.reduce((t,a)=>t+(a[i]=="0"),0)<m.length/2)),v2=v1.map(w=>1-w),q(v1.join``,2)*q(v2.join``,2));
44
+ // const codegolf = v=>(m=v.trim().split`\n`,v1=range(m[0].length).map(i=>+(m.reduce((t,a)=>t+(a[i]=="0"),0)<m.length/2)),v2=v1.map(w=>1-w),parseInt(v1.join``,2)*parseInt(v2.join``,2));
45
+ console . log ( codegolf ( input . trim ( ) . split ( "\n" ) ) ) ;
46
+
47
+
48
+ let res : number [ ] = [ ] ;
49
+ range ( itms [ 0 ] . length ) . map ( i => {
50
+ let zeros = 0 ;
51
+ let ones = 0 ;
52
+ itms . forEach ( cv => {
53
+ const c = cv [ i ] ;
54
+ if ( c === "0" ) zeros ++ ;
55
+ else ones ++ ;
56
+ } )
57
+ if ( zeros > ones ) res . push ( 0 ) ;
58
+ else res . push ( 1 ) ;
59
+ } ) ;
60
+
61
+ const ares = res . map ( w => 1 - w ) ;
62
+
63
+ console . log ( parseInt ( res . join ( "" ) , 2 ) * parseInt ( ares . join ( "" ) , 2 ) ) ;
64
+
65
+ res . dwth ( log )
66
+ ares . dwth ( log )
0 commit comments