Learning F#

Project Euler – Problem 68 Solution

Prob­lem Con­sid­er the fol­low­ing “mag­ic” 3-gon ring, filled with the num­bers 1 to 6, and each line adding to nine. Work­ing clock­wise, and start­ing from the group of three with the numer­i­cal­ly low­est exter­nal node (4,3,2 in this exam­ple), each solu­tion can be described unique­ly. For exam­ple, the above solu­tion can be described by the …

Project Euler – Prob­lem 68 Solu­tionRead More »

Project Euler – Problem 64 Solution

Prob­lem All square roots are peri­od­ic when writ­ten as con­tin­ued frac­tions and can be writ­ten in the form: For exam­ple, let us con­sid­er ?23: If we con­tin­ue we would get the fol­low­ing expan­sion: The process can be sum­marised as fol­lows: It can be seen that the sequence is repeat­ing. For con­cise­ness, we use the nota­tion …

Project Euler – Prob­lem 64 Solu­tionRead More »

Project Euler – Problem 80 Solution

Prob­lem It is well known that if the square root of a nat­ur­al num­ber is not an inte­ger, then it is irra­tional. The dec­i­mal expan­sion of such square roots is infi­nite with­out any repeat­ing pat­tern at all. The square root of two is 1.41421356237309504880…, and the dig­i­tal sum of the first one hun­dred dec­i­mal dig­its …

Project Euler – Prob­lem 80 Solu­tionRead More »

Project Euler – Problem 61 Solution

Prob­lem Tri­an­gle, square, pen­tag­o­nal, hexag­o­nal, hep­tag­o­nal, and octag­o­nal num­bers are all fig­u­rate (polyg­o­nal) num­bers and are gen­er­at­ed by the fol­low­ing for­mu­lae: The ordered set of three 4-dig­it num­bers: 8128, 2882, 8281, has three inter­est­ing prop­er­ties. The set is cyclic, in that the last two dig­its of each num­ber is the first two dig­its of the …

Project Euler – Prob­lem 61 Solu­tionRead More »

Project Euler – Problem 60 Solution

Prob­lem The primes 3, 7, 109, and 673, are quite remark­able. By tak­ing any two primes and con­cate­nat­ing them in any order the result will always be prime. For exam­ple, tak­ing 7 and 109, both 7109 and 1097 are prime. The sum of these four primes, 792, rep­re­sents the low­est sum for a set of …

Project Euler – Prob­lem 60 Solu­tionRead More »

F# – inline functions and member constraints

Gener­ic type para­me­ters were intro­duced in C# 2.0, and they gave us the abil­i­ty to write code that works against any type that match­es a set of con­straints and remove the need to cre­ate type-spe­­cif­ic over­loads, e.g.: A few years passed, and dynam­ic types was intro­duced in C# 4, which allows us to bypass com­pile-time …

F# – inline func­tions and mem­ber con­straintsRead More »

Project Euler — Problem 65 Solution

Prob­lem The square root of 2 can be writ­ten as an infi­nite con­tin­ued frac­tion. The infi­nite con­tin­ued frac­tion can be writ­ten, ?2 = [1;(2)], (2) indi­cates that 2 repeats ad infini­tum. In a sim­i­lar way, ?23 = [4;(1,3,1,8)]. It turns out that the sequence of par­tial val­ues of con­tin­ued frac­tions for square roots pro­vide the …

Project Euler — Prob­lem 65 Solu­tionRead More »

Project Euler — Problem 71 Solution

Prob­lem Con­sid­er the frac­tion, n/d, where n and d are pos­i­tive inte­gers. If n < d and HCF(n,d)=1, it is called a reduced prop­er frac­tion. If we list the set of reduced prop­er frac­tions for d <= 8 in ascend­ing order of size, we get: 1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, …

Project Euler — Prob­lem 71 Solu­tionRead More »

Project Euler — Problem 59 Solution

Prob­lem Each char­ac­ter on a com­put­er is assigned a unique code and the pre­ferred stan­dard is ASCII (Amer­i­can Stan­dard Code for Infor­ma­tion Inter­change). For exam­ple, upper­case A = 65, aster­isk (*) = 42, and low­er­case k = 107. A mod­ern encryp­tion method is to take a text file, con­vert the bytes to ASCII, then XOR …

Project Euler — Prob­lem 59 Solu­tionRead More »

Project Euler — Problem 79 Solution

Prob­lem A com­mon secu­ri­ty method used for online bank­ing is to ask the user for three ran­dom char­ac­ters from a pass­code. For exam­ple, if the pass­code was 531278, they may ask for the 2nd, 3rd, and 5th char­ac­ters; the expect­ed reply would be: 317. The text file, keylog.txt, con­tains fifty suc­cess­ful login attempts. Giv­en that …

Project Euler — Prob­lem 79 Solu­tionRead More »

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close