slawekssj4

efszarp mhm 1

Nov 17th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.10 KB | None | 0 0
  1. open System.Collections.Generic
  2.  
  3. let tab2d = array2D [[0;0;0;1];[0;0;0;0];[0;0;0;1];[0;1;0;0]]
  4.  
  5.  
  6. //.WYPISZ
  7. for i = 0 to 3 do  
  8.   for j = 0 to 3 do  
  9.     printf "%A " tab2d.[i,j]  
  10.   printf "\n"
  11. printf "\n"
  12.  
  13. //.WYPISZ SOMSIADUF
  14.  
  15. for i = 0 to 3 do
  16.   printf "%A" i
  17.   printf ".["
  18.   for j = 0 to 3 do  
  19.     if tab2d.[i,j] =1 then printf "%A " j; printf ","
  20.   printf "]\n"
  21. printf "\n"
  22. //somsiedzi wieszcholka
  23.  
  24. let smosiedzi_wierzcholka node ()=
  25.   printf "%A" node
  26.   printf ".["
  27.   for j = 0 to 3 do  
  28.     if tab2d.[node,j] =1 then printf "%A " j; printf ","
  29.   printf "]\n"
  30. printf "\n"
  31. smosiedzi_wierzcholka 2 ()
  32.  
  33. //TRANSPOZE
  34. let transpozed tab = Array2D.init (Array2D.length2 tab) (Array2D.length1 tab) (fun r c -> tab.[c,r])
  35.  
  36. let tab_t = transpozed tab2d
  37.  
  38.  
  39.  
  40. type Lista<'a> =
  41. | Data of 'a * Lista<'a> ref
  42. | Nil
  43.  
  44.  
  45.  
  46. //333333 zadoo
  47. let rnd = new System.Random()
  48.  
  49. let losy = new Dictionary<int,int>();;
  50. for i=0 to 100 do
  51.  let los = rnd.Next(0,10)
  52.  
  53.  let (ya, buff) = losy.TryGetValue(los)
  54.  if ya then
  55.    losy.Remove(los)
  56.    losy.Add(los, (buff+1))
  57.  else
  58.    losy.Add(los, 1)
  59.  
  60. for i=0 to 9 do
  61.  printf "%A " i
  62.  printf ".= "
  63.  let (ya, buff) = losy.TryGetValue(i)
  64.  if ya then
  65.    printf "%A " buff
  66.  printf "\n"
  67.  
  68.  
  69. //TRANSPOZE
  70. let primed tab = Array.init (Array2D.length1 tab) (fun i ->[ for j in [0..3] do if tab.[i,j]=1 then yield j ] )
  71.  
  72. let primed2MAP tab = List.init (Array2D.length1 tab) (fun i ->[ for j in [0..3] do if tab.[i,j]=1 then yield j ] )|>List.indexed |> Map.ofList
  73.  
  74. printf "\n"
  75. printfn "%A" (primed tab2d)
  76. printf "\n"
  77. printfn "%A" (primed2MAP tab2d)
  78.  
  79.  
  80. //part twoooooooooooooooooooooooo
  81. type Lista<'a> =
  82. | Data of 'a * Lista<'a> ref
  83. | Nil
  84.  
  85.  
  86. //let rec zlicz l ilosc =
  87. //  match l with
  88. //  |> Data (a, ref)-> zlicz l.Data.value (ilosc+1)
  89. //  |> Nil -> ilosc
  90.  
  91. //wypisz
  92. //let rec wypisz l=
  93. //  match l with
  94. //  |> Data -> printf "%A" Data.value; zlicz l.Data.value
  95. //  |> Nil -> printf "end"
  96.  
  97. //dodaj
  98. //let rec zlicz l=
  99. //  match l with
  100. //  |> Data -> printf "%A" Data.value; zlicz l.Data.value
  101. //  |> Nil -> l.Data.value = new  'a * Lista<'a>
Add Comment
Please, Sign In to add comment