<commit_before>// Modules
var range  = require( 'range' ).range;
var prompt = require( 'prompt' );

// // Find the cube root of a perfect cube
// prompt.start();
// prompt.get([
//   {
//     name        : 'x',
//     description : 'Enter a interger'
//   }
// ], function( err, results ) {

//   var x   = parseInt( results.x, 10 );
//   var ans = 0;

//   while ( Math.pow( ans, 3 ) < Math.abs( x )) {

//     ans += 1;
//     console.log( 'Current guess:', ans );

//   }

//   if ( Math.pow( ans, 3 ) !== Math.abs( x )) {

//     console.log( x, 'is not a perfect cube' );
  
//   } else {

//     if ( x < 0 ) {
//       ans = -ans;
//     }

//     console.log( 'Cube root of ' + x.toString() + ' is ' + ans.toString());

//   }

// });

// Find the cube root of a perfect cube
prompt.start();
prompt.get([
  {
    name        : 'x',
    description : 'Enter a interger'
  }
], function( err, results ) {

  var x = parseInt( results.x, 10 );
  var ans;

  for ( ans in range( 0, Math.abs( x ) + 1 )) {

    if ( Math.pow( ans, 3 ) === Math.abs( x )) {
      break;
    }

  }

  if ( Math.pow( ans, 3 ) !== Math.abs( x )) {

    console.log( x + ' is not a perfect cube' );

  } else {

    console.log( 'Cube root of ' + x.toString() + ' is ' + ans.toString());

  }

});<commit_msg>Find closest number to be a square root of another number - brute force<commit_after>// Modules
var range  = require( 'range' ).range;
var prompt = require( 'prompt' );

// // Find the cube root of a perfect cube
// prompt.start();
// prompt.get([
//   {
//     name        : 'x',
//     description : 'Enter a interger'
//   }
// ], function( err, results ) {

//   var x   = parseInt( results.x, 10 );
//   var ans = 0;

//   while ( Math.pow( ans, 3 ) < Math.abs( x )) {

//     ans += 1;
//     console.log( 'Current guess:', ans );

//   }

//   if ( Math.pow( ans, 3 ) !== Math.abs( x )) {

//     console.log( x, 'is not a perfect cube' );
  
//   } else {

//     if ( x < 0 ) {
//       ans = -ans;
//     }

//     console.log( 'Cube root of ' + x.toString() + ' is ' + ans.toString());

//   }

// });

// // Find the cube root of a perfect cube
// prompt.start();
// prompt.get([
//   {
//     name        : 'x',
//     description : 'Enter a interger'
//   }
// ], function( err, results ) {

//   var x = parseInt( results.x, 10 );
//   var ans;

//   for ( ans in range( 0, Math.abs( x ) + 1 )) {

//     if ( Math.pow( ans, 3 ) === Math.abs( x )) {
//       break;
//     }

//   }

//   if ( Math.pow( ans, 3 ) !== Math.abs( x )) {

//     console.log( x + ' is not a perfect cube' );

//   } else {

//     console.log( 'Cube root of ' + x.toString() + ' is ' + ans.toString());

//   }

// });

// Find closest number to be a square root of another number
var x          = 25;
var epsilon    = 0.01;
var numGuesses = 0;
var ans        = 0;

while ( Math.abs( Math.pow( ans, 2 ) - x ) >= epsilon && ans <= x ) {

  ans += 0.00001;
  numGuesses += 1;

}

console.log( 'numGuesses: ' + numGuesses );

if ( Math.abs( Math.pow( ans, 2 ) - x >= epsilon )) {
  console.log( 'Failed on square root of ' + x.toString());
} else {
  console.log( ans.toString() + ' is close to square root of ' + x.toString());
}
{'fraction_non_alphanumeric': 0.2076587795765878, 'fraction_numerical': 0.013075965130759652, 'mean_word_length': 1.7674418604651163, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1118636', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1172, 'n_words': 351}