acho que a sequencia correta é essa:
4 8 15 16 23 42
rs
acho que a sequencia correta é essa:
4 8 15 16 23 42
rs
Ops
56 ?
Pelo menos o 56 é o mais popular por enquanto… mas esse não é o critério da seqüência…
Como o próximo número deve ser ímpar, creio que será 57 !
De fato o próximo número é ímpar (e isso não é mera coincidência!). Mas o que isso tem a ver com o intervalo 0-63?
[quote=rodrigousp]Pelo menos o 56 é o mais popular por enquanto… mas esse não é o critério da seqüência…
[/quote]
Hum?!
Segui essa logica:
0 , 12 , 23 , 29 , 34 , 46 , 49 , 56
De 12 a 34 a diferena eh = 22 para provar isso pegamos os numeros no intervalo:
12 - 23 = 11
23 - 29 = 6
29 - 34 = 5
Total = 11 + 6 + 5 = 22
Então
34 + 22 = 56 Provando:
34 - 46 = 12
46 - 49 = 3
Total 15 - 22 = 7 restam 7
O ultimo numero 49 + 7 = 56
Olhando o conjunto, percebi que realmente não era mera coincidencia o número ser ímpar, qto ao número 57, eu chutei pq observei que outros números ímpares já haviam sido colocados aqui…rsrs
[quote=rodrigousp]Qual o próximo número da seqüência:
0 , 12 , 23 , 29 , 34 , 46 , 49 [/quote]
Dá pra pensar um monte de coisa sobre essa sequencia. Um artíficio bom de responder a pergunta é mudando a pergunta sem alterar a resposta.
Uma das que veio na minha cabeça foi a seguinte:
Colocando a sequencia na vertical, temos:
00 + 12
12 + 11
23 + 6
29 + 5
34 + 12
46 + 3
49 + ?
Então podemos perguntar: quem vem depois da sequência: 12, 11, 6, 5, 12, 3, ?
Aí fica uma sequência mais regular. Colocando em termos de expressões:
0 - 00 + (12/1 + 0)
1 - 12 + (12/1 - 1)
2 - 23 + (12/2 + 0)
3 - 29 + (12/2 - 1)
4 - 34 + (12/1 + 0)
5 - 46 + (12/4 + 0)
6 - 49 + (12/4 - 1)
7 - 51
Daí o número seria 51. A logica da sequencia ficaria assim:
an+1 = an + (12/1 + 0) se n mod 4 = 0; ou
sendo x = floor(n / 4) + 1,
an+1 = an + (12/2^x + 0) se x for impar
an+1 = an + (12/2^x - 1) se x for par
Daí minha resposta é 51.
T+
A resposta correta é 59
:lol: :lol: :lol: :lol: :lol: :lol: :lol:
A resposta correta é mesmo 59.
A resposta correta é mesmo 59.
[/quote]
Sobre ser correta, com uma sequencia pequena voce pode tomar várias premissas.
Daí fica a critério de quem perguntou quem vai adivinhar o seu raciocínio =)
T+
A resposta correta é mesmo 59.
[/quote]
Prq?
Então, eu posso dar a resposta completa mais antes disso vou dar mais uma dica. Os números representam posições em um tabuleiro de xadrez (enumerado de 0 a 63).
se desenhar um tabuleiro e marcar as cordenadas vai perceber que é a única linha e coluna que ainda não foi marcada.
import java.awt.Graphics;
public class Desafio {
private short lin;
private short col;
private Desafio des;
public Desafio (short c, Desafio q)
{
col = c;
lin = 1;
des = q;
}
public boolean achaSolucao()
{
while (des!=null && des.podeAtacar(lin, col))
if (!avanca())
return false;
return true;
}
public boolean avanca()
{
if ( lin<8 ) {
lin++;
return achaSolucao();
}
if (des!= null) {
if (!des.avanca())
return false;
if (!des.achaSolucao())
return false;
}
else
return false;
lin = 1;
return achaSolucao();
}
private boolean podeAtacar(int tlin, int tcol) {
int colDif = tcol - col;
if ( (lin == tlin) || (lin + colDif == tlin) ||//
(lin - colDif == tlin))
return true;
if (des!= null)
return des.podeAtacar(tlin, tcol);
return false;
}
public String toString()
{
return("("+col + ", "+lin+")");
}
public void imprime()
{
if(des!= null)
des.imprime();
System.out.println(this);
}
public void paint(Graphics g) {
if (des!= null)
des.paint(g);
int x = (lin-1)*50;
int y = (col-1)*50;
g.drawOval(x+20, y+20, 10,10);
}
}
testar...
/*
* soluciona o problema
*/
public class Principal{
public static void main (String[] xyz) {
Desafio desafio;
desafio= null;
for (short i=1; i<=8; i++)
{
desafio= new Desafio(i, desafio);
desafio.achaSolucao();
}
desafio.imprime();
}
}
Essa classe de resposta não ajudou muita coisa… porque 59???
Eu considero que vocês já acharam a resposta certa…
public class AgentTable {
public final static int size = 8;
byte[][] table;
public AgentTable(){
table = new byte[size][size];
for (int i=0 ; i < size; i++) {
table[i] = new byte[size];
}
for (int i=0 ; i < size; i++) {
for (int j=0 ; j < size; j++) {
table[i][j] = 0;
}
}
}
public void putQueen(int row, int col) {
for (int i =0; i < size; i++) {
table[row][i]++;
}
for (int i =0; i < size; i++) {
table[i][col]++;
}
for (int i = row, j = col; i >= 0 && j >= 0; i--,j--) {
table[i][j]++;
}
for (int i = row, j = col; i >= 0 && j < 8; i--,j++) {
table[i][j]++;
}
for (int i = row, j = col; i < 8 && j < 8 ; i++,j++) {
table[i][j]++;
}
for (int i = row, j = col; i < 8 && j >= 0; i++,j--) {
table[i][j]++;
}
table[row][col] = 88;
}
public void removeQueen(int row, int col) {
for (int i =0; i < size; i++) {
table[row][i]--;
}
for (int i =0; i < size; i++) {
table[i][col]--;
}
for (int i = row, j = col; i >= 0 && j >= 0; i--,j--) {
table[i][j]--;
}
for (int i = row, j = col; i >= 0 && j < 8 ; i--,j++) {
table[i][j]--;
}
for (int i = row, j = col; i < 8 && j < 8 ; i++,j++) {
table[i][j]--;
}
for (int i = row, j = col; i < 8 && j >= 0; i++,j--) {
table[i][j]--;
}
table[row][col] = 0;
}
NumberFormat decimalFormat = new DecimalFormat("00");
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
for (int i=0 ; i < size; i++) {
buffer.append('-');
for (int j=0 ; j < size; j++) {
buffer.append(decimalFormat.format(table[i][j]));
buffer.append('-');
}
buffer.append('\n');
}
return buffer.toString();
}
public String getSequence(){
StringBuffer buffer = new StringBuffer();
for (int i=0 ; i < size; i++) {
buffer.append('-');
for (int j=0 ; j < size; j++) {
if (table[i][j] > 80) {
buffer.append(i*8 +j);
buffer.append('-');
}
}
}
return buffer.toString();
}
}
public class Agent {
public static void main(String[] args) {
Agent agent = new Agent();
agent.execute();
}
private AgentTable agentTable;
private void execute() {
agentTable = new AgentTable();
colocaPecas(8, 0);
System.out.println(agentTable);
System.out.println(agentTable.getSequence());
}
int count = 0;
private boolean colocaPecas(int i, int j) {
boolean move = false;
while (!move) {
j = posicaoPossivel(j);
if (j == -1) return false;
agentTable.putQueen(j/8, j%8);
if (count < 8) {
count++;
}
if (i > 1){
move = colocaPecas(i - 1, j + 1);
} else {
move = true;
}
if (!move) agentTable.removeQueen(j/8, j%8);
j++;
}
return move;
}
private int posicaoPossivel(int j) {
for(int i = j ; i < 64 ; i++)
if (agentTable.table[i/8][i%8] ==0 ) return i;
return -1;
}
}