RosettaCodeData/Task/Semordnilap/Jq/semordnilap.jq
2023-07-01 13:44:08 -04:00

11 lines
336 B
Text

# Produce a stream
def report:
split("\n") as $list
# construct the dictionary:
| (reduce $list[] as $entry ({}; . + {($entry): 1})) as $dict
# construct the list of semordnilaps:
| $list[]
| select( (explode|reverse|implode) as $rev
| (. < $rev and $dict[$rev]) );
[report] | (.[0:5][], "length = \(length)")