This file contains 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
// https://pt.stackoverflow.com/q/355941/5878 | |
$gabarito = '1;1;A|2;1;B|3;1;C|4;1;A|5;1;A|6;2;D|7;2;C|8;2;B|9;2;A|10;2;A'; | |
$materias = []; | |
foreach (explode('|', $gabarito) as $resposta) { | |
list($pergunta, $materia, $alternativa) = str_getcsv($resposta, ';'); | |
if ( ! array_key_exists($materia, $materias)) { |
This file contains 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
<?php | |
use Psr\Http\Message\ResponseInterface; | |
use Psr\Http\Message\ServerRequestInterface; | |
use Psr\Http\Server\RequestHandlerInterface; | |
use Zend\Diactoros\ServerRequestFactory; | |
use Zend\Diactoros\Response\HtmlResponse; | |
use Woss\Pipeline; | |
require "../vendor/autoload.php"; |
This file contains 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
$pipeline = new Pipeline([ | |
function ($request, $next) { | |
if (!isset($request->getAttribute('user'))) { | |
return new Response(401, 'Sai daqui demônio!'); | |
} | |
return $next->handle($request); | |
}, | |
function ($request, $next) { |
This file contains 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
class Pipeline implements RequestHandlerInterface | |
{ | |
public function __constuct($handlers) | |
{ | |
$this->handlers = $handlers; | |
} | |
public function handle(Request $request): Response | |
{ | |
$handler = current($this->handlers); |
This file contains 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
import time | |
def is_prime(number): | |
i = 3 | |
while i**2 <= number: | |
if number % i == 0: | |
return False | |
i += 2 | |
return True |
This file contains 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
import math, time | |
def sieve_of_eratosthene(N): | |
# Cria-se uma lista referente a todos os inteiros entre 0 e N: | |
A = [True] * (N+1) | |
# Define os números 0 e 1 como não primos: | |
A[0] = A[1] = False |
This file contains 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
code = ''' | |
def perfect_numbers(N): | |
def sieve_of_eratosthene(N): | |
A = [True] * (N+1) | |
A[0] = A[1] = False | |
for value, prime in enumerate(A): | |
if prime: | |
yield value |
This file contains 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 perfect_numbers(N): | |
def sieve_of_eratosthene(N): | |
A = [True] * (N+1) | |
A[0] = A[1] = False | |
for value, prime in enumerate(A): | |
if prime: | |
yield value | |
for i in range(value**2, N+1, value): | |
A[i] = False |
This file contains 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
from math import factorial, radians, isclose, sin | |
def seno(x, n=7): | |
x = radians(x) | |
def termo_geral(x, i): | |
return ((-1)**i / factorial(2*i+1)) * (x**(2*i+1)) | |
def termos(x, n): | |
for i in range(n): |
This file contains 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
from math import factorial, radians, isclose, sin | |
def seno(x, n=7): | |
# Se o ângulo for em graus, converte para radianos | |
if x > 1: | |
x = radians(x) | |
def termo_geral(x, i): | |
return ((-1)**i / factorial(2*i+1)) * (x**(2*i+1)) |