Skip to content

Instantly share code, notes, and snippets.

struct div_result {
int z1;
int z2;
};
/*@ requires x1 >= 0;
requires x2 > 0;
ensures \result.z1 * x2 + \result.z2 == x1;
ensures 0 <= \result.z2 <= x2;
*/
struct div_result div(int x1, int x2) {
+-----------+-------------+----------+----------+----------+----------+----------+----------+---------+
| no. bytes | bits for cp | first cp | last cp | byte 0 | byte 1 | byte 2 | byte 3 | cps |
+-----------+-------------+----------+----------+----------+----------+----------+----------+---------+
| 1 | 7 | U+0000 | U+007F | 0xxxxxxx | | | | 127 |
| | | | | 0-7F | | | | |
+-----------+-------------+----------+----------+----------+----------+----------+----------+---------+
| 2 | 11 | U+0080 | U+07FF | 110xxxxx | 10xxxxxx | | | 1919 |
| | | | | C0-DF | 80-BF | | | |
+-----------+-------------+----------+----------+----------+----------+----------+----------+---------+
| 3 | 16 | U+0800 | U+FFFF | 1110xxxx | 10xxxxxx | 10xxxxxx |
#include <fstream>
int S(int n) {
return n == 1 ? 1 : 2 * S(n - 1) + 1;
}
int main() {
int n;
printf("Enter n: ");
scanf("%d", &n);
import System.Random
import Data.List (delete,unwords)
data Chord = D | A | E | Dm | Am | Em | G | C
deriving (Show, Enum, Eq, Ord)
allChords = [D .. C]
combinations :: [Chord] -> [(Chord,Chord)]
combinations [] = []
@rbakbashev
rbakbashev / get.cpp
Created December 10, 2014 10:41
Simple to use http getter using libcurl
#include "get.hpp"
void Get_init()
{
curl = curl_easy_init();
if (!curl)
throw std::runtime_error("curl_easy_init() failed");
}
static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb,
SUBROUTINE F(X, Y, J) F 00010
COMMON/A1/M1,N F 00020
COMMON/A10/NF F 00030
DOUBLE PRECISION X(N), Y(M1) F 00040
F 00050
IF (.NOT.(J.EQ.0.OR.J.EQ.-1)) GO TO 1 F 00060
Y(M1) = 3*(X(1)**2) - 2*X(2) F 00070
NF = NF+1 F 00080
1 IF (.NOT.(J.EQ.1.OR.J.EQ.-1)) GO TO 2 F 00090
Y(1) = 2*X(1) + X(2) - 4 F 00100
this gist contains dotfiles: .zshrc.local, .xinitrc, .conkyrc, .Xresources and .ctags
dwm distro: dl.dropboxusercontent.com/u/84285293/distro.tar.bz2
@rbakbashev
rbakbashev / hlackjack.hs
Last active December 29, 2015 05:59
Blackjack in Haskell (newbie code ahead)
import Data.List (delete, nub, intersperse)
import System.IO (hFlush, stdout)
import System.Random
import System.Exit
import Control.Monad (when)
data Suit = Spades | Clubs | Hearts | Diamonds deriving (Eq)
data Rank = Number Int | Jack | Queen | King | Ace deriving (Eq)
type Card = (Rank, Suit)
@rbakbashev
rbakbashev / mn-tree.cpp
Created October 27, 2013 11:26
Tree with variable amount of nodes
#include <iostream>
#include <queue>
#include <vector>
#include <memory>
#include <cstdarg>
using namespace std;
class Tree {
public:
@rbakbashev
rbakbashev / bf.hs
Last active December 21, 2015 22:19
Brainfuck interpreter in Haskell. May contain dumb things because I am learning.
import Data.Char (chr)
modifyAt :: Num a => Int -> [a] -> (a -> a) -> [a]
modifyAt pos list func = let splitList = splitAt pos list
(x:xs) = snd splitList
in (fst splitList) ++ [func x] ++ xs
data BFstate = BFstate { tape :: [Integer],
tapePtr :: Int,
output :: [Char] }