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

```
Using foldLeft:

```
   sorted match {    
      case Nil | List(_) => None
      case x :: xs => Some(
        (xs.foldLeft((Integer.MAX_VALUE, x)) {
          case ((min, prev), next) => (math.min(min, next - prev), next)
        })._1
      )
    }

```