Title: Duplicate Permutations Unaddressed · Issue #56 · KxSystems/docs · GitHub
Open Graph Title: Duplicate Permutations Unaddressed · Issue #56 · KxSystems/docs
X Title: Duplicate Permutations Unaddressed · Issue #56 · KxSystems/docs
Description: Issue In several locations across code.kx.com we deal with finding all permutations. e.x. https://code.kx.com/q/learn/reading/strings/#its-more-fun-to-permute https://code.kx.com/phrases/math/#permutations In both of these cases, I find ...
Open Graph Description: Issue In several locations across code.kx.com we deal with finding all permutations. e.x. https://code.kx.com/q/learn/reading/strings/#its-more-fun-to-permute https://code.kx.com/phrases/math/#perm...
X Description: Issue In several locations across code.kx.com we deal with finding all permutations. e.x. https://code.kx.com/q/learn/reading/strings/#its-more-fun-to-permute https://code.kx.com/phrases/math/#perm...
Opengraph URL: https://github.com/KxSystems/docs/issues/56
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Duplicate Permutations Unaddressed","articleBody":"# Issue\r\nIn several locations across code.kx.com we deal with finding all permutations. e.x.\r\n- https://code.kx.com/q/learn/reading/strings/#its-more-fun-to-permute\r\n- https://code.kx.com/phrases/math/#permutations\r\n\r\nIn both of these cases, I find that duplicate permutations are just completely unaddressed. If we are dealing with a set, naturally there will be no problem with duplicates. But the phrasebook does not clearly specify that we are dealing with sets, and the reading room puzzle goes further to specify our input is a string (clearly not a set). Furthermore, even if we assume that we are dealing with permutations of a set, we should ensure that the official solutions we provide handle these in a standardized and expected manner. \r\n\r\n\r\n\r\nClearly this is not the case. \r\n\r\n# Solutions \r\nWe should either: \r\n1. Clarify that the solutions provided only deal with unique elements, and have undefined behaviour otherwise\r\n2. Standardize the solutions to remove all duplicates\r\n3. Standardize the solutions to enumerate all permutations, regardless of duplicates\r\n\r\nWe can also do any combination of these (e.x. solution (1) for phrasebook and (2) for the reading room problem).\r\n\r\n# My Contribution\r\nI believe solution 2 is the best option. A list of permutations with duplicates seems redundant and unnecessary. You might as well `distinct` the output, in which case we should do this in the solutions provided. I don't know if applying `distinct` is necessarily the best solution here, in fact I have little experience with q, but it seems the most straightforward solution.\r\n\r\n## Phrasebook\r\n- Before: `{(1 0#x){raze(1 rotate)scan'x,'y}/x}`\r\n- After: `{(1 0#x){distinct raze(1 rotate)scan'x,'y}/x}`\r\n\r\n## Reading room cats cradle solution 1\r\nThis solution is actually incomplete and incorrect which is a separate issue of its own that caused this entire investigation. I have done the best I can to fix the solution and will provide it as a PR after discussion of this ticket.\r\n- Before: `{x {flip[y]where x=sum y}[s;] s vs til\"j\"$s xexp s:count x}`, incorrect\r\n- After: `{distinct x @ b where all each (til c) in/:b:flip c vs til \"j\"$c xexp c:count x}`\r\n\r\n## Reading room cats cradle solution 2\r\n- Before: `{(1 0#x) {raze({raze reverse 0 1 _ x}\\)each x,'y}/ x}`, strongly based off the phrasebook solution\r\n- After: `{(1 0#x) {distinct raze({raze reverse 0 1 _ x}\\)each x,'y}/ x}`","author":{"url":"https://github.com/Scowluga","@type":"Person","name":"Scowluga"},"datePublished":"2021-12-31T04:02:59.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/56/docs/issues/56"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:cd2187fe-ea82-9ced-95b9-7f227fd5c203 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EA1E:AE4D:25A31D2:307D959:698C1326 |
| html-safe-nonce | a859704e4b134adfe4554f1d23a6c000f2f359b81c871707ef3df5c6b3dfb80a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQTFFOkFFNEQ6MjVBMzFEMjozMDdEOTU5OjY5OEMxMzI2IiwidmlzaXRvcl9pZCI6IjQ4MzE1MjU2ODY0NzU0OTQxODIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6e9cde48922c504a297613deaa0b414bdde4fc3907b75a9d0d3dcc17767805ae |
| hovercard-subject-tag | issue:1091404634 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/KxSystems/docs/56/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a891bbea31e49233d46fa30609df370194df6bef58e59bca3c98c9f400531423/KxSystems/docs/issues/56 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a891bbea31e49233d46fa30609df370194df6bef58e59bca3c98c9f400531423/KxSystems/docs/issues/56 |
| og:image:alt | Issue In several locations across code.kx.com we deal with finding all permutations. e.x. https://code.kx.com/q/learn/reading/strings/#its-more-fun-to-permute https://code.kx.com/phrases/math/#perm... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Scowluga |
| hostname | github.com |
| expected-hostname | github.com |
| None | 640eeb7b6ff4d8d106235d228c0c286e82592d4d2403227b5b2b4fc5832297a4 |
| turbo-cache-control | no-preview |
| go-import | github.com/KxSystems/docs git https://github.com/KxSystems/docs.git |
| octolytics-dimension-user_id | 11446750 |
| octolytics-dimension-user_login | KxSystems |
| octolytics-dimension-repository_id | 175059605 |
| octolytics-dimension-repository_nwo | KxSystems/docs |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 175059605 |
| octolytics-dimension-repository_network_root_nwo | KxSystems/docs |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3d444f0a47beeeac94cddbb51c91ab408befe8d4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width