Skip to content

Instantly share code, notes, and snippets.

@emirikol
Last active August 13, 2025 08:52
Show Gist options
  • Save emirikol/ab4230d0c0f2b119f62135093ea2b52d to your computer and use it in GitHub Desktop.
Save emirikol/ab4230d0c0f2b119f62135093ea2b52d to your computer and use it in GitHub Desktop.
J palindromes
range =: 100 }. i. 1000
uniq_prods =: ~. @: , @: (*/~)
palindrome =: (-: |."1) @ (":"0)
>./ (#~ palindrome) uniq_prods range
>./ ( palindrome # ] ) ~. , */~ range
t =: ...
table =: 20 20 $ t
transposed =: > table ; (|: table) ; ([ /. table) ; ([ /. |. table)
cycles =: 0 ,"1 (0 ,"0 i. 20)
foursomes =: 4 {."1 cycles |. transposed
>./ , */"1 foursomes
Or better
table =: 20 20 $ ...
transposed =: (] ` |: ` ([ /.) ` ([ /.@|.)) `:0 table
>./ , 4 */\"1 transposed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment