i made some code that does what i wanted and will post it as the answer to my question;
heres the code;
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace project
{
class part_4
{
public void group_lines(string[] forward_line_numbers, string[] reverse_line_numbers, int new_how_many_lines)
{
// Reverse again.
Array.Reverse(reverse_line_numbers);
for (int i = 0; i < new_how_many_lines / 2; ++i)
{
Console.WriteLine("//////////////////");
Console.WriteLine(forward_line_numbers[i]);
Console.WriteLine(reverse_line_numbers[i]);
}
}
public static int CountWords(string test)
{
int count = 0;
bool inWord = false;
foreach (char t in test)
{
if (char.IsWhiteSpace(t))
{
inWord = false;
}
else
{
if (!inWord) count++;
inWord = true;
}
}
return count;
}
public void compare(string[] new_shortened_list, string[] forward_line_numbers, string missing_words, string missing_lines, int i)
{
int test = 0;
string[] myarray = missing_words.Split(' ');
foreach (string temp in myarray)
{
if ((temp == " ") && (temp == "") && (temp == null)) break;
bool result = Regex.IsMatch(new_shortened_list[i], temp);
if (result == false)
{
test = 1;
}
}
if (test == 0)
{
Console.WriteLine(missing_lines);
Console.WriteLine(forward_line_numbers[i]);
}
}
public void difference(string[] new_shortened_list,
string[] working_array,
string[] forward_line_numbers,
int new_how_many_lines,
int how_many_repetitions)
{
string missing_words = "";
string missing_lines = "";
int counter = 0;
int word_counter = 0;
StringBuilder s = new StringBuilder();
StringBuilder t = new StringBuilder();
for (int i = 0; i < new_how_many_lines; ++i)
{
for (int j = 0; j < how_many_repetitions; ++j)
{
bool result_1 = Regex.IsMatch(new_shortened_list[i], working_array[j]); // compare words in each line to every word counted
if (result_1 == false) // if the word is missing in the line
{
bool result_2 = Regex.IsMatch(missing_words, working_array[j]); // is the word missing in the missing word list
if ((result_2 == false) && (counter < (how_many_repetitions - 1))) // if it is missing, and the list of missing words is less than the total number of words, i can write it to the missing word list
{
s.Append(working_array[j]);
s.Append(" ");
t.Append(forward_line_numbers[i]);
t.Append(" ");
counter++;
}
}
}
missing_words = s.ToString();
missing_lines = t.ToString();
word_counter = CountWords(new_shortened_list[i]);
if (word_counter < how_many_repetitions)
{
compare(new_shortened_list, forward_line_numbers, missing_words, missing_lines, i);
}
}
}
public void split_sentence(string[] new_shortened_list, int new_how_many_lines)
{
for (int i = 0; i < new_how_many_lines; ++i)
{
if (new_shortened_list[i].Length > 0)
{
int j = new_shortened_list[i].IndexOf(" ") + 1;
new_shortened_list[i] = new_shortened_list[i].Substring(j);
}
}
}
public void get_first_number(string[] new_shortened_list,
string[] forward_line_numbers,
string[] reverse_line_numbers,
int new_how_many_lines)
{
for (int i = 0; i < new_how_many_lines; ++i)
{
forward_line_numbers[i] = new_shortened_list[i].Split(new char[] { ' ' })[0];
reverse_line_numbers[i] = new_shortened_list[i].Split(new char[] { ' ' })[0];
}
}
public void get_first_word(string[] working_array, int how_many_repetitions)
{
for (int i = 0; i < how_many_repetitions; ++i)
{
working_array[i] = working_array[i].Split(new char[] { ' ' })[0];
}
}
/* working array contents:
* lion 6 1 2 4 5 6 7
* and 6 1 2 3 4 5 6
* mouse 6 1 2 3 4 6 7
*/
/* new_shortened_list array contents:
* 2 lion and mouse
* 3 and mouse
* 4 lion and mouse
* 5 lion and
* 6 lion and mouse
* 7 lion mouse
*/
public void step_1(string[] new_shortened_list,
string[] working_array,
int new_how_many_lines,
int how_many_repetitions)
{
get_first_word(working_array, how_many_repetitions);
string[] forward_line_numbers = new string[new_how_many_lines];
string[] reverse_line_numbers = new string[new_how_many_lines];
get_first_number(new_shortened_list, forward_line_numbers, reverse_line_numbers, new_how_many_lines);
split_sentence(new_shortened_list, new_how_many_lines);
difference(new_shortened_list, working_array, forward_line_numbers, new_how_many_lines, how_many_repetitions);
group_lines(forward_line_numbers, reverse_line_numbers, new_how_many_lines);
}
}
}
heres the program results;
Code:
3 5
7
//////////////////
2
7
//////////////////
3
6
//////////////////
4
5
Press any key to continue . . .