Attempt to clear up some ambiguity in the descriptions

of the "HammingCodes" coding contracts as well as having the
"HammingCodes: Encoded Binary to Integer" coding contract generate valid
Hamming codes.
This commit is contained in:
s2ks 2022-05-27 21:36:03 +02:00
parent 605dd87e90
commit 4b37603ea5

@ -2,7 +2,7 @@ import { getRandomInt } from "../utils/helpers/getRandomInt";
import { MinHeap } from "../utils/Heap"; import { MinHeap } from "../utils/Heap";
import { comprGenChar, comprLZGenerate, comprLZEncode, comprLZDecode } from "../utils/CompressionContracts"; import { comprGenChar, comprLZGenerate, comprLZEncode, comprLZDecode } from "../utils/CompressionContracts";
import { HammingEncode, HammingDecode } from "../utils/HammingCodeTools"; import { HammingEncode, HammingDecode, HammingEncodeProperly } from "../utils/HammingCodeTools";
/* tslint:disable:completed-docs no-magic-numbers arrow-return-shorthand */ /* tslint:disable:completed-docs no-magic-numbers arrow-return-shorthand */
/* Function that generates a valid 'data' for a contract type */ /* Function that generates a valid 'data' for a contract type */
@ -1257,16 +1257,16 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
return [ return [
"You are given the following decimal Value: \n", "You are given the following decimal Value: \n",
`${n} \n`, `${n} \n`,
"Convert it into a binary string and encode it as a 'Hamming-Code'. eg:\n ", "Convert it to a binary representation and encode it as an 'extended Hamming code'. Eg:\n ",
"Value 8 will result into binary '1000', which will be encoded", "Value 8 is expressed in binary as '1000', which will be encoded",
"with the pattern 'pppdpddd', where p is a paritybit and d a databit,\n", "with the pattern 'pppdpddd', where p is a parity bit and d a data bit,\n",
"or '10101' (Value 21) will result into (pppdpdddpd) '1001101011'.\n\n", "or '10101' (Value 21) will result into (pppdpdddpd) '1001101011'.\n\n",
"NOTE: You need an parity Bit on Index 0 as an 'overall'-paritybit. \n", "NOTE: the endianness of the data bits is reversed in relation to the endianness of the parity bits.\n",
"NOTE 2: You should watch the HammingCode-video from 3Blue1Brown, which explains the 'rule' of encoding,", "NOTE: The bit at index zero is the overall parity bit, this should be set last.\n",
"including the first Index parity-bit mentioned on the first note.\n\n", "NOTE 2: You should watch the Hamming Code video from 3Blue1Brown, which explains the 'rule' of encoding,",
"Now the only one rule for this encoding:\n", "including the first index parity bit mentioned in the previous note.\n\n",
" It's not allowed to add additional leading '0's to the binary value\n", "Extra rule for encoding:\n",
"That means, the binary value has to be encoded as it is", "There should be no leading zeros in the 'data bit' section",
].join(" "); ].join(" ");
}, },
gen: (): number => { gen: (): number => {
@ -1284,17 +1284,21 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
return [ return [
"You are given the following encoded binary String: \n", "You are given the following encoded binary String: \n",
`'${n}' \n`, `'${n}' \n`,
"Treat it as a Hammingcode with 1 'possible' error on an random Index.\n", "Treat it as an extended Hamming code with 1 'possible' error at a random index.\n",
"Find the 'possible' wrong bit, fix it and extract the decimal value, which is hidden inside the string.\n\n", "Find the 'possible' wrong bit, fix it and extract the decimal value, which is hidden inside the string.\n\n",
"Note: The length of the binary string is dynamic, but it's encoding/decoding is following Hammings 'rule'\n", "Note: The length of the binary string is dynamic, but it's encoding/decoding follows Hamming's 'rule'\n",
"Note 2: Index 0 is an 'overall' parity bit. Watch the Hammingcode-video from 3Blue1Brown for more information\n", "Note 2: Index 0 is an 'overall' parity bit. Watch the Hamming code video from 3Blue1Brown for more information\n",
"Note 3: There's a ~55% chance for an altered Bit. So... MAYBE there is an altered Bit 😉\n", "Note 3: There's a ~55% chance for an altered Bit. So... MAYBE there is an altered Bit 😉\n",
"Extranote for automation: return the decimal value as a string", "Note: The endianness of the \
encoded decimal value is reversed in relation to the endianness of the Hamming code. Where \
the Hamming code is expressed as little-endian (LSB at index 0), the decimal value encoded in it is expressed as big-endian \
(MSB at index 0)\n",
"Extra note for automation: return the decimal value as a string",
].join(" "); ].join(" ");
}, },
gen: (): string => { gen: (): string => {
const _alteredBit = Math.round(Math.random()); const _alteredBit = Math.round(Math.random());
const _buildArray: Array<string> = HammingEncode( const _buildArray: Array<string> = HammingEncodeProperly(
getRandomInt(Math.pow(2, 4), Math.pow(2, getRandomInt(1, 57))), getRandomInt(Math.pow(2, 4), Math.pow(2, getRandomInt(1, 57))),
).split(""); ).split("");
if (_alteredBit) { if (_alteredBit) {