iTSangar
5/20/2016 - 3:29 AM

Sanduicherias.swift

//: Playground - noun: a place where people can play

import UIKit
import AVFoundation

extension CollectionType {
  /// Return a copy of `self` with its elements shuffled
  func shuffle() -> [Generator.Element] {
    var list = Array(self)
    list.shuffleInPlace()
    return list
  }
}

extension MutableCollectionType where Index == Int {
  /// Shuffle the elements of `self` in-place.
  mutating func shuffleInPlace() {
    // empty and single-element collections don't shuffle
    if count < 2 { return }
    
    for i in 0..<count - 1 {
      let j = Int(arc4random_uniform(UInt32(count - i))) + i
      guard i != j else { continue }
      swap(&self[i], &self[j])
    }
  }
}


enum Gordinho {
  case ItaloSangar
  case LeticiaRibeiro
}

struct Sanduicheria {
  let nome: String!
  let endereco: String!
  let telefone: String!
  
  var notas = [[Gordinho: Double]]()
  var numeroDaSorte = 0
  
  init(nome: String, endereco: String, telefone: String) {
    self.nome = nome
    self.endereco = endereco
    self.telefone = telefone
  }
}


let a = Sanduicheria(nome: "Paidim House Burger",
                      endereco: "Avenida Cariri, N420, Urias Magalhães",
                      telefone: "3534-4641")

let b = Sanduicheria(nome: "14 Bis Burger & Grill",
                      endereco: "Praça do Avião",
                      telefone: "3928-1634")

let c = Sanduicheria(nome: "Brasa Burger",
                      endereco: "foodtruck. Siga no Instagram do Brasa Burger para saber onde encontrar.",
                      telefone: "9525-8584")

let d = Sanduicheria(nome: "Pier 13",
                      endereco: "Avenida Portugal, N818, Setor Marista",
                      telefone: "3926-1313")

let e = Sanduicheria(nome: "Retrô Food & Drinks",
                      endereco: "Rua 1136, N 550, Setor Marista",
                      telefone: "3624-4100")

let f = Sanduicheria(nome: "Life Box",
                      endereco: "Av. R11, N 1056, Setor Oeste",
                      telefone: "3091-7163")

let g = Sanduicheria(nome: "Lá em Casa Tragos e Grelhados",
                      endereco: "Rua C155, N986, Jardim América",
                      telefone: "3093-3134")

let h = Sanduicheria(nome: "Dakota Burger’s Grill",
                      endereco: "Rua T-47, N 15, Setor Oeste",
                      telefone: "3877-4045")

let i = Sanduicheria(nome: "Madero",
                      endereco: "Avenida T10, N 1300, Setor Bueno",
                      telefone: "3233-3090")

let j = Sanduicheria(nome: "Underdog Street Food",
                      endereco: "Avenida T13 com T36, Setor Bueno",
                      telefone: "-")

let k = Sanduicheria(nome: "Studio Burger",
                      endereco: "Rua T-37, Esquina com Rua T-61, Quadra 123, Lote 12, Edifício Ônix Bueno, Setor Bueno",
                      telefone: "4101-4206")

let l = Sanduicheria(nome: "Dororó Brasil",
                      endereco: "Alpha Mall, loja 30, Avenida Alphaville Flamboyant, N160, Setor Alphaville Flamboyant",
                      telefone: "3996-5066")

let m = Sanduicheria(nome: "Container Bistrô",
                      endereco: "siga eles no Instagram",
                      telefone: "8402-2728")

let n = Sanduicheria(nome: "Cabeça de Porco Burger",
                      endereco: "Avenida T-9 esquina com Rua C-146, Jd América",
                      telefone: "9961-2201")

let o = Sanduicheria(nome: "Casa do Cordeiro",
                      endereco: "Avenida Engenheiro Eurico Viana, N 35, Loja 7, Setor Vila Maria José",
                      telefone: "3642-4884")

let p = Sanduicheria(nome: "Jack Burger's",
                      endereco: "Rua C-162, quadra 311, lote 06, Jardim América",
                      telefone: "3988-0293")

var sanduicherias = [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p]



struct Sorteio {
  
  var todasSanduicherias = [Sanduicheria]()
  
  func numeroEscolhido(numeroEscolhido: Int) -> Sanduicheria {
    var sanduicheriasSemVoto = [Sanduicheria]()
    for sanduicheria in todasSanduicherias where sanduicheria.notas.count == 0 {
      sanduicheriasSemVoto.append(sanduicheria)
    }
    
    var prontasProSorteio = [Sanduicheria]()
    for (index, sanduicheria) in sanduicheriasSemVoto.shuffle().enumerate() {
      var sand = sanduicheria
      sand.numeroDaSorte = index
      prontasProSorteio.append(sand)
    }
    
    return prontasProSorteio[numeroEscolhido]
  }
}

var sorteando = Sorteio(todasSanduicherias: sanduicherias)
let escolhido = sorteando.numeroEscolhido(7)
escolhido.nome