Template:ClassMatrix: Difference between revisions

No edit summary
No edit summary
Line 46: Line 46:
   local M = {};
   local M = {};
   local i=1;
   local i=1;
   for k,v in string.gmatch(xaxis, "(%S+) (%S+)") do
    
    xval[k] = i; i = i + 1; print(k .. "; ");
  end
   local xmax = i;
   local xmax = i;
   i = 1;
   i = 1;
Line 59: Line 57:
     y = string.sub(id, {{{4}}}, {{{5}}});
     y = string.sub(id, {{{4}}}, {{{5}}});
     print("accessing " .. xval[x] .. " : " .. yval[y]);
     print("accessing " .. xval[x] .. " : " .. yval[y]);
     if (M[xval[x]][yval[y]] == nil)
     if (M[x][y] == nil)
       then M[xval[x]][yval[y]] = 1;
       then M[x][y] = 1;
       else M[xval[x]][yval[y]] = M[xval[x]][yval[y]] + 1;
       else M[x][y] = M[x][y] + 1;
     end
     end
   end
   end
   for i=1, xmax do
   for x,v in string.gmatch(xaxis, "(%S+) (%S+)") do
     for j=1, ymax do
     for y,v in string.gmatch(yaxis, "(%S+) (%S+)") do
       print(M[i][j]);
       print(M[x][y] .. " ");
     end
     end
     print("\n");
     print("\n");
   end
   end
 
|{{#var:X-AXIS}}&&{{#var:Y-AXIS}}&&{{#var:ALL}}
|{{#var:X-AXIS}}&&{{#var:Y-AXIS}}&&{{#var:ALL}}
}}
}}

Revision as of 07:57, 18 December 2008




{{#lua:

 local input = stdin:match(".+");
 local xaxis, yaxis, all = string.match(input, "([^&]+)&&([^&]+)&&(.+)");
 local xval = {};
 local yval = {};
 local M = {};
 local i=1;
 
 local xmax = i;
 i = 1;
 for k,v in string.gmatch(yaxis, "(%S+) (%S+)") do
   yval[k] = i; i = i + 1; print(k .. "; ");
 end
 local ymax = i;
 for id in string.gmatch(all,"%S+") do
   x = string.sub(id, {{{2}}}, {{{3}}});
   y = string.sub(id, {{{4}}}, {{{5}}});
   print("accessing " .. xval[x] .. " : " .. yval[y]);
   if (M[x][y] == nil)
     then M[x][y] = 1;
     else M[x][y] = M[x][y] + 1;
   end
 end
 for x,v in string.gmatch(xaxis, "(%S+) (%S+)") do
   for y,v in string.gmatch(yaxis, "(%S+) (%S+)") do
     print(M[x][y] .. " ");
   end
   print("\n");
 end
 

|{{#lua:

 local H = {};
 local T = {};
 for id in stdin:gmatch("%w+") do
   str = string.sub(id,{{{2}}},{{{3}}});
   if (H[str] == nil)
     then H[str] = 1; table.insert(T, str);
     else H[str] = H[str] + 1;
   end
 end
 table.sort(T);
 for i=1,table.getn(T) do
   local k = T[i];
   print(k .. " " .. H[k]);
 end

| }}&&{{#lua:

 local H = {};
 local T = {};
 for id in stdin:gmatch("%w+") do
   str = string.sub(id,{{{4}}},{{{5}}});
   if (H[str] == nil)
     then H[str] = 1; table.insert(T, str);
     else H[str] = H[str] + 1;
   end
 end
 table.sort(T);
 for i=1,table.getn(T) do
   local k = T[i];
   print(k .. " " .. H[k]);
 end

| }}&& }}


{{#lua:}}! ({{{1}}} () {{{1}}} () for (id in stdin:gmatch("%w+") do) {{{1}}} () {{{1}}} () {{{1}}} () {{{1}}} () end () end () table.sort(T); () {{{1}}} () {{{1}}} () print(k (.. " " .. H[k]);) end () () ())