Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
2
Task/CRC-32/Jq/crc-32-1.jq
Normal file
2
Task/CRC-32/Jq/crc-32-1.jq
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
def div($j):
|
||||
((. - (. % $j)) / $j) | round;
|
||||
34
Task/CRC-32/Jq/crc-32-2.jq
Normal file
34
Task/CRC-32/Jq/crc-32-2.jq
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
include "bitwise" {search: "."}; # see above
|
||||
|
||||
# non-negative decimal integer to hex string
|
||||
def hex:
|
||||
def stream:
|
||||
recurse(if . >= 16 then ./16|floor else empty end) | . % 16 ;
|
||||
[stream] | reverse
|
||||
| map(if . < 10 then 48 + . else . + 87 end) | implode ;
|
||||
|
||||
### CRC-32
|
||||
|
||||
def crc32Table:
|
||||
reduce range(0; 256) as $i ([];
|
||||
. + [reduce range(0; 8) as $j ($i;
|
||||
if bitwise_and(.;1) == 1
|
||||
then bitwise_xor(rightshift(1); 3988292384) # 0xedb88320
|
||||
else rightshift( 1 )
|
||||
end) ] );
|
||||
|
||||
# Input: an ASCII string
|
||||
# Output: its CRC-32
|
||||
def crc32:
|
||||
explode as $s
|
||||
| crc32Table as $table
|
||||
| reduce range(0; $s|length) as $i (4294967295 ; # ~0
|
||||
# 0xff is 255
|
||||
bitwise_and(.; 255 ) as $crb
|
||||
| bitwise_xor( $table[bitwise_xor($crb; $s[$i])] ; rightshift(8)) )
|
||||
| flip(32) ;
|
||||
|
||||
def task:
|
||||
crc32 | hex;
|
||||
|
||||
"The quick brown fox jumps over the lazy dog" | task
|
||||
Loading…
Add table
Add a link
Reference in a new issue