Advertisement
VladSmirN

F# lab

May 30th, 2021
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1.  //task2 lab1
  2.    (*
  3.     let list  = [
  4.        for i in 1 .. 10 do
  5.         yield (1+i)*i/2-i+1
  6.     ]
  7.     printf "%A" list
  8.      *)
  9.    
  10.     //task1 lab2
  11.     (*
  12.     let list123 = [ 1; 2; 3;4 ]
  13.     let rec printList listx max   =
  14.         match listx with
  15.             | head :: tail -> if head%2=0&&max<head then printList tail head
  16.                                    else printList  tail max
  17.             | [] -> max
  18.     let ans = printList  list123 -1
  19.     printf "%A" ans
  20.    *)
  21.  
  22.  
  23.     //task2 lab2
  24.     (*
  25.     let list  = List.rev [0; 1;2;1; 0 ]
  26.     //printf "%A" list
  27.     let checkPalindrom list listRev = List.fold2 (fun acc elem1 elem2 -> if (elem1 <> elem2) then false else acc ) true list listRev
  28.     let ans = checkPalindrom list (List.rev list)
  29.     printf "%A" ans
  30.    *)
  31.  
  32.  
  33.     //task3 lab2
  34.     (*
  35.     let s = seq { 2; 5; 4; 7; 11; 16}
  36.    // let s = seq { 2; 5; 8; 11; 14; 17}  
  37.     let seqWindows = Seq.windowed 2 s
  38.     let seqSubtract = Seq.map (fun elem->(Array.get elem 1) - (Array.get elem 0)) seqWindows
  39.     let d = Seq.head seqSubtract
  40.     let f = Seq.fold (fun acc elem -> if (Seq.head seqSubtract <> elem) then false else acc ) true  seqSubtract
  41.     let a1 = Seq.head s
  42.  
  43.     if f then printf "Это арифмитическая прогрессия  . а1= %A  ,d = %A " a1 d
  44.     else printf "Не арифмитическая прогрессия ."
  45.     *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement