Skip to content

Instantly share code, notes, and snippets.

View scottoasis's full-sized avatar
🐫
Oh, camel!

Scott Wang scottoasis

🐫
Oh, camel!
  • Smartcuts
  • Shanghai, China
View GitHub Profile

Keybase proof

I hereby claim:

  • I am scottoasis on github.
  • I am scottoasis (https://keybase.io/scottoasis) on keybase.
  • I have a public key ASC2moFGfe3C14Y3b-DN0tsEl_ewiCd9jptDOylJpu8Tkwo

To claim this, I am signing this object:

first layer

second layer

third layer

Footnotes

hidden text

@scottoasis
scottoasis / fill_gap.rb
Created July 27, 2015 10:18
Fill gap interview quiz in ruby.
#!/usr/bin/env ruby
#
#
# - Water Filling Problem -
#
# Imagine we have several columns of bricks forming a
# wall-like structure just like this,:
#
# +-+ +-+ +-+ +-+
# +-+ +-+-+-+ +-+ +-+-+ +-+-+
/*
* test cases
*
* case 1.
*
* #============#
* #===#====#===#
* #==##==#######
* #=############
* #=############
#include <stdio.h>
int main () {
int num;
scanf("%d", &num);
if (num <= 0) {
object InsertSort {
type T = Int
def apply(xs: Seq[T]) = insertSort (Nil) (xs)
def insertSort(xs: Seq[T])(ys: Seq[T]): Seq[T] =
if (ys isEmpty) xs
else insertSort (insertWhile (x => x >= ys.head) (ys.head) (xs)) (ys.tail)
def insertWhile(crit: T => Boolean)(x: T)(xs: Seq[T]): Seq[T] =
object PlayWithString {
def isMatching(pat: String)(str: String): Boolean =
/*
-- termination --
*/
if (pat == "*" || (pat.isEmpty && str.isEmpty)) true
else if ((pat.isEmpty && !str.isEmpty) || (str.isEmpty)) false
/*
-- induction --