Question: I write a python telnet client to communicate with a server through telnet. However, many people tell me that it's no secure. How can I convert it to ssh? Should I need to totally rewrite my program?

Answer: 
```
val sorted = List(1, 5, 15, 37, 39, 42, 50)
(sorted.tail,sorted).zipped.map(_-_).min
//res2: Int = 2

```

**[Edit]**

You can use a fold as well:

```
sorted.tail.foldLeft((sorted.head,Int.MaxValue))((x,y) => (y, math.min(y-x._1,x._2)))._2

```
Imperative (and possible faster) version:

```
  if (sorted.isEmpty) {
    None
  } else {
    var sortedTail = sorted.tail
    if (sortedTail.isEmpty) {
      None
    } else {
      var minDiff = Int.MaxValue
      var prev = sorted.head
      do {
        val curr = sortedTail.head
        minDiff = minDiff min math.abs(curr - prev)
        sortedTail = sortedTail.tail
        prev = curr
      } while (!sortedTail.isEmpty)
      Some(minDiff)
    }
  }

```