Skip to content

Instantly share code, notes, and snippets.

@el0911
Last active June 13, 2019 18:49
Show Gist options
  • Save el0911/e8bce66c2d0aae01562308d4df743302 to your computer and use it in GitHub Desktop.
Save el0911/e8bce66c2d0aae01562308d4df743302 to your computer and use it in GitHub Desktop.
createDataSet=(maxNum)=>{
let inputs = []
let targets = []
for(let i = 0 ;i<=maxNum;i++){
let binarry = (i).toString(2)
if (binarry.length>10){
throw 'this number has a binary representation longer than 10'
return -1
console.log('this number has a binary representation longer than 10')
}
if(binarry.length!=10){
const remain = 10 - binarry.length
for (let j = 0;j<remain;j++){
binarry = '0'+binarry
}
}
inputs.push(binarry.split('').map(Number))
if(i%2==0){
//even number
targets.push(1)
}else{
targets.push(0)
}
}
return {inputs,targets}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment