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
| object sqrtTest extends App | |
| { | |
| def sqrt(x: Double) = | |
| { | |
| def sqrtIter(guess: Double): Double = | |
| { | |
| if(isGoodEnough(guess)) guess | |
| else sqrtIter(improve(guess)) | |
| } | |
| def improve(guess: Double) = |
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
| object sqrtTest extends App | |
| { | |
| def sqrt(x: Double) = | |
| { | |
| def sqrtIter(guess: Double): Double = | |
| { | |
| if(isGoodEnough(guess)) guess | |
| else sqrtIter(improve(guess)) | |
| } | |
| def improve(guess: Double) = |
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
| object LoopUnlessTest extends App | |
| { | |
| def loop(body: => Unit): LoopUnlessCond = | |
| new LoopUnlessCond(body) | |
| protected class LoopUnlessCond(body: => Unit) | |
| { | |
| def unless(cond: => Boolean) | |
| { | |
| body |
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
| package handson | |
| class Node(l: Node, r: Node, n: String) | |
| { | |
| var left = l | |
| var right = r | |
| var name = n | |
| } |
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
| use strict; | |
| use warnings; | |
| my @output; | |
| sub printBrackets($$) | |
| { | |
| my ($nLeft, $nRight) = @_; | |
| # recursion end condition | |
| if($nLeft == 0 && $nRight == 0) | |
| { |
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
| extern char array[] = {1, 2, 3, 4}; |
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
| # | |
| # create a named changelist with certain description | |
| # | |
| # Usages: | |
| # p4change | |
| # p4change "This is my changelist" | |
| # | |
| if [ ! "$1" ] |
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
| export exe=`echo $1 | awk -F. '{print $1}'` | |
| #make sure the g++ version is 47 | |
| g++ $1 -std=c++11 -o $exe | |
| ./$exe |
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
| // 给你一个数组,找出这个数组中是否有两个数的和为某个指定的值 | |
| // int array[] = {1, 4, 12, -1, 6, 4}, | |
| // sum = 10, return true; | |
| // sum = 100, return false; | |
| import java.util.Arrays; | |
| import java.util.HashMap; | |
| import java.util.Map.Entry; | |
| public final class ArraySum |