Skip to content

Instantly share code, notes, and snippets.

@ebedkm
ebedkm / Missing Integer
Created June 16, 2015 06:45
Filter, Sorting, Check
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A) {
// write your code in C++11
vector<int> keep;
for(vector<int>::iterator it=A.begin(); it!= A.end() ; ++it){
@ebedkm
ebedkm / Drag Number
Last active August 24, 2016 07:41
Drag and Drop Event HTML 5
<!DOCTYPE HTML>
<html>
<head>
<style>
#div1 {width:70px;height:70px;padding:10px;border:1px solid #aaaaaa;}
#div2 {width:70px;height:70px;padding:10px;border:1px solid #aaaaaa;}
#div3 {width:70px;height:70px;padding:10px;border:1px solid #aaaaaa;}
#div4 {width:70px;height:70px;padding:10px;border:1px solid #aaaaaa;}
@ebedkm
ebedkm / Tester
Last active August 29, 2015 14:05
Simple Regex Tester with PHP & AJAX
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Regex Tester</title>
<!-- Bootstrap -->
@ebedkm
ebedkm / Codility Lesson: FrogRiverOne
Created August 18, 2014 11:29
Counting Element to check existence of an integer. Whenever the sum is equal to the expected sum (X*(X+1)/2) return the index. Pay attention at the variable size.
int solution(int X, vector<int> &A) {
vector<bool> count(100001);
long long sum = 0;
long long x = X;
long long exp = x*(x+1)/2;
for(int i=0;i<(int)A.size();i++){
if( A[i] <= X && count[ A[i] ] == false) {
count[A[i]] = true;
sum+= A[i];
if(sum == exp) return i;
@ebedkm
ebedkm / Codility Lesson: PermCheck
Created August 16, 2014 03:18
Check permutation of 1 to N or not. Complexity O(n). Use extra array to count each element. If there is double value or value beyond limit, return 0.
int solution(vector<int> &A) {
// write your code in C++11
vector<int> B(100002);
int N = A.size();
int flag = 1;
for(int i=0;i<N;i++){
if(A[i] <= N){
if(B[A[i]] > 0){ flag = 0; break;}
B[ A[i] ]++;
@ebedkm
ebedkm / Codility Lesson: PermMissingElem
Created August 7, 2014 09:06
Finding Missing Element in [1..N+1] permutation.
int solution(vector<int> &A) {
// write your code in C++11
int N = A.size();
long long sum = 0;
for(int i=0;i<N;i++){
sum+=A[i];
}
long long expected = (long long)(N+1)*(long long)(N+1 + 1)/2;
int output = expected - sum;
return output;
@ebedkm
ebedkm / array
Last active August 29, 2015 14:02
11608
#include <cstdio>
int main(){
int S, c = 1;
while(scanf("%d", &S), S>= 0){
int problems[15], need[15];
problems[0] = S;
for(int i=1;i<=12;i++){
@ebedkm
ebedkm / Koordinat Gedung
Created May 28, 2014 10:07
Koordinat Gedung UKDW
private Point[][] Buildings = new Point[50][50];
{
Buildings[AGAPE][0] = new Point(-7.787122, 110.377872);
Buildings[AGAPE][1] = new Point(-7.787192, 110.378326);
Buildings[AGAPE][2] = new Point(-7.786715, 110.378402);
Buildings[AGAPE][3] = new Point(-7.786641, 110.377947);
Buildings[BIBLOS][0] = new Point(-7.786243, 110.378112);
Buildings[BIBLOS][1] = new Point(-7.786268, 110.378268);
@ebedkm
ebedkm / Codility: Tape Equilibrium
Created May 22, 2014 12:16
Codility: Tape Equilibrium
// you can also use includes, for example:
#include <iostream>
#include <algorithm>
using namespace std;
int solution(vector<int> &A) {
// write your code in C++98
for(int i=1;i<(int)A.size();i++){
A[i] = A[i-1] + A[i];
}
@ebedkm
ebedkm / BuildingCheck
Created May 22, 2014 05:24
Checking a coordinate inside a building using algorithm -> sum of degree. If 360 then true.
import java.util.*;
class BuildingCheck{
static final double EPS = 1e-9;
static class point implements Comparable<point>{
double x, y; // only used if more precision is needed
point() { x = y = 0.0; } // default constructor
point(double _x, double _y) { x = _x; y = _y; } // user-defined
// use EPS (1e-9) when testing equality of two floating points