mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 01:33:54 +01:00
added coments, removed possible infinite loop, changed problem phrasing
This commit is contained in:
parent
27180ebccb
commit
cb756808a2
@ -93,14 +93,14 @@ The list contains the name of (i.e. the value returned by
|
||||
| Subarray with Maximum Sum | | Given an array of integers, find the contiguous subarray (containing |
|
||||
| | | at least one number) which has the largest sum and return that sum. |
|
||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
||||
| Total Ways to Sum | | Given a number, how many different ways can that number be written as |
|
||||
| Total Ways to Sum | | Given a number, how many different distinct ways can that number be written as |
|
||||
| | | a sum of at least two positive integers? |
|
||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
||||
| Total Ways to Sum II | | You are given an array with two elements. The first element is an integer n. |
|
||||
| | | The second element is an array of numbers representing set of available integers. |
|
||||
| | | How many different ways can that number n be written as |
|
||||
| | | a sum of integers containing in a given set? |
|
||||
| | | You can use same integer from a set infinitely many times. |
|
||||
| | | The second element is an array of numbers representing the set of available integers. |
|
||||
| | | How many different distinct ways can that number n be written as |
|
||||
| | | a sum of integers containing in the given set? |
|
||||
| | | You may use each integer in the set zero or more times. |
|
||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
||||
| Spiralize Matrix | | Given an array of array of numbers representing a 2D matrix, return the |
|
||||
| | | elements of that matrix in clockwise spiral order. |
|
||||
|
@ -124,7 +124,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
" 2 + 2\n",
|
||||
" 2 + 1 + 1\n",
|
||||
" 1 + 1 + 1 + 1\n\n",
|
||||
`How many different ways can the number ${n} be written as a sum of at least`,
|
||||
`How many different distinct ways can the number ${n} be written as a sum of at least`,
|
||||
"two positive integers?",
|
||||
].join(" ");
|
||||
},
|
||||
@ -148,39 +148,39 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: (data: any[]): string => {
|
||||
desc: (data: [number, number[]]): string => {
|
||||
const n: number = data[0];
|
||||
const s: number[] = data[1];
|
||||
return [
|
||||
`How many different ways can the number ${n} be written`,
|
||||
"as a sum of integers containing in set\n\n",
|
||||
`How many different distinct ways can the number ${n} be written`,
|
||||
"as a sum of integers containing in the set\n\n",
|
||||
`[${s}]?\n\n`,
|
||||
"You can use same integer from a set infinitely many times.",
|
||||
"You may use each integer in the set zero or more times.",
|
||||
].join(" ");
|
||||
},
|
||||
difficulty: 2,
|
||||
gen: (): any[] => {
|
||||
const n: number = getRandomInt(8, 200);
|
||||
gen: (): [number, number[]] => {
|
||||
const n: number = getRandomInt(12, 200);
|
||||
const maxLen: number = getRandomInt(8, 12);
|
||||
let s: number[] = [];
|
||||
while (s.length < 4) {
|
||||
s = [];
|
||||
for (let i = 1; i <= n; i++) {
|
||||
if (s.length == maxLen) {
|
||||
break;
|
||||
}
|
||||
if (Math.random() < 0.6) {
|
||||
s.push(i);
|
||||
}
|
||||
const s: number[] = [];
|
||||
// Bias towards small numbers is intentional to have much bigger answers in general
|
||||
// to force people better optimize their solutions
|
||||
for (let i = 1; i <= n; i++) {
|
||||
if (s.length == maxLen) {
|
||||
break;
|
||||
}
|
||||
if (Math.random() < 0.6 || n - i < maxLen - s.length) {
|
||||
s.push(i);
|
||||
}
|
||||
}
|
||||
return [n, s];
|
||||
},
|
||||
name: "Total Ways to Sum II",
|
||||
numTries: 10,
|
||||
solver: (data: any[], ans: string): boolean => {
|
||||
const n: number = data[0];
|
||||
const s: number[] = data[1];
|
||||
solver: (data: [number, number[]], ans: string): boolean => {
|
||||
// https://www.geeksforgeeks.org/coin-change-dp-7/?ref=lbp
|
||||
const n = data[0];
|
||||
const s = data[1];
|
||||
const ways: number[] = [1];
|
||||
ways.length = n + 1;
|
||||
ways.fill(0, 1);
|
||||
|
Loading…
Reference in New Issue
Block a user