Skip to content

Instantly share code, notes, and snippets.

View MichaelSelsky's full-sized avatar

Michael Selsky MichaelSelsky

View GitHub Profile
import Foundation
extension Collection where Self.Iterator.Element: RandomAccessCollection {
// PRECONDITION: `self` must be rectangular, i.e. every row has equal size.
func transposed() -> [[Self.Iterator.Element.Iterator.Element]] {
guard let firstRow = first else { return [] }
return firstRow.indices.map { index in
self.map { $0[index] }
}
}

Cesarian Cypher

Encoding/Decoding a string using a cypher with an arbitray offset

Process

  • Generate an encoding dictionary that maps an original value to a new value based on an offset
  • Use enc_dict to write an encoded string
  • Generate a decoding dict that maps an encoded value back to the original based on the negative offset
  • Reverse the encoding

Ensures understanding of

import random
# Most of this code is more advanced than what I'd expect from the students. Lots of list comprehension that can be replaced with loops
def removePunctuation(s):
'''
Remove all the punctuation and replace with spaces.
'''
return ''.join(ch if ch not in string.punctuation else ' ' for ch in s)
### Keybase proof
I hereby claim:
* I am michaelselsky on github.
* I am michaelselsky (https://keybase.io/michaelselsky) on keybase.
* I have a public key whose fingerprint is AAF3 A478 926A 06B2 9B18 343F CA4D 4AF6 9BC6 7870
To claim this, I am signing this object:
@MichaelSelsky
MichaelSelsky / NJIT CS356 Homework 3
Last active August 29, 2015 14:15
Swift script to solve homework 3 for NJIT CS 356
let giga = 1000000000
let mega = 1000000
let kilo = 1000
let fileSize = 20*giga
let serverUploadSpeed = 20*mega
let clientDownloadSpeed = 2*mega
func serverTime(numberOfClients: Int, uploadSpeedOfClients: Int) -> Int {
let serverToUploadNFiles = numberOfClients * fileSize / serverUploadSpeed