<commit_before>// The activity selection problem is a combinatorial optimization problem concerning the selection of non-conflicting activities
// to perform within a given time frame, given a set of activities each marked by a start time (si) and finish time (fi).
// The problem is to select the maximum number of activities that can be performed by a single person or machine,
// assuming that a person can only work on a single activity at a time.

// You are given n activities with their start and finish times.
// Select the maximum number of activities that can be performed by a single person,
// assuming that a person can only work on a single activity at a time.

// Example:

// Consider the following 6 activities.
//      start  =  [1, 3, 0, 5, 8, 5];
//      finish =  [2, 4, 6, 7, 9, 9];

// The maximum set of activities that can be executed by a single person is [0, 1, 3, 4]


function activitySelect( start, finish ){
    var result = [],
        last;

    for( var i = 0; i<start.length; i++ ){
        if( start[i-1] !== undefined ){ // 0 can be falsy
            if( start[i] < finish[i] && last < start[i]){
               result.push(i);
               last = finish[i];
            }
        } else{
          if( start[i] < finish[i] ){
            result.push(i);
            last = finish[i];
          }
        }
    }
    return result;
}
var start  =  [1, 3, 0, 5, 8, 5];
var finish =  [2, 4, 6, 7, 9, 9];
console.log(activitySelect( start, finish ))<commit_msg>add solution<commit_after>// The activity selection problem is a combinatorial optimization problem concerning the selection of non-conflicting activities
// to perform within a given time frame, given a set of activities each marked by a start time (si) and finish time (fi).
// The problem is to select the maximum number of activities that can be performed by a single person or machine,
// assuming that a person can only work on a single activity at a time.

// You are given n activities with their start and finish times.
// Select the maximum number of activities that can be performed by a single person,
// assuming that a person can only work on a single activity at a time.

// Example:

// Consider the following 6 activities.
//      start  =  [1, 3, 0, 5, 8, 5];
//      finish =  [2, 4, 6, 7, 9, 9];

// The maximum set of activities that can be executed by a single person is [0, 1, 3, 4]


function printMaxActivities( start, finish ){
    // The first activity is always selected
    var i = 0,
        result = [i];
    // Consider rest of the activities
    for(var j = 1; j<finish.length; j++ ){
        // If this activity has start time greater than or equal to
        // the finish time of previously selected activity, then select it
        if ( start[j] >= finish[i] ){
          result.push(j)
          i = j; // save as last activity
        }
    }
    return result;
}

s = [1 , 3 , 0 , 5 , 8 , 5]
f = [2 , 4 , 6 , 7 , 9 , 9]
console.log( printMaxActivities(s , f) );
// ------------------------------------------

function activitySelect( start, finish ){
    var result = [],
        last;

    for( var i = 0; i<start.length; i++ ){
        if( start[i-1] !== undefined ){ // 0 can be falsy
            if( start[i] < finish[i] && last < start[i]){
               result.push(i);
               last = finish[i];
            }
        } else{
          if( start[i] < finish[i] ){
            result.push(i);
            last = finish[i];
          }
        }
    }
    return result;
}
// var start  =  [1, 3, 0, 5, 8, 5];
// var finish =  [2, 4, 6, 7, 9, 9];
// console.log(activitySelect( start, finish ))
{'fraction_non_alphanumeric': 0.12297556958550646, 'fraction_numerical': 0.021410925061762284, 'mean_word_length': 2.146804835924007, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '356106', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1036, 'n_words': 488}