{"id":201,"date":"2009-02-24T00:00:47","date_gmt":"2009-02-24T07:00:47","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=847"},"modified":"2009-02-24T00:00:47","modified_gmt":"2009-02-24T07:00:47","slug":"n-to-the-power-of-n-with-strings","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=201","title":{"rendered":"N to the power of N (with strings)"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar input:String =  &quot;a, b, c&quot;;\r\n\r\nvar words:Array = input.split(&quot;, &quot;);\r\nvar max:String = &quot;&quot;;\r\nvar maxD:String =  (words.length - 1).toString();\r\nfor (var i:int = 0; i&lt;words.length; i++){\r\n\tmax += maxD;\r\n}\r\nvar maxInt:int = parseInt(max,words.length);\r\n\r\nfor(i = 0; i&lt;=maxInt; i++){\r\n\t var indices:String = i.toString(words.length);\r\n\t var r:String = &quot;&quot;;\r\n\t var k:int=0;\r\n\t for (var j:int = 0; j&lt;indices.length; j++){\r\n\t\t r += words&#x5B;parseInt(indices.charAt(j))] +&quot; &quot;;\r\n\t\t k++;\r\n\t }\r\n\t while(k &lt; words.length) {\r\n\t\tr = words&#x5B;0] +&quot; &quot;+ r;\r\n\t\tk++;\r\n\t }\r\n\ttrace(r);\r\n}\r\ntrace(i, &quot; variations&quot;);\r\n<\/pre>\n<p>Like many things on this site, I coded this rather quickly and it can probably be cleaned up&#8230;<\/p>\n<p>Setting the input variable of the above snippet to &#8220;a, b&#8221; will output:<\/p>\n<p>a a<br \/>\na b<br \/>\nb a<br \/>\nb b<br \/>\n4  variations<\/p>\n<p>Setting the input to &#8220;a, b, c&#8221; will output:<\/p>\n<p>a a a<br \/>\na a b<br \/>\na a c<br \/>\na b a<br \/>\na b b<br \/>\na b c<br \/>\na c a<br \/>\na c b<br \/>\na c c<br \/>\nb a a<br \/>\nb a b<br \/>\nb a c<br \/>\nb b a<br \/>\nb b b<br \/>\nb b c<br \/>\nb c a<br \/>\nb c b<br \/>\nb c c<br \/>\nc a a<br \/>\nc a b<br \/>\nc a c<br \/>\nc b a<br \/>\nc b b<br \/>\nc b c<br \/>\nc c a<br \/>\nc c b<br \/>\nc c c<br \/>\n27  variations<\/p>\n<p>I created this to work with words&#8230; inputs like &#8220;bread, breath, blobs, backwards&#8221;. Be careful because you can quickly get millions of outputs:<\/p>\n<p>1 to the power of 1 is 1<br \/>\n2 to the power of 2 is 4<br \/>\n3 to the power of 3 is 27<br \/>\n4 to the power of 4 is 256<br \/>\n5 to the power of 5 is 3125<br \/>\n6 to the power of 6 is 46,656<br \/>\n7 to the power of 7 is 823,543<br \/>\n8 to the power of 8 is 16,777,216<br \/>\netc&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>var input:String = &quot;a, b, c&quot;; var words:Array = input.split(&quot;, &quot;); var max:String = &quot;&quot;; var maxD:String = (words.length &#8211; 1).toString(); for (var i:int = 0; i&lt;words.length; i++){ max += maxD; } var maxInt:int = parseInt(max,words.length); for(i = 0; i&lt;=maxInt; i++){ var indices:String = i.toString(words.length); var r:String = &quot;&quot;; var k:int=0; for (var j:int = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[121,94,20],"tags":[3,4],"class_list":["post-201","post","type-post","status-publish","format-standard","hentry","category-math","category-misc","category-string-manipulation","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=201"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/201\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}