Skip to content

Instantly share code, notes, and snippets.

@laxman954
Created April 3, 2019 12:13
Show Gist options
  • Save laxman954/748a1a5202ca679a32cb301fc8c66c75 to your computer and use it in GitHub Desktop.
Save laxman954/748a1a5202ca679a32cb301fc8c66c75 to your computer and use it in GitHub Desktop.
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<h3>Find House Number </h3>
<quote>
A certain street has houses in a row, numbered 1, 2, 3, 4, … consecutively. There is a certain house on the street such that the sum of all the house numbers to the left side of it is equal to the sum of all the house numbers to its right. Find the number of this house.?,
</quote>
<br />
<div id="status">
</div>
<button id="stop">Stop</button> &nbsp;&nbsp; <button id="start">Start</button> <br /> <br />
<div id="number">
</div>
</body>
<script>
var interval;
$(document).ready(function(){
var i = 2;
interval = setInterval(findNumber,10);
function findNumber(){
var number = Math.sqrt( ( i*(i+1) ) / 2 );
$("#status").html("<h4>Finding for number " + i + " and result is "+number+"</h4>");
if(number % 1 == 0){
$('#number').append("For Total house of "+ i +" house number is - " +number + "<br />");
}
i++;
}
$("#stop").click(function(){
clearInterval(interval);
return false;
});
$("#start").click(function(){
interval = setInterval(findNumber,10);
return false;
});
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment