This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <string> | |
#include <iostream> | |
struct Node { | |
int element; | |
Node* next; | |
Node* prev; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let (>=>) p1 p2 input k = p1 input (fun input -> p2 input k) | |
let (>=>>) p1 p2 input = p1 input (fun input -> p2 input List.isEmpty) | |
let digit input k = | |
let rec loop input = | |
match input with | |
| [] -> k [] | |
| x :: input when Char.IsDigit x -> loop input | |
| input -> k input | |
match input with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec range start stop = if start > stop then [] else start :: range (succ start) stop | |
let sum xs = List.fold_left (+) 0 xs | |
let (>>) f g a = a |> f |> g | |
module type Excel = sig | |
type t | |
val create: int -> char -> unit | |
val set: int -> char -> int -> unit | |
val get: int -> char -> int | |
val sum: int -> char -> string list -> int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type constr = Equal | Less | Greater | |
let adjacents matrix (x,y) = | |
matrix | |
|> Array.mapi (fun ri row -> row |> Array.mapi (fun ci _col -> ri,ci)) | |
|> Array.to_list | |
|> Array.concat | |
|> Array.to_list | |
|> List.filter (fun (ri, ci) -> (ri = x) <> (ci = y)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace interview { | |
class Program { | |
// check if the last 2 chars with c are the same | |
public static bool predicate (string s, char c) { | |
if (s.Length < 2) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let (>>) f g a = a |> f |> g | |
let input_lines file = | |
let rec loop chan = | |
match input_line chan with | |
| line -> line :: loop chan | |
| exception End_of_file -> [] | |
in | |
let chan = open_in file in | |
let result = loop chan in | |
close_in chan; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
for line in `echo add.txt | cat | awk '{print $2}'`; do | |
git add "$line" | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git status | tail -n +5 | head -n -8 | awk '{print $2}' | grep -v snarkyjs | xargs git add |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn sort<const N: usize>(arr: [i32; N]) -> Vec<i32> { | |
let mut max = arr[0]; | |
// Find the max of the array | |
for i in 0..arr.len() { | |
if arr[i] > max { | |
max = arr[i] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn calculate_offset(c: u32, l: u32, t: &String) -> usize { | |
let (c, l) = (c as usize, l as usize); | |
// Line is 0 indexed so we don't need to skip the | |
// line that the cursor is currently on. | |
// It will be done automatically during the `take`, because | |
// of the 0 index. | |
let count = t | |
.split('\n') | |
.take(l) | |
.collect::<Vec<_>>() |