add 2021
This commit is contained in:
BIN
2021/01/first
Executable file
BIN
2021/01/first
Executable file
Binary file not shown.
21
2021/01/first.go
Normal file
21
2021/01/first.go
Normal file
@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func checkErr(e error) {
|
||||
if e!=nil{
|
||||
panic(e)
|
||||
}
|
||||
}
|
||||
func main(){
|
||||
numbers := getNumbers("numbers")
|
||||
|
||||
}
|
||||
func getNumbers(filename string)[]byte{
|
||||
dat, err := os.ReadFile(filename)
|
||||
checkErr(err)
|
||||
return dat
|
||||
}
|
8
2021/01/first.js
Normal file
8
2021/01/first.js
Normal file
@ -0,0 +1,8 @@
|
||||
import fs from 'fs'
|
||||
let input = fs.readFileSync('numbers',{encoding:"utf8"}).split('\n')
|
||||
let result = 0
|
||||
for (let i = 1; i < input.length; i++) {
|
||||
if (Number(input[i]) >= Number(input[i - 1]))
|
||||
result++
|
||||
}
|
||||
console.log(result)
|
2000
2021/01/numbers
Normal file
2000
2021/01/numbers
Normal file
File diff suppressed because it is too large
Load Diff
11
2021/01/package.json
Normal file
11
2021/01/package.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "01",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"type":"module",
|
||||
"scripts": {
|
||||
"first": "node first.js",
|
||||
"second": "node second.js"
|
||||
}
|
||||
}
|
11
2021/01/second.js
Normal file
11
2021/01/second.js
Normal file
@ -0,0 +1,11 @@
|
||||
import fs from 'fs'
|
||||
let input = fs.readFileSync('numbers',{encoding:"utf8"}).split('\n').map(x=>Number(x))
|
||||
|
||||
let result = 0
|
||||
let sums = []
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
sums.push(input[i] + input[i + 1] + input[i + 2])
|
||||
if (sums[sums.length-1] > sums[sums.length - 2])
|
||||
result++
|
||||
}
|
||||
console.log(result)
|
Reference in New Issue
Block a user