Skip to content

Instantly share code, notes, and snippets.

View Rag0n's full-sized avatar

Alexander Guschin Rag0n

View GitHub Profile
@Rag0n
Rag0n / 3SUM Problem for O(n)
Created October 17, 2013 19:37
Python 3Sum problem using radix sort
# -*- coding: utf-8 -*-
def radixSort(a, n, maxLen):
'''
Цифровая сортировка:
a - array
n - кол-во возможных значения одного разряда
maxLen - максимальное количество разрядов
Циклически обходим каждый разряд,
@Rag0n
Rag0n / Huffman
Last active March 19, 2018 21:56
Huffman implementation in C language
#include <stdio.h>
#include <string.h>
struct CharAndFreq
{
char ch;
unsigned freq;
};
#include <fstream>//qsort by marsharp
#include <iostream>
#include <algorithm>
using namespace std;
int a[100005];
void qsort(int l,int r)
{
int i,j,tmp=a[(r+l)/2];
if(r==l)return;
i=l;
@Rag0n
Rag0n / radix sort(python)
Created December 5, 2013 20:08
Radix sort python implementation
def radixSort(a, n, maxLen):
'''
Цифровая сортировка:
a - array
n - кол-во возможных значения одного разряда
maxLen - максимальное количество разрядов
Циклически обходим каждый разряд,
для каждого разряда создаем корзины
В зависимости от разряда добавляем число в один из 10 массивов.
'''
# Русский перевод для https://github.com/plataformatec/devise/tree/v1.4.7
# Другие переводы на http://github.com/plataformatec/devise/wiki/I18n
ru:
errors:
messages:
expired: "устарела. Пожалуйста, запросите новую"
not_found: "не найдена"
already_confirmed: "уже подтверждена. Пожалуйста, попробуйте войти в систему"
not_locked: "не заблокирована"
@Rag0n
Rag0n / bwt
Created February 17, 2014 19:59
Преобразование Барроуза-Уиллера(предварительная обработка для Хаффмана)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// #include <stdbool.h> // bool
#define BLOCKSIZE 50
// Преобразование Барроуза-Уиллера
void swap(char *f, char *l, int memory)
{
@Rag0n
Rag0n / huffman C implementation
Last active August 29, 2015 13:56
bwt[quicksort] + mtf + huffman
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// #include <stdbool.h> // bool
#define BLOCKSIZE 5000
#define MAX_TREE_HT 100
// Преобразование Барроуза-Уиллера
// int f = 53; // колво символов в алфавите mtf
struct CharAndFreq
@Rag0n
Rag0n / crc8
Last active May 30, 2018 18:24
crc8 C implementation
// c = t%(m+1)
// T - итоговая сумма, M - макс допустимое значение контрольной суммы
#include <stdio.h>
#define MAX 256
#define POLYNOMIAL 0x81
FILE *file;
unsigned char crc8(unsigned int len)
@Rag0n
Rag0n / heap
Created April 12, 2014 18:09
Binary heap
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int heap[1000000];
int size = 0;
int StrCompare(char *Str1,char *Str2)
{
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct node
{
int data;
struct node* next;
};