Colorful Number
Function Name: isColorful
Description
A 'colorful' number is one where the product of every digit of a contiguous subset of its digits is different. For instance, the number 263 is a colorful number because (2, 6, 3, 2*6, 6*3, 2*6*3) are all different.
Write a function `isColorful` that determines if a given number is colorful or not.
The function should take an integer as a parameter and return a boolean indicating whether the number is colorful.
Requirements
- The function must handle numbers of at least 3 digits and up to 6 digits in size.
- If the number is less than 3 digits, the function should return False.
- The function should be able to check the product of digits for any contiguous subset of its digits.
- No external libraries should be used; only standard language features are allowed.
- Consider optimizing the function for time and space complexity.
Examples
Given the number 263, the function `isColorful(263)` should return `True`.Given the number 236, since (2*3*6) and (2*3) have the same product, the function `isColorful(236)` should return `False`.
Links
Pathfinding on a Grid
Fri Sep 27 2024
Write a function that takes a grid of walkable and non-walkable cells, as well as a start and an end position. The grid will be represented as a 2D array where 0s are walkable spaces and 1s are barriers. The start and end positions will be given as tuples (row, column). Your function should compute the shortest path from start to end and return the path as a list of tuples, detailing each step taken. If there is no path, return an empty list.
Tic Tac Toe Validator
Sun Sep 29 2024
Write a function to validate a Tic Tac Toe game state. The game is played on a 3x3 grid. The function should determine if the given game state is a possible state that could be reached within the rules of Tic Tac Toe. The board is presented as a single array with 9 elements, representing rows from top to bottom, where 'X', 'O', or an empty string '' are the possible values for each cell.The function should return true if the board configuration is valid, and false otherwise. A valid Tic Tac Toe board has either 'X' or 'O' as the winner, or the game is ongoing or is a draw, but it cannot contain both 'X' and 'O' as winners. Additionally, the number of 'X's must be equal to or one more than the number of 'O's.