mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 13:43:49 +01:00
Add new coding contract descriptions to docs
Add descriptions for the following contracts: * HammingCodes: Integer to Encoded Binary * HammingCodes: Encoded Binary to Integer * Proper 2-Coloring of a Graph
This commit is contained in:
parent
5490d8c837
commit
86034bddce
@ -84,24 +84,24 @@ The following is a list of all of the problem types that a Coding Contract can c
|
|||||||
The list contains the name of (i.e. the value returned by
|
The list contains the name of (i.e. the value returned by
|
||||||
:js:func:`getContractType`) and a brief summary of the problem it poses.
|
:js:func:`getContractType`) and a brief summary of the problem it poses.
|
||||||
|
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Name | Problem Summary |
|
| Name | Problem Summary |
|
||||||
+====================================+==========================================================================================+
|
+=========================================+==========================================================================================+
|
||||||
| Find Largest Prime Factor | | Given a number, find its largest prime factor. A prime factor |
|
| Find Largest Prime Factor | | Given a number, find its largest prime factor. A prime factor |
|
||||||
| | | is a factor that is a prime number. |
|
| | | is a factor that is a prime number. |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Subarray with Maximum Sum | | Given an array of integers, find the contiguous subarray (containing |
|
| 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. |
|
| | | at least one number) which has the largest sum and return that sum. |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Total Ways to Sum | | Given a number, how many different distinct 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? |
|
| | | 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. |
|
| 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 the set of available integers. |
|
| | | 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 |
|
| | | How many different distinct ways can that number n be written as |
|
||||||
| | | a sum of integers contained in the given set? |
|
| | | a sum of integers contained in the given set? |
|
||||||
| | | You may use each integer in the set zero or more times. |
|
| | | 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 |
|
| Spiralize Matrix | | Given an array of array of numbers representing a 2D matrix, return the |
|
||||||
| | | elements of that matrix in clockwise spiral order. |
|
| | | elements of that matrix in clockwise spiral order. |
|
||||||
| | | |
|
| | | |
|
||||||
@ -112,7 +112,7 @@ The list contains the name of (i.e. the value returned by
|
|||||||
| | | [9, 10, 11, 12] |
|
| | | [9, 10, 11, 12] |
|
||||||
| | | |
|
| | | |
|
||||||
| | | is [1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7] |
|
| | | is [1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7] |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Array Jumping Game | | You are given an array of integers where each element represents the |
|
| Array Jumping Game | | You are given an array of integers where each element represents the |
|
||||||
| | | maximum possible jump distance from that position. For example, if you |
|
| | | maximum possible jump distance from that position. For example, if you |
|
||||||
| | | are at position i and your maximum jump length is n, then you can jump |
|
| | | are at position i and your maximum jump length is n, then you can jump |
|
||||||
@ -120,7 +120,7 @@ The list contains the name of (i.e. the value returned by
|
|||||||
| | | |
|
| | | |
|
||||||
| | | Assuming you are initially positioned at the start of the array, determine |
|
| | | Assuming you are initially positioned at the start of the array, determine |
|
||||||
| | | whether you are able to reach the last index of the array. |
|
| | | whether you are able to reach the last index of the array. |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Array Jumping Game II | | You are given an array of integers where each element represents the |
|
| Array Jumping Game II | | You are given an array of integers where each element represents the |
|
||||||
| | | maximum possible jump distance from that position. For example, if you |
|
| | | maximum possible jump distance from that position. For example, if you |
|
||||||
| | | are at position i and your maximum jump length is n, then you can jump |
|
| | | are at position i and your maximum jump length is n, then you can jump |
|
||||||
@ -130,7 +130,7 @@ The list contains the name of (i.e. the value returned by
|
|||||||
| | | the minimum number of jumps to reach the end of the array. |
|
| | | the minimum number of jumps to reach the end of the array. |
|
||||||
| | | |
|
| | | |
|
||||||
| | | If it's impossible to reach the end, then the answer should be 0. |
|
| | | If it's impossible to reach the end, then the answer should be 0. |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Merge Overlapping Intervals | | Given an array of intervals, merge all overlapping intervals. An interval |
|
| Merge Overlapping Intervals | | Given an array of intervals, merge all overlapping intervals. An interval |
|
||||||
| | | is an array with two numbers, where the first number is always less than |
|
| | | is an array with two numbers, where the first number is always less than |
|
||||||
| | | the second (e.g. [1, 5]). |
|
| | | the second (e.g. [1, 5]). |
|
||||||
@ -140,7 +140,7 @@ The list contains the name of (i.e. the value returned by
|
|||||||
| | | Example: |
|
| | | Example: |
|
||||||
| | | [[1, 3], [8, 10], [2, 6], [10, 16]] |
|
| | | [[1, 3], [8, 10], [2, 6], [10, 16]] |
|
||||||
| | | merges into [[1, 6], [8, 16]] |
|
| | | merges into [[1, 6], [8, 16]] |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Generate IP Addresses | | Given a string containing only digits, return an array with all possible |
|
| Generate IP Addresses | | Given a string containing only digits, return an array with all possible |
|
||||||
| | | valid IP address combinations that can be created from the string. |
|
| | | valid IP address combinations that can be created from the string. |
|
||||||
| | | |
|
| | | |
|
||||||
@ -150,7 +150,7 @@ The list contains the name of (i.e. the value returned by
|
|||||||
| | | Examples: |
|
| | | Examples: |
|
||||||
| | | 25525511135 -> [255.255.11.135, 255.255.111.35] |
|
| | | 25525511135 -> [255.255.11.135, 255.255.111.35] |
|
||||||
| | | 1938718066 -> [193.87.180.66] |
|
| | | 1938718066 -> [193.87.180.66] |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Algorithmic Stock Trader I | | You are given an array of numbers representing stock prices, where the |
|
| Algorithmic Stock Trader I | | You are given an array of numbers representing stock prices, where the |
|
||||||
| | | i-th element represents the stock price on day i. |
|
| | | i-th element represents the stock price on day i. |
|
||||||
| | | |
|
| | | |
|
||||||
@ -158,7 +158,7 @@ The list contains the name of (i.e. the value returned by
|
|||||||
| | | transaction (i.e. you can buy an sell the stock once). If no profit |
|
| | | transaction (i.e. you can buy an sell the stock once). If no profit |
|
||||||
| | | can be made, then the answer should be 0. Note that you must buy the stock |
|
| | | can be made, then the answer should be 0. Note that you must buy the stock |
|
||||||
| | | before you can sell it. |
|
| | | before you can sell it. |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Algorithmic Stock Trader II | | You are given an array of numbers representing stock prices, where the |
|
| Algorithmic Stock Trader II | | You are given an array of numbers representing stock prices, where the |
|
||||||
| | | i-th element represents the stock price on day i. |
|
| | | i-th element represents the stock price on day i. |
|
||||||
| | | |
|
| | | |
|
||||||
@ -167,7 +167,7 @@ The list contains the name of (i.e. the value returned by
|
|||||||
| | | share of the stock. Note that you cannot engage in multiple transactions at |
|
| | | share of the stock. Note that you cannot engage in multiple transactions at |
|
||||||
| | | once. In other words, you must sell the stock before you buy it again. If no |
|
| | | once. In other words, you must sell the stock before you buy it again. If no |
|
||||||
| | | profit can be made, then the answer should be 0. |
|
| | | profit can be made, then the answer should be 0. |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Algorithmic Stock Trader III | | You are given an array of numbers representing stock prices, where the |
|
| Algorithmic Stock Trader III | | You are given an array of numbers representing stock prices, where the |
|
||||||
| | | i-th element represents the stock price on day i. |
|
| | | i-th element represents the stock price on day i. |
|
||||||
| | | |
|
| | | |
|
||||||
@ -176,7 +176,7 @@ The list contains the name of (i.e. the value returned by
|
|||||||
| | | of the stock. Note that you cannot engage in multiple transactions at once. |
|
| | | of the stock. Note that you cannot engage in multiple transactions at once. |
|
||||||
| | | In other words, you must sell the stock before you buy it again. If no profit |
|
| | | In other words, you must sell the stock before you buy it again. If no profit |
|
||||||
| | | can be made, then the answer should be 0. |
|
| | | can be made, then the answer should be 0. |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Algorithmic Stock Trader IV | | You are given an array with two elements. The first element is an integer k. |
|
| Algorithmic Stock Trader IV | | You are given an array with two elements. The first element is an integer k. |
|
||||||
| | | The second element is an array of numbers representing stock prices, where the |
|
| | | The second element is an array of numbers representing stock prices, where the |
|
||||||
| | | i-th element represents the stock price on day i. |
|
| | | i-th element represents the stock price on day i. |
|
||||||
@ -186,24 +186,24 @@ The list contains the name of (i.e. the value returned by
|
|||||||
| | | Note that you cannot engage in multiple transactions at once. In other words, |
|
| | | Note that you cannot engage in multiple transactions at once. In other words, |
|
||||||
| | | you must sell the stock before you can buy it. If no profit can be made, then |
|
| | | you must sell the stock before you can buy it. If no profit can be made, then |
|
||||||
| | | the answer should be 0. |
|
| | | the answer should be 0. |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Minimum Path Sum in a Triangle | | You are given a 2D array of numbers (array of array of numbers) that represents a |
|
| Minimum Path Sum in a Triangle | | You are given a 2D array of numbers (array of array of numbers) that represents a |
|
||||||
| | | triangle (the first array has one element, and each array has one more element than |
|
| | | triangle (the first array has one element, and each array has one more element than |
|
||||||
| | | the one before it, forming a triangle). Find the minimum path sum from the top to the |
|
| | | the one before it, forming a triangle). Find the minimum path sum from the top to the |
|
||||||
| | | bottom of the triangle. In each step of the path, you may only move to adjacent |
|
| | | bottom of the triangle. In each step of the path, you may only move to adjacent |
|
||||||
| | | numbers in the row below. |
|
| | | numbers in the row below. |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Unique Paths in a Grid I | | You are given an array with two numbers: [m, n]. These numbers represent a |
|
| Unique Paths in a Grid I | | You are given an array with two numbers: [m, n]. These numbers represent a |
|
||||||
| | | m x n grid. Assume you are initially positioned in the top-left corner of that |
|
| | | m x n grid. Assume you are initially positioned in the top-left corner of that |
|
||||||
| | | grid and that you are trying to reach the bottom-right corner. On each step, |
|
| | | grid and that you are trying to reach the bottom-right corner. On each step, |
|
||||||
| | | you may only move down or to the right. |
|
| | | you may only move down or to the right. |
|
||||||
| | | |
|
| | | |
|
||||||
| | |
|
| | | |
|
||||||
| | | Determine how many unique paths there are from start to finish. |
|
| | | Determine how many unique paths there are from start to finish. |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Unique Paths in a Grid II | | You are given a 2D array of numbers (array of array of numbers) representing |
|
| Unique Paths in a Grid II | | You are given a 2D array of numbers (array of array of numbers) representing |
|
||||||
| | | a grid. The 2D array contains 1's and 0's, where 1 represents an obstacle and |
|
| | | a grid. The 2D array contains 1's and 0's, where 1 represents an obstacle and |
|
||||||
| | |
|
| | | |
|
||||||
| | | 0 represents a free space. |
|
| | | 0 represents a free space. |
|
||||||
| | | |
|
| | | |
|
||||||
| | | Assume you are initially positioned in top-left corner of that grid and that you |
|
| | | Assume you are initially positioned in top-left corner of that grid and that you |
|
||||||
@ -211,7 +211,7 @@ The list contains the name of (i.e. the value returned by
|
|||||||
| | | or to the right. Furthermore, you cannot move onto spaces which have obstacles. |
|
| | | or to the right. Furthermore, you cannot move onto spaces which have obstacles. |
|
||||||
| | | |
|
| | | |
|
||||||
| | | Determine how many unique paths there are from start to finish. |
|
| | | Determine how many unique paths there are from start to finish. |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Shortest Path in a Grid | | You are given a 2D array of numbers (array of array of numbers) representing |
|
| Shortest Path in a Grid | | You are given a 2D array of numbers (array of array of numbers) representing |
|
||||||
| | | a grid. The 2D array contains 1's and 0's, where 1 represents an obstacle and |
|
| | | a grid. The 2D array contains 1's and 0's, where 1 represents an obstacle and |
|
||||||
| | | 0 represents a free space. |
|
| | | 0 represents a free space. |
|
||||||
@ -228,7 +228,7 @@ The list contains the name of (i.e. the value returned by
|
|||||||
| | | [[0,1], |
|
| | | [[0,1], |
|
||||||
| | | [1,0]] -> "" |
|
| | | [1,0]] -> "" |
|
||||||
| | | |
|
| | | |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Sanitize Parentheses in Expression | | Given a string with parentheses and letters, remove the minimum number of invalid |
|
| Sanitize Parentheses in Expression | | Given a string with parentheses and letters, remove the minimum number of invalid |
|
||||||
| | | parentheses in order to validate the string. If there are multiple minimal ways |
|
| | | parentheses in order to validate the string. If there are multiple minimal ways |
|
||||||
| | | to validate the string, provide all of the possible results. |
|
| | | to validate the string, provide all of the possible results. |
|
||||||
@ -240,7 +240,7 @@ The list contains the name of (i.e. the value returned by
|
|||||||
| | | ()())() -> [()()(), (())()] |
|
| | | ()())() -> [()()(), (())()] |
|
||||||
| | | (a)())() -> [(a)()(), (a())()] |
|
| | | (a)())() -> [(a)()(), (a())()] |
|
||||||
| | | )( -> [""] |
|
| | | )( -> [""] |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
| Find All Valid Math Expressions | | You are given a string which contains only digits between 0 and 9 as well as a target |
|
| Find All Valid Math Expressions | | You are given a string which contains only digits between 0 and 9 as well as a target |
|
||||||
| | | number. Return all possible ways you can add the +, -, and * operators to the string |
|
| | | number. Return all possible ways you can add the +, -, and * operators to the string |
|
||||||
| | | of digits such that it evaluates to the target number. |
|
| | | of digits such that it evaluates to the target number. |
|
||||||
@ -256,4 +256,53 @@ The list contains the name of (i.e. the value returned by
|
|||||||
| | | |
|
| | | |
|
||||||
| | | Input: digits = "105", target = 5 |
|
| | | Input: digits = "105", target = 5 |
|
||||||
| | | Output: [1*0+5, 10-5] |
|
| | | Output: [1*0+5, 10-5] |
|
||||||
+------------------------------------+------------------------------------------------------------------------------------------+
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
|
| HammingCodes: Integer to Encoded Binary | | You are given a decimal value. |
|
||||||
|
| | | Convert it into a binary string and encode it as a 'Hamming-Code'. eg: |
|
||||||
|
| | | Value 8 will result into binary '1000', which will be encoded |
|
||||||
|
| | | with the pattern 'pppdpddd', where p is a paritybit and d a databit, |
|
||||||
|
| | | or '10101' (Value 21) will result into (pppdpdddpd) '1001101011'. |
|
||||||
|
| | | NOTE: You need an parity Bit on Index 0 as an 'overall'-paritybit. |
|
||||||
|
| | | NOTE 2: You should watch the HammingCode-video from 3Blue1Brown, which |
|
||||||
|
| | | explains the 'rule' of encoding, |
|
||||||
|
| | | including the first Index parity-bit mentioned on the first note. |
|
||||||
|
| | | Now the only one rule for this encoding: |
|
||||||
|
| | | It's not allowed to add additional leading '0's to the binary value |
|
||||||
|
| | | That means, the binary value has to be encoded as it is |
|
||||||
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
|
| HammingCodes: Encoded Binary to Integer | | You are given an encoded binary string. |
|
||||||
|
| | | Treat it as a Hammingcode with 1 'possible' error on an random Index. |
|
||||||
|
| | | 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 2: Index 0 is an 'overall' parity bit. Watch the Hammingcode-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", |
|
||||||
|
| | | Extranote for automation: return the decimal value as a string", |
|
||||||
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
|
| Proper 2-Coloring of a Graph | | You are given data, representing a graph. Note that "graph", as used here, refers to |
|
||||||
|
| | | the field of graph theory, and has no relation to statistics or plotting. |
|
||||||
|
| | | |
|
||||||
|
| | | The first element of the data represents the number of vertices in the graph. Each |
|
||||||
|
| | | vertex is a unique number between 0 and ${data[0] - 1}. The next element of the data |
|
||||||
|
| | | represents the edges of the graph. |
|
||||||
|
| | | |
|
||||||
|
| | | Two vertices u,v in a graph are said to be adjacent if there exists an edge [u,v]. |
|
||||||
|
| | | Note that an edge [u,v] is the same as an edge [v,u], as order does not matter. |
|
||||||
|
| | | |
|
||||||
|
| | | You must construct a 2-coloring of the graph, meaning that you have to assign each |
|
||||||
|
| | | vertex in the graph a "color", either 0 or 1, such that no two adjacent vertices have |
|
||||||
|
| | | the same color. Submit your answer in the form of an array, where element i |
|
||||||
|
| | | represents the color of vertex i. If it is impossible to construct a 2-coloring of |
|
||||||
|
| | | the given graph, instead submit an empty array. |
|
||||||
|
| | | |
|
||||||
|
| | | Examples: |
|
||||||
|
| | | |
|
||||||
|
| | | Input: [4, [[0, 2], [0, 3], [1, 2], [1, 3]]] |
|
||||||
|
| | | Output: [0, 0, 1, 1] |
|
||||||
|
| | | |
|
||||||
|
| | | Input: [3, [[0, 1], [0, 2], [1, 2]]] |
|
||||||
|
| | | Output: [] |
|
||||||
|
+-----------------------------------------+------------------------------------------------------------------------------------------+
|
||||||
|
Loading…
Reference in New Issue
Block a user