mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-20 05:05:47 +01:00
rm some any
This commit is contained in:
parent
8fe824e8cd
commit
86c0913bd3
@ -74,8 +74,8 @@ export const GameOptionsSidebar = (props: IProps): React.ReactElement => {
|
||||
const data = await saveObject.getImportDataFromString(base64Save);
|
||||
setImportData(data);
|
||||
setImportSaveOpen(true);
|
||||
} catch (ex: any) {
|
||||
SnackbarEvents.emit(ex.toString(), ToastVariant.ERROR, 5000);
|
||||
} catch (e: unknown) {
|
||||
SnackbarEvents.emit(String(e), ToastVariant.ERROR, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,8 +84,8 @@ export const GameOptionsSidebar = (props: IProps): React.ReactElement => {
|
||||
|
||||
try {
|
||||
await saveObject.importGame(importData.base64);
|
||||
} catch (ex: any) {
|
||||
SnackbarEvents.emit(ex.toString(), ToastVariant.ERROR, 5000);
|
||||
} catch (e: unknown) {
|
||||
SnackbarEvents.emit(String(e), ToastVariant.ERROR, 5000);
|
||||
}
|
||||
|
||||
setImportSaveOpen(false);
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { toNative } from "./toNative";
|
||||
import * as libarg from "arg";
|
||||
import libarg from "arg";
|
||||
|
||||
export function Flags(vargs: string[]): any {
|
||||
return () =>
|
||||
|
@ -20,9 +20,11 @@ export function toNative(pseudoObj: any): any {
|
||||
if (pseudoObj.hasOwnProperty("class") && pseudoObj.class === "Array") {
|
||||
nativeObj = [];
|
||||
const length = defaultInterpreter.getProperty(pseudoObj, "length");
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (defaultInterpreter.hasProperty(pseudoObj, i)) {
|
||||
nativeObj[i] = toNative(defaultInterpreter.getProperty(pseudoObj, i));
|
||||
if (typeof length === "number") {
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (defaultInterpreter.hasProperty(pseudoObj, i)) {
|
||||
nativeObj[i] = toNative(defaultInterpreter.getProperty(pseudoObj, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -94,7 +94,7 @@ export function ThemeEditorModal(props: IProps): React.ReactElement {
|
||||
}
|
||||
|
||||
function onColorChange(name: string, value: string): void {
|
||||
setCustomTheme((old: any) => {
|
||||
setCustomTheme((old: { [key: string]: string | undefined }) => {
|
||||
old[name] = value;
|
||||
return old;
|
||||
});
|
||||
|
10
src/ThirdParty/JSInterpreter.d.ts
vendored
10
src/ThirdParty/JSInterpreter.d.ts
vendored
@ -1 +1,9 @@
|
||||
export declare let Interpreter: any;
|
||||
export declare class Interpreter {
|
||||
constructor(code: string, opt_initFunc: (int: Interpreter, scope: Object) => void, lineOffset?: number);
|
||||
getProperty(obj: Value, name: Value): Value;
|
||||
hasProperty(obj: Value, name: Value): boolean;
|
||||
}
|
||||
|
||||
// Object and Value are 2 different things in the interpreter;
|
||||
export declare type Object = unknown;
|
||||
export declare type Value = unknown;
|
||||
|
@ -6,14 +6,14 @@ import { HammingEncode, HammingDecode } from "../utils/HammingCodeTools";
|
||||
/* tslint:disable:completed-docs no-magic-numbers arrow-return-shorthand */
|
||||
|
||||
/* Function that generates a valid 'data' for a contract type */
|
||||
export type GeneratorFunc = () => any;
|
||||
export type GeneratorFunc = () => unknown;
|
||||
|
||||
/* Function that checks if the provided solution is the correct one */
|
||||
export type SolverFunc = (data: any, answer: string) => boolean;
|
||||
export type SolverFunc = (data: unknown, answer: string) => boolean;
|
||||
|
||||
/* Function that returns a string with the problem's description.
|
||||
Requires the 'data' of a Contract as input */
|
||||
export type DescriptionFunc = (data: any) => string;
|
||||
export type DescriptionFunc = (data: unknown) => string;
|
||||
|
||||
interface ICodingContractTypeMetadata {
|
||||
desc: DescriptionFunc;
|
||||
@ -49,10 +49,10 @@ function removeQuotesFromString(str: string): string {
|
||||
return strCpy;
|
||||
}
|
||||
|
||||
function convert2DArrayToString(arr: any[][]): string {
|
||||
function convert2DArrayToString(arr: unknown[][]): string {
|
||||
const components: string[] = [];
|
||||
arr.forEach((e: any) => {
|
||||
let s: string = e.toString();
|
||||
arr.forEach((e: unknown) => {
|
||||
let s = String(e);
|
||||
s = ["[", s, "]"].join("");
|
||||
components.push(s);
|
||||
});
|
||||
@ -62,7 +62,7 @@ function convert2DArrayToString(arr: any[][]): string {
|
||||
|
||||
export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
{
|
||||
desc: (n: number): string => {
|
||||
desc: (n: unknown): string => {
|
||||
return ["A prime factor is a factor that is a prime number.", `What is the largest prime factor of ${n}?`].join(
|
||||
" ",
|
||||
);
|
||||
@ -73,7 +73,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Find Largest Prime Factor",
|
||||
numTries: 10,
|
||||
solver: (data: number, ans: string): boolean => {
|
||||
solver: (data: unknown, ans: string): boolean => {
|
||||
if (typeof data !== "number") throw new Error("solver expected number");
|
||||
let fac = 2;
|
||||
let n: number = data;
|
||||
while (n > (fac - 1) * (fac - 1)) {
|
||||
@ -87,7 +88,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (n: number[]): string => {
|
||||
desc: (_n: unknown): string => {
|
||||
const n = _n as number[];
|
||||
return [
|
||||
"Given the following integer array, find the contiguous subarray",
|
||||
"(containing at least one number) which has the largest sum and return that sum.",
|
||||
@ -108,7 +110,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Subarray with Maximum Sum",
|
||||
numTries: 10,
|
||||
solver: (data: number[], ans: string): boolean => {
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as number[];
|
||||
const nums: number[] = data.slice();
|
||||
for (let i = 1; i < nums.length; i++) {
|
||||
nums[i] = Math.max(nums[i], nums[i] + nums[i - 1]);
|
||||
@ -118,7 +121,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (n: number): string => {
|
||||
desc: (n: unknown): string => {
|
||||
if (typeof n !== "number") throw new Error("solver expected number");
|
||||
return [
|
||||
"It is possible write four as a sum in exactly four different ways:\n\n",
|
||||
" 3 + 1\n",
|
||||
@ -135,7 +139,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Total Ways to Sum",
|
||||
numTries: 10,
|
||||
solver: (data: number, ans: string): boolean => {
|
||||
solver: (data: unknown, ans: string): boolean => {
|
||||
if (typeof data !== "number") throw new Error("solver expected number");
|
||||
const ways: number[] = [1];
|
||||
ways.length = data + 1;
|
||||
ways.fill(0, 1);
|
||||
@ -149,7 +154,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (data: [number, number[]]): string => {
|
||||
desc: (_data: unknown): string => {
|
||||
const data = _data as [number, number[]];
|
||||
const n: number = data[0];
|
||||
const s: number[] = data[1];
|
||||
return [
|
||||
@ -178,7 +184,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Total Ways to Sum II",
|
||||
numTries: 10,
|
||||
solver: (data: [number, number[]], ans: string): boolean => {
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as [number, number[]];
|
||||
// https://www.geeksforgeeks.org/coin-change-dp-7/?ref=lbp
|
||||
const n = data[0];
|
||||
const s = data[1];
|
||||
@ -194,7 +201,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (n: number[][]): string => {
|
||||
desc: (_n: unknown): string => {
|
||||
const n = _n as number[][];
|
||||
let d: string = [
|
||||
"Given the following array of arrays of numbers representing a 2D matrix,",
|
||||
"return the elements of the matrix as an array in spiral order:\n\n",
|
||||
@ -252,7 +260,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Spiralize Matrix",
|
||||
numTries: 10,
|
||||
solver: (data: number[][], ans: string): boolean => {
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as number[][];
|
||||
const spiral: number[] = [];
|
||||
const m: number = data.length;
|
||||
const n: number = data[0].length;
|
||||
@ -299,11 +308,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
}
|
||||
}
|
||||
|
||||
const sanitizedPlayerAns: string = removeBracketsFromArrayString(ans).replace(/\s/g, "");
|
||||
const playerAns: any[] = sanitizedPlayerAns.split(",");
|
||||
for (let i = 0; i < playerAns.length; ++i) {
|
||||
playerAns[i] = parseInt(playerAns[i], 10);
|
||||
}
|
||||
const sanitizedPlayerAns = removeBracketsFromArrayString(ans).replace(/\s/g, "");
|
||||
const playerAns = sanitizedPlayerAns.split(",").map((s) => parseInt(s));
|
||||
if (spiral.length !== playerAns.length) {
|
||||
return false;
|
||||
}
|
||||
@ -317,7 +323,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (arr: number[]): string => {
|
||||
desc: (_arr: unknown): string => {
|
||||
const arr = _arr as number[];
|
||||
return [
|
||||
"You are given the following array of integers:\n\n",
|
||||
`${arr}\n\n`,
|
||||
@ -348,7 +355,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Array Jumping Game",
|
||||
numTries: 1,
|
||||
solver: (data: number[], ans: string): boolean => {
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as number[];
|
||||
const n: number = data.length;
|
||||
let i = 0;
|
||||
for (let reach = 0; i < n && i <= reach; ++i) {
|
||||
@ -359,7 +367,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (arr: number[]): string => {
|
||||
desc: (_arr: unknown): string => {
|
||||
const arr = _arr as number[];
|
||||
return [
|
||||
"You are given the following array of integers:\n\n",
|
||||
`${arr}\n\n`,
|
||||
@ -391,7 +400,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Array Jumping Game II",
|
||||
numTries: 3,
|
||||
solver: (data: number[], ans: string): boolean => {
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as number[];
|
||||
const n: number = data.length;
|
||||
let reach = 0;
|
||||
let jumps = 0;
|
||||
@ -415,7 +425,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (arr: number[][]): string => {
|
||||
desc: (_arr: unknown): string => {
|
||||
const arr = _arr as number[][];
|
||||
return [
|
||||
"Given the following array of arrays of numbers representing a list of",
|
||||
"intervals, merge all overlapping intervals.\n\n",
|
||||
@ -442,7 +453,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Merge Overlapping Intervals",
|
||||
numTries: 15,
|
||||
solver: (data: number[][], ans: string): boolean => {
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as number[][];
|
||||
const intervals: number[][] = data.slice();
|
||||
intervals.sort((a: number[], b: number[]) => {
|
||||
return a[0] - b[0];
|
||||
@ -469,7 +481,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (data: string): string => {
|
||||
desc: (data: unknown): string => {
|
||||
return [
|
||||
"Given the following string containing only digits, return",
|
||||
"an array with all possible valid IP address combinations",
|
||||
@ -495,17 +507,18 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Generate IP Addresses",
|
||||
numTries: 10,
|
||||
solver: (data: string, ans: string): boolean => {
|
||||
solver: (data: unknown, ans: string): boolean => {
|
||||
if (typeof data !== "string") throw new Error("solver expected string");
|
||||
const ret: string[] = [];
|
||||
for (let a = 1; a <= 3; ++a) {
|
||||
for (let b = 1; b <= 3; ++b) {
|
||||
for (let c = 1; c <= 3; ++c) {
|
||||
for (let d = 1; d <= 3; ++d) {
|
||||
if (a + b + c + d === data.length) {
|
||||
const A: number = parseInt(data.substring(0, a), 10);
|
||||
const B: number = parseInt(data.substring(a, a + b), 10);
|
||||
const C: number = parseInt(data.substring(a + b, a + b + c), 10);
|
||||
const D: number = parseInt(data.substring(a + b + c, a + b + c + d), 10);
|
||||
const A = parseInt(data.substring(0, a), 10);
|
||||
const B = parseInt(data.substring(a, a + b), 10);
|
||||
const C = parseInt(data.substring(a + b, a + b + c), 10);
|
||||
const D = parseInt(data.substring(a + b + c, a + b + c + d), 10);
|
||||
if (A <= 255 && B <= 255 && C <= 255 && D <= 255) {
|
||||
const ip: string = [A.toString(), ".", B.toString(), ".", C.toString(), ".", D.toString()].join("");
|
||||
if (ip.length === data.length + 3) {
|
||||
@ -533,7 +546,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (data: number[]): string => {
|
||||
desc: (_data: unknown): string => {
|
||||
const data = _data as number[];
|
||||
return [
|
||||
"You are given the following array of stock prices (which are numbers)",
|
||||
"where the i-th element represents the stock price on day i:\n\n",
|
||||
@ -557,7 +571,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Algorithmic Stock Trader I",
|
||||
numTries: 5,
|
||||
solver: (data: number[], ans: string): boolean => {
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as number[];
|
||||
let maxCur = 0;
|
||||
let maxSoFar = 0;
|
||||
for (let i = 1; i < data.length; ++i) {
|
||||
@ -569,7 +584,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (data: number[]): string => {
|
||||
desc: (_data: unknown): string => {
|
||||
const data = _data as number[];
|
||||
return [
|
||||
"You are given the following array of stock prices (which are numbers)",
|
||||
"where the i-th element represents the stock price on day i:\n\n",
|
||||
@ -595,7 +611,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Algorithmic Stock Trader II",
|
||||
numTries: 10,
|
||||
solver: (data: number[], ans: string): boolean => {
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as number[];
|
||||
let profit = 0;
|
||||
for (let p = 1; p < data.length; ++p) {
|
||||
profit += Math.max(data[p] - data[p - 1], 0);
|
||||
@ -605,7 +622,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (data: number[]): string => {
|
||||
desc: (_data: unknown): string => {
|
||||
const data = _data as number[];
|
||||
return [
|
||||
"You are given the following array of stock prices (which are numbers)",
|
||||
"where the i-th element represents the stock price on day i:\n\n",
|
||||
@ -631,9 +649,10 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Algorithmic Stock Trader III",
|
||||
numTries: 10,
|
||||
solver: (data: number[], ans: string): boolean => {
|
||||
let hold1: number = Number.MIN_SAFE_INTEGER;
|
||||
let hold2: number = Number.MIN_SAFE_INTEGER;
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as number[];
|
||||
let hold1 = Number.MIN_SAFE_INTEGER;
|
||||
let hold2 = Number.MIN_SAFE_INTEGER;
|
||||
let release1 = 0;
|
||||
let release2 = 0;
|
||||
for (const price of data) {
|
||||
@ -647,9 +666,10 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (data: any[]): string => {
|
||||
const k: number = data[0];
|
||||
const prices: number[] = data[1];
|
||||
desc: (_data: unknown): string => {
|
||||
const data = _data as [number, number[]];
|
||||
const k = data[0];
|
||||
const prices = data[1];
|
||||
return [
|
||||
"You are given the following array with two elements:\n\n",
|
||||
`[${k}, [${prices}]]\n\n`,
|
||||
@ -665,9 +685,9 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
].join(" ");
|
||||
},
|
||||
difficulty: 8,
|
||||
gen: (): any[] => {
|
||||
const k: number = getRandomInt(2, 10);
|
||||
const len: number = getRandomInt(3, 50);
|
||||
gen: (): [number, number[]] => {
|
||||
const k = getRandomInt(2, 10);
|
||||
const len = getRandomInt(3, 50);
|
||||
const prices: number[] = [];
|
||||
prices.length = len;
|
||||
for (let i = 0; i < len; ++i) {
|
||||
@ -678,7 +698,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Algorithmic Stock Trader IV",
|
||||
numTries: 10,
|
||||
solver: (data: any[], ans: string): boolean => {
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as [number, number[]];
|
||||
const k: number = data[0];
|
||||
const prices: number[] = data[1];
|
||||
|
||||
@ -717,7 +738,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (data: number[][]): string => {
|
||||
desc: (_data: unknown): string => {
|
||||
const data = _data as number[][];
|
||||
function createTriangleRecurse(data: number[][], level = 0): string {
|
||||
const numLevels: number = data.length;
|
||||
if (level >= numLevels) {
|
||||
@ -771,7 +793,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Minimum Path Sum in a Triangle",
|
||||
numTries: 10,
|
||||
solver: (data: number[][], ans: string): boolean => {
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as number[][];
|
||||
const n: number = data.length;
|
||||
const dp: number[] = data[n - 1].slice();
|
||||
for (let i = n - 2; i > -1; --i) {
|
||||
@ -784,7 +807,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (data: number[]): string => {
|
||||
desc: (_data: unknown): string => {
|
||||
const data = _data as number[];
|
||||
const numRows = data[0];
|
||||
const numColumns = data[1];
|
||||
return [
|
||||
@ -808,7 +832,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Unique Paths in a Grid I",
|
||||
numTries: 10,
|
||||
solver: (data: number[], ans: string): boolean => {
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as number[];
|
||||
const n: number = data[0]; // Number of rows
|
||||
const m: number = data[1]; // Number of columns
|
||||
const currentRow: number[] = [];
|
||||
@ -827,7 +852,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (data: number[][]): string => {
|
||||
desc: (_data: unknown): string => {
|
||||
const data = _data as number[][];
|
||||
let gridString = "";
|
||||
for (const line of data) {
|
||||
gridString += `${line.toString()},\n`;
|
||||
@ -876,7 +902,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Unique Paths in a Grid II",
|
||||
numTries: 10,
|
||||
solver: (data: number[][], ans: string): boolean => {
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as number[][];
|
||||
const obstacleGrid: number[][] = [];
|
||||
obstacleGrid.length = data.length;
|
||||
for (let i = 0; i < obstacleGrid.length; ++i) {
|
||||
@ -900,7 +927,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
{
|
||||
name: "Shortest Path in a Grid",
|
||||
desc: (data: number[][]): string => {
|
||||
desc: (_data: unknown): string => {
|
||||
const data = _data as number[][];
|
||||
return [
|
||||
"You are located in the top-left corner of the following grid:\n\n",
|
||||
` [${data.map((line) => "[" + line + "]").join(",\n ")}]\n\n`,
|
||||
@ -950,7 +978,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
|
||||
return grid;
|
||||
},
|
||||
solver: (data: number[][], ans: string): boolean => {
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as number[][];
|
||||
const width = data[0].length;
|
||||
const height = data.length;
|
||||
const dstY = height - 1;
|
||||
@ -1033,7 +1062,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (data: string): string => {
|
||||
desc: (data: unknown): string => {
|
||||
return [
|
||||
"Given the following string:\n\n",
|
||||
`${data}\n\n`,
|
||||
@ -1073,7 +1102,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Sanitize Parentheses in Expression",
|
||||
numTries: 10,
|
||||
solver: (data: string, ans: string): boolean => {
|
||||
solver: (data: unknown, ans: string): boolean => {
|
||||
if (typeof data !== "string") throw new Error("solver expected string");
|
||||
let left = 0;
|
||||
let right = 0;
|
||||
const res: string[] = [];
|
||||
@ -1141,7 +1171,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (data: any[]): string => {
|
||||
desc: (_data: unknown): string => {
|
||||
const data = _data as [string, number];
|
||||
const digits: string = data[0];
|
||||
const target: number = data[1];
|
||||
|
||||
@ -1166,7 +1197,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
].join(" ");
|
||||
},
|
||||
difficulty: 10,
|
||||
gen: (): any[] => {
|
||||
gen: (): [string, number] => {
|
||||
const numDigits = getRandomInt(4, 12);
|
||||
const digitsArray: string[] = [];
|
||||
digitsArray.length = numDigits;
|
||||
@ -1185,9 +1216,10 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
name: "Find All Valid Math Expressions",
|
||||
numTries: 10,
|
||||
solver: (data: any[], ans: string): boolean => {
|
||||
const num: string = data[0];
|
||||
const target: number = data[1];
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as [string, number];
|
||||
const num = data[0];
|
||||
const target = data[1];
|
||||
|
||||
function helper(
|
||||
res: string[],
|
||||
@ -1253,7 +1285,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
name: "HammingCodes: Integer to Encoded Binary",
|
||||
numTries: 10,
|
||||
difficulty: 5,
|
||||
desc: (n: number): string => {
|
||||
desc: (n: unknown): string => {
|
||||
return [
|
||||
"You are given the following decimal Value: \n",
|
||||
`${n} \n`,
|
||||
@ -1272,7 +1304,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
gen: (): number => {
|
||||
return getRandomInt(Math.pow(2, 4), Math.pow(2, getRandomInt(1, 57)));
|
||||
},
|
||||
solver: (data: number, ans: string): boolean => {
|
||||
solver: (data: unknown, ans: string): boolean => {
|
||||
if (typeof data !== "number") throw new Error("solver expected number");
|
||||
return ans === HammingEncode(data);
|
||||
},
|
||||
},
|
||||
@ -1280,7 +1313,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
name: "HammingCodes: Encoded Binary to Integer",
|
||||
difficulty: 8,
|
||||
numTries: 10,
|
||||
desc: (n: string): string => {
|
||||
desc: (n: unknown): string => {
|
||||
return [
|
||||
"You are given the following encoded binary string: \n",
|
||||
`'${n}' \n`,
|
||||
@ -1304,7 +1337,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
}
|
||||
return _buildArray.join("");
|
||||
},
|
||||
solver: (data: string, ans: string): boolean => {
|
||||
solver: (data: unknown, ans: string): boolean => {
|
||||
if (typeof data !== "string") throw new Error("solver expected string");
|
||||
return parseInt(ans, 10) === HammingDecode(data);
|
||||
},
|
||||
},
|
||||
@ -1312,7 +1346,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
name: "Proper 2-Coloring of a Graph",
|
||||
difficulty: 7,
|
||||
numTries: 5,
|
||||
desc: (data: [number, [number, number][]]): string => {
|
||||
desc: (_data: unknown): string => {
|
||||
const data = _data as [number, [number, number][]];
|
||||
return [
|
||||
`You are given the following data, representing a graph:\n`,
|
||||
`${JSON.stringify(data)}\n`,
|
||||
@ -1359,7 +1394,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
}
|
||||
|
||||
//Randomize array in-place using Durstenfeld shuffle algorithm.
|
||||
function shuffle(array: any[]): void {
|
||||
function shuffle<T>(array: T[]): void {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
@ -1382,7 +1417,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
|
||||
return [n + m, edges];
|
||||
},
|
||||
solver: (data: [number, [number, number][]], ans: string): boolean => {
|
||||
solver: (_data: unknown, ans: string): boolean => {
|
||||
const data = _data as [number, [number, number][]];
|
||||
//Case where the player believes there is no solution.
|
||||
//Attempt to construct one to check if this is correct.
|
||||
if (ans == "[]") {
|
||||
@ -1463,7 +1499,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
name: "Compression I: RLE Compression",
|
||||
difficulty: 2,
|
||||
numTries: 10,
|
||||
desc: (plaintext: string): string => {
|
||||
desc: (plaintext: unknown): string => {
|
||||
return [
|
||||
"Run-length encoding (RLE) is a data compression technique which encodes data as a series of runs of",
|
||||
"a repeated single character. Runs are encoded as a length, followed by the character itself. Lengths",
|
||||
@ -1503,7 +1539,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
|
||||
return plain.substring(0, length);
|
||||
},
|
||||
solver: (plain: string, ans: string): boolean => {
|
||||
solver: (plain: unknown, ans: string): boolean => {
|
||||
if (typeof plain !== "string") throw new Error("solver expected string");
|
||||
if (ans.length % 2 !== 0) {
|
||||
return false;
|
||||
}
|
||||
@ -1542,7 +1579,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
name: "Compression II: LZ Decompression",
|
||||
difficulty: 4,
|
||||
numTries: 10,
|
||||
desc: (compressed: string): string => {
|
||||
desc: (compressed: unknown): string => {
|
||||
return [
|
||||
"Lempel-Ziv (LZ) compression is a data compression technique which encodes data using references to",
|
||||
"earlier parts of the data. In this variant of LZ, data is encoded in two types of chunk. Each chunk",
|
||||
@ -1569,7 +1606,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
gen: (): string => {
|
||||
return comprLZEncode(comprLZGenerate());
|
||||
},
|
||||
solver: (compr: string, ans: string): boolean => {
|
||||
solver: (compr: unknown, ans: string): boolean => {
|
||||
if (typeof compr !== "string") throw new Error("solver expected string");
|
||||
return ans === comprLZDecode(compr);
|
||||
},
|
||||
},
|
||||
@ -1577,7 +1615,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
name: "Compression III: LZ Compression",
|
||||
difficulty: 10,
|
||||
numTries: 10,
|
||||
desc: (plaintext: string): string => {
|
||||
desc: (plaintext: unknown): string => {
|
||||
return [
|
||||
"Lempel-Ziv (LZ) compression is a data compression technique which encodes data using references to",
|
||||
"earlier parts of the data. In this variant of LZ, data is encoded in two types of chunk. Each chunk",
|
||||
@ -1607,7 +1645,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
gen: (): string => {
|
||||
return comprLZGenerate();
|
||||
},
|
||||
solver: (plain: string, ans: string): boolean => {
|
||||
solver: (plain: unknown, ans: string): boolean => {
|
||||
if (typeof plain !== "string") throw new Error("solver expected string");
|
||||
return comprLZDecode(ans) === plain && ans.length <= comprLZEncode(plain).length;
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user