Skip to content

Instantly share code, notes, and snippets.

View VardanGrigoryan's full-sized avatar

Vardan VardanGrigoryan

View GitHub Profile
/*
* A fast exponentiation.
* The algo has O(log(m)) time complexity, additionally it gets a boost because of compile time.
*/
template <int n, int mod, int debug_info, int m>
struct fast_exp {
static constexpr int value = (m % 2 == 0) ? fast_exp<(n * n) % mod, mod, debug_info, m / 2>::value : (n * fast_exp<(n * n) % mod, mod, debug_info, (m - 1) / 2>::value) % mod;
static constexpr void run_debug() {
static_assert(value == debug_info, "failed");
#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
int main()
{
int size;
std::cin >> size;
rm -rf *.o *.bin *.img
nasm -f bin bootsect.asm -o bootsect.bin
gcc -ffreestanding -c main.c -o main.o
gcc -c video.c -o video.o
gcc -c ports.c -o ports.o
ld -e main -Ttext 0x1000 -o kernel.o main.o video.o ports.o
ld -i -e main -Ttext 0x1000 -o kernel.o main.o video.o ports.o
objcopy -R .note -R .comment -S -O binary kernel.o kernel.bin
./makeboot a.img bootsect.bin kernel.bin
[BITS 16] ; We need 16-bit intructions for Real mode
[ORG 0x7C00] ; The BIOS loads the boot sector into memory location 0x7C00
;jmp word load
global _start
jmp _start
drive db 0
; jmp reset_drive
; jmp enter_pm
@VardanGrigoryan
VardanGrigoryan / gist:9450697
Last active August 29, 2015 13:57
Փոխարինել հետևյալ ռեկուրսիան իտերացւայով։
void backtrack(int* a, int k, int n)
{
if (k == n)
{
for(int i = 1; i <=k; ++i)
{
if (a[i] == true)
{
std::cout << i << " ";
}
@VardanGrigoryan
VardanGrigoryan / gist:8899883
Last active January 2, 2022 12:42
Երկու տողերի միջև Լևենշտեյնի հեռավորության որոշում, Վագներ Ֆիշերի ալգորիթմի իրականացում C++ լեզվով
#include <vector>
double vagner_fisher_sed_algo(const std::string& s,
const std::string& d)
{
std::vector<std::vector<double> > t(s.length() + 1,
std::vector<double>(d.length() + 1));
t[0][0] = 0;
double o;
@VardanGrigoryan
VardanGrigoryan / main.cpp
Created January 26, 2014 17:39
Տրված է չուղղորդված և կշռված գրաֆ, որի բոլոր գագաթների/կողերի կշիռները դրական թվեր են։ Տրված է նաև s բնական թիվը, որը համապատասխանում է գրաֆի մի ինչ-որ գագաթի։ Գտել s գագաթից դեպի մյուս գագաթները ընկած կարճագույն ճանապարհները։
#include <iostream>
#include <limits.h>
#include <stdlib.h>
#include <queue>
struct node
{
int d;
int w;
@VardanGrigoryan
VardanGrigoryan / heap
Last active January 2, 2016 22:29
Ինչպիսի՞ տվյալների կառուցվածք է առավել հաճախ օգտագործվում նախապատվություններով հերթի կառուցման դեպքում:
#include <iostream>
class heap
{
private:
int size;
private:
int get_left(int i);
int get_rigth(int i);
@VardanGrigoryan
VardanGrigoryan / ascii_to_bin
Last active January 2, 2016 19:09
ASCII character to binary code
#include <iostream>
int main()
{
int a[8];
const char c = 'a';
for(unsigned int i = 0; i < sizeof(char)*8; ++i)
{
if(c & (1 << i))