{"id":35,"date":"2013-03-08T12:00:00","date_gmt":"2013-03-08T12:00:00","guid":{"rendered":"https:\/\/eric.tedjamulia.com\/blog\/recursive-permutations\/"},"modified":"2013-03-08T12:00:00","modified_gmt":"2013-03-08T12:00:00","slug":"recursive-permutations","status":"publish","type":"post","link":"https:\/\/eric.tedjamulia.com\/blog\/recursive-permutations\/","title":{"rendered":"Permutations and interview questions"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I have been working through interview-style programming questions and wrote a little page to generate permutations of a string. Give it 1234 and it prints all twenty-four arrangements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The recursive step is pretty simple: choose a character, find all the permutations of what is left, then put the chosen character at the beginning of each result. A one-character string is the stopping point. I store the results as object keys so repeated characters do not leave repeated answers in the output.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The first version takes its input from the query string and writes the answers straight into the document. Nothing fancy, but having the results on a page makes it easier to check the recursive reasoning against a few examples. It is also a good reminder that a short recursive function can produce a lot of output very quickly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/etedj.com\/projects\/fun\/permutations.html\">Original permutations page<\/a> &middot; <a href=\"https:\/\/etedj.com\/projects\/questions\/permutations.html\">Another copy<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been working through interview-style programming questions and wrote a little page to generate permutations of a string. Give it 1234 and it prints all twenty-four arrangements. The recursive step is pretty simple: choose a character, find all the permutations of what is left, then put the chosen character at the beginning of each [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[28,3,30],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-experiments","tag-algorithms","tag-javascript","tag-recursion"],"_links":{"self":[{"href":"https:\/\/eric.tedjamulia.com\/blog\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eric.tedjamulia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eric.tedjamulia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eric.tedjamulia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eric.tedjamulia.com\/blog\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":0,"href":"https:\/\/eric.tedjamulia.com\/blog\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"wp:attachment":[{"href":"https:\/\/eric.tedjamulia.com\/blog\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eric.tedjamulia.com\/blog\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eric.tedjamulia.com\/blog\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}