<commit_before>/* qqq : implement */
let _;

if( typeof module !== 'undefined' )
{
  _ = require( 'wTools' );
  require( 'wConsequence' );
}

const fork1 = { isAvailable : true }
const fork2 = { isAvailable : true }
const fork3 = { isAvailable : true }
const fork4 = { isAvailable : true }
const fork5 = { isAvailable : true }

const philosopher1 =
{
  leftFork : fork5,
  rightFork : fork1,
  leftHand : null,
  rightHand : null,
  getHungry : 2500,
  eatingTime : 5000
}
const philosopher2 =
{
  leftFork : fork1,
  rightFork : fork2,
  leftHand : null,
  rightHand : null,
  getHungry : 4500,
  eatingTime : 5000
}
const philosopher3 =
{
  leftFork : fork2,
  rightFork : fork3,
  leftHand : null,
  rightHand : null,
  getHungry : 5000,
  eatingTime : 5000
}
const philosopher4 =
{
  leftFork : fork3,
  rightFork : fork4,
  leftHand : null,
  rightHand : null,
  getHungry : 6500,
  eatingTime : 5000
}
const philosopher5 =
{
  leftFork : fork4,
  rightFork : fork5,
  leftHand : null,
  rightHand : null,
  getHungry : 3500,
  eatingTime : 5000
}<commit_msg>DiningPhilosophers task, some progres<commit_after>/* qqq : implement */
let _;

if( typeof module !== 'undefined' )
{
  _ = require( 'wTools' );
  require( 'wConsequence' );
}

const fork1 = { id : 1, isAvailable : true }
const fork2 = { id : 2, isAvailable : true }
const fork3 = { id : 3, isAvailable : true }
const fork4 = { id : 4, isAvailable : true }
const fork5 = { id : 5, isAvailable : true }

const forks = [ fork1, fork2, fork3, fork4, fork5 ];

const philosophers =
[
  { // will eat
    id : 1,
    name : 'Plato',
    isEating : false,
    leftFork : fork5,
    rightFork : fork1,
    getHungry : 2500,
    eatingTime : 5000
  },
  {
    id : 2,
    name : 'Aristotle',
    isEating : false,
    leftFork : fork1,
    rightFork : fork2,
    getHungry : 4500,
    eatingTime : 5000
  },
  { // will eat
    id : 3,
    name : 'Heraclitus',
    isEating : false,
    leftFork : fork2,
    rightFork : fork3,
    getHungry : 6500,
    eatingTime : 5000
  },
  {
    id : 4,
    name : 'Diogenes',
    isEating : false,
    leftFork : fork3,
    rightFork : fork4,
    getHungry : 5000,
    eatingTime : 5000
  },
  {
    id : 5,
    name : 'Cicero',
    isEating : false,
    leftFork : fork4,
    rightFork : fork5,
    getHungry : 3500,
    eatingTime : 5000
  }
];

const startTime = _.time.now();
const con = new _.Consequence().take( null );

run( 1 );

//

function run( k )
{
  for( let i = 0; i < philosophers.length; i++ )
  {
    const ph = philosophers[ i ];
    _.time.out( ph.id === 1 || ph.id === 3 ? ph.getHungry * k : ph.getHungry, () => getHungry( ph ) );
  }

  // if( k === 1 )
  // _.time.out( 30000, () => run( 2 ) )
}

//

function getHungry( ph )
{
  console.log( `+ ph_${ph.id} is hungry - ${status()}` );

  // if( ph.leftFork.isAvailable && ph.rightFork.isAvailable )
  // {
  //   con.then( () => startEating( ph ) )
  // }
}

//

function status()
{
  const busyFokrs = forks.filter( ( fork ) => !fork.isAvailable ).map( ( fork ) => fork.id );
  const eatingPh = philosophers.filter( ( ph ) => ph.isEating ).map( ( ph ) => ph.id );
  return `time: ${_.time.spent( startTime )}, busyFokrs: ${busyFokrs}, eatingPh: ${eatingPh}`;
}

//

function startEating( ph )
{
  ph.leftFork.isAvailable = false;
  ph.rightFork.isAvailable = false;
  console.log( `` );
}

//

function stopEating( ph )
{

}

//

// function checkLeftSide( ph )
// {

// }

//

// function checkRightSide( ph )
// {

// }
{'fraction_non_alphanumeric': 0.15259089607787002, 'fraction_numerical': 0.040366447180074434, 'mean_word_length': 2.602061855670103, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 10, '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': '925065', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1335, 'n_words': 328}