Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 63b3d1d

Browse files
committedMay 5, 2017
Fix huge numbers in Challenge 8 (now it passes submit case :)
1 parent 9cc67e9 commit 63b3d1d

File tree

5 files changed

+362
-205
lines changed

5 files changed

+362
-205
lines changed
 

‎Challenge 08/output.txt

-200
This file was deleted.

‎Challenge 08/script.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
const fs = require('fs')
44
const input = './submitInput.txt'
5-
const output = './output.txt'
5+
const output = './submitOutput.txt'
6+
const bigInt = require('big-integer')
67
const utf16ToASCII = require('./unicode')
78

89
fs.unlink(output, err => err && console.error(err))
@@ -13,9 +14,12 @@ function stringToHex (s) {
1314
// First, turn the string into decimal numbers
1415
const a = utf16ToASCII(s)
1516
// Second, parse the string to Number
16-
const n = Number(a)
17-
// Third, return the hex version of the number
18-
return isNaN(n) ? 'N/A' : n.toString(16)
17+
try {
18+
// Third, return the hex version of the number
19+
return bigInt(a).toString(16)
20+
} catch (err) {
21+
return 'N/A'
22+
}
1923
}
2024

2125
fs.readFileSync(input, 'utf16le').toString().split('\n').forEach((num, t) => {
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Please sign in to comment.