<commit_before>package cribcalc;

import java.util.ArrayList;

import java.util.Iterator;
import java.util.List;

import jcrib.Score;
import jcrib.Scoring;
import jcrib.cards.Card;
import jcrib.cards.Deck;
import jcrib.cards.Hand;

public class CribCalc {

    public static void main(String[] cards) {

        Deck deck = new Deck();
        Hand hand = new Hand();
        for (String card : cards) {
            Card c = new Card(card);
            deck.removeCard(c);
            hand.addCard(c);
        }
        List<Hand> handCombinations = buildHandCombinations(hand);
        for (Hand h : handCombinations) {
            System.out.println(h);
            int total = 0;
            for (Score s : Scoring.scoreHand(h)) {
                total += s.getPoints();
            }
            System.out.println(total + " points");
        }
        System.out.println(handCombinations.size());
    }

    private static List<Hand> buildHandCombinations(Hand seedHand) {
        List<Hand> hands = new ArrayList<>();
        scanHands(new Hand(), seedHand, hands);
        return hands;
    }

    private static void scanHands(Hand currentHand, Hand baseHand,
            List<Hand> hands) {
        if (currentHand.size() == 4) {
            hands.add(currentHand);
            return;
        }

        Iterator<Card> it = baseHand.iterator();
        while (it.hasNext()) {
            Card c = it.next();
            it.remove();

            baseHand.removeCard(c);
            Hand newCurrent = new Hand(currentHand);
            newCurrent.addCard(c);

            Hand newBase = new Hand(baseHand);
            newBase.removeCard(c);

            scanHands(newCurrent, newBase, hands);
        }
    }
}<commit_msg>Fix concurrent modification exception<commit_after>package cribcalc;

import java.util.ArrayList;

import java.util.Iterator;
import java.util.List;

import jcrib.Score;
import jcrib.Scoring;
import jcrib.cards.Card;
import jcrib.cards.Deck;
import jcrib.cards.Hand;

public class CribCalc {

    public static void main(String[] cards) {

        Deck deck = new Deck();
        Hand hand = new Hand();
        for (String card : cards) {
            Card c = new Card(card);
            deck.removeCard(c);
            hand.addCard(c);
        }
        List<Hand> handCombinations = buildHandCombinations(hand);
        for (Hand h : handCombinations) {
            System.out.println(h);
            int total = 0;
            for (Score s : Scoring.scoreHand(h)) {
                total += s.getPoints();
            }
            System.out.println(total + " points");
        }
        System.out.println(handCombinations.size());
    }

    private static List<Hand> buildHandCombinations(Hand seedHand) {
        List<Hand> hands = new ArrayList<>();
        scanHands(new Hand(), seedHand, hands);
        return hands;
    }

    private static void scanHands(Hand currentHand, Hand baseHand,
            List<Hand> hands) {
        if (currentHand.size() == 4) {
            hands.add(currentHand);
            return;
        }

        Iterator<Card> it = baseHand.iterator();
        while (it.hasNext()) {
            Card c = it.next();
            it.remove();

            Hand newCurrent = new Hand(currentHand);
            newCurrent.addCard(c);

            Hand newBase = new Hand(baseHand);
            newBase.removeCard(c);

            scanHands(newCurrent, newBase, hands);
        }
    }
}
{'fraction_non_alphanumeric': 0.11413673232908458, 'fraction_numerical': 0.0011587485515643105, 'mean_word_length': 1.9412265758091993, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6244284', 'n_tokens_mistral': 1019, 'n_tokens_neox': 982, 'n_words': 234}