This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn fatorial [n] | |
| {:pre [(> n 0)]} | |
| (if (< n 2) 1 | |
| (* n (fatorial (dec n))))) | |
| (fatorial 3) | |
| ; 6 | |
| (fatorial -2) | |
| ; AssertionError Assert failed: (> n 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Bom dia | |
| No dia 14 de Março comprei uma camiseta personalizada com o logotipo da linguagem de programação Clojure, | |
| com o intuito de usá-la no próximo encontro do grupo e no minicurso que vou ministrar em um evento técnico | |
| na próxima semana. | |
| Gostaria de compartilhar minha experiência com o site Kamisetas, para que vocês possam corrigir os pontos | |
| negativos e manter os pontos positivos. | |
| Pontos positivos: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; Uma equação de segundo grau segue a forma ax² + bx + c | |
| ;; Então, em x² - x - 2c = 0 teríamos | |
| ;; a = 1 | |
| ;; b = -1 | |
| ;; c = -2 | |
| ;; Então vamos invocar a função com (bhaskara 1 -1 2) | |
| ;; e vamos receber um array com os valores possiveis de x | |
| (defn bhaskara [a b c] | |
| [(/ (+ (- b) (Math/sqrt (- (* b b) (* 4 a c)))) (* 2 a)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; Uma equação de segundo grau segue a forma ax² + bx + c | |
| ;; Então, em x² - x - 2c = 0 teríamos | |
| ;; a = 1 | |
| ;; b = -1 | |
| ;; c = -2 | |
| ;; Então vamos invocar a função com (bhaskara 1 -1 2) | |
| ;; e vamos receber um array com os valores possiveis de x | |
| (defn bhaskara [a b c] | |
| (let [menos-b (- b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; Uma equação de segundo grau segue a forma ax² + bx + c | |
| ;; Então, em x² - x - 2c = 0 teríamos | |
| ;; a = 1 | |
| ;; b = -1 | |
| ;; c = -2 | |
| ;; Então vamos invocar a função com (bhaskara 1 -1 2) | |
| ;; e vamos receber um array com os valores possiveis de x | |
| (defn bhaskara [a b c] | |
| (let [menos-b (- b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mac-gusworks:game pbalduino$ lein run | |
| > Broadcast: Aguardando jogadores | |
| > Broadcast: Servidor pronto na porta 4567 | |
| > Broadcast: Um jogador conectado | |
| > Broadcast: Dois jogadores conectados | |
| > Broadcast: Jogando o jogo da velha | |
| > Broadcast: É a vez do jogador 1 | |
| > Broadcast: Jogador 1: 0 | |
| > Broadcast: | |
| O | | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Para a resposta, basta apresentar a expressão regular utilizada e o parâmetro, caso seja utilizado, | |
| 1. Dada uma lista de CEPs válidos, escreva uma expressão regular que funcione com todos os itens: | |
| 04567003 | |
| 04567-003 | |
| 04.567-003 | |
| 04.567.003 | |
| 04 567 003 | |
| 04567 003 | |
| 04567.003 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; Por que existe um tipo para números racionais em Clojure? | |
| (/ 1 3) ; Clojure retorna o tipo Ratio por padrão numa divisão | |
| ; 1/3 | |
| (double (/ 1 3)) ; agora temos um tipo Double do Java | |
| ; 0.3333333333333333 | |
| (->> 1/3 ; o valor de 1 / 3 | |
| double ; é convertido para Double |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (def trans (transient [])) | |
| (conj! trans "Main thread") | |
| (defn outra-thread [] | |
| (conj! trans "New thread")) | |
| (. (Thread. outra-thread) start) | |
| ; Exception in thread "Thread-21" java.lang.IllegalAccessError: Transient used by non-owner thread | |
| ; at clojure.lang.PersistentVector$TransientVector.ensureEditable(PersistentVector.java:464) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (def matches [[:bra 3 :cro 1] | |
| [:mex 1 :cam 0] | |
| [:esp 1 :hol 5] | |
| [:chi 3 :aus 1] | |
| [:col 3 :gre 0] | |
| [:cdm 2 :jap 1] | |
| [:uru 1 :cos 3] | |
| [:ing 1 :ita 2] | |
| [:sui 2 :equ 1] | |
| [:fra 3 :hon 0] |