Skip to content

Instantly share code, notes, and snippets.

@krisys
krisys / sudoku.cpp
Created April 28, 2011 16:49
Sudoku Solver
#include<iostream>
using namespace std;
int sudoku[9][9],ptr[162],xstart[9]={0,3,6,0,3,6,0,3,6}, ystart[9]={0,0,0,3,3,3,6,6,6};
int valid(){
int valid=1;
int hashtable[10];
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
for(int k=j+1;k<9;k++){
if(sudoku[i][j]==0) continue;
@krisys
krisys / permutation-recursive.cpp
Last active September 25, 2015 15:58
Permutation (Recursive)
#include<iostream>
#include<string>
using namespace std;
string deleteKthCharacter(string str, int k){
return str.erase(k, 1);
}
void permute( string dest, string source, int len){
if( dest.length() == len){
@krisys
krisys / permutation-minimal_change.cpp
Created April 28, 2011 17:50
Permutation (Minimal Change)
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int n;
char c;
vector < string > next, current;
@krisys
krisys / Johnson_trotter.cpp
Created April 28, 2011 18:49
Permutations (Johnson Trotter)
#include<iostream>
#include<string>
#include<vector>
#define SIZE 4
#define debug(x) cout<< #x << " = "<< x <<endl
#define swap(typ,A,B) { typ temp;temp=B; B=A;A=temp;}
using namespace std;
vector <int> permset;
string flags;
@krisys
krisys / SpellCheck.cpp
Created April 30, 2011 10:28
Spell Check - Trie
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int found=0;
class node{
public:
char info;
@krisys
krisys / LargeInteger.cpp
Created April 30, 2011 12:14
Multiplication of Large Numbers in C++
#include<iostream>
#include<string>
#include<sstream>
#define SIZE 700
using namespace std;
class large{
int no[SIZE];
/*
array is used to store the large number.
@krisys
krisys / HuffmanEncoding.cpp
Created April 30, 2011 12:22
Huffman Encoding
#include<iostream>
#include<string>
#define debug(x) cout<< #x << " = "<< x <<endl
#define swap(typ,A,B) { typ temp;temp=B; B=A;A=temp;}
using namespace std;
class Node{
friend class HuffmanTree;
char ch;
float prob;
@krisys
krisys / projeuler_oneliners.py
Created June 7, 2011 18:16
ProjectEuler Python One liners
# Problem 1
"""Find the sum of all the multiples of 3 or 5 below 1000."""
sum( [ num for num in range(3,1000) if num % 3 == 0 or num % 5 == 0 ] )
# Problem 4
"""
A palindromic number reads the same both ways. The largest palindrome
made from the product of two 2-digit numbers is 9009 = 91 99.
@krisys
krisys / swype.py
Last active August 10, 2022 15:58
How swype works?
'''
The MIT License (MIT)
Copyright (c) 2013 Krishna Bharadwaj <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@krisys
krisys / Add field to an existing Django app with South
Created September 7, 2011 06:49 — forked from DaveEveritt/Add field to an existing Django app with South
quickly add field(s) to existing Django models with South
====================================================================
Simple-as-possible instructions to add a field (or more) using South
to an existing Django model with existing data.
====================================================================
Two versions:
1. Super-condensed (the bare minimum - jfdi)
2. Detailed-but-brief (if you want more information).
Notes: