Advertisement
justlilith

FP&U.fs

Apr 8th, 2021
3,009
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.03 KB | None | 0 0
  1. open System
  2.  
  3. //Functional Programming and You! 🌈
  4. //L6 2021
  5. //code from talk given in April
  6.  
  7. let deck = [
  8.   "Six of Swords";
  9.   "The Empress";
  10.   "The Hanged Man";
  11.   "Page of Cups";
  12.   "The Lovers";
  13.   "Justice";
  14.   "Three of Swords";
  15.   "Five of Pentacles";
  16.   "The Sun";
  17.   "Temperance";
  18.   "Death"
  19. ]
  20.  
  21. let rec shuffle (startingDeck : string list) (tempDeck : string list) (resultDeck : string list) : string list =
  22.   let seed = Random()
  23.   let sdLength = startingDeck.Length
  24.   let currentCard = seed.Next(0,tempDeck.Length)
  25.   match resultDeck.Length = startingDeck.Length with
  26.     | true ->
  27.       resultDeck
  28.     | false ->
  29.       let newDeck = resultDeck @ [tempDeck.Item(currentCard)]
  30.       let currentDeck = List.except [tempDeck.Item(currentCard)] tempDeck
  31.       shuffle startingDeck tempDeck newDeck
  32.  
  33. let addTheMoon x =
  34.   x @ ["The Moon"]
  35.  
  36. let newDeck = addTheMoon deck
  37. let shuffledDeck = shuffle deck deck []
  38.  
  39. printfn "%A" deck
  40. printfn "%A" newDeck
  41. printfn "%A" shuffledDeck
  42. printfn "%A" (addTheMoon shuffledDeck)
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement