{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":2260,"title":"GJam 2011 Africa Qual A: Maximum Loop Size","description":"This Challenge is derived from \u003chttp://code.google.com/codejam/contest/837485/dashboard GJam 2011 Africa: Closing the Loop\u003e. Small Case\r\nGoogle Code Jam 2014 Kicks Off its Qualifier round April 11. \u003chttp://code.google.com/codejam GJam Registration\u003e. The Test Suite, at the bottom, contains a full GJam file input read, process, and Output example.\r\n\r\nCreate the maximum length Loop of alternating Segment types (0 or 1). Return Maximum Length. Segment connection Knots reduce the Length by 1, including the end to the start knot. \r\nIf no valid loop can be created then return 0. \r\n\r\n*Input:* M, 2xN matrix of [Lengths(1:N);Types(1:N)], Types are 0 or 1\r\n\r\n*Output:* L, maximum Loop Length of valid alternating segment types \r\n\r\n*Example:*\r\nM=[6 1 7 3;1 0 1 0], L=13\r\n\r\n\r\n\r\nAdditional GJam solutions can be found at \u003chttp://go-hero.net/jam Example GJam Matlab solutions\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.","description_html":"\u003cp\u003eThis Challenge is derived from \u003ca href = \"http://code.google.com/codejam/contest/837485/dashboard\"\u003eGJam 2011 Africa: Closing the Loop\u003c/a\u003e. Small Case\r\nGoogle Code Jam 2014 Kicks Off its Qualifier round April 11. \u003ca href = \"http://code.google.com/codejam\"\u003eGJam Registration\u003c/a\u003e. The Test Suite, at the bottom, contains a full GJam file input read, process, and Output example.\u003c/p\u003e\u003cp\u003eCreate the maximum length Loop of alternating Segment types (0 or 1). Return Maximum Length. Segment connection Knots reduce the Length by 1, including the end to the start knot. \r\nIf no valid loop can be created then return 0.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e M, 2xN matrix of [Lengths(1:N);Types(1:N)], Types are 0 or 1\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e L, maximum Loop Length of valid alternating segment types\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\r\nM=[6 1 7 3;1 0 1 0], L=13\u003c/p\u003e\u003cp\u003eAdditional GJam solutions can be found at \u003ca href = \"http://go-hero.net/jam\"\u003eExample GJam Matlab solutions\u003c/a\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.\u003c/p\u003e","function_template":"function L=Loop(m)\r\n% L, Length of valid Loop with knots subtracted\r\n% m, [2,N] array\r\n\r\n L=0;\r\nend","test_suite":"%\r\nm=[5 ;1 ];\r\nLexp= 0;\r\nL=Loop(m);\r\nassert(isequal(Lexp,L))\r\n%%\r\nm=[6 1 7 3 ;0 1 0 1 ];\r\nLexp= 13;\r\nL=Loop(m);\r\nassert(isequal(Lexp,L))\r\n%%\r\nm=[5 4 3 2 5 4 3 ;1 0 0 0 0 0 0 ];\r\nLexp= 8;\r\nL=Loop(m);\r\nassert(isequal(Lexp,L))\r\n%%\r\nm=[46 39 3 40 12 36 83 24 61 66 19 87 38 62 27 12 66 39 48 25 89 3 13 80 61 4 76 26 99 89 62 79 25 45 19 5 3 97 1 20 97 86 73 89 26 62 22 41 13 55 28 87 95 16 41 30 62 44 11 34 48 47 33 51 22 15 42 32 33 91 21 57 26 78 66 65 78 97 57 97 19 78 27 23 8 14 37 47 59 38 43 90 96 3 92 59 42 99 92 32 30 6 19 20 62 84 25 87 83 42 51 80 10 16 15 23 40 3 76 13 39 78 94 3 21 94 87 21 74 64 55 43 8 4 46 24 93 69 78 53 28 59 95 29 79 54 64 81 26 5 61 51 47 92 31 53 43 28 79 63 68 14 69 95 35 16 30 34 77 67 65 69 82 79 63 65 82 82 62 98 7 58 29 70 93 14 7 82 20 99 88 77 39 59 65 35 62 51 13 51 37 59 91 84 34 50 62 88 67 12 82 13 75 66 31 69 97 71 21 70 6 53 71 47 40 39 56 5 76 80 60 38 63 89 18 79 55 16 53 7 61 97 88 19 68 97 52 94 90 60 60 29 53 88 50 11 57 81 75 50 28 58 92 1 14 74 20 92 45 52 97 37 10 52 8 93 17 34 76 40 59 34 67 73 73 36 4 71 90 33 71 12 92 98 88 10 6 6 90 15 4 66 72 39 60 69 38 7 20 81 11 98 51 79 71 25 36 60 96 70 46 22 35 27 88 3 30 81 28 53 88 16 57 25 23 14 98 38 16 66 10 5 59 72 19 4 63 73 30 22 61 1 10 73 1 18 49 32 91 12 18 83 42 34 50 36 75 37 34 69 30 10 25 36 38 18 13 5 22 89 56 95 32 68 54 86 80 3 37 30 98 49 85 49 2 7 68 9 96 54 43 1 87 56 66 30 43 54 46 71 90 76 1 35 26 16 97 48 52 73 8 3 5 21 89 15 40 60 12 14 90 15 42 37 27 3 75 52 82 16 77 39 12 85 18 76 81 81 19 6 2 19 33 41 58 17 54 41 2 37 39 43 69 76 37 45 77 67 96 38 34 52 67 1 84 77 11 8 36 19 18 79 13 89 67 99 77 15 47 16 9 89 36 84 56 33 97 95 80 93 47 90 75 88 76 61 16 26 8 75 60 61 23 37 98 29 62 17 13 59 8 38 12 4 50 64 44 9 4 55 53 91 79 29 49 23 8 42 76 82 43 55 46 39 59 12 5 40 36 94 29 89 13 39 91 92 71 35 97 6 25 42 95 38 57 88 84 80 17 38 39 77 45 66 27 42 51 72 35 7 88 18 60 20 98 78 10 32 56 14 25 82 58 3 65 19 11 75 66 21 51 28 58 92 95 16 77 37 89 36 44 70 72 40 4 64 50 69 8 31 16 64 69 6 17 71 82 31 18 68 59 80 51 24 82 63 40 36 33 40 42 48 86 48 10 88 61 17 3 53 69 85 39 44 79 39 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1 1 1 0 1 1 0 1 0 0 0 1 0 0 0 0 0 0 0 1 1 0 1 1 1 1 0 1 0 0 1 1 1 1 0 0 0 0 0 1 0 1 0 1 1 1 1 1 1 1 1 0 1 1 0 1 0 1 0 0 1 1 0 1 1 1 0 1 0 0 0 1 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 0 0 ];\r\nLexp= 32240;\r\nL=Loop(m);\r\nassert(isequal(Lexp,L))\r\n%%\r\nm=[60 44 41 80 31 96 12 58 31 13 61 58 55 64 83 6 13 23 18 47 22 44 70 8 31 99 85 80 80 39 33 65 43 67 33 25 82 37 79 84 28 66 74 26 68 54 33 35 2 3 64 8 44 17 70 7 24 78 36 78 46 38 91 26 95 98 58 90 11 32 96 5 63 31 7 93 10 35 12 70 85 2 9 24 83 64 22 74 53 77 98 57 52 88 6 15 90 77 94 94 12 69 80 50 78 10 71 80 95 95 58 79 6 90 15 59 22 96 56 53 65 53 46 23 3 81 34 63 50 95 2 87 40 38 73 1 23 91 42 57 73 71 57 32 25 60 1 79 98 27 71 77 32 93 31 74 53 40 33 39 72 93 43 59 58 90 91 52 29 2 37 8 13 84 29 33 79 23 85 78 75 48 83 80 35 88 61 2 37 72 1 7 78 69 32 76 26 53 93 40 50 95 27 25 86 7 83 14 63 66 52 44 54 83 61 48 31 40 61 98 57 69 32 44 42 76 41 74 64 87 32 19 21 92 6 80 54 85 17 66 75 57 95 81 61 60 62 11 51 36 51 62 10 55 60 12 54 35 50 16 28 94 31 91 6 76 7 26 44 16 58 41 96 99 94 73 53 46 63 6 54 60 96 13 74 76 18 55 34 27 67 67 73 82 35 72 56 27 78 51 49 65 79 73 45 32 40 9 97 43 12 68 25 65 2 86 46 63 70 74 88 18 69 58 37 77 76 31 57 19 91 87 86 45 31 83 55 85 26 56 94 10 48 86 34 85 52 55 20 12 83 39 39 34 17 64 94 72 33 55 87 64 16 78 13 28 53 2 23 92 70 69 45 57 55 3 32 5 5 22 23 45 55 45 79 92 7 68 52 52 4 79 58 96 34 63 74 36 17 73 93 30 94 66 71 82 79 70 7 67 35 41 3 7 79 38 92 84 74 32 92 45 47 66 88 19 14 59 23 42 26 82 4 35 65 54 87 49 87 39 88 59 30 11 56 6 85 66 16 5 56 65 71 36 66 26 29 97 19 51 71 65 71 46 68 47 64 82 29 27 85 22 98 11 28 97 11 14 95 5 52 22 90 2 64 28 54 93 45 90 88 61 3 74 22 57 24 24 26 85 11 76 67 85 48 60 15 23 68 19 68 8 43 16 73 51 62 45 70 59 39 59 39 44 27 72 80 66 20 86 12 27 63 80 41 12 1 92 65 96 80 22 49 29 78 51 69 97 23 4 79 38 30 88 52 53 95 17 81 22 48 33 47 38 88 39 84 84 67 79 38 90 84 79 21 89 58 13 58 36 53 16 51 5 84 97 76 44 54 92 38 62 50 76 99 85 96 95 56 52 57 14 19 83 87 6 56 76 17 83 48 75 76 53 74 58 87 68 5 35 58 30 44 48 44 68 6 76 61 22 60 28 93 65 6 34 2 21 54 21 78 65 30 79 6 53 67 53 76 43 84 9 22 82 24 56 14 39 58 48 57 59 52 31 47 10 71 13 24 45 14 4 80 68 81 56 11 80 94 82 15 65 97 72 31 54 27 15 63 10 32 77 16 5 9 99 50 81 33 90 78 51 55 25 32 35 21 11 3 44 70 90 18 67 67 69 12 59 88 94 88 41 67 46 62 41 38 34 52 97 13 69 86 60 91 11 31 19 15 41 78 46 85 59 36 20 35 25 27 61 16 44 30 34 3 70 72 21 35 5 12 26 20 59 12 83 64 78 30 19 38 70 24 3 94 27 80 15 69 67 33 28 39 80 60 99 44 63 1 8 1 91 58 98 6 15 43 37 4 53 55 51 74 61 58 96 60 75 97 13 41 76 5 71 25 29 16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61 98 11 2 12 99 37 26 10 86 18 88 42 43 38 62 5 36 56 5 86 78 29 64 27 54 72 96 73 36 99 81 55 90 55 73 51 94 11 82 15 45 67 63 79 75 22 4 18 39 1 75 57 92 49 24 16 68 52 70 88 56 38 25 88 86 29 15 89 37 96 85 40 86 76 26 73 42 24 45 22 40 36 35 11 65 22 69 3 9 27 28 78 40 68 62 75 32 65 49 15 35 32 88 73 20 95 67 94 60 73 81 93 76 67 56 37 1 74 59 35 51 38 92 56 37 89 54 67 78 11 62 68 99 61 45 48 74 92 15 74 96 31 33 21 50 98 7 31 51 62 27 26 47 81 66 3 13 98 83 94 ;0 1 1 1 1 0 1 1 0 1 1 0 0 1 1 1 0 1 0 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 1 0 0 1 0 1 1 0 0 1 0 0 1 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0 0 1 0 0 1 1 0 1 1 0 1 0 1 1 1 0 0 0 0 1 1 0 0 1 0 0 1 0 1 0 0 0 1 1 0 1 1 0 1 0 0 0 1 1 1 0 1 0 0 0 0 0 0 1 1 0 0 1 1 1 0 0 1 1 1 1 1 0 1 1 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 1 1 0 ];\r\nLexp= 8346;\r\nL=Loop(m);\r\nassert(isequal(Lexp,L))\r\n%%\r\n% A Method to Read, Process, and Output a GJam Entry\r\n% Read a file into a Cell Array variable for each case\r\n% Open Output file\r\n% Loop thru Cases using cell array loaded\r\n% Write each case's solution\r\n% Generalized function to Process a Concise Data set\r\n\r\n% function GJam_SA_2011A\r\n% %Segment Loop\r\n% %fn='A-small-practice.in';\r\n% fn='A-large-practice.in';\r\n% [data] = read_file(fn);\r\n% \r\n% %fidG = fopen('A-small-output.out', 'w');\r\n% fidG = fopen('A-large-output.out', 'w');\r\n% tic\r\n% for i=1:size(data,2)\r\n%  L = Loop(data{i}) ;% data 2xN, row 1 Length row 2 Type\r\n%  toc\r\n%   fprintf(fidG,'Case #%i: %i\\n', i,L);\r\n%   fprintf('Case #%i: %i\\n', i,L);\r\n%   \r\n% end\r\n% toc\r\n% \r\n% fclose(fidG);\r\n% \r\n% end\r\n% \r\n% function [d] = read_file(fn)\r\n% %Read a numeric of lines to count\r\n% fid=fopen(fn);\r\n% fgetl(fid); % Total Count ignore\r\n% set=0;\r\n% while ~feof(fid)\r\n%  fgetl(fid); % Qty in a row, ignore\r\n%  strv=fgetl(fid); % read line of data as a string since mixed numeric/char\r\n%  m=str2num(strrep(strrep(strv,'R',''),'B','')); % Remove R and B to get Lengths\r\n%  % Extract R and B and convert to a binary vector\r\n%  m(2,:)=str2num(strrep(strrep(strv(regexp(strv,'[RB]','start')),'R','0 '),'B','1 '));\r\n%  \r\n%  set=set+1;\r\n%  d{set}=m;\r\n% end\r\n% \r\n% fclose(fid);\r\n% \r\n% end\r\n% \r\n% function L=Loop(m)\r\n% % Create two descending vectors\r\n% % L=sum of paired sets - qty of paired sets\r\n%  L=0;\r\n%  m0=m(1,m(2,:)==0);\r\n%  m1=m(1,m(2,:)==1);\r\n%  if isempty(m0),return;end\r\n%  if isempty(m1),return;end\r\n%  m0=sort(m0,'descend');\r\n%  m1=sort(m1,'descend');\r\n%  q=min(length(m0),length(m1));\r\n%  L=sum([m0(1:q) m1(1:q)])-2*q;\r\n%  \r\n% end\r\n% \r\n% Google File Input\r\n%5\r\n%1\r\n%5B\r\n%4\r\n%6R 1B 7R 3B\r\n%7\r\n%5B 4R 3R 2R 5R 4R 3R\r\n%673\r\n% Data line of 673 values not included\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":7,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":15,"test_suite_updated_at":"2014-03-29T20:39:55.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-03-29T18:45:27.000Z","updated_at":"2014-03-29T20:39:55.000Z","published_at":"2014-03-29T19:21:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is derived from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam/contest/837485/dashboard\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam 2011 Africa: Closing the Loop\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Small Case Google Code Jam 2014 Kicks Off its Qualifier round April 11.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam Registration\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. The Test Suite, at the bottom, contains a full GJam file input read, process, and Output example.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCreate the maximum length Loop of alternating Segment types (0 or 1). Return Maximum Length. Segment connection Knots reduce the Length by 1, including the end to the start knot. If no valid loop can be created then return 0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e M, 2xN matrix of [Lengths(1:N);Types(1:N)], Types are 0 or 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e L, maximum Loop Length of valid alternating segment types\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e M=[6 1 7 3;1 0 1 0], L=13\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAdditional GJam solutions can be found at\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://go-hero.net/jam\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eExample GJam Matlab solutions\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":2262,"title":"GJam 2011 Africa Qualifier B: Optimum Profit","description":"This Challenge is derived from GJam 2011 Africa: Investing at the Market. Google Code Jam 2014 Kicks Off its Qualifier round April 11. GJam Registration. The Test Suite, at the bottom, contains a full GJam file input read (fgetl and dlmread), process, and Output example.\r\nDetermine the single optimal Buy and Sell time to optimize Profit. \r\nIf multiple cases exist then provide set with minimum Buy cost.\r\nInvestment buys are made in whole units. If no profit is possible return [0 0 0].\r\nInput: M,x Where M is Investment and x,size(1,12), is Commodity Buy/Sell Price\r\nOutput: BSP, [BuyPt SellPt Profit]\r\nExample: M=100; x=[52 50 25 100 61 63 70 51 71 55 10 5];\r\nOutput: 3 4 300\r\nAdditional GJam solutions can be found at Example GJam Matlab solutions. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 324px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 162px; transform-origin: 407px 162px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 96px 8px; transform-origin: 96px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis Challenge is derived from\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eGJam 2011 Africa: Investing at the Market\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 148px 8px; transform-origin: 148px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. Google Code Jam 2014 Kicks Off its Qualifier round April 11.\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eGJam Registration\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 273.5px 8px; transform-origin: 273.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. The Test Suite, at the bottom, contains a full GJam file input read (fgetl and dlmread), process, and Output example.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 46.5px 8px; transform-origin: 46.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eDetermine the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 21.5px 8px; transform-origin: 21.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003esingle\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 139px 8px; transform-origin: 139px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e optimal Buy and Sell time to optimize Profit. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 193.5px 8px; transform-origin: 193.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf multiple cases exist then provide set with minimum Buy cost.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 243px 8px; transform-origin: 243px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eInvestment buys are made in whole units. If no profit is possible return [0 0 0].\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 20px 8px; transform-origin: 20px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eInput:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 229.5px 8px; transform-origin: 229.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e M,x Where M is Investment and x,size(1,12), is Commodity Buy/Sell Price\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 26px 8px; transform-origin: 26px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eOutput:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 79.5px 8px; transform-origin: 79.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e BSP, [BuyPt SellPt Profit]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 31.5px 8px; transform-origin: 31.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eExample:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 158.5px 8px; transform-origin: 158.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e M=100; x=[52 50 25 100 61 63 70 51 71 55 10 5];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 49.5px 8px; transform-origin: 49.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eOutput: 3 4 300\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 132.5px 8px; transform-origin: 132.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAdditional GJam solutions can be found at\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eExample GJam Matlab solutions\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 142px 8px; transform-origin: 142px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function BSP=Profit(M,x)\r\n% M investment amount\r\n% X future value of stock size(1,12)\r\n% BSP [BuyMonth SellMonth Profit]  to Maximize Profit\r\n% Investment in whole shares\r\n% Smallest BuyCost set if multiple optimal Profit solutions\r\n BSP=[0 0 0];\r\n \r\nend","test_suite":"%%\r\nm=[100 1 2 3 4 5 6 7 8 9 10 11 12 ];\r\nBSPexp= [1 12 1100];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[100 52 50 25 100 61 63 70 51 71 55 10 5 ];\r\nBSPexp= [3 4 300];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[100 200 150 250 132 125 110 210 220 180 176 108 113 ];\r\nBSPexp= [0 0 0];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[450 100 132 169 179 194 204 186 180 228 140 145 144 ];\r\nBSPexp= [1 9 512];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[250 12 212 9 89 8 88 7 87 6 86 5 85 ];\r\nBSPexp= [11 12 4000];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[260 199 30 198 16 54 242 12 220 105 78 178 224 ];\r\nBSPexp= [7 12 4452];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[362 96 95 85 126 242 71 144 139 25 198 153 11 ];\r\nBSPexp= [9 10 2422];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[403 133 193 224 246 38 138 103 113 126 154 189 136 ];\r\nBSPexp= [5 11 1510];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[260 126 56 231 199 192 75 87 113 63 70 128 167 ];\r\nBSPexp= [2 3 700];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\n% function GJam_Africa_2011B\r\n% %fn='B-small-practice.in';\r\n% fn='B-large-practice.in';\r\n% [data] = read_file(fn);\r\n% \r\n% %fidG = fopen('B-small-output1.out', 'w');\r\n% fidG = fopen('B-large-output.out', 'w');\r\n% tic\r\n% for i=1:size(data,2)\r\n%  BSP = Profit(data{i}(1),data{i}(2:end) ) ;% data 12 vector, \r\n%  toc\r\n% % continue\r\n%  if BSP(1)==0\r\n%   fprintf(fidG,'Case #%i: IMPOSSIBLE\\n',i);\r\n%   fprintf('Case #%i: IMPOSSIBLE\\n',i);\r\n%   \r\n%  else\r\n%   fprintf(fidG,'Case #%i: %i %i %i\\n',i, BSP);\r\n%   fprintf('Case #%i: %i %i %i\\n',i, BSP);\r\n%   \r\n%  end\r\n% \r\n% end\r\n% toc\r\n% \r\n% fclose(fidG);\r\n% end\r\n% \r\n% function [d] = read_file(fn)\r\n% %Read a numeric of lines to count\r\n% fid=fopen(fn);\r\n% fgetl(fid); % Total Count ignore\r\n% set=0;\r\n% while ~feof(fid)\r\n%  M=str2num(fgetl(fid)); % Qty in a row, ignore\r\n%  P=str2num(fgetl(fid)); % read line of data, convert to vector\r\n%   \r\n%  set=set+1;\r\n%  d{set}=[M P];\r\n% end\r\n%  fclose(fid);\r\n% end\r\n% \r\n% % alternate read using dlmread; useful for numeric array input files\r\n% function [d]=read_dlm_file(fn)\r\n%  M=dlmread(fn);\r\n%  q=M(1);\r\n%  d{q}=[];\r\n%  for i=1:q\r\n%   w=find(M(2*i+1,:)\u003e0,1,'last');\r\n%   d{i}=[M(2*i) M(2*i+1,1:w)];\r\n%  end\r\n% end\r\n% \r\n% \r\n% function BSP=Profit(M,x)\r\n%  BSP=[0 0 0];\r\n%  PU=floor(M./x);\r\n%  m=repmat(x,12,1)-repmat(x',1,12);\r\n%  m=m.*triu(ones(12),1);\r\n%  m=m.*repmat(PU',1,12);\r\n%  [b,s]=find(m==max(m(:)));\r\n%  if x(s(1))\u003c=x(b(1)),return;end\r\n%  ptr=find(x(b)==min(x(b)));\r\n%  BSP=[b(ptr) s(ptr) max(m(:))];\r\n% end\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":5,"created_by":3097,"edited_by":223089,"edited_at":"2022-10-11T16:20:46.000Z","deleted_by":null,"deleted_at":null,"solvers_count":14,"test_suite_updated_at":"2014-03-30T01:11:35.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-03-30T01:00:29.000Z","updated_at":"2022-10-11T16:20:46.000Z","published_at":"2014-03-30T01:07:59.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is derived from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam 2011 Africa: Investing at the Market\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Google Code Jam 2014 Kicks Off its Qualifier round April 11.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam Registration\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. The Test Suite, at the bottom, contains a full GJam file input read (fgetl and dlmread), process, and Output example.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDetermine the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esingle\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e optimal Buy and Sell time to optimize Profit. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf multiple cases exist then provide set with minimum Buy cost.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInvestment buys are made in whole units. If no profit is possible return [0 0 0].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e M,x Where M is Investment and x,size(1,12), is Commodity Buy/Sell Price\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e BSP, [BuyPt SellPt Profit]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e M=100; x=[52 50 25 100 61 63 70 51 71 55 10 5];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput: 3 4 300\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAdditional GJam solutions can be found at\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eExample GJam Matlab solutions\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":2264,"title":"GJam 2011 Africa Qualifier C: House, maximum area rectangle","description":"This Challenge is derived from \u003chttp://code.google.com/codejam/contest/837485/dashboard#s=p2 GJam 2011 Africa: Building a House\u003e.\r\nGoogle Code Jam 2014 Kicks Off its Qualifier round April 11. \u003chttp://code.google.com/codejam GJam Registration\u003e. The Test Suite, at the bottom, contains a full GJam file input read (fgetl, string), process, and Output example.\r\n\r\nDetermine maximum area rectangular House that can be placed on a plot given a text terrain map of G-Grass,S-Shrubs,R-Rock,W-Water, and T-Tree. The house can not be placed over Water, Trees, or Rocks.  Square is a special rectangle.\r\n\r\n*Input:* M, Text Array of GWRST\r\n\r\n*Output:* A, maximum House area that can be placed\r\n\r\n*Example:*\r\n\r\n  GGTGG  A=9\r\n  TGGGG\r\n  GSSGT\r\n  GGGGT\r\n  GWGGG\r\n  RGTRT\r\n  RTGWT\r\n  WTWGR\r\n\r\n\r\n\r\nAdditional GJam solutions can be found at \u003chttp://go-hero.net/jam Example GJam Matlab solutions\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.","description_html":"\u003cp\u003eThis Challenge is derived from \u003ca href = \"http://code.google.com/codejam/contest/837485/dashboard#s=p2\"\u003eGJam 2011 Africa: Building a House\u003c/a\u003e.\r\nGoogle Code Jam 2014 Kicks Off its Qualifier round April 11. \u003ca href = \"http://code.google.com/codejam\"\u003eGJam Registration\u003c/a\u003e. The Test Suite, at the bottom, contains a full GJam file input read (fgetl, string), process, and Output example.\u003c/p\u003e\u003cp\u003eDetermine maximum area rectangular House that can be placed on a plot given a text terrain map of G-Grass,S-Shrubs,R-Rock,W-Water, and T-Tree. The house can not be placed over Water, Trees, or Rocks.  Square is a special rectangle.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e M, Text Array of GWRST\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e A, maximum House area that can be placed\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eGGTGG  A=9\r\nTGGGG\r\nGSSGT\r\nGGGGT\r\nGWGGG\r\nRGTRT\r\nRTGWT\r\nWTWGR\r\n\u003c/pre\u003e\u003cp\u003eAdditional GJam solutions can be found at \u003ca href = \"http://go-hero.net/jam\"\u003eExample GJam Matlab solutions\u003c/a\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.\u003c/p\u003e","function_template":"function A=House(m)\r\n% GRWST: G1 R0 W0 S1 T0    [0 11 16 12 13] on G subtract\r\n A=0;\r\nend","test_suite":"%%\r\nnc=1;\r\nstr='G';\r\nAexp=1;\r\nA=House(reshape(str,nc,[])');\r\nassert(isequal(Aexp,A))\r\n%%\r\nnc=2;\r\nstr='GSSG';\r\nAexp=4;\r\nA=House(reshape(str,nc,[])');\r\nassert(isequal(Aexp,A))\r\n%%\r\nnc=2;\r\nstr='GTGG';\r\nAexp=2;\r\nA=House(reshape(str,nc,[])');\r\nassert(isequal(Aexp,A))\r\n%%\r\nnc=5;\r\nstr='GGTGGTGGGGGSSGTGGGGGRWTRTRTWWTWTWRR';\r\nAexp=9;\r\nA=House(reshape(str,nc,[])');\r\nassert(isequal(Aexp,A))\r\n%%\r\nnc=48;\r\nstr='SSGSGSSGGGWSSSGSGGGGGGSGGSGSSGGSGGGSSSSGSSSSSSGSGSSSSGSGGSGSSSGGGGGGSGSGSGSSSSSSSSGGGGGSGGGSGSSSSGGSGSSGSGSSGSSSGSGGGSGSSSGSSGGGGSGSSSSSSGGGSGGGGGGSGSGSSSSGGGSSSGGGGGSGSSSGSGSSGSGGSSSSSSGGSSGGGSGSGGGGSSGGGGSSSSSSGGSGGSGGSGSGGSSGGGGSRGSGGSGSSSSSGSGGSSSSGSGGSSSSGSSSGSGGSSGGGGSSGSSGSSGGSGGSSGSSGSGSGGSGSGGSGGGGGGGGGSGGSGSSSSSGSSSGGGSSSGSSGSGSSGGSGSSGGSGGSGSSSGSGGGSGSSSSSGGSGGGGGGGSSGGSSSSSGGGGSGSSSGGGSSGSGSGGGGGSSSGGSG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\r\n%%\r\nnc=8;\r\nstr='TGGSWGSRRSGWTGGTTSSGSGGGRGSSSGSSSGGGRSRSSSSGSSSSGGGSSGSGSTSSTSGSSGSGSSTS';\r\nAexp=16;\r\nA=House(reshape(str,nc,[])');\r\nassert(isequal(Aexp,A))\r\n%%\r\nnc=41;\r\nstr='SSGSGSGGGGSSGSSSGSGGSGSSSGSGGSGGGGSGGSGSSGGSWGSSSSSGSGSSGGSSGSSSGSSGSGGGSGSSGSGGGSGSGGTGSGSGSGGGSSSGSGSSGSSGSGSSGSGSSSGGGGGSSSSSGGSSSGGSSGSSSSSSGGSSGSGSSSSGGGSSGGSGGGGSSGGSGSSGSGGGGGGGGSWSSRSSSSSGGSGSGGSGSSGSSSGGGSGSGGSSGSWSGGSSGGSSSGGGGGSGGSSSGGSSSGSGGSSGGGSSGSSGSGSSWSSSSSSSGGGGGSGGSGSSSSSSTSGSSSSSSGSGWSSGSSSSSGGGSSGSSSGGGGSSSSGSGSGWSSGSGSSGSSSGGSSSGSGSGGGSGSSGGGSSSGGGSGGSGGGSGGGGGGGSSGGGSGSGGGSSSSSRSSGSGSGGGGSGSSSGSGSSGGGGGSSSGSGSGSSGGGGSSSGSSSS';\r\nAexp=144;\r\nA=House(reshape(str,nc,[])');\r\nassert(isequal(Aexp,A))\r\n%%\r\nnc=35;\r\nstr='SSSGGSSSSSSGSSGGGGGGSSGGGGGGGSGGSSGGSGGSGSGGGRSGSSSGSSGSGGTGSGSGGSGSSGSGSGGSGGGGSSSGGGGGGGSGSSGSGGGSGSGGSGSSSGSSSGSSGSSSGGSGSGSSSGGGGGSSSGGGSSSSSSSSGGGSSGGSGSSGGGGGGGGGSGSSSSGGGGGSSGGSGSGSSSGGSSSSSGGGGGSGSRSSGGSGSSGSSSSGSGGGSSGSGSSSSSSSGSGSSSGGG';\r\nAexp=150;\r\nA=House(reshape(str,nc,[])');\r\nassert(isequal(Aexp,A))\r\n%%\r\n% function GJam_Africa_2011C\r\n% %House\r\n% %fn='C-small-practice.in';\r\n% fn='C-large-practice.in';\r\n% [data] = read_file(fn);\r\n% \r\n% %fidG = fopen('C-small-output.out', 'w');\r\n% fidG = fopen('C-large-output.out', 'w');\r\n% tic\r\n% for i=1:size(data,1) % Cell array has N rows of cases\r\n%  A = House(reshape(data{i,2},data{i,1},[])' ) ;% data matrix GWRST \r\n%  toc\r\n% % continue\r\n%    fprintf(fidG,'Case #%i: %i\\n',i,A);\r\n%    fprintf('Case #%i: %i\\n',i,A);\r\n%   \r\n% end\r\n% toc\r\n% \r\n% fclose(fidG);\r\n% fclose(fidC);\r\n% \r\n% end\r\n% \r\n% function [d] = read_file(fn)\r\n% %Read a numeric of lines to count\r\n% fid=fopen(fn);\r\n% fgetl(fid); % Total Count ignore\r\n% set=0;\r\n% while ~feof(fid)\r\n%  nrc=str2num(fgetl(fid)); % [nc nr]\r\n%  str='';\r\n%  for i=1:nrc(2)\r\n%   str=[str fgetl(fid)]; % read line of data, convert to vector\r\n%  end\r\n%  set=set+1;\r\n%  d{set,1}=nrc(1); % need to do a transpose after\r\n%  d{set,2}=str;\r\n% end\r\n%  fclose(fid);\r\n% end\r\n% \r\n% function A=House(m)\r\n% % GRWST: G1 R0 W0 S1 T0    [0 11 16 12 13] on G subtract\r\n%  m=m-'G'; % Convert String array to binary\r\n%  m(m==12)=0;\r\n%  m=double(~m);\r\n% \r\n%  [nr,nc]=size(m);\r\n%  A=0;\r\n%  % try all [1:nr,1:nc] overlay convolutions and find max\r\n%  for i=1:nr\r\n%   for j=1:nc\r\n%    if i*j\u003eA % speed enhance, faster than continue continue \r\n%     mc=conv2(m,ones(i,j)); \r\n%     if nnz(mc==i*j) % fastest array compare\r\n%      A=i*j; % Current Max Rectangle\r\n%     end\r\n%    end\r\n%   end % j\r\n%  end % i\r\n%  \r\n% end % House\r\n%\r\n% Data input example\r\n%10\r\n%1 1\r\n%G\r\n%2 2\r\n%GS\r\n%SG\r\n%2 2\r\n%GT\r\n%GG\r\n%8 9\r\n%GGGSGGSG\r\n%RSGGSGGG\r\n%GSSGSGGG\r\n%GGSSSGSS\r\n%SGGGSSRS\r\n%SSWGSSSS\r\n%GGGSSGSG\r\n%SGSSSWGS\r\n%SGSGSSGS\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":20,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-03-31T04:20:54.000Z","updated_at":"2026-01-22T14:29:29.000Z","published_at":"2014-03-31T04:32:30.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is derived from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam/contest/837485/dashboard#s=p2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam 2011 Africa: Building a House\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Google Code Jam 2014 Kicks Off its Qualifier round April 11.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam Registration\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. The Test Suite, at the bottom, contains a full GJam file input read (fgetl, string), process, and Output example.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDetermine maximum area rectangular House that can be placed on a plot given a text terrain map of G-Grass,S-Shrubs,R-Rock,W-Water, and T-Tree. The house can not be placed over Water, Trees, or Rocks. Square is a special rectangle.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e M, Text Array of GWRST\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e A, maximum House area that can be placed\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[GGTGG  A=9\\nTGGGG\\nGSSGT\\nGGGGT\\nGWGGG\\nRGTRT\\nRTGWT\\nWTWGR]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAdditional GJam solutions can be found at\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://go-hero.net/jam\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eExample GJam Matlab solutions\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":2260,"title":"GJam 2011 Africa Qual A: Maximum Loop Size","description":"This Challenge is derived from \u003chttp://code.google.com/codejam/contest/837485/dashboard GJam 2011 Africa: Closing the Loop\u003e. Small Case\r\nGoogle Code Jam 2014 Kicks Off its Qualifier round April 11. \u003chttp://code.google.com/codejam GJam Registration\u003e. The Test Suite, at the bottom, contains a full GJam file input read, process, and Output example.\r\n\r\nCreate the maximum length Loop of alternating Segment types (0 or 1). Return Maximum Length. Segment connection Knots reduce the Length by 1, including the end to the start knot. \r\nIf no valid loop can be created then return 0. \r\n\r\n*Input:* M, 2xN matrix of [Lengths(1:N);Types(1:N)], Types are 0 or 1\r\n\r\n*Output:* L, maximum Loop Length of valid alternating segment types \r\n\r\n*Example:*\r\nM=[6 1 7 3;1 0 1 0], L=13\r\n\r\n\r\n\r\nAdditional GJam solutions can be found at \u003chttp://go-hero.net/jam Example GJam Matlab solutions\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.","description_html":"\u003cp\u003eThis Challenge is derived from \u003ca href = \"http://code.google.com/codejam/contest/837485/dashboard\"\u003eGJam 2011 Africa: Closing the Loop\u003c/a\u003e. Small Case\r\nGoogle Code Jam 2014 Kicks Off its Qualifier round April 11. \u003ca href = \"http://code.google.com/codejam\"\u003eGJam Registration\u003c/a\u003e. The Test Suite, at the bottom, contains a full GJam file input read, process, and Output example.\u003c/p\u003e\u003cp\u003eCreate the maximum length Loop of alternating Segment types (0 or 1). Return Maximum Length. Segment connection Knots reduce the Length by 1, including the end to the start knot. \r\nIf no valid loop can be created then return 0.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e M, 2xN matrix of [Lengths(1:N);Types(1:N)], Types are 0 or 1\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e L, maximum Loop Length of valid alternating segment types\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\r\nM=[6 1 7 3;1 0 1 0], L=13\u003c/p\u003e\u003cp\u003eAdditional GJam solutions can be found at \u003ca href = \"http://go-hero.net/jam\"\u003eExample GJam Matlab solutions\u003c/a\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.\u003c/p\u003e","function_template":"function L=Loop(m)\r\n% L, Length of valid Loop with knots subtracted\r\n% m, [2,N] array\r\n\r\n L=0;\r\nend","test_suite":"%\r\nm=[5 ;1 ];\r\nLexp= 0;\r\nL=Loop(m);\r\nassert(isequal(Lexp,L))\r\n%%\r\nm=[6 1 7 3 ;0 1 0 1 ];\r\nLexp= 13;\r\nL=Loop(m);\r\nassert(isequal(Lexp,L))\r\n%%\r\nm=[5 4 3 2 5 4 3 ;1 0 0 0 0 0 0 ];\r\nLexp= 8;\r\nL=Loop(m);\r\nassert(isequal(Lexp,L))\r\n%%\r\nm=[46 39 3 40 12 36 83 24 61 66 19 87 38 62 27 12 66 39 48 25 89 3 13 80 61 4 76 26 99 89 62 79 25 45 19 5 3 97 1 20 97 86 73 89 26 62 22 41 13 55 28 87 95 16 41 30 62 44 11 34 48 47 33 51 22 15 42 32 33 91 21 57 26 78 66 65 78 97 57 97 19 78 27 23 8 14 37 47 59 38 43 90 96 3 92 59 42 99 92 32 30 6 19 20 62 84 25 87 83 42 51 80 10 16 15 23 40 3 76 13 39 78 94 3 21 94 87 21 74 64 55 43 8 4 46 24 93 69 78 53 28 59 95 29 79 54 64 81 26 5 61 51 47 92 31 53 43 28 79 63 68 14 69 95 35 16 30 34 77 67 65 69 82 79 63 65 82 82 62 98 7 58 29 70 93 14 7 82 20 99 88 77 39 59 65 35 62 51 13 51 37 59 91 84 34 50 62 88 67 12 82 13 75 66 31 69 97 71 21 70 6 53 71 47 40 39 56 5 76 80 60 38 63 89 18 79 55 16 53 7 61 97 88 19 68 97 52 94 90 60 60 29 53 88 50 11 57 81 75 50 28 58 92 1 14 74 20 92 45 52 97 37 10 52 8 93 17 34 76 40 59 34 67 73 73 36 4 71 90 33 71 12 92 98 88 10 6 6 90 15 4 66 72 39 60 69 38 7 20 81 11 98 51 79 71 25 36 60 96 70 46 22 35 27 88 3 30 81 28 53 88 16 57 25 23 14 98 38 16 66 10 5 59 72 19 4 63 73 30 22 61 1 10 73 1 18 49 32 91 12 18 83 42 34 50 36 75 37 34 69 30 10 25 36 38 18 13 5 22 89 56 95 32 68 54 86 80 3 37 30 98 49 85 49 2 7 68 9 96 54 43 1 87 56 66 30 43 54 46 71 90 76 1 35 26 16 97 48 52 73 8 3 5 21 89 15 40 60 12 14 90 15 42 37 27 3 75 52 82 16 77 39 12 85 18 76 81 81 19 6 2 19 33 41 58 17 54 41 2 37 39 43 69 76 37 45 77 67 96 38 34 52 67 1 84 77 11 8 36 19 18 79 13 89 67 99 77 15 47 16 9 89 36 84 56 33 97 95 80 93 47 90 75 88 76 61 16 26 8 75 60 61 23 37 98 29 62 17 13 59 8 38 12 4 50 64 44 9 4 55 53 91 79 29 49 23 8 42 76 82 43 55 46 39 59 12 5 40 36 94 29 89 13 39 91 92 71 35 97 6 25 42 95 38 57 88 84 80 17 38 39 77 45 66 27 42 51 72 35 7 88 18 60 20 98 78 10 32 56 14 25 82 58 3 65 19 11 75 66 21 51 28 58 92 95 16 77 37 89 36 44 70 72 40 4 64 50 69 8 31 16 64 69 6 17 71 82 31 18 68 59 80 51 24 82 63 40 36 33 40 42 48 86 48 10 88 61 17 3 53 69 85 39 44 79 39 61 53 96 32 59 52 79 96 97 86 43 34 35 28 79 17 13 ;1 0 0 0 1 1 0 0 0 1 1 1 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 0 1 0 0 0 1 0 0 1 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 0 1 1 1 1 0 1 1 0 0 1 0 0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 1 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 0 0 ];\r\nLexp= 32240;\r\nL=Loop(m);\r\nassert(isequal(Lexp,L))\r\n%%\r\nm=[60 44 41 80 31 96 12 58 31 13 61 58 55 64 83 6 13 23 18 47 22 44 70 8 31 99 85 80 80 39 33 65 43 67 33 25 82 37 79 84 28 66 74 26 68 54 33 35 2 3 64 8 44 17 70 7 24 78 36 78 46 38 91 26 95 98 58 90 11 32 96 5 63 31 7 93 10 35 12 70 85 2 9 24 83 64 22 74 53 77 98 57 52 88 6 15 90 77 94 94 12 69 80 50 78 10 71 80 95 95 58 79 6 90 15 59 22 96 56 53 65 53 46 23 3 81 34 63 50 95 2 87 40 38 73 1 23 91 42 57 73 71 57 32 25 60 1 79 98 27 71 77 32 93 31 74 53 40 33 39 72 93 43 59 58 90 91 52 29 2 37 8 13 84 29 33 79 23 85 78 75 48 83 80 35 88 61 2 37 72 1 7 78 69 32 76 26 53 93 40 50 95 27 25 86 7 83 14 63 66 52 44 54 83 61 48 31 40 61 98 57 69 32 44 42 76 41 74 64 87 32 19 21 92 6 80 54 85 17 66 75 57 95 81 61 60 62 11 51 36 51 62 10 55 60 12 54 35 50 16 28 94 31 91 6 76 7 26 44 16 58 41 96 99 94 73 53 46 63 6 54 60 96 13 74 76 18 55 34 27 67 67 73 82 35 72 56 27 78 51 49 65 79 73 45 32 40 9 97 43 12 68 25 65 2 86 46 63 70 74 88 18 69 58 37 77 76 31 57 19 91 87 86 45 31 83 55 85 26 56 94 10 48 86 34 85 52 55 20 12 83 39 39 34 17 64 94 72 33 55 87 64 16 78 13 28 53 2 23 92 70 69 45 57 55 3 32 5 5 22 23 45 55 45 79 92 7 68 52 52 4 79 58 96 34 63 74 36 17 73 93 30 94 66 71 82 79 70 7 67 35 41 3 7 79 38 92 84 74 32 92 45 47 66 88 19 14 59 23 42 26 82 4 35 65 54 87 49 87 39 88 59 30 11 56 6 85 66 16 5 56 65 71 36 66 26 29 97 19 51 71 65 71 46 68 47 64 82 29 27 85 22 98 11 28 97 11 14 95 5 52 22 90 2 64 28 54 93 45 90 88 61 3 74 22 57 24 24 26 85 11 76 67 85 48 60 15 23 68 19 68 8 43 16 73 51 62 45 70 59 39 59 39 44 27 72 80 66 20 86 12 27 63 80 41 12 1 92 65 96 80 22 49 29 78 51 69 97 23 4 79 38 30 88 52 53 95 17 81 22 48 33 47 38 88 39 84 84 67 79 38 90 84 79 21 89 58 13 58 36 53 16 51 5 84 97 76 44 54 92 38 62 50 76 99 85 96 95 56 52 57 14 19 83 87 6 56 76 17 83 48 75 76 53 74 58 87 68 5 35 58 30 44 48 44 68 6 76 61 22 60 28 93 65 6 34 2 21 54 21 78 65 30 79 6 53 67 53 76 43 84 9 22 82 24 56 14 39 58 48 57 59 52 31 47 10 71 13 24 45 14 4 80 68 81 56 11 80 94 82 15 65 97 72 31 54 27 15 63 10 32 77 16 5 9 99 50 81 33 90 78 51 55 25 32 35 21 11 3 44 70 90 18 67 67 69 12 59 88 94 88 41 67 46 62 41 38 34 52 97 13 69 86 60 91 11 31 19 15 41 78 46 85 59 36 20 35 25 27 61 16 44 30 34 3 70 72 21 35 5 12 26 20 59 12 83 64 78 30 19 38 70 24 3 94 27 80 15 69 67 33 28 39 80 60 99 44 63 1 8 1 91 58 98 6 15 43 37 4 53 55 51 74 61 58 96 60 75 97 13 41 76 5 71 25 29 16 48 14 61 55 62 3 95 86 75 41 16 22 68 63 33 62 78 67 37 32 93 31 38 97 32 40 90 72 11 10 6 6 45 14 86 12 66 82 89 19 68 72 2 29 71 88 90 55 99 40 98 64 97 86 94 37 94 43 69 57 92 4 64 25 20 65 71 87 26 26 11 97 4 16 53 25 23 47 51 57 68 36 54 50 65 15 83 34 ;1 1 1 1 0 1 1 0 1 1 0 0 0 0 0 1 0 1 1 0 0 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0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 0 1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 0 1 1 0 0 1 0 1 0 0 1 0 0 1 1 0 0 0 0 0 0 1 0 0 1 1 1 0 0 1 0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 0 1 0 1 0 0 0 0 1 1 1 1 1 1 0 0 1 0 0 1 0 0 1 1 1 0 1 0 1 1 1 0 1 1 1 1 1 0 1 0 1 0 0 1 1 1 0 0 1 1 0 1 1 1 0 1 0 1 1 0 0 1 1 0 1 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 1 0 1 1 1 1 0 0 1 0 0 1 0 0 1 0 0 0 0 1 1 0 0 1 1 0 1 0 0 0 1 1 1 0 1 0 0 1 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 1 1 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 0 1 0 0 1 1 0 0 1 1 0 1 1 1 0 0 0 1 0 0 1 0 1 0 0 0 0 0 1 1 1 0 ];\r\nLexp= 45294;\r\nL=Loop(m);\r\nassert(isequal(Lexp,L))\r\n%%\r\nm=[94 61 98 11 2 12 99 37 26 10 86 18 88 42 43 38 62 5 36 56 5 86 78 29 64 27 54 72 96 73 36 99 81 55 90 55 73 51 94 11 82 15 45 67 63 79 75 22 4 18 39 1 75 57 92 49 24 16 68 52 70 88 56 38 25 88 86 29 15 89 37 96 85 40 86 76 26 73 42 24 45 22 40 36 35 11 65 22 69 3 9 27 28 78 40 68 62 75 32 65 49 15 35 32 88 73 20 95 67 94 60 73 81 93 76 67 56 37 1 74 59 35 51 38 92 56 37 89 54 67 78 11 62 68 99 61 45 48 74 92 15 74 96 31 33 21 50 98 7 31 51 62 27 26 47 81 66 3 13 98 83 94 ;0 1 1 1 1 0 1 1 0 1 1 0 0 1 1 1 0 1 0 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 1 0 0 1 0 1 1 0 0 1 0 0 1 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0 0 1 0 0 1 1 0 1 1 0 1 0 1 1 1 0 0 0 0 1 1 0 0 1 0 0 1 0 1 0 0 0 1 1 0 1 1 0 1 0 0 0 1 1 1 0 1 0 0 0 0 0 0 1 1 0 0 1 1 1 0 0 1 1 1 1 1 0 1 1 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 1 1 0 ];\r\nLexp= 8346;\r\nL=Loop(m);\r\nassert(isequal(Lexp,L))\r\n%%\r\n% A Method to Read, Process, and Output a GJam Entry\r\n% Read a file into a Cell Array variable for each case\r\n% Open Output file\r\n% Loop thru Cases using cell array loaded\r\n% Write each case's solution\r\n% Generalized function to Process a Concise Data set\r\n\r\n% function GJam_SA_2011A\r\n% %Segment Loop\r\n% %fn='A-small-practice.in';\r\n% fn='A-large-practice.in';\r\n% [data] = read_file(fn);\r\n% \r\n% %fidG = fopen('A-small-output.out', 'w');\r\n% fidG = fopen('A-large-output.out', 'w');\r\n% tic\r\n% for i=1:size(data,2)\r\n%  L = Loop(data{i}) ;% data 2xN, row 1 Length row 2 Type\r\n%  toc\r\n%   fprintf(fidG,'Case #%i: %i\\n', i,L);\r\n%   fprintf('Case #%i: %i\\n', i,L);\r\n%   \r\n% end\r\n% toc\r\n% \r\n% fclose(fidG);\r\n% \r\n% end\r\n% \r\n% function [d] = read_file(fn)\r\n% %Read a numeric of lines to count\r\n% fid=fopen(fn);\r\n% fgetl(fid); % Total Count ignore\r\n% set=0;\r\n% while ~feof(fid)\r\n%  fgetl(fid); % Qty in a row, ignore\r\n%  strv=fgetl(fid); % read line of data as a string since mixed numeric/char\r\n%  m=str2num(strrep(strrep(strv,'R',''),'B','')); % Remove R and B to get Lengths\r\n%  % Extract R and B and convert to a binary vector\r\n%  m(2,:)=str2num(strrep(strrep(strv(regexp(strv,'[RB]','start')),'R','0 '),'B','1 '));\r\n%  \r\n%  set=set+1;\r\n%  d{set}=m;\r\n% end\r\n% \r\n% fclose(fid);\r\n% \r\n% end\r\n% \r\n% function L=Loop(m)\r\n% % Create two descending vectors\r\n% % L=sum of paired sets - qty of paired sets\r\n%  L=0;\r\n%  m0=m(1,m(2,:)==0);\r\n%  m1=m(1,m(2,:)==1);\r\n%  if isempty(m0),return;end\r\n%  if isempty(m1),return;end\r\n%  m0=sort(m0,'descend');\r\n%  m1=sort(m1,'descend');\r\n%  q=min(length(m0),length(m1));\r\n%  L=sum([m0(1:q) m1(1:q)])-2*q;\r\n%  \r\n% end\r\n% \r\n% Google File Input\r\n%5\r\n%1\r\n%5B\r\n%4\r\n%6R 1B 7R 3B\r\n%7\r\n%5B 4R 3R 2R 5R 4R 3R\r\n%673\r\n% Data line of 673 values not included\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":7,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":15,"test_suite_updated_at":"2014-03-29T20:39:55.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-03-29T18:45:27.000Z","updated_at":"2014-03-29T20:39:55.000Z","published_at":"2014-03-29T19:21:07.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is derived from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam/contest/837485/dashboard\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam 2011 Africa: Closing the Loop\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Small Case Google Code Jam 2014 Kicks Off its Qualifier round April 11.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam Registration\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. The Test Suite, at the bottom, contains a full GJam file input read, process, and Output example.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCreate the maximum length Loop of alternating Segment types (0 or 1). Return Maximum Length. Segment connection Knots reduce the Length by 1, including the end to the start knot. If no valid loop can be created then return 0.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e M, 2xN matrix of [Lengths(1:N);Types(1:N)], Types are 0 or 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e L, maximum Loop Length of valid alternating segment types\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e M=[6 1 7 3;1 0 1 0], L=13\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAdditional GJam solutions can be found at\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://go-hero.net/jam\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eExample GJam Matlab solutions\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":2262,"title":"GJam 2011 Africa Qualifier B: Optimum Profit","description":"This Challenge is derived from GJam 2011 Africa: Investing at the Market. Google Code Jam 2014 Kicks Off its Qualifier round April 11. GJam Registration. The Test Suite, at the bottom, contains a full GJam file input read (fgetl and dlmread), process, and Output example.\r\nDetermine the single optimal Buy and Sell time to optimize Profit. \r\nIf multiple cases exist then provide set with minimum Buy cost.\r\nInvestment buys are made in whole units. If no profit is possible return [0 0 0].\r\nInput: M,x Where M is Investment and x,size(1,12), is Commodity Buy/Sell Price\r\nOutput: BSP, [BuyPt SellPt Profit]\r\nExample: M=100; x=[52 50 25 100 61 63 70 51 71 55 10 5];\r\nOutput: 3 4 300\r\nAdditional GJam solutions can be found at Example GJam Matlab solutions. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 324px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 162px; transform-origin: 407px 162px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 96px 8px; transform-origin: 96px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis Challenge is derived from\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eGJam 2011 Africa: Investing at the Market\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 148px 8px; transform-origin: 148px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. Google Code Jam 2014 Kicks Off its Qualifier round April 11.\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eGJam Registration\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 273.5px 8px; transform-origin: 273.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. The Test Suite, at the bottom, contains a full GJam file input read (fgetl and dlmread), process, and Output example.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 46.5px 8px; transform-origin: 46.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eDetermine the \u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 21.5px 8px; transform-origin: 21.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003esingle\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 139px 8px; transform-origin: 139px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e optimal Buy and Sell time to optimize Profit. \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 193.5px 8px; transform-origin: 193.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf multiple cases exist then provide set with minimum Buy cost.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 243px 8px; transform-origin: 243px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eInvestment buys are made in whole units. If no profit is possible return [0 0 0].\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 20px 8px; transform-origin: 20px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eInput:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 229.5px 8px; transform-origin: 229.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e M,x Where M is Investment and x,size(1,12), is Commodity Buy/Sell Price\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 26px 8px; transform-origin: 26px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eOutput:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 79.5px 8px; transform-origin: 79.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e BSP, [BuyPt SellPt Profit]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 31.5px 8px; transform-origin: 31.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eExample:\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 158.5px 8px; transform-origin: 158.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e M=100; x=[52 50 25 100 61 63 70 51 71 55 10 5];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 49.5px 8px; transform-origin: 49.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eOutput: 3 4 300\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 42px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 21px; text-align: left; transform-origin: 384px 21px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 132.5px 8px; transform-origin: 132.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAdditional GJam solutions can be found at\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003eExample GJam Matlab solutions\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 142px 8px; transform-origin: 142px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function BSP=Profit(M,x)\r\n% M investment amount\r\n% X future value of stock size(1,12)\r\n% BSP [BuyMonth SellMonth Profit]  to Maximize Profit\r\n% Investment in whole shares\r\n% Smallest BuyCost set if multiple optimal Profit solutions\r\n BSP=[0 0 0];\r\n \r\nend","test_suite":"%%\r\nm=[100 1 2 3 4 5 6 7 8 9 10 11 12 ];\r\nBSPexp= [1 12 1100];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[100 52 50 25 100 61 63 70 51 71 55 10 5 ];\r\nBSPexp= [3 4 300];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[100 200 150 250 132 125 110 210 220 180 176 108 113 ];\r\nBSPexp= [0 0 0];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[450 100 132 169 179 194 204 186 180 228 140 145 144 ];\r\nBSPexp= [1 9 512];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[250 12 212 9 89 8 88 7 87 6 86 5 85 ];\r\nBSPexp= [11 12 4000];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[260 199 30 198 16 54 242 12 220 105 78 178 224 ];\r\nBSPexp= [7 12 4452];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[362 96 95 85 126 242 71 144 139 25 198 153 11 ];\r\nBSPexp= [9 10 2422];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[403 133 193 224 246 38 138 103 113 126 154 189 136 ];\r\nBSPexp= [5 11 1510];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\nm=[260 126 56 231 199 192 75 87 113 63 70 128 167 ];\r\nBSPexp= [2 3 700];\r\nBSP=Profit(m(1),m(2:end));\r\nassert(isequal(BSPexp,BSP))\r\n%%\r\n% function GJam_Africa_2011B\r\n% %fn='B-small-practice.in';\r\n% fn='B-large-practice.in';\r\n% [data] = read_file(fn);\r\n% \r\n% %fidG = fopen('B-small-output1.out', 'w');\r\n% fidG = fopen('B-large-output.out', 'w');\r\n% tic\r\n% for i=1:size(data,2)\r\n%  BSP = Profit(data{i}(1),data{i}(2:end) ) ;% data 12 vector, \r\n%  toc\r\n% % continue\r\n%  if BSP(1)==0\r\n%   fprintf(fidG,'Case #%i: IMPOSSIBLE\\n',i);\r\n%   fprintf('Case #%i: IMPOSSIBLE\\n',i);\r\n%   \r\n%  else\r\n%   fprintf(fidG,'Case #%i: %i %i %i\\n',i, BSP);\r\n%   fprintf('Case #%i: %i %i %i\\n',i, BSP);\r\n%   \r\n%  end\r\n% \r\n% end\r\n% toc\r\n% \r\n% fclose(fidG);\r\n% end\r\n% \r\n% function [d] = read_file(fn)\r\n% %Read a numeric of lines to count\r\n% fid=fopen(fn);\r\n% fgetl(fid); % Total Count ignore\r\n% set=0;\r\n% while ~feof(fid)\r\n%  M=str2num(fgetl(fid)); % Qty in a row, ignore\r\n%  P=str2num(fgetl(fid)); % read line of data, convert to vector\r\n%   \r\n%  set=set+1;\r\n%  d{set}=[M P];\r\n% end\r\n%  fclose(fid);\r\n% end\r\n% \r\n% % alternate read using dlmread; useful for numeric array input files\r\n% function [d]=read_dlm_file(fn)\r\n%  M=dlmread(fn);\r\n%  q=M(1);\r\n%  d{q}=[];\r\n%  for i=1:q\r\n%   w=find(M(2*i+1,:)\u003e0,1,'last');\r\n%   d{i}=[M(2*i) M(2*i+1,1:w)];\r\n%  end\r\n% end\r\n% \r\n% \r\n% function BSP=Profit(M,x)\r\n%  BSP=[0 0 0];\r\n%  PU=floor(M./x);\r\n%  m=repmat(x,12,1)-repmat(x',1,12);\r\n%  m=m.*triu(ones(12),1);\r\n%  m=m.*repmat(PU',1,12);\r\n%  [b,s]=find(m==max(m(:)));\r\n%  if x(s(1))\u003c=x(b(1)),return;end\r\n%  ptr=find(x(b)==min(x(b)));\r\n%  BSP=[b(ptr) s(ptr) max(m(:))];\r\n% end\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":5,"created_by":3097,"edited_by":223089,"edited_at":"2022-10-11T16:20:46.000Z","deleted_by":null,"deleted_at":null,"solvers_count":14,"test_suite_updated_at":"2014-03-30T01:11:35.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-03-30T01:00:29.000Z","updated_at":"2022-10-11T16:20:46.000Z","published_at":"2014-03-30T01:07:59.000Z","restored_at":null,"restored_by":null,"spam":null,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is derived from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam 2011 Africa: Investing at the Market\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Google Code Jam 2014 Kicks Off its Qualifier round April 11.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam Registration\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. The Test Suite, at the bottom, contains a full GJam file input read (fgetl and dlmread), process, and Output example.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDetermine the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esingle\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e optimal Buy and Sell time to optimize Profit. \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf multiple cases exist then provide set with minimum Buy cost.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInvestment buys are made in whole units. If no profit is possible return [0 0 0].\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e M,x Where M is Investment and x,size(1,12), is Commodity Buy/Sell Price\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e BSP, [BuyPt SellPt Profit]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e M=100; x=[52 50 25 100 61 63 70 51 71 55 10 5];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput: 3 4 300\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAdditional GJam solutions can be found at\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eExample GJam Matlab solutions\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":2264,"title":"GJam 2011 Africa Qualifier C: House, maximum area rectangle","description":"This Challenge is derived from \u003chttp://code.google.com/codejam/contest/837485/dashboard#s=p2 GJam 2011 Africa: Building a House\u003e.\r\nGoogle Code Jam 2014 Kicks Off its Qualifier round April 11. \u003chttp://code.google.com/codejam GJam Registration\u003e. The Test Suite, at the bottom, contains a full GJam file input read (fgetl, string), process, and Output example.\r\n\r\nDetermine maximum area rectangular House that can be placed on a plot given a text terrain map of G-Grass,S-Shrubs,R-Rock,W-Water, and T-Tree. The house can not be placed over Water, Trees, or Rocks.  Square is a special rectangle.\r\n\r\n*Input:* M, Text Array of GWRST\r\n\r\n*Output:* A, maximum House area that can be placed\r\n\r\n*Example:*\r\n\r\n  GGTGG  A=9\r\n  TGGGG\r\n  GSSGT\r\n  GGGGT\r\n  GWGGG\r\n  RGTRT\r\n  RTGWT\r\n  WTWGR\r\n\r\n\r\n\r\nAdditional GJam solutions can be found at \u003chttp://go-hero.net/jam Example GJam Matlab solutions\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.","description_html":"\u003cp\u003eThis Challenge is derived from \u003ca href = \"http://code.google.com/codejam/contest/837485/dashboard#s=p2\"\u003eGJam 2011 Africa: Building a House\u003c/a\u003e.\r\nGoogle Code Jam 2014 Kicks Off its Qualifier round April 11. \u003ca href = \"http://code.google.com/codejam\"\u003eGJam Registration\u003c/a\u003e. The Test Suite, at the bottom, contains a full GJam file input read (fgetl, string), process, and Output example.\u003c/p\u003e\u003cp\u003eDetermine maximum area rectangular House that can be placed on a plot given a text terrain map of G-Grass,S-Shrubs,R-Rock,W-Water, and T-Tree. The house can not be placed over Water, Trees, or Rocks.  Square is a special rectangle.\u003c/p\u003e\u003cp\u003e\u003cb\u003eInput:\u003c/b\u003e M, Text Array of GWRST\u003c/p\u003e\u003cp\u003e\u003cb\u003eOutput:\u003c/b\u003e A, maximum House area that can be placed\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample:\u003c/b\u003e\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eGGTGG  A=9\r\nTGGGG\r\nGSSGT\r\nGGGGT\r\nGWGGG\r\nRGTRT\r\nRTGWT\r\nWTWGR\r\n\u003c/pre\u003e\u003cp\u003eAdditional GJam solutions can be found at \u003ca href = \"http://go-hero.net/jam\"\u003eExample GJam Matlab solutions\u003c/a\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.\u003c/p\u003e","function_template":"function A=House(m)\r\n% GRWST: G1 R0 W0 S1 T0    [0 11 16 12 13] on G subtract\r\n A=0;\r\nend","test_suite":"%%\r\nnc=1;\r\nstr='G';\r\nAexp=1;\r\nA=House(reshape(str,nc,[])');\r\nassert(isequal(Aexp,A))\r\n%%\r\nnc=2;\r\nstr='GSSG';\r\nAexp=4;\r\nA=House(reshape(str,nc,[])');\r\nassert(isequal(Aexp,A))\r\n%%\r\nnc=2;\r\nstr='GTGG';\r\nAexp=2;\r\nA=House(reshape(str,nc,[])');\r\nassert(isequal(Aexp,A))\r\n%%\r\nnc=5;\r\nstr='GGTGGTGGGGGSSGTGGGGGRWTRTRTWWTWTWRR';\r\nAexp=9;\r\nA=House(reshape(str,nc,[])');\r\nassert(isequal(Aexp,A))\r\n%%\r\nnc=48;\r\nstr='SSGSGSSGGGWSSSGSGGGGGGSGGSGSSGGSGGGSSSSGSSSSSSGSGSSSSGSGGSGSSSGGGGGGSGSGSGSSSSSSSSGGGGGSGGGSGSSSSGGSGSSGSGSSGSSSGSGGGSGSSSGSSGGGGSGSSSSSSGGGSGGGGGGSGSGSSSSGGGSSSGGGGGSGSSSGSGSSGSGGSSSSSSGGSSGGGSGSGGGGSSGGGGSSSSSSGGSGGSGGSGSGGSSGGGGSRGSGGSGSSSSSGSGGSSSSGSGGSSSSGSSSGSGGSSGGGGSSGSSGSSGGSGGSSGSSGSGSGGSGSGGSGGGGGGGGGSGGSGSSSSSGSSSGGGSSSGSSGSGSSGGSGSSGGSGGSGSSSGSGGGSGSSSSSGGSGGGGGGGSSGGSSSSSGGGGSGSSSGGGSSGSGSGGGGGSSSGGSGGGGSSSGGGGGSGSSSSSGGSGSSSTGGSSSSSSSSSGSGRGGSSSGSGGSSGSSGGGSSGGGGGGSGGGSGGSGGGGSGSSSGSGGSSSGGGSGSGSGGGGSSSGGGSSSGSSSGGGGGGGSGSGSSSSSGSSGGSGGSGSGGSGSSGGGSGSSGSSGSSSSGSGGGGGSGGGSGSGSSSSGGSSGGSSGGSSGGGGSSGGGGGGSSSGSSGSSSGGGGS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GGSSGSSSGSSGSGGGSGSSGSGGGSGSGGTGSGSGSGGGSSSGSGSSGSSGSGSSGSGSSSGGGGGSSSSSGGSSSGGSSGSSSSSSGGSSGSGSSSSGGGSSGGSGGGGSSGGSGSSGSGGGGGGGGSWSSRSSSSSGGSGSGGSGSSGSSSGGGSGSGGSSGSWSGGSSGGSSSGGGGGSGGSSSGGSSSGSGGSSGGGSSGSSGSGSSWSSSSSSSGGGGGSGGSGSSSSSSTSGSSSSSSGSGWSSGSSSSSGGGSSGSSSGGGGSSSSGSGSGWSSGSGSSGSSSGGSSSGSGSGGGSGSSGGGSSSGGGSGGSGGGSGGGGGGGSSGGGSGSGGGSSSSSRSSGSGSGGGGSGSSSGSGSSGGGGGSSSGSGSGSSGGGGSSSGSSSS';\r\nAexp=144;\r\nA=House(reshape(str,nc,[])');\r\nassert(isequal(Aexp,A))\r\n%%\r\nnc=35;\r\nstr='SSSGGSSSSSSGSSGGGGGGSSGGGGGGGSGGSSGGSGGSGSGGGRSGSSSGSSGSGGTGSGSGGSGSSGSGSGGSGGGGSSSGGGGGGGSGSSGSGGGSGSGGSGSSSGSSSGSSGSSSGGSGSGSSSGGGGGSSSGGGSSSSSSSSGGGSSGGSGSSGGGGGGGGGSGSSSSGGGGGSSGGSGSGSSSGGSSSSSGGGGGSGSRSSGGSGSSGSSSSGSGGGSSGSGSSSSSSSGSGSSSGGG';\r\nAexp=150;\r\nA=House(reshape(str,nc,[])');\r\nassert(isequal(Aexp,A))\r\n%%\r\n% function GJam_Africa_2011C\r\n% %House\r\n% %fn='C-small-practice.in';\r\n% fn='C-large-practice.in';\r\n% [data] = read_file(fn);\r\n% \r\n% %fidG = fopen('C-small-output.out', 'w');\r\n% fidG = fopen('C-large-output.out', 'w');\r\n% tic\r\n% for i=1:size(data,1) % Cell array has N rows of cases\r\n%  A = House(reshape(data{i,2},data{i,1},[])' ) ;% data matrix GWRST \r\n%  toc\r\n% % continue\r\n%    fprintf(fidG,'Case #%i: %i\\n',i,A);\r\n%    fprintf('Case #%i: %i\\n',i,A);\r\n%   \r\n% end\r\n% toc\r\n% \r\n% fclose(fidG);\r\n% fclose(fidC);\r\n% \r\n% end\r\n% \r\n% function [d] = read_file(fn)\r\n% %Read a numeric of lines to count\r\n% fid=fopen(fn);\r\n% fgetl(fid); % Total Count ignore\r\n% set=0;\r\n% while ~feof(fid)\r\n%  nrc=str2num(fgetl(fid)); % [nc nr]\r\n%  str='';\r\n%  for i=1:nrc(2)\r\n%   str=[str fgetl(fid)]; % read line of data, convert to vector\r\n%  end\r\n%  set=set+1;\r\n%  d{set,1}=nrc(1); % need to do a transpose after\r\n%  d{set,2}=str;\r\n% end\r\n%  fclose(fid);\r\n% end\r\n% \r\n% function A=House(m)\r\n% % GRWST: G1 R0 W0 S1 T0    [0 11 16 12 13] on G subtract\r\n%  m=m-'G'; % Convert String array to binary\r\n%  m(m==12)=0;\r\n%  m=double(~m);\r\n% \r\n%  [nr,nc]=size(m);\r\n%  A=0;\r\n%  % try all [1:nr,1:nc] overlay convolutions and find max\r\n%  for i=1:nr\r\n%   for j=1:nc\r\n%    if i*j\u003eA % speed enhance, faster than continue continue \r\n%     mc=conv2(m,ones(i,j)); \r\n%     if nnz(mc==i*j) % fastest array compare\r\n%      A=i*j; % Current Max Rectangle\r\n%     end\r\n%    end\r\n%   end % j\r\n%  end % i\r\n%  \r\n% end % House\r\n%\r\n% Data input example\r\n%10\r\n%1 1\r\n%G\r\n%2 2\r\n%GS\r\n%SG\r\n%2 2\r\n%GT\r\n%GG\r\n%8 9\r\n%GGGSGGSG\r\n%RSGGSGGG\r\n%GSSGSGGG\r\n%GGSSSGSS\r\n%SGGGSSRS\r\n%SSWGSSSS\r\n%GGGSSGSG\r\n%SGSSSWGS\r\n%SGSGSSGS\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":20,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-03-31T04:20:54.000Z","updated_at":"2026-01-22T14:29:29.000Z","published_at":"2014-03-31T04:32:30.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis Challenge is derived from\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam/contest/837485/dashboard#s=p2\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam 2011 Africa: Building a House\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Google Code Jam 2014 Kicks Off its Qualifier round April 11.\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://code.google.com/codejam\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eGJam Registration\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. The Test Suite, at the bottom, contains a full GJam file input read (fgetl, string), process, and Output example.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eDetermine maximum area rectangular House that can be placed on a plot given a text terrain map of G-Grass,S-Shrubs,R-Rock,W-Water, and T-Tree. The house can not be placed over Water, Trees, or Rocks. Square is a special rectangle.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e M, Text Array of GWRST\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eOutput:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e A, maximum House area that can be placed\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[GGTGG  A=9\\nTGGGG\\nGSSGT\\nGGGGT\\nGWGGG\\nRGTRT\\nRTGWT\\nWTWGR]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAdditional GJam solutions can be found at\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://go-hero.net/jam\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eExample GJam Matlab solutions\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Select Find Solutions, change Language to Matlab. There were only 50 Qualifier Matlab entrants in 2013 and a mere 2 Matlab users achieved round 2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"2011\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"2011\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"2011\"","","\"","2011","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f1960159070\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f1960158fd0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f19601585d0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f1960159430\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f19601592f0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f19601591b0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f1960159110\u003e":"tag:\"2011\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f1960159110\u003e":"tag:\"2011\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"2011\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"2011\"","","\"","2011","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f1960159070\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f1960158fd0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f19601585d0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f1960159430\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f19601592f0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f19601591b0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f1960159110\u003e":"tag:\"2011\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f1960159110\u003e":"tag:\"2011\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":2260,"difficulty_rating":"easy-medium"},{"id":2262,"difficulty_rating":"easy-medium"},{"id":2264,"difficulty_rating":"medium"}]}}