Last active
August 29, 2015 14:06
-
-
Save AlexArchive/fd58e7f01ada8665fb57 to your computer and use it in GitHub Desktop.
Solutions for https://github.com/karan/projects/
This file contains 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 coins = [ | |
"quarter", 0.25m; | |
"dime", 0.10m; | |
"nickel", 0.05m; | |
"penny", 0.01m | |
] | |
let rec giveChange (change : decimal) = | |
let coin = coins |> List.tryFind (fun (_, coinValue) -> change >= coinValue) | |
match coin with | |
| Some (name, coin) -> | |
Console.WriteLine name | |
giveChange (change - coin) | |
| None -> () | |
let cost = 1.10m | |
let amountGiven = 2.00m | |
giveChange (amountGiven-cost) |
This file contains 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
open System | |
open System.Linq | |
let Main() = | |
let isPalindrome (text : string) = | |
let reversedText = | |
text | |
|> Seq.fold (fun acc char -> (string) char + acc) "" | |
text = reversedText | |
let inputText = Console.ReadLine() | |
Console.WriteLine (isPalindrome inputText) | |
() | |
Main() |
This file contains 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
open System | |
open System.Linq | |
let enumerateVowels text = | |
let vowels = [| 'a'; 'e'; 'i'; 'o'; 'u' |] | |
let charIsVowel char = Seq.exists ((=) char) vowels | |
text | |
|> Seq.groupBy char | |
|> Seq.where (fst >> charIsVowel) | |
|> Seq.iter (fun (char, seq) -> Console.WriteLine("{0}: {1}", char, seq.Count())) | |
let Main() = | |
Console.Write "Enter a word: " | |
let inputText = Console.ReadLine() | |
enumerateVowels inputText | |
Main() |
This file contains 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
open System | |
open System.IO | |
open System.Linq | |
let delimiters = [| " "; Environment.NewLine |] | |
let countWords (sentence : string) = | |
sentence.Split(delimiters, StringSplitOptions.RemoveEmptyEntries).Count() | |
let Main() = | |
Console.Write "Enter file path: " | |
let path = Console.ReadLine() | |
let wordCount = | |
File.ReadLines(path) | |
|> Seq.sumBy (fun line -> countWords line) | |
Console.WriteLine("Word Count for: {0}", wordCount) | |
() | |
Main() |
This file contains 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 convert number = | |
match number with | |
| 0 | 1 -> string number | |
| _ -> | |
let remainder = string (number % 2) | |
(convert (number / 2)) + remainder | |
Console.WriteLine (convert 10) |
This file contains 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
open System | |
open System.Text.RegularExpressions | |
open System.Net.Http | |
type Stock = { | |
ask : string | |
change : string | |
companyName : string | |
} | |
let DownloadString (requestUri : string) = | |
use client = new HttpClient() | |
client.GetStringAsync(requestUri).Result | |
let HydrateStocks (response : string) = | |
let records = response.Split([|Environment.NewLine|], StringSplitOptions.RemoveEmptyEntries) | |
seq { | |
for record in records do | |
let fields = record.Split ',' | |
yield { | |
companyName = fields.[0].Replace("\"", "") | |
ask = fields.[1]; | |
change = fields.[2] | |
} | |
} | |
let Main = | |
Console.Write "Enter the stock ticker symbols to track (delimitered by '+'): " | |
let inputText = Console.ReadLine() | |
let response = DownloadString(String.Concat("http://finance.yahoo.com/d/quotes.csv?s=", inputText, "&f=nac1")) | |
let stocks = HydrateStocks response | |
for stock in stocks do | |
Console.WriteLine stock.companyName | |
Console.WriteLine stock.ask | |
Console.WriteLine stock.change | |
if stock.change.Contains "-" then | |
Console.ForegroundColor <- ConsoleColor.Red | |
Console.WriteLine "▼" | |
else | |
Console.ForegroundColor <- ConsoleColor.Green | |
Console.WriteLine "▲" | |
Console.ForegroundColor <- ConsoleColor.Gray | |
Console.WriteLine "---" | |
() |
This file contains 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
open System | |
open System.Linq | |
let rec Main() = | |
Console.Write "Enter some text: " | |
let inputText = Console.ReadLine() | |
if inputText = "exit" then | |
() | |
else | |
let reversedText = | |
inputText | |
|> Seq.fold (fun acc character -> (string) character + acc) "" | |
Console.WriteLine reversedText | |
Main() | |
Main() |
This file contains 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
open System | |
open System.Xml | |
open System.ServiceModel.Syndication | |
let Main = | |
use reader = XmlReader.Create("http://toddmotto.com/feed.xml") | |
let feed = SyndicationFeed.Load(reader) | |
for item in feed.Items do | |
Console.WriteLine item.Title.Text | |
() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment