Index finite lists of positive integers: Difference between revisions

Content added Content deleted
Line 598: Line 598:
changes would be required if using jaq as jaq does not (as of this writing in 2024) support
changes would be required if using jaq as jaq does not (as of this writing in 2024) support
the `include` or `module` directives.
the `include` or `module` directives.
===Fibonacci-based encoding===
===Bijective map based on Fibonacci encoding===
<syntaxhighlight lang="jq">
<syntaxhighlight lang="jq">
include "fibonacci" {search: "./"}; # see https://rosettacode.org/wiki/Category:Jq/fibonacci.jq
include "fibonacci" {search: "./"}; # see https://rosettacode.org/wiki/Category:Jq/fibonacci.jq
Line 607: Line 607:
map(fibencode | map(tostring) | join(""))
map(fibencode | map(tostring) | join(""))
| join("")
| join("")
| explode | reverse | implode ;
| explode | reverse[1:] | implode ;


def unrank:
def unrank:
"1" + tostring
tostring | explode | reverse | implode
| explode | reverse | implode
| split("11")
| split("11")
| .[:-1]
| .[:-1]
Line 661: Line 662:
50544
50544
],
],
"encoded": 10000010101010101010000110010010100010100100011100101000010100010100111001000010010010000100110010001001010010101011100000001000000000010111000101001010010101000101101001000010001001000001100010001000100000000001110000100100000010001000011000010101001000001001,
"encoded": 110000010101010101010000110010010100010100100011100101000010100010100111001000010010010000100110010001001010010101011100000001000000000010111000101001010010101000101101001000010001001000001100010001000100000000001110000100100000010001000011000010101001000001001,
"check": true
"check": true
}
}