Skip to content

Instantly share code, notes, and snippets.

View shailesh's full-sized avatar
🌱

Shailesh Singh shailesh

🌱
View GitHub Profile
@shailesh
shailesh / friends.json
Created June 29, 2017 09:17
I have some friends records in a text file (friends.json) -- one friend per line, JSON-encoded. I want to invite any friends within 100km of our Bangalore office which is almost like our home (GPS coordinates 12.9611159,77.6362214) for some food and drinks on us. Write a program that will read the full list of friends and output the names and us…
{"latitude": "12.986375", "user_id": 12, "name": "Chris", "longitude": "77.043701"}
{"latitude": "11.92893", "user_id": 1, "name": "Alice", "longitude": "78.27699"}
{"latitude": "11.8856167", "user_id": 2, "name": "Ian", "longitude": "78.4240911"}
{"latitude": "12.3191841", "user_id": 3, "name": "Jack", "longitude": "78.5072391"}
{"latitude": "13.807778", "user_id": 28, "name": "Charlie", "longitude": "76.714444"}
{"latitude": "13.4692815", "user_id": 7, "name": "Frank", "longitude": "-9.436036"}
{"latitude": "14.0894797", "user_id": 8, "name": "Eoin", "longitude": "77.18671"}
{"latitude": "13.038056", "user_id": 26, "name": "Stephen", "longitude": "76.613889"}
{"latitude": "14.1225", "user_id": 27, "name": "Enid", "longitude": "78.143333"}
{"latitude": "13.1229599", "user_id": 6, "name": "Theresa", "longitude": "77.2701202"}
@shailesh
shailesh / sol.rb
Last active June 29, 2017 04:56
This will print three elements in an array whose sum is equal to an existing array
arr = [1, 2, 4, 10, 90, 302, 312, 500]
(2..arr.count).each do |len|
arr.combination(len).each do |comb|
sum = comb.inject(:+)
if arr.include? sum
puts (comb << sum).inspect
end
end
end
from setuptools import setup
# reading long description from file
with open('DESCRIPTION.txt') as file:
long_description = file.read()
# specify requirements of your package here
REQUIREMENTS = ['requests']
var minimax = function (depth, game, isMaximisingPlayer) {
if (depth === 0) {
return -evaluateBoard(game.board());
}
var newGameMoves = game.ugly_moves();
if (isMaximisingPlayer) {
var bestMove = -9999;
for (var i = 0; i < newGameMoves.length; i++) {
game.ugly_move(newGameMoves[i]);
bestMove = Math.max(bestMove, minimax(depth - 1, game, !isMaximisingPlayer));
var calculateBestMove = function (game) {
var newGameMoves = game.ugly_moves();
var bestMove = null;
//use any negative large number
var bestValue = -9999;
for (var i = 0; i < newGameMoves.length; i++) {
var newGameMove = newGameMoves[i];
game.ugly_move(newGameMove);
var calculateBestMove =function(game) {
//generate all the moves for a given position
var newGameMoves = game.ugly_moves();
return newGameMoves[Math.floor(Math.random() * newGameMoves.length)];
};
#include <cstdio>
#include <vector>
using namespace std;
#define root 0
#define N 10100
#define LN 14
vector <int> adj[N], costs[N], indexx[N];
int baseArray[N], ptr;