Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- display all pythagorean triplets until n
  2. pyth n = [(x,y,z)|x<-[1..n],y<-[x..n],z<-[x..n], x^2+y^2==z^2]
  3.  
  4.  
  5. -- signum if get 0, standardsize as 0, other number is 1
  6.  
  7. signum 0 = 0
  8. signum n = 1
  9.  
  10. -- write a program to read a list of tuples from the user of the form
  11. -- [(1,"sam",25),(2,"john",24),(3,"mary",26)] and display the list of the form
  12. -- [(1,25),(2,24),(3,26)]
  13.  
  14. mydisplay xs = [(x,z)|(x,y,z)<-xs]
  15.  
  16. -- write a program to read a list of tuples from the user of the form
  17. -- [(2,4),(1,6),(0,3)] and produce the output
  18. -- [8,6,0]
  19.  
  20. myprods xs = [(x*y)|(x,y)<-xs]
  21.  
  22. -- check if the list is sorted in ascending
  23.  
  24. pairup xs = zip xs (tail xs)
  25. checkorder xs = and[(x<y)| (x,y)<-pairup xs ]
  26.  
  27. -- dot product
  28. dotpro xs ys = sum [(x*y)|(x,y)<-zip xs ys]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement