diff --git a/challenges/easy/24_rainbow_table/starter/starter.cu b/challenges/easy/24_rainbow_table/starter/starter.cu index 8e8bf474..2308c751 100644 --- a/challenges/easy/24_rainbow_table/starter/starter.cu +++ b/challenges/easy/24_rainbow_table/starter/starter.cu @@ -1,13 +1,13 @@ #include -__device__ unsigned int fnv1a_hash(int input) { +__device__ unsigned int fnv1a_hash(unsigned int input) { const unsigned int FNV_PRIME = 16777619; const unsigned int OFFSET_BASIS = 2166136261; unsigned int hash = OFFSET_BASIS; for (int byte_pos = 0; byte_pos < 4; byte_pos++) { - unsigned char byte = (input >> (byte_pos * 8)) & 0xFF; + unsigned char byte = (input >> (byte_pos * 8)) & 0xFFu; hash = (hash ^ byte) * FNV_PRIME; } diff --git a/challenges/easy/24_rainbow_table/starter/starter.cute.py b/challenges/easy/24_rainbow_table/starter/starter.cute.py index 4cc4f642..7c0047a4 100644 --- a/challenges/easy/24_rainbow_table/starter/starter.cute.py +++ b/challenges/easy/24_rainbow_table/starter/starter.cute.py @@ -2,15 +2,14 @@ import cutlass.cute as cute -def fnv1a_hash_u32_scalar(x): +def fnv1a_hash_u32_scalar(x: cute.Uint32) -> cute.Uint32: FNV_PRIME = 16777619 OFFSET_BASIS = 2166136261 - val = cute.Uint32(x) hash_val = cute.Uint32(OFFSET_BASIS) prime = cute.Uint32(FNV_PRIME) mask = cute.Uint32(0xFF) for byte_pos in range(4): - byte = (val >> (byte_pos * 8)) & mask + byte = (x >> (byte_pos * 8)) & mask hash_val = (hash_val ^ byte) * prime return cute.Uint32(hash_val) diff --git a/challenges/easy/24_rainbow_table/starter/starter.jax.py b/challenges/easy/24_rainbow_table/starter/starter.jax.py index d28e0fff..fe0ebea7 100644 --- a/challenges/easy/24_rainbow_table/starter/starter.jax.py +++ b/challenges/easy/24_rainbow_table/starter/starter.jax.py @@ -5,12 +5,11 @@ def fnv1a_hash(x: jax.Array) -> jax.Array: FNV_PRIME = jnp.uint32(16777619) OFFSET_BASIS = jnp.uint32(2166136261) - x_u32 = x.astype(jnp.uint32) - hash_val = jnp.full_like(x_u32, OFFSET_BASIS, dtype=jnp.uint32) + hash_val = jnp.full_like(x, OFFSET_BASIS, dtype=jnp.uint32) MASK_FF = jnp.uint32(0xFF) for byte_pos in range(4): - byte = (x_u32 >> jnp.uint32(byte_pos * 8)) & MASK_FF + byte = (x >> jnp.uint32(byte_pos * 8)) & MASK_FF hash_val = hash_val ^ byte hash_val = hash_val * FNV_PRIME diff --git a/challenges/easy/24_rainbow_table/starter/starter.mojo b/challenges/easy/24_rainbow_table/starter/starter.mojo index be57bdba..25f9960f 100644 --- a/challenges/easy/24_rainbow_table/starter/starter.mojo +++ b/challenges/easy/24_rainbow_table/starter/starter.mojo @@ -4,14 +4,14 @@ from std.memory import UnsafePointer from std.math import ceildiv -def fnv1a_hash(input: Int32) -> UInt32: +def fnv1a_hash(input: UInt32) -> UInt32: alias FNV_PRIME: UInt32 = 16777619 alias OFFSET_BASIS: UInt32 = 2166136261 var hash: UInt32 = OFFSET_BASIS for byte_pos in range(4): - var byte_val: UInt32 = UInt32((input >> (byte_pos * 8)) & 0xFF) + var byte_val: UInt32 = (input >> (byte_pos * 8)) & UInt32(0xFF) hash = (hash ^ byte_val) * FNV_PRIME return hash