Skip to content

Instantly share code, notes, and snippets.

View Mr-Kumar-Abhishek's full-sized avatar

Abhishek Kumar Mr-Kumar-Abhishek

View GitHub Profile
@Mr-Kumar-Abhishek
Mr-Kumar-Abhishek / gridland.c
Created October 13, 2016 17:28
Gridland metro algorithm
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
void get_meta(long int* meta_data){
// getting the meta data of the problem
for (long int i = 0; i < 3; i++){
scanf("%ld", &meta_data[i]);
@Mr-Kumar-Abhishek
Mr-Kumar-Abhishek / two_char.c
Created October 13, 2016 17:25
Two characters algorithm
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
char get_min (char* u, char* s){
@Mr-Kumar-Abhishek
Mr-Kumar-Abhishek / Sock-merchant.c
Created October 13, 2016 17:21
Sock Merchant algorithm
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
int n;
function findElement(arr, func) {
var num;
for(var i = 0; i < arr.length; i++){
if(func(arr[i])) { return arr[i]; }
}
return num;
}
findElement([1, 2, 3, 4], function(num){ return num % 2 === 0; });
@Mr-Kumar-Abhishek
Mr-Kumar-Abhishek / scm.js
Created October 13, 2016 17:12
smallest comman multiple
function LCM(a, b){
var min;
var max;
var maxmul = 1;
var minmul = 1;
// just in case...
if(a > b){
max = a;
min = b;
@Mr-Kumar-Abhishek
Mr-Kumar-Abhishek / sum-prime.js
Created October 13, 2016 17:11
sum all prime numbers
function checkPrime(num){
for(var i = 2; i < num-1; i++){
if(num%i === 0){
return false;
}
}
return true;
}
function sumPrimes(num) {
@Mr-Kumar-Abhishek
Mr-Kumar-Abhishek / sum-odd-fibonacci.js
Created October 13, 2016 17:10
Sum all odd fibonacci numbers
function sumFibs(num){
var sum = 0;
var first = 0;
var second = 1;
var total = 0;
while(second <= num){
first = second;
if (first%2 == 1){
total = total + first;
}
function convertHTML(str) {
// &colon;&rpar;
//replacing &
str = str.replace(/&/g, '&amp;').replace(/</g,'&lt;').replace(/>/g, '&gt;')
.replace(/"/g,'&quot;').replace(/'/g, '&apos;');
return str;
}
@Mr-Kumar-Abhishek
Mr-Kumar-Abhishek / convert-html-entity.js
Created October 13, 2016 17:08
convert html entities
function convertHTML(str) {
// &colon;&rpar;
//replacing &
str = str.replace(/&/g, '&amp;').replace(/</g,'&lt;').replace(/>/g, '&gt;')
.replace(/"/g,'&quot;').replace(/'/g, '&apos;');
return str;
}
function uniteUnique(arr) {
var args = Array.from(arguments);
var unique = [];
for(var i = 0; i < args.length; i++){
for (var j = 0; j < args[i].length; j++){
var flag = 0;
for(var k = 0; k < unique.length; k++){
if(args[i][j] == unique[k]){