Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#include <cstdio>
#include <vector>
#include <cuda_runtime.h>
#include <cusolverDn.h>
#include <limits>
#define CHECK_CUDA(call) \
do { \
cudaError_t err = call; \
if (err != cudaSuccess) { \
@lakshayg
lakshayg / sudoku.pi
Created August 7, 2024 18:41
Solve sudoku using the cp module in Picat (http://picat-lang.org/)
import cp. % ::, all_different
import util. % transpose
write_sudoku(S) =>
foreach (R in S)
foreach (X in R)
printf("%d ", X)
end,
printf("%n")
end.
@lakshayg
lakshayg / ttt.c
Last active July 9, 2024 21:39
Tic-Tac-Toe in C
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/// TicTacToe ==========================================================================================================
typedef char Player;
const Player EMPTY = ' ';
//
// A solution to the problem described in
// https://www.youtube.com/watch?v=_-AfhLQfb6w
//
// How many sets of 5, 5-letter words exist such
// that the set has 25 distinct characters?
//
// It takes ~8sec to run on my machine.
//
// Usage: ./a.out < words_alpha.txt
@lakshayg
lakshayg / knights_and_knaves.prolog
Created March 5, 2024 22:36
A prolog program to solve the knight and knaves logic puzzles
person(knight).
person(knave).
persons(List) :- maplist(person, List).
claim(knight, Stmt) :- Stmt.
claim(knave, Stmt) :- \+Stmt.
% A puzzle taken from https://dmackinnon1.github.io/knaves/
% You have met a group of 6 islanders. Their names are Justin, Samuel, Ira, Frank, Beatrix, and Pamela.
@lakshayg
lakshayg / sudoku.hs
Last active March 7, 2024 18:03
Solve sudoku in haskell
import Data.Char (ord)
import Data.Maybe (isJust)
data CellValue = CellValue { index :: Int
, row :: Int
, col :: Int
, box :: Int
, value :: Int
}
@lakshayg
lakshayg / median_accumulator.cpp
Created September 23, 2018 15:56
An accumulator for computing median of a stream
#include <queue>
#include <cassert>
#include <vector>
#include <iostream>
template <typename T>
class MedianAccumulator {
public:
MedianAccumulator();
void operator()(T val);
@lakshayg
lakshayg / erfinv.h
Last active August 22, 2019 08:03
The inverse error function
// This code has been migrated to https://github.com/lakshayg/erfinv