Skip to content

Instantly share code, notes, and snippets.

View ahmadyan's full-sized avatar

Adel Ahmadyan ahmadyan

View GitHub Profile
@ahmadyan
ahmadyan / Script-ExtendedMonitor
Created August 29, 2012 17:15
AutoIt Script file for Showing Desktop on (Extended Monitor Setting) & (Monitor 2 only), Only works on windows 7 with AutoIt, Highly system-dependent
Run("C:\WINDOWS\system32\control.exe desk.cpl", "C:\Windows\system32\")
WinWait("Screen Resolution")
ControlCommand("Screen Resolution", "", "ComboBox3", "SetCurrentSelection", "1")
ControlClick("Screen Resolution", "", "Button4")
WinWait("Display Settings")
ControlClick("Display Settings", "", "Button1")
@ahmadyan
ahmadyan / utility.cpp
Created September 2, 2012 05:28
Utility
#include "utility.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
namespace utility {
using namespace std;
// Generate a random number between 0 and 1
// return a uniform number in [0,1].
@ahmadyan
ahmadyan / utility.cpp
Created September 6, 2012 01:07
tick-tock
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <string>
#include "utils.h"
using namespace std;
namespace utils {
void demo(){
double r = 0.5 ;
double area = M_PI * r * r;
double** samples = new double*[sample_count];
for(int i=0;i<sample_count;i++){
samples[i] = new double[2];
samples[i][0] = 1.0*rand()/INT_MAX;
samples[i][1] = 1.0*rand()/INT_MAX;
}
cout << "The exact area is " << area << endl ;
void verify(double r, double** samples){
DT dt2;
VD vd;
Cropped_voronoi_from_delaunay vor;
Iso_rectangle_2 bbox(0,0,1,1);
vor = Cropped_voronoi_from_delaunay(bbox);
for(int i=0;i< sample_count;i++){
vd.insert( Site_2( samples[i][0], samples[i][1] ) );
}
void mc(double r, double** samples){
cout << "Monte Carlo simulation" << endl ;
using namespace boost::math;
double sample_inside=0;
cout << "sizeof(sample_count)=" << sizeof(samples) << endl ;
for(int i=0;i<sample_count;i++){
double x = samples[i][0];
double y = samples[i][1];
@ahmadyan
ahmadyan / count-set-bits.cpp
Created May 8, 2016 20:36
Count the number of set bits in an integer
unsigned long long int v; //counts the number of bits set in v
unsigned int count=0; // counts is the total bits set in v
while(v){
v &= v-1;
c++;
}
#include<bitset>
unsigned long long int v;
bitset<64> n(v);
int count = n.count();
auto v2 = n.to_ullong();
size_t count() const
{ // count number of set bits
static char _Bitsperhex[] = "\0\1\1\2\1\2\2\3\1\2\2\3\2\3\3\4";
size_t _Val = 0;
for (int _Wpos = _Words; 0 <= _Wpos; --_Wpos)
for (_Ty _Wordval = _Array[_Wpos]; _Wordval != 0; _Wordval >>= 4)
_Val += _Bitsperhex[_Wordval & 0xF];
return (_Val);
}
@ahmadyan
ahmadyan / bfs_list.cpp
Created December 8, 2016 00:25
The BFS algorithm implemented using std::list
//list is basically a linked-list
int bfs_list(Graph* g){
int sig=0;
vector<bool> visited(g->getSize(), false);
list<int> q;
auto init = rand()%g->getSize();
q.push_back(init);
visited[init]=true;
while(!q.empty()){
auto u = q.front();