Skip to content

Instantly share code, notes, and snippets.

@squiidz
squiidz / README.md
Last active March 3, 2021 12:57
Seats assignment

CMD: go run main.go R1C4 R1C6 R2C3 R2C7 R3C9 R3C10 then enter the number of seats you want to reserve

@squiidz
squiidz / hourglass.go
Created November 15, 2019 20:07
hourglass O(n)
func hourglassSum(arr [][]int32) int32 {
var maxVal int32 = -63
for i, j := 0, 0; i < len(arr) - 2; j++ {
tr := arr[i][j] + arr[i][j+1] + arr[i][j+2]
mr := arr[i+1][j+1]
br := arr[i+2][j] + arr[i+2][j+1] + arr[i+2][j+2]
total := tr + mr + br
if total > maxVal {
maxVal = total
}
@squiidz
squiidz / merkletree.go
Created May 28, 2019 20:08
MerkleTree
package merkletree
import (
"bytes"
"crypto/sha256"
"errors"
"fmt"
)
//Content represents the data that is stored and verified by the tree. A type that
@squiidz
squiidz / doubleLinkedList.cpp
Last active August 29, 2017 22:13
Virtual Double Linked List C++
#include <iostream>
#include "node.h"
#include "nodeValue.h"
using namespace std;
struct animal: public nodeValue {
int age;
@squiidz
squiidz / btree.c
Last active January 31, 2023 15:22
Btree implementation in C
#include "stdio.h"
#include "stdlib.h"
#define M 3
typedef struct _node {
int n; /* n < M No. of keys in node will always less than order of B tree */
int keys[M - 1]; /*array of keys*/
struct _node *p[M]; /* (n+1 pointers will be in use) */
} node;
@squiidz
squiidz / main.c
Last active August 23, 2017 21:20
Clang double pointer linked list
#include "stdio.h"
#include "stdlib.h"
typedef struct _node {
int value;
struct _node *next;
} node;
// Create a new node with the provided value
node *new_node(int _value) {
@squiidz
squiidz / balanced.rs
Last active April 18, 2017 03:43
balanced symbols
#[macro_use]
extern crate lazy_static;
use std::collections::HashMap;
lazy_static!(
static ref MAPPING: HashMap<char, char> = [('}', '{'), (')', '('), (']', '[')]
.iter()
.cloned()
.collect();
);
@squiidz
squiidz / narci.cc
Created March 27, 2017 13:20
narcissistic numbers
#include <vector>
#include <math.h>
namespace number {
bool is_narci(int num) {
int num_cp = num;
int num_length = num == 1 ? 1 : ceil(log10(num));
int length = num_length;
int acc = 0;
@squiidz
squiidz / armstrong_numbers.rb
Last active March 25, 2017 22:00
armstrong numbers in ruby
# num = 1234
# num_length = Math.log(num, 10).ceil => 4
# base = 10 ** (num_length - 1) => 1000
def is_armstrong(num)
if (1..9).include?(num)
return true
elsif num == 10
return false
end
@squiidz
squiidz / playground.rs
Created March 9, 2017 19:52 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::io::{self, Read, Write};
struct StringRW {
value: String,
buffer: Vec<u8>,
}
impl StringRW {
fn new(value: &str) -> Self {
StringRW {