Jackpotjoy

## Project Euler Question 15

Question: Starting in the top left corner of a 2*2 grid, there are 6 routes (without backtracking) to the bottom right corner.How many routes are there through a 20*20 grid? Solution: This is not a particular question for programming ,it seems like a more mathematics  problem for me . for moving from top left to right down , only consist two direction "down/ right", all path is a combination of 20 down and 20 right moves, so ,solution is just number of combination 20 of 40 instruction on move . For Read more [...]

## Project Euler Problem 26

Question A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given: 1/2 = 0.5 1/3 = 0.(3) 1/4 = 0.25 1/5 = 0.2 1/6 = 0.1(6) 1/7 = 0.(142857) 1/8 = 0.125 1/9 = 0.(1) 1/10 = 0.1 Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle. Find the value of d $\lt$1000 for which 1/d contains Read more [...]

## Project Euler Question 14

Question: The following iterative sequence is defined for the set of positive integers: n $\rightarrow$n/2 (n is even) n $\rightarrow$ 3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 $\rightarrow$ 40 $\rightarrow$ 20 $\rightarrow$10 $\rightarrow$ 5 $\rightarrow$ 16 $\rightarrow$ 8 $\rightarrow$ 4 $\rightarrow$ 2 $\rightarrow$ 1 It can be seen that this sequence (starting at 13 and finishing Read more [...]

## Project Euler Question 29

Question: Consider all integer combinations of ab for 2 $\leq$ a $\leq$ 5 and 2 $\leq$ b $\leq$ 5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, 35=243 42=16, 43=64, 44=256, 45=1024 52=25, 53=125, 54=625, 55=3125 If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms: 4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125 How many distinct terms are in the sequence generated by ab for 2 $\leq$ a $\leq$ 100 Read more [...]

## VBA and Regular Expression

a job task about how to apply regular expression on VBA . in Excel 2010 , a string "a;b;c" can be easily split into 3 cells with value "a" ,"b" ,"c" . but in Excel 2003 (ok, I'm a caveman ), it doesn't support such function . Tutorial on VBA  is a good start . let get down to real business: We need to split via a character ";"  from a string "Test#=14;NA=1;Email=4;Defective Email=0;" to get value 14,1,4,0 . there are 2 types in regular expression testing : Match or Not :   to Read more [...]

## Project Euler Question 31

Question 31: In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation: 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).x It is possible to make £2 in the following way: 1X£1 + 1x50p + 2x20p + 1x5p + 1x2p + 3x1p How many different ways can £2 be made using any number of coins? Solution : actually this is a linear algebra question : Find all possible $x_{n}$ that satisfy below equation $x_{1}*100+x_{2}*50+x_{3}*20+x_{4}*10+x_{5}*5+x_{6}*2+x_{7}*1=200$ Algorithm Read more [...]

## Pattern Matching in Ocaml

Pattern Matching is distinguish feature that own by ocaml, it's really powerful and saving a lot of type in code. Matching with Value Define in function with explict specifying "Match .. With" keyword # let rec fib i = match i with 0 -> 0 | 1 -> 1 | j -> fib (j 2) + fib (j 1);; Shorthand Matching within Function . function is same with fun with one parameter # let rec fib = function 0 -> 0 | 1 -> 1 | i -> fib (i 1) + fib (i 2);; val fib : int -> int = <fun> cluster Read more [...]

## Arrays / String in Ocaml

Disclaimer : code and structure most from  <Introduction to Objective Caml, Jason Hickey>, <http://pleac.sourceforge.net/pleac_ocaml/> personally use this article to be served as a learning note. Definition of Array: Fixed Length ; Same Type, form : [| a; b; c; ....|], Mutable Create a Array: (1) explicitly specify elements in a array : let a = [|1; 3; 5; 7|];; (2) using function Arrary.create # let a = Array.create 10 1;; val a : int array = [|1; 1; 1; 1; 1; 1; 1; 1; Read more [...]

## Lovely Python with zip()/izip()

Zip() zip() function in Python served as combine elements in iterable by position level to form a tuple list. >>> a = [1,2,3,4,5] >>> b = [6,7,8,9,10] >>> zip(a,b) [(1, 6), (2, 7), (3, 8), (4, 9), (5, 10)] The above example combine two list to a tuple list . zip() also applies to strings, tuples .If length of two iterable are not equal, the longer portion will be chop off . >>> t1 = (1,2,3,4) >>> t2 = (5,6,7,8) >>> zip(t1,t2) [(1, Read more [...]

## Records in Ocaml

It seems similar concept to structure in C . Record is a several data type mix structure with labeled names. Definition Example from <Introduction to Objective Caml>, with "name ""height" as Identifier followed by a colon and then a data type . # type db_entry = { name : string; height : float; phone : string; salary : float };; type db_entry = { name: string; height: float; phone: string; salary: float } Instantaneous a Record # let jason = { name = "Jason"; height Read more [...]