It should take a list that includes a string (the output label) and list of values in a truth table for a digital logic course (4, 8, or 16 values probably strings each one can be one of four things 0, 1, X, or i -- technically i is a possible value but it would not be used when a kMap is required, though it is found in this sample question for reasons).
As a debugging exercise I have scaled back the subroutine to only deal with a list of 8 values in test2.pg.
So if the truth table is
A | B | C | O1 | O2 |
0 | 0 | 0 | 0 | 1 |
0 | 0 | 1 | 0 | 1 |
0 | 1 | 0 | 0 | 1 |
0 | 1 | 1 | 1 | i |
1 | 0 | 0 | 1 | i |
1 | 0 | 1 | 0 | 1 |
1 | 1 | 0 | X | 0 |
1 | 1 | 1 | 1 | 0 |
Then the rough Kmap answer table (that I am trying to create) should be:
O1 | 00 | 01 | 11 | 10 |
0 | 0 | 0 | 1 | 0 |
1 | 1 | 0 | 1 | X |
O2 | 00 | 01 | 11 | 10 |
0 | 1 | 1 | i | 1 |
1 | i | 1 | 0 | 0 |
I believe the problem is that I am making a 3d array using the subroutine but I'm not sure what to do differently.
I receive the following errors in my webwork question (I get the same output for test.pg).
ERRORS from evaluating PG file: Not a HASH reference at line 35 of setWorking/test2.pg from within main::wrapCell called at line 45 of setWorking/test2.pg from within main::convertRow called at line 51 of setWorking/test2.pg from within main::PGMLTable called at line 488 of setWorking/test2.pgI know the issue isn't in PGMLTable, convertRow, or wrapCell as those work for all the other tables in this problem.
At first I thought the issue was that I was pushing making a 3d table (as per lines 493 to 498 in test.pg) but I fixed that in the scaled down version and it didn't fix the issue. I didn't realize I could only attach one file to this post. I've put the code mentioned here (that is different in test.pg) at the bottom of this post.
In test2.pg the subroutine is on lines 62 to 93
Using the subroutine is on lines 481 to 489.
I have commented out the lines that call the PGMLTables function on lines 491 and 494.
FYI: This question has code provided by Andrew Parker. Among his work is all of the PGML helper functions on lines 22 to 59.
----------------------------
Code from test.pg (not test2.pg the scaled back version)
The subroutine for all sizes of Kmaps
sub KmapMaker { # row number locations in Kmap @kmapOrder = ( [[0, 1], [2, 3]], [[0, 1, 3, 2], [4, 5, 7, 6]], [[0, 1, 3, 2], [4, 5, 7, 6], [12, 13, 15, 14], [8, 9, 11, 10]] ); my $nVar = ($#_ == 16 ? 4 : ($#_ == 8 ? 3 : 2)); my $nRow = ($nVar < 4 ? 2 : 4); my $nCol = ($nVar < 3 ? 2 : 4); my $label = shift; @cLabels; push @cLabels, $label; if ($nVar < 3) { push @cLabels, "0"; push @cLabels, "1"; } else { push @cLabels, "00"; push @cLabels, "01"; push @cLabels, "11"; push @cLabels, "10"; } @rLabels; if ($nVar < 4) { @rLabels = ["0", "1"]; } else { @rLabels = ["00", "01", "11", "10"]; } my @kmap = ($cLabels); for $i (0 .. $nRow-1) { my @row; push @row, $rlabels[$i]; for $j (0..$nCol-1) { push @row, $_[$kmapOrder[$nVar-2][$i][$j]]; } push @{ $kmap[ $i + 1 ] }, ~~@row; } return @kmap; }
Using the subroutine and making a 3d array .... I think
@kmapAns; for my $i (0 .. $#f) { my @column; push @column, map {$ans[$i][$j]} (0 .. $numRows-1); push @kmapAns, KmapMaker($fLabel[$i], @column); }