Skip to content

Instantly share code, notes, and snippets.

View NicolasFrancaX's full-sized avatar
🎯
Focusing

Nicolas França NicolasFrancaX

🎯
Focusing
View GitHub Profile
// Lendo valores no JS via console
// http://nodejs.org/api/readline.html#readline_readline
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
@NicolasFrancaX
NicolasFrancaX / gist:5653664
Created May 26, 2013 18:43
Código para fazer comunicação serial com o Java e reproduzir sons com a Shield Wave.
int RST=3;
int CLK=9;
int DAT=8;
int byteEntrada = 0;
void setup() {
// Entra no espaço "9600" da porta. Esse espaço é PADRÃO.
Serial.begin(9600);
}
/*
Button
Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
// Authors: Nicolas and Mariane
int RST=3;
int CLK=9;
const int botao = 7; // the number of the pushbutton pin
const int ledPin = 2; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
// Authors: Nicolas and Mariane
int RST=3;
int CLK=9;
const int botao = 7;
const int ledPin = 2;
int buttonState = 0;
const int buttonPin = 8;
const int ledPin = 2;
int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
=begin
Each new term in the Fibonacci sequence is generated by adding the previous two terms.
By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million,
find the sum of the even-valued terms.
http://projecteuler.net/problem=2
=end
# http://projecteuler.net/problem=1
sum = 0
(0..999).each do |n|
if n % 3 == 0 || n % 5 == 0
sum += n
end
end
alunos_aprovados = 0
(1..10).each do |n|
puts "Aluno #{n} - Aprovado (digite - a) ou Reprovado (digite - r)?"
teste = gets.chomp
alunos_aprovados += 1 if teste == "a"
end
if alunos_aprovados >= 8
function fatorial(n) {
if (n == 1) {
return 1;
} else {
return n * fatorial(n - 1);
}
}
console.log(fatorial(5));