Advertisement
daegron

dsadsa

Apr 21st, 2023
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. module ControlTasks
  2.  
  3. type ConcurrentStack<'T>() =
  4. let mutable _stack : List<'T> = []
  5.  
  6. member this.Push value =
  7. lock _stack (fun () ->
  8. _stack <- value :: _stack)
  9.  
  10. member this.TryPop() =
  11. lock _stack (fun () ->
  12. match _stack with
  13. | result :: newStack ->
  14. _stack <- newStack
  15. result |> Some
  16. | [] -> None
  17. )
  18.  
  19. let diamond n =
  20. let rec line n x =
  21. if x = n then ""
  22. else " " + line n (x + 1)
  23. let rec stars n x =
  24. if x = n then "*"
  25. else "*" + stars n (x + 1)
  26. let rec top halfRows row =
  27. if row = halfRows + 1 then ""
  28. else
  29. (line halfRows row) + (stars (row * 2 - 1) 1) + "\n" + (top halfRows (row + 1))
  30. let rec bottom halfRows row =
  31. if row = 0 then ""
  32. else
  33. (line halfRows row) + (stars (row * 2 - 1) 1) + "\n" + (bottom halfRows (row - 1))
  34. top n 1 + bottom n (n - 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement