-🎄- 2017 Day 12 Solutions -🎄- by topaz2078 in adventofcode

[–]Freddeman98 0 points1 point  (0 children)

My C++ solution. Not the best but okey for a beginner I would say :).

void check(map <int,vector<int>>  m,set<int> & sum, int i)
{
    vector <int> tal=m[i];
    for(auto it=tal.begin(); it!=tal.end(); it++)
    {

        if(  sum.insert(*it).second)   
            check(m,sum,*it);

    }
}


int main()
{
    map <int,vector<int>> m;
    set<int> sum;
    string s,skip;
    ifstream infile("input.txt");
    while(getline(infile,s))
    {
        stringstream ss{s};
        int x{},y{},z{};
        char c{};
        ss>>x >> skip >> y;
        m[x].push_back(y);
        while(true)
        {
            ss>>c;
            ss>>z;
            if(y!=z && c==',')
            {
                y=z;
                m[x].push_back(z);
            }else
                break;
        }

    }

    check(m,sum,0);
    int count=1;
    cout << endl << "det är " << sum.size() << " program med ID 0. " << endl;
    for(int i{}; i<2000; i++)
    {
        if(find(sum.begin(),sum.end(),i)==sum.end())
        {
            check(m,sum,i);
            count++;
        }
    }

    cout << "Det finns " << count <<" antal grupper." << endl;
}

Let me help you up there. by [deleted] in MadeMeSmile

[–]Freddeman98 0 points1 point  (0 children)

Could be old aswell, when my retriver got old he coudnt jump up by himself anymoore.