Guest User

Untitled

a guest
Aug 17th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Problema: Defina uma função que associa um numero decimal ao seu representante na base 2
  2. -- Solução.: Luan Leonardo
  3.  
  4. -- Main> binario 15
  5. -- [1,1,1,1]
  6.  
  7. -- Main> binario 89
  8. -- [1,0,1,1,0,0,1]
  9.  
  10. -- Main> binario 100
  11. -- [1,1,0,0,1,0,0]
  12.  
  13. -- Main> binario 55
  14. -- [1,1,0,1,1,1]
  15.  
  16. -- Main> binario 37
  17. -- [1,0,0,1,0,1]
  18.  
  19. binario n =
  20.        
  21.         if n == 0 then [0]
  22.         else
  23.         if n == 1 then [1]
  24.         else
  25.            binario (div n 2) ++ [(mod n 2)]
Add Comment
Please, Sign In to add comment