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 TowerOfHanoi fromPole destPole tempPole disks = | |
| if disks > 0 then | |
| TowerOfHanoi fromPole tempPole destPole (disks - 1) | |
| printfn "Moving from %c to %c" fromPole destPole | |
| TowerOfHanoi tempPole destPole fromPole (disks - 1) | |
| TowerOfHanoi '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
| let rec factorial n = | |
| match n with | |
| | 0 | 1 -> 1 | |
| | _ -> n * factorial(n - 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
| let factorial n = | |
| [1..n] |> List.reduce (*) |
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 fibonacci n = | |
| match n with | |
| | 1 | 2 -> 1 | |
| | _ -> fibonacci (n - 1) + fibonacci (n - 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
| public int GCD(int first, int second) | |
| { | |
| return second == 0 | |
| ? first | |
| : GCD (second, first % second); | |
| } |
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
| private BufferBlock<int> queue = new BufferBlock<int>(); | |
| void Main() | |
| { | |
| var producers = Enumerable.Range(0, 10).Select(async x => | |
| { | |
| await Producer(); | |
| }); | |
| var consumer = Consumer(); |
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
| private readonly BlockingCollection<int> _blockingQueue = new BlockingCollection<int>(); | |
| void Main() | |
| { | |
| var producer = Producer(); | |
| var consumer = Consumer(); | |
| Task.WaitAll(producer, consumer); | |
| Console.WriteLine("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
| public int FirstDivisor(int number) | |
| { | |
| return Enumerable.Range(2, (int)Math.Sqrt(number)).FirstOrDefault(x => number % x == 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
| String.prototype.times = function(count) { | |
| return count < 1 ? '' : new Array(count + 1).join(this); | |
| }; |
NewerOlder