File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 1+ const fs = require ( "fs" ) ;
2+ const filePath =
3+ process . platform === "linux" ? "/dev/stdin" : "./서정우/input.txt" ;
4+ const input = fs
5+ . readFileSync ( filePath )
6+ . toString ( )
7+ . trim ( )
8+ . split ( "\n" )
9+ . map ( ( el ) => el . trim ( ) ) ;
10+
11+ const number = input [ 0 ] ;
12+ const numbers = number
13+ . slice ( 0 , - 1 )
14+ . split ( "" )
15+ . map ( ( el ) => ( Number . isNaN ( Number ( el ) ) ? el : Number ( el ) ) ) ;
16+ const checkNumber = Number ( number . at ( - 1 ) ) ;
17+ const starIndex = numbers . findIndex ( ( el ) => el === "*" ) ;
18+
19+ const sum = numbers . reduce (
20+ ( acc , cur , idx ) =>
21+ Number . isInteger ( cur ) ? acc + cur * ( idx % 2 === 0 ? 1 : 3 ) : acc ,
22+ 0 ,
23+ ) ;
24+
25+ for ( let i = 0 ; i < 10 ; i ++ ) {
26+ if ( ( sum + i * ( starIndex % 2 === 0 ? 1 : 3 ) + checkNumber ) % 10 === 0 ) {
27+ console . log ( i ) ;
28+ break ;
29+ }
30+ }
Original file line number Diff line number Diff line change 1- 5
2- 300 400 500 400 300
1+ 9788968322*73
You can’t perform that action at this time.
0 commit comments