Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'ve got a list in a text file with the top 1000 words used in the english lang

ID: 3527163 • Letter: I

Question

I've got a list in a text file with the top 1000 words used in the english language. Each line has a list of up to 50 words, like this: the,stuff,is,thing,hi,bye,hello,a,stuffs cool,free,awesome,the,pray,is,crime etc. I need to write code using that file as input, to make an output file with the a list of pairs of words which appear together in at least fifty different lists. For example, in the above example, THE & IS appear together twice, but every other pair appears only once. I can't store all possible pairs of words, so no brute force . I'm trying to learn the language and i'm stuck on this exercise of the book. Please help. Any logic, guidance or if you could give me the code in php for this would help me. I'm trying to move on to the next section. This is what I have so far. It doesn't do what's intended but i'm stuck: Code in php: //open the file $handle = fopen("list.txt", 'r'); $count = 0; $is = 0; while(!feof($handle)) { $line = fgets($handle); $words = explode(',', $line); echo $count . "

"; print_r($words); foreach ($words as $word) { if ($word == "is") { $is++; } } echo "

"; $count++; } echo "Is count: $is"; //close the file fclose($handle); $fp = fopen('output.txt', 'w'); fwrite($fp, "is count: " . $is); fclose($fp); This is what I came up with but I think it's too bloated: plan: check the first value of the $words array store the value into $cur_word store $cur_word as a key in an array ($compare) and store the counter (line number) as the value of that key it'll be 1 at this point see if $cur_word is on each line and if it is then put the value into $compare with the key as $cur_word if array has at least 50 values then continue else go to the next value of the $words array if it has 50 values then go to the next value and do the samething compare both lists to see how many values match if it's at least 50 then append the words to the output file repeat this process with every word

Explanation / Answer

$handle = fopen("list.txt", 'r'); $count = 0; $is = 0; while(!feof($handle)) { $line = fgets($handle); $words = explode(',', $line); echo $count . "

"; print_r($words); foreach ($words as $word) { if ($word == "is") { $is++; } } echo "

"; $count++; } echo "Is count: $is"; //close the file fclose($handle); $fp = fopen('output.txt', 'w'); fwrite($fp, "is count: " . $is); fclose($fp);
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote