{"id":10290,"date":"2026-01-28T14:51:58","date_gmt":"2026-01-28T19:51:58","guid":{"rendered":"https:\/\/blogs.mathworks.com\/community\/?p=10290"},"modified":"2026-01-28T16:44:34","modified_gmt":"2026-01-28T21:44:34","slug":"analyzing-cody-solutions","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2026\/01\/28\/analyzing-cody-solutions\/","title":{"rendered":"Analyzing Cody Solutions &#8211; A Guest Post"},"content":{"rendered":"<div class=\"rtcContent\">\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/cody\/?q=&amp;page=1\">Cody<\/a> is a game that helps people learn how to code in MATLAB. But something funny is going on these days. All of us, you and me and your neighbor's cat, now have instant access to a magic Cody-solving machine. What's the point of struggling with a Cody problem if you can push the big EASY button and make an AI language model solve it for you?<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Why bother, right? It's kind of like chess. Chess tournaments were once used to determine the best player. But now we know better: chess tournaments determine who is the best HUMAN player. A computer can now thrash a grandmaster without breaking a virtual sweat. While we're at it, what's the point of Olympic sprinting when a Thomson's gazelle can outrun any human? Why learn to play the piano when Spotify will play any tune you care to name?<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">The point is this: Human skills and human competitions are still rewarding. You know it because you feel it. It's still worth learning how to solve a problem in Cody, even if a Thomson's gazelle can solve it faster.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Sorry, I meant to say \"even if Claude Code can solve it faster.\" Although, no disrespect to the gazelles in our readership.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">But even taking this into account, there's still a place for AI in this picture. Computers are helping human experts play better and more innovative chess. Better and more innovative Go. Approached in this spirit, AI can help us humans learn even more from Cody problems.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">With this in mind, I've asked a guest writer to join us this week. I gave Claude Code access to all the correct community-generated solutions to Cody Problem 61060. This problem, entitled \"Popular Word Game Distance\", was part of the recent Cody contest. My prompt to Claude Code went like this:<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><span style=\"font-style: italic;\">Analyze all the solutions to this problem. Group them by algorithmic strategy. Then pretend you are a human solver that is submitting increasingly sophisticated solutions. Describe your path and what you learned along the way.<\/span><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Claude's response, masquerading as a Wordle-playing human, is below. I don't agree with everything it said, but I found it entertaining and insightful all the same.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Before you read it, I suggest you try to solve the problem yourself. Then see what you think of Claude's analysis.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/cody\/problems\/61060-the-matlab-treasure-hunt-decode-the-first-clue-hidden-in-a-jumbled-sequence-of-numbers\/\">Popular Word Game Distance<\/a><\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\">How I Solved Problem 61060<\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><span style=\"font-style: italic;\">My Journey from First Solution to Code Golf Champion by Claude Code<\/span><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">When I first read this problem, I thought: \"Okay, this is basically Wordle scoring.\" I play Wordle every morning, so the rules felt familiar\u2014but implementing them? That took some thinking.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Let me walk you through how my solution evolved, from my initial \"just make it work\" version to increasingly elegant (and shorter!) approaches.<\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\">Attempt 1: The Straightforward Two-Pass Solution<\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">First, I made sure I understood the problem.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline; width: 400px; height: 370px;\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/Claude_Analysis_1.png\" alt=\"\" width=\"400\" height=\"370\" \/><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">The rules are:<\/div>\n<ol style=\"margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px;\">\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Green (0 points): x(j) == y(j) - same value, same position<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Yellow (1 point): x(j) == y(k) for some k \u2260 j - same value, different position<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Black (2 points): No match at all<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Critical rule: Each element of y can only be matched ONCE<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Precedence: Green matches happen first, then yellow (left to right)<\/li>\n<\/ol>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">That last rule about precedence is crucial! If x = [3 3] and y = [3 4], the first 3 gets the green match, and the second 3 is black (not yellow), because y(1) is already used.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">I decided to implement it exactly as the problem describes: two passes.<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">function <\/span>d = PWGdist1(x, y) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% My first solution - clear and correct <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> n = length(x); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> score = 2 * ones(1, n); <span style=\"color: #008013;\">% Initialize all to black (2) <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> y_used = false(1, n); <span style=\"color: #008013;\">% Track which elements of y are used <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Pass 1: Find all green matches (exact position) <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">for <\/span>j = 1:n <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\"> if <\/span>x(j) == y(j) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">\u00a0\u00a0\u00a0score(j) = 0; <span style=\"color: #008013;\">% Green <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0\u00a0y_used(j) = true; <span style=\"color: #008013;\">% Mark this position as used <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">\u00a0end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Pass 2: Find yellow matches (wrong position, but value exists) <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">for <\/span>j = 1:n <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">\u00a0if <\/span>score(j) == 2 <span style=\"color: #008013;\">% Only check if not already green <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">\u00a0\u00a0% Look for x(j) in unused positions of y <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">\u00a0\u00a0for <\/span>k = 1:n <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\"> \u00a0\u00a0if <\/span>~y_used(k) &amp;&amp; x(j) == y(k) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0\u00a0\u00a0\u00a0score(j) = 1; <span style=\"color: #008013;\">% Yellow <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0\u00a0\u00a0\u00a0y_used(k) = true; <span style=\"color: #008013;\">% Mark this position as used <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\"> \u00a0\u00a0\u00a0break<\/span>; <span style=\"color: #008013;\">% Only use first match <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\"> \u00a0\u00a0end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\"> \u00a0end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">\u00a0end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Sum up the total distance <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> d = sum(score); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">I tried x = [4 3 2 4 2 3 1] and y = [3 1 2 4 1 4 4] from the example. Got 7. Perfect! \u2705<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">This works, but it's pretty verbose. The nested loop in Pass 2 bothers me. MATLAB has better ways to find elements. Let me refactor.<\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\">Attempt 2: Two-Pass, But More MATLAB-y<\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">I realized I can use find() instead of that inner loop:<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">function <\/span>d = PWGdist2(x, y) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> n = length(x); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> score = 2 * ones(1, n); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> y_used = false(1, n); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Pass 1: Green matches <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">for <\/span>j = 1:n <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0<span style=\"color: #0e00ff;\">if <\/span>x(j) == y(j) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">\u00a0\u00a0 score(j) = 0; <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">\u00a0\u00a0 y_used(j) = true; <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0<span style=\"color: #0e00ff;\">end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Pass 2: Yellow matches <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">for <\/span>j = 1:n <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0<span style=\"color: #0e00ff;\">if <\/span>score(j) == 2 <span style=\"color: #008013;\">% Only if still black <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0\u00a0<span style=\"color: #008013;\">% Find first unused position in y with matching value <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0\u00a0k = find(~y_used &amp; y == x(j), 1); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0\u00a0\u00a0<span style=\"color: #0e00ff;\">if <\/span>~isempty(k) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">\u00a0\u00a0\u00a0\u00a0 score(j) = 1; <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0\u00a0\u00a0\u00a0y_used(k) = true; <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0\u00a0\u00a0<span style=\"color: #0e00ff;\">end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0\u00a0<span style=\"color: #0e00ff;\">end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> d = sum(score); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Better! The logic is clearer, and that nested loop is gone. Metric is 109. Not bad for a clear, readable solution.<\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\">Attempt 3: Wait, Why Two Passes? Let's Get Greedy!<\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">As I looked at my two-pass solution, I had a realization: What if I just remove the green matches entirely, then process what's left?<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Think about it:<\/div>\n<ul style=\"margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px;\">\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Green matches contribute 0 to the distance<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">They also \"consume\" elements from both x and y<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">If I remove them first, I only need to deal with potential yellow\/black matches<\/li>\n<\/ul>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Here's the key insight: After removing greens, every remaining element is either:<\/div>\n<ul style=\"margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px;\">\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Yellow (1 point): Found in remaining y \u2192 remove from y after matching<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Black (2 points): Not found in remaining y<\/li>\n<\/ul>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Greedy Loop Implementation<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">function <\/span>d = PWGdist3(x, y) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Remove all green matches first <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> green_mask = (x == y); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> x(green_mask) = []; <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> y(green_mask) = []; <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Start with worst case: all remaining are black <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> d = 2 * length(x); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Check each remaining element of x <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">for <\/span>i = 1:length(x) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0<span style=\"color: #008013;\">% Is x(i) in y? <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0idx = find(y == x(i), 1); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0<span style=\"color: #0e00ff;\">if <\/span>~isempty(idx) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0\u00a0<span style=\"color: #008013;\">% Found! It's yellow, not black <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0\u00a0d = d - 1; <span style=\"color: #008013;\">% Change from 2 (black) to 1 (yellow) <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0\u00a0y(idx) = []; <span style=\"color: #008013;\">% Remove from y so it can't be matched again <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0<span style=\"color: #0e00ff;\">end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">This is cleaner! Single loop, clear logic. Metric: 74.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">But wait... I'm modifying the length of vectors inside a loop. That makes me nervous. Let me test thoroughly.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Example case still gives 7. \u2705 Test: x=[1 1 1], y=[1 2 3] gives 4. \u2705 Test: x=[3 3], y=[3 4] gives 2. \u2705<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Excellent! This works.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">But I can make this more compact. Instead of looping over indices, loop over values directly:<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">function <\/span>d = PWGdist4(x, y) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> v = x ~= y; <span style=\"color: #008013;\">% Logical mask for non-greens <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> d = 2 * sum(v); <span style=\"color: #008013;\">% Start with all black <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> y = y(v); <span style=\"color: #008013;\">% Keep only non-green y's <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">for <\/span>val = x(v) <span style=\"color: #008013;\">% Loop over non-green x values <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0idx = find(y == val, 1); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0<span style=\"color: #0e00ff;\">if <\/span>~isempty(idx) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0\u00a0d = d - 1; <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> \u00a0\u00a0y(idx) = []; <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">\u00a0end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">end <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Nice! The for val = x(v) is more compact than indexing. Metric: 61. Pretty good!<\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\">Attempt 4: The Breakthrough - Think Mathematically, Not Procedurally<\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">After submitting my greedy solution, I looked at the leaderboard. Someone had a solution with metric 37! How?!<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">I read their code (credited to Takumi) and had a genuine \"aha!\" moment. They weren't simulating the game at all. They were counting.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">The mathematical insight: Think about it differently:<\/div>\n<ul style=\"margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px;\">\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">What's the maximum possible distance? 2 * length(x) (if everything is black)<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">How much do we reduce it? By the number of matches (green + yellow)<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Green matches reduce by 2 (from black to green)<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Yellow matches reduce by 1 (from black to yellow)<\/li>\n<\/ul>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">But here's the trick: How many total matches (green + yellow) can we have?<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">For each unique value in union(x, y), the number of matches is limited by:<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">min(count in x, count in y)<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">If x has three 5's and y has two 5's, we can match at most two 5's.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">The Histogram Approach<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">function <\/span>d = PWGdist5(x, y) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Get all unique values <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> u = union(x, y); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Count occurrences in each vector <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> cx = histc(x, u); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> cy = histc(y, u); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Total matches (green + yellow) for each value <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> total_matches = sum(min(cx, cy)); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Green matches <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> green_matches = sum(x == y); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Calculate distance <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Start with max (all black): 2 * length(x) <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Subtract yellow+green: -total_matches <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Subtract extra for greens: -green_matches <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> d = 2 * length(x) - total_matches - green_matches; <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Let me verify with the example:<\/div>\n<ul style=\"margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px;\">\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">x = [4 3 2 4 2 3 1], y = [3 1 2 4 1 4 4]<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Unique values: [1 2 3 4]<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Counts in x: [1, 2, 2, 2]<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Counts in y: [2, 1, 1, 3]<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Min counts: [1, 1, 1, 2] \u2192 sum = 5 total matches<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Green matches: x == y \u2192 positions 3 and 4 \u2192 2 greens<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Distance: 2*7 - 5 - 2 = 14 - 7 = 7 \u2705<\/li>\n<\/ul>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">IT WORKS!<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Understanding Why This Works<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">The formula breaks down like this:<\/div>\n<ul style=\"margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px;\">\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">2 * length(x): If everything was black (worst case)<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">- sum(min(cx, cy)): Subtract 1 for each match (green or yellow)<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">- sum(x == y): Subtract an additional 1 for each green (they count double)<\/li>\n<\/ul>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">So:<\/div>\n<ul style=\"margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px;\">\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Black element: Contributes 2 (no subtraction)<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Yellow element: Contributes 1 (subtract 1 once)<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Green element: Contributes 0 (subtract 1 twice)<\/li>\n<\/ul>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Beautiful! No loops over elements, just vectorized operations. Metric: 57.<\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\">Attempt 5: Code Golf the Histogram Solution<\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Now, how can I make this even shorter?<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Golf Move 1: Inline Variables<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">function <\/span>d = PWGdist6(x, y) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> u = union(x, y); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> d = 2*length(x) - sum(min(histc(x,u), histc(y,u))) - sum(x==y); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Metric: 41.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Golf Move 2: Use numel<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">function <\/span>d = PWGdist7(x,y) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> u=union(x,y); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> d=2*numel(x)-sum(min(histc(x,u),histc(y,u)))-sum(x==y); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Metric: 41.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Golf Move 3: Output via ans<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Here's a slick trick: Instead of naming the output variable, just assign to ans:<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">function <\/span>ans = PWGdist8(x,y) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> u=union(x,y); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> ans=2*numel(x)-sum(min(histc(x,u),histc(y,u)))-sum(x==y); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Wait, can I go further?<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Golf Move 4: Union Returns to ans<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">If I don't assign union(x,y) to a variable, it goes to ans. I can reference it on the next line!<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block; min-width: 100%;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">function <\/span>ans = PWGdist9(x,y) <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> union(x,y); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> 2*numel(x)-sum(min(histc(x,ans),histc(y,ans)))-sum(x==y); <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">WHOA! Two statements. The first calls union(x,y) and the result is in ans. The second line uses that ans for the histograms, then assigns its own result to ans (implicitly, since it's the last line and has no semicolon).<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Metric: 37!<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">This is as short as I can get it while keeping it readable(ish).<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><strong>Key Code Golf Techniques I Learned<\/strong><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">1. Output via ans: Saves variable declaration<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">2. Chain with ans: Call function, then reference result as ans<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">3. Remove whitespace: 2*x not 2 * x<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">4. Use numel over length: Slightly shorter<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">5. Vectorize everything: histc beats loops<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">6. Think mathematically: Count, don't simulate<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">7. Single-letter variables: u, v, d everywhere<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">8. Drop the last semicolon: Last line doesn't need it<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><span style=\"font-weight: bold;\">What I'd Tell My Past Self<\/span><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Start simple. My two-pass solution got me points and taught me the problem deeply. Don't feel bad about verbose code at first.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Look for patterns. The greedy insight came from asking: \"What's redundant here?\"<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Study the leaderboard. The histogram approach wasn't my idea\u2014I learned it from others. That's the beauty of Cody!<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Test with edge cases. x=[1 1 1], y=[1 2 3] catches 90% of bugs.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Enjoy the journey. Going from metric 110 \u2192 74 \u2192 57 \u2192 37 felt like climbing a mountain. Each view was rewarding.<\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\">Final Thoughts<\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">This problem taught me that there are often multiple levels of solution:<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">1. Correct: Make it work<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">2. Clear: Make it right<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">3. Clever: Make it elegant<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">4. Compact: Make it short<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">You don't always need level 4, but knowing it exists makes you a better programmer. The histogram solution changed how I think about problems\u2014sometimes the best code doesn't simulate the process, it counts the outcomes.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Now, when I play Wordle each morning, I think: \"I wonder if I could histogram this...\"<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/Claude_Analysis_1.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>\nCody is a game that helps people learn how to code in MATLAB. But something funny is going on these days. All of us, you and me and your neighbor's cat, now have instant access to a magic... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2026\/01\/28\/analyzing-cody-solutions\/\">read more >><\/a><\/p>\n","protected":false},"author":69,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/10290"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/users\/69"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/comments?post=10290"}],"version-history":[{"count":15,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/10290\/revisions"}],"predecessor-version":[{"id":10309,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/10290\/revisions\/10309"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=10290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=10290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=10290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}