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
| namespace FSharpKoans | |
| open FSharpKoans.Core | |
| //--------------------------------------------------------------- | |
| // Apply Your Knowledge! | |
| // | |
| // Below is a list containing comma separated data about | |
| // Microsoft's stock prices during March of 2012. Without | |
| // modifying the list, programatically find the day with the | |
| // greatest difference between the opening and closing prices. |
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
| static long repeatedString(string s, long n) | |
| { | |
| if(s.Length == 1 && s.Equals("a")) | |
| { | |
| return n; | |
| } | |
| long total = 0; | |
| foreach(var letter in s) |
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
| static int jumpingOnClouds(int[] c) { | |
| int totalJumps = 0; | |
| if (c.Length == 2) | |
| { | |
| if (c[0] == 0 && c[1] == 0) | |
| return 1; | |
| else | |
| return 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
| public static int countingValleys(int steps, string path) | |
| { | |
| int initialValue = 1; | |
| int valleys = 0; | |
| for(int i = 0; i < steps; i ++){ | |
| if(path[i].Equals('U')) { | |
| initialValue++; | |
| if(initialValue == 1) | |
| valleys++; | |
| } else { |
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
| static int sockMerchant(int n, int[] ar) { | |
| var hashSet = new HashSet<int>(); | |
| int pairs = 0; | |
| for(int i = 0; i < n; i ++){ | |
| if(!hashSet.Contains(ar[i])) { | |
| hashSet.Add(ar[i]); | |
| } else { | |
| pairs++; | |
| hashSet.Remove(ar[i]); | |
| } |