extract data from the list

Asked

Viewed 87 times

0

I made a few attempts, but I’m still picking up follows what I added in the code.

How can I make this limitation within the code that results in the closure below? I lacked logic of how to implement reading data from text file.

Here you have 4 if 4 (10 tens).

  • Example1:

if they are drawn: 1,3,5,6,8,9 among the 10 I have a block or several.

  • Exemplo2:

let’s assume another draw that I missed two tens 12 and 19 type: 1,3,5,6,12,19 in this case I only got 4 out of 10, if I look for those 4 tens in the lock below, I have at least that set or be a block.

********************************************
resultado a ser alcançado
********************************************

total dezenas: 10
conjunto 6
garantia 4
para acerto 4

01 02 03 04 05 06,
01 02 03 05 07 09,
01 02 03 06 07 08,
01 02 03 06 09 10,
01 02 04 06 07 10,
01 02 04 07 08 09,
01 02 05 07 08 10,
01 03 04 05 07 10,
01 03 04 05 08 09,
01 03 05 06 08 10,
01 04 06 08 09 10,
01 05 06 07 09 10,
02 03 04 06 08 09,
02 03 04 07 09 10,
02 03 05 08 09 10,
02 04 05 06 07 09,
02 04 05 06 08 10,
03 04 06 07 08 10,
03 05 06 07 08 09,
04 05 07 08 09 10,

to facilitate am posting

txt list.

01  02  03  04  05  06,
01  02  03  04  05  07,
01  02  03  04  05  08,
01  02  03  04  05  09,
01  02  03  04  05  10,
01  02  03  04  06  07,
01  02  03  04  06  08,
01  02  03  04  06  09,
01  02  03  04  06  10,
01  02  03  04  07  08,
01  02  03  04  07  09,
01  02  03  04  07  10,
01  02  03  04  08  09,
01  02  03  04  08  10,
01  02  03  04  09  10,
01  02  03  05  06  07,
01  02  03  05  06  08,
01  02  03  05  06  09,
01  02  03  05  06  10,
01  02  03  05  07  08,
01  02  03  05  07  09,
01  02  03  05  07  10,
01  02  03  05  08  09,
01  02  03  05  08  10,
01  02  03  05  09  10,
01  02  03  06  07  08,
01  02  03  06  07  09,
01  02  03  06  07  10,
01  02  03  06  08  09,
01  02  03  06  08  10,
01  02  03  06  09  10,
01  02  03  07  08  09,
01  02  03  07  08  10,
01  02  03  07  09  10,
01  02  03  08  09  10,
01  02  04  05  06  07,
01  02  04  05  06  08,
01  02  04  05  06  09,
01  02  04  05  06  10,
01  02  04  05  07  08,
01  02  04  05  07  09,
01  02  04  05  07  10,
01  02  04  05  08  09,
01  02  04  05  08  10,
01  02  04  05  09  10,
01  02  04  06  07  08,
01  02  04  06  07  09,
01  02  04  06  07  10,
01  02  04  06  08  09,
01  02  04  06  08  10,
01  02  04  06  09  10,
01  02  04  07  08  09,
01  02  04  07  08  10,
01  02  04  07  09  10,
01  02  04  08  09  10,
01  02  05  06  07  08,
01  02  05  06  07  09,
01  02  05  06  07  10,
01  02  05  06  08  09,
01  02  05  06  08  10,
01  02  05  06  09  10,
01  02  05  07  08  09,
01  02  05  07  08  10,
01  02  05  07  09  10,
01  02  05  08  09  10,
01  02  06  07  08  09,
01  02  06  07  08  10,
01  02  06  07  09  10,
01  02  06  08  09  10,
01  02  07  08  09  10,
01  03  04  05  06  07,
01  03  04  05  06  08,
01  03  04  05  06  09,
01  03  04  05  06  10,
01  03  04  05  07  08,
01  03  04  05  07  09,
01  03  04  05  07  10,
01  03  04  05  08  09,
01  03  04  05  08  10,
01  03  04  05  09  10,
01  03  04  06  07  08,
01  03  04  06  07  09,
01  03  04  06  07  10,
01  03  04  06  08  09,
01  03  04  06  08  10,
01  03  04  06  09  10,
01  03  04  07  08  09,
01  03  04  07  08  10,
01  03  04  07  09  10,
01  03  04  08  09  10,
01  03  05  06  07  08,
01  03  05  06  07  09,
01  03  05  06  07  10,
01  03  05  06  08  09,
01  03  05  06  08  10,
01  03  05  06  09  10,
01  03  05  07  08  09,
01  03  05  07  08  10,
01  03  05  07  09  10,
01  03  05  08  09  10,
01  03  06  07  08  09,
01  03  06  07  08  10,
01  03  06  07  09  10,
01  03  06  08  09  10,
01  03  07  08  09  10,
01  04  05  06  07  08,
01  04  05  06  07  09,
01  04  05  06  07  10,
01  04  05  06  08  09,
01  04  05  06  08  10,
01  04  05  06  09  10,
01  04  05  07  08  09,
01  04  05  07  08  10,
01  04  05  07  09  10,
01  04  05  08  09  10,
01  04  06  07  08  09,
01  04  06  07  08  10,
01  04  06  07  09  10,
01  04  06  08  09  10,
01  04  07  08  09  10,
01  05  06  07  08  09,
01  05  06  07  08  10,
01  05  06  07  09  10,
01  05  06  08  09  10,
01  05  07  08  09  10,
01  06  07  08  09  10,
02  03  04  05  06  07,
02  03  04  05  06  08,
02  03  04  05  06  09,
02  03  04  05  06  10,
02  03  04  05  07  08,
02  03  04  05  07  09,
02  03  04  05  07  10,
02  03  04  05  08  09,
02  03  04  05  08  10,
02  03  04  05  09  10,
02  03  04  06  07  08,
02  03  04  06  07  09,
02  03  04  06  07  10,
02  03  04  06  08  09,
02  03  04  06  08  10,
02  03  04  06  09  10,
02  03  04  07  08  09,
02  03  04  07  08  10,
02  03  04  07  09  10,
02  03  04  08  09  10,
02  03  05  06  07  08,
02  03  05  06  07  09,
02  03  05  06  07  10,
02  03  05  06  08  09,
02  03  05  06  08  10,
02  03  05  06  09  10,
02  03  05  07  08  09,
02  03  05  07  08  10,
02  03  05  07  09  10,
02  03  05  08  09  10,
02  03  06  07  08  09,
02  03  06  07  08  10,
02  03  06  07  09  10,
02  03  06  08  09  10,
02  03  07  08  09  10,
02  04  05  06  07  08,
02  04  05  06  07  09,
02  04  05  06  07  10,
02  04  05  06  08  09,
02  04  05  06  08  10,
02  04  05  06  09  10,
02  04  05  07  08  09,
02  04  05  07  08  10,
02  04  05  07  09  10,
02  04  05  08  09  10,
02  04  06  07  08  09,
02  04  06  07  08  10,
02  04  06  07  09  10,
02  04  06  08  09  10,
02  04  07  08  09  10,
02  05  06  07  08  09,
02  05  06  07  08  10,
02  05  06  07  09  10,
02  05  06  08  09  10,
02  05  07  08  09  10,
02  06  07  08  09  10,
03  04  05  06  07  08,
03  04  05  06  07  09,
03  04  05  06  07  10,
03  04  05  06  08  09,
03  04  05  06  08  10,
03  04  05  06  09  10,
03  04  05  07  08  09,
03  04  05  07  08  10,
03  04  05  07  09  10,
03  04  05  08  09  10,
03  04  06  07  08  09,
03  04  06  07  08  10,
03  04  06  07  09  10,
03  04  06  08  09  10,
03  04  07  08  09  10,
03  05  06  07  08  09,
03  05  06  07  08  10,
03  05  06  07  09  10,
03  05  06  08  09  10,
03  05  07  08  09  10,
03  06  07  08  09  10,
04  05  06  07  08  09,
04  05  06  07  08  10,
04  05  06  07  09  10,
04  05  06  08  09  10,
04  05  07  08  09  10,
04  06  07  08  09  10,
05  06  07  08  09  10,

***********************//*******************

java code

package br.teste;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;

public class LerArquivoTxT {

    ArrayList<String[]> lista = new ArrayList<>();
    ArrayList<String[]> novaLista = new ArrayList<>();

    public void LerArquivo(){

        try {
            FileReader fr = new FileReader("C:/Conteudo/listaIII.txt");
            BufferedReader br = new BufferedReader(fr);
            String temp;

            while ((temp = br.readLine()) != null) { 
                lista.add(temp.split(";"));
                compararLista(lista);

            }
        } catch (FileNotFoundException ex) {
            System.out.println("Arquivo nao encontrado!");
        } catch (IOException ex) {
            Logger.getLogger(LerArquivoTxT.class.getName()).log(Level.SEVERE, null, ex);
        }

        lista.forEach(a -> System.out.println(Arrays.toString(a)));
    }

    // METODO PARA COMPARA OS CONJUNTOS
    public void compararLista(ArrayList<String[]> lista) {        

        for(int i = 0; i < lista.size(); i++) {            
            for(int j = i + 1; j < lista.size(); j++) {
                if(lista.get(i).equals(lista.get(j))){
                    lista.remove(j);
                    j--;                    
                }
            }
        }

    }

    // SALVAR O ARQUIVO EM DISCO
    public void SalvarResumoDaLista(ArrayList<String[]> lista) throws IOException {
        try {

            FileOutputStream arquivo = new FileOutputStream("C:/Conteudo/RESUMO.txt");
            ObjectOutputStream gravador = new ObjectOutputStream(arquivo);
            gravador.writeObject(lista);
            gravador.close();
            arquivo.close();            
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        }
    }

    public static void main(String[] args) {

        LerArquivoTxT lista = new LerArquivoTxT();
        lista.LerArquivo();

        ArrayList<String[]> lista2 = null;
        try {
            lista.SalvarResumoDaLista(lista2);
        } catch (IOException ex) {
            System.out.println("Conteudo salvo com sucesso!");
        }        
    }
}
  • You’re reading every line and doing split(";"), yet all I see is , on several lines. In addition said if each , is at the end of each line so it becomes unnecessary as the line break will already serve as separation between the various lines.

  • Good day Isac if I don’t use the split he will consider each number separating by the comma so, 0,1, 0,2, 0,3,0,4,0,5,0,6 to in the case of the number 10 he will put the 1,0, if I take the zero gets like this 1,2,3,4,5,1,0. if last number is 10.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.