CONTRACTS: Fix nbsp rendering as text rather than a space (#2225)

This commit is contained in:
gmcew
2025-07-06 18:10:36 +01:00
committed by GitHub
parent fe13c3e2ca
commit f2e7babcf3
8 changed files with 64 additions and 69 deletions

View File

@@ -88,7 +88,7 @@ export class CodingContract {
}
getDescription(): string {
return CodingContractTypes[this.type].desc(this.getData()).replaceAll(" ", " ");
return CodingContractTypes[this.type].desc(this.getData());
}
getDifficulty(): number {

View File

@@ -17,13 +17,13 @@ export const compression: Pick<
"are encoded as a single ASCII digit; runs of 10 characters or more are encoded by splitting them",
"into multiple runs.\n\n",
"You are given the following input string:\n",
`&nbsp; &nbsp; ${plaintext}\n`,
` ${plaintext}\n`,
"Encode it using run-length encoding with the minimum possible output length.\n\n",
"Examples:\n\n",
"&nbsp; &nbsp; aaaaabccc &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-> &nbsp;5a1b3c\n",
"&nbsp; &nbsp; aAaAaA &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -> &nbsp;1a1A1a1A1a1A\n",
"&nbsp; &nbsp; 111112333 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-> &nbsp;511233\n",
"&nbsp; &nbsp; zzzzzzzzzzzzzzzzzzz &nbsp;-> &nbsp;9z9z1z &nbsp;(or 9z8z2z, etc.)",
" aaaaabccc -> 5a1b3c\n",
" aAaAaA -> 1a1A1a1A1a1A\n",
" 111112333 -> 511233\n",
" zzzzzzzzzzzzzzzzzzz -> 9z9z1z (or 9z8z2z, etc.)",
].join(" ");
},
generate: (): string => {
@@ -85,14 +85,14 @@ export const compression: Pick<
"is the start of a new chunk. The two chunk types alternate, starting with type 1, and the final",
"chunk may be of either type.\n\n",
"You are given the following LZ-encoded string:\n",
`&nbsp; &nbsp; ${compressed}\n`,
` ${compressed}\n`,
"Decode it and output the original string.\n\n",
"Example: decoding '5aaabb450723abb' chunk-by-chunk\n\n",
"&nbsp; &nbsp; 5aaabb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -> &nbsp;aaabb\n",
"&nbsp; &nbsp; 5aaabb45 &nbsp; &nbsp; &nbsp; &nbsp; -> &nbsp;aaabbaaab\n",
"&nbsp; &nbsp; 5aaabb450 &nbsp; &nbsp; &nbsp; &nbsp;-> &nbsp;aaabbaaab\n",
"&nbsp; &nbsp; 5aaabb45072 &nbsp; &nbsp; &nbsp;-> &nbsp;aaabbaaababababa\n",
"&nbsp; &nbsp; 5aaabb450723abb &nbsp;-> &nbsp;aaabbaaababababaabb",
" 5aaabb -> aaabb\n",
" 5aaabb45 -> aaabbaaab\n",
" 5aaabb450 -> aaabbaaab\n",
" 5aaabb45072 -> aaabbaaababababa\n",
" 5aaabb450723abb -> aaabbaaababababaabb",
].join(" ");
},
generate: (): string => {
@@ -120,17 +120,17 @@ export const compression: Pick<
"is the start of a new chunk. The two chunk types alternate, starting with type 1, and the final",
"chunk may be of either type.\n\n",
"You are given the following input string:\n",
`&nbsp; &nbsp; ${plaintext}\n`,
` ${plaintext}\n`,
"Encode it using Lempel-Ziv encoding with the minimum possible output length.\n\n",
"Examples (some have other possible encodings of minimal length):\n",
"&nbsp; &nbsp; abracadabra &nbsp; &nbsp; -> &nbsp;7abracad47\n",
"&nbsp; &nbsp; mississippi &nbsp; &nbsp; -> &nbsp;4miss433ppi\n",
"&nbsp; &nbsp; aAAaAAaAaAA &nbsp; &nbsp; -> &nbsp;3aAA53035\n",
"&nbsp; &nbsp; 2718281828 &nbsp; &nbsp; &nbsp;-> &nbsp;627182844\n",
"&nbsp; &nbsp; abcdefghijk &nbsp; &nbsp; -> &nbsp;9abcdefghi02jk\n",
"&nbsp; &nbsp; aaaaaaaaaaaa &nbsp; &nbsp;-> &nbsp;3aaa91\n",
"&nbsp; &nbsp; aaaaaaaaaaaaa &nbsp; -> &nbsp;1a91031\n",
"&nbsp; &nbsp; aaaaaaaaaaaaaa &nbsp;-> &nbsp;1a91041",
" abracadabra -> 7abracad47\n",
" mississippi -> 4miss433ppi\n",
" aAAaAAaAaAA -> 3aAA53035\n",
" 2718281828 -> 627182844\n",
" abcdefghijk -> 9abcdefghi02jk\n",
" aaaaaaaaaaaa -> 3aaa91\n",
" aaaaaaaaaaaaa -> 1a91031\n",
" aaaaaaaaaaaaaa -> 1a91041",
].join(" ");
},
generate: (): string => {

View File

@@ -14,7 +14,7 @@ export const encryption: Pick<
"For example, with a left shift of 3, D would be replaced by A, ",
"E would become B, and A would become X (because of rotation).\n\n",
"You are given an array with two elements:\n",
`&nbsp;&nbsp;["${data[0]}", ${data[1]}]\n`,
` ["${data[0]}", ${data[1]}]\n`,
"The first element is the plaintext, the second element is the left shift value.\n\n",
"Return the ciphertext as uppercase string. Spaces remains the same.",
].join(" ");
@@ -73,25 +73,25 @@ export const encryption: Pick<
return [
"Vigenère cipher is a type of polyalphabetic substitution. It uses ",
"the Vigenère square to encrypt and decrypt plaintext with a keyword.\n\n",
"&nbsp;&nbsp;Vigenère square:\n",
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \n",
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +----------------------------------------------------\n",
"&nbsp;&nbsp;&nbsp;&nbsp; A | A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \n",
"&nbsp;&nbsp;&nbsp;&nbsp; B | B C D E F G H I J K L M N O P Q R S T U V W X Y Z A \n",
"&nbsp;&nbsp;&nbsp;&nbsp; C | C D E F G H I J K L M N O P Q R S T U V W X Y Z A B\n",
"&nbsp;&nbsp;&nbsp;&nbsp; D | D E F G H I J K L M N O P Q R S T U V W X Y Z A B C\n",
"&nbsp;&nbsp;&nbsp;&nbsp; E | E F G H I J K L M N O P Q R S T U V W X Y Z A B C D\n",
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...\n",
"&nbsp;&nbsp;&nbsp;&nbsp; Y | Y Z A B C D E F G H I J K L M N O P Q R S T U V W X\n",
"&nbsp;&nbsp;&nbsp;&nbsp; Z | Z A B C D E F G H I J K L M N O P Q R S T U V W X Y\n\n",
" Vigenère square:\n",
" A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \n",
" +----------------------------------------------------\n",
" A | A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \n",
" B | B C D E F G H I J K L M N O P Q R S T U V W X Y Z A \n",
" C | C D E F G H I J K L M N O P Q R S T U V W X Y Z A B\n",
" D | D E F G H I J K L M N O P Q R S T U V W X Y Z A B C\n",
" E | E F G H I J K L M N O P Q R S T U V W X Y Z A B C D\n",
" ...\n",
" Y | Y Z A B C D E F G H I J K L M N O P Q R S T U V W X\n",
" Z | Z A B C D E F G H I J K L M N O P Q R S T U V W X Y\n\n",
"For encryption each letter of the plaintext is paired with the corresponding letter of a repeating keyword.",
"For example, the plaintext DASHBOARD is encrypted with the keyword LINUX:\n",
"&nbsp;&nbsp; Plaintext: DASHBOARD\n",
"&nbsp;&nbsp; Keyword:&nbsp;&nbsp;&nbsp;LINUXLINU\n",
" Plaintext: DASHBOARD\n",
" Keyword: LINUXLINU\n",
"So, the first letter D is paired with the first letter of the key L. Therefore, row D and column L of the ",
"Vigenère square are used to get the first cipher letter O. This must be repeated for the whole ciphertext.\n\n",
"You are given an array with two elements:\n",
`&nbsp;&nbsp;["${data[0]}", "${data[1]}"]\n`,
` ["${data[0]}", "${data[1]}"]\n`,
"The first element is the plaintext, the second element is the keyword.\n\n",
"Return the ciphertext as uppercase string.",
].join(" ");

View File

@@ -12,7 +12,7 @@ export const minimumPathSumInATriangle: Pick<CodingContractTypes, CodingContract
}
const numSpaces = numLevels - level + 1;
let str: string = ["&nbsp;".repeat(numSpaces), "[", data[level].toString(), "]"].join("");
let str: string = [" ".repeat(numSpaces), "[", data[level].toString(), "]"].join("");
if (level < numLevels - 1) {
str += ",";
}
@@ -32,10 +32,10 @@ export const minimumPathSumInATriangle: Pick<CodingContractTypes, CodingContract
"The triangle is represented as a 2D array of numbers:\n\n",
`${triangle}\n\n`,
"Example: If you are given the following triangle:\n\n[\n",
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[2],\n",
"&nbsp;&nbsp;&nbsp;&nbsp;[3,4],\n",
"&nbsp;&nbsp;&nbsp;[6,5,7],\n",
"&nbsp;&nbsp;[4,1,8,3]\n",
" [2],\n",
" [3,4],\n",
" [6,5,7],\n",
" [4,1,8,3]\n",
"]\n\n",
"The minimum path sum is 11 (2 -> 3 -> 5 -> 1).",
].join(" ");

View File

@@ -7,7 +7,7 @@ export const shortestPathInAGrid: Pick<CodingContractTypes, CodingContractName.S
desc: (data: number[][]): string => {
return [
"You are located in the top-left corner of the following grid:\n\n",
`&nbsp;&nbsp;[${data.map((line) => `[${line}]`).join(",\n&nbsp;&nbsp;&nbsp;")}]\n\n`,
` [${data.map((line) => `[${line}]`).join(",\n ")}]\n\n`,
"You are trying to find the shortest path to the bottom-right corner of the grid,",
"but there are obstacles on the grid that you cannot move onto.",
"These obstacles are denoted by '1', while empty spaces are denoted by 0.\n\n",
@@ -17,12 +17,12 @@ export const shortestPathInAGrid: Pick<CodingContractTypes, CodingContractName.S
"If there is no path, the answer should be an empty string.\n",
"NOTE: The data returned for this contract is an 2D array of numbers representing the grid.\n\n",
"Examples:\n\n",
"&nbsp;&nbsp;&nbsp;&nbsp;[[0,1,0,0,0],\n",
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[0,0,0,1,0]]\n",
" [[0,1,0,0,0],\n",
" [0,0,0,1,0]]\n",
"\n",
"Answer: 'DRRURRD'\n\n",
"&nbsp;&nbsp;&nbsp;&nbsp;[[0,1],\n",
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1,0]]\n",
" [[0,1],\n",
" [1,0]]\n",
"\n",
"Answer: ''",
].join(" ");

View File

@@ -12,30 +12,25 @@ export const spiralizeMatrix: Pick<CodingContractTypes, CodingContractName.Spira
// for (const line of n) {
// d += `${line.toString()},\n`;
// }
d += "&nbsp;&nbsp;&nbsp;&nbsp;[\n";
d += " [\n";
d += n
.map(
(line: number[]) =>
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[" +
line.map((x: number) => `${x}`.padStart(2, " ")).join(",") +
"]",
)
.map((line: number[]) => " [" + line.map((x: number) => `${x}`.padStart(2, " ")).join(",") + "]")
.join("\n");
d += "\n&nbsp;&nbsp;&nbsp;&nbsp;]\n";
d += "\n ]\n";
d += [
"\nHere is an example of what spiral order should be:\n\n",
"&nbsp;&nbsp;&nbsp;&nbsp;[\n",
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1, 2, 3]\n",
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[4, 5, 6]\n",
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[7, 8, 9]\n",
"&nbsp;&nbsp;&nbsp;&nbsp;]\n\n",
" [\n",
" [1, 2, 3]\n",
" [4, 5, 6]\n",
" [7, 8, 9]\n",
" ]\n\n",
"Answer: [1, 2, 3, 6, 9, 8 ,7, 4, 5]\n\n",
"Note that the matrix will not always be square:\n\n",
"&nbsp;&nbsp;&nbsp;&nbsp;[\n",
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1,&nbsp;&nbsp;2,&nbsp;&nbsp;3,&nbsp;&nbsp;4]\n",
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[5,&nbsp;&nbsp;6,&nbsp;&nbsp;7,&nbsp;&nbsp;8]\n",
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[9,&nbsp;10,&nbsp;11,&nbsp;12]\n",
"&nbsp;&nbsp;&nbsp;&nbsp;]\n\n",
" [\n",
" [1, 2, 3, 4]\n",
" [5, 6, 7, 8]\n",
" [9, 10, 11, 12]\n",
" ]\n\n",
"Answer: [1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7]",
].join(" ");

View File

@@ -10,10 +10,10 @@ export const totalWaysToSum: Pick<
desc: (n: number): string => {
return [
"It is possible write four as a sum in exactly four different ways:\n\n",
"&nbsp;&nbsp;&nbsp;&nbsp;3 + 1\n",
"&nbsp;&nbsp;&nbsp;&nbsp;2 + 2\n",
"&nbsp;&nbsp;&nbsp;&nbsp;2 + 1 + 1\n",
"&nbsp;&nbsp;&nbsp;&nbsp;1 + 1 + 1 + 1\n\n",
" 3 + 1\n",
" 2 + 2\n",
" 2 + 1 + 1\n",
" 1 + 1 + 1 + 1\n\n",
`How many different distinct ways can the number ${n} be written as a sum of at least`,
"two positive integers?",
].join(" ");

View File

@@ -66,7 +66,7 @@ export function CodingContractModal(): React.ReactElement {
const description = [];
for (const [i, value] of contractType.desc(contract.c.getData()).split("\n").entries()) {
description.push(
<span key={i}>
<span key={i} style={{ whiteSpace: "pre-wrap" }}>
{value} <br />
</span>,
);