This is a interesting math puzzle:
X, Y and Z is an integer between 0 to 9. so what are they? We can write a PowerShell script to search for every possible values from 1 to 9, for X, Y and Z respectively.
for ($X = 1; $X -le 9; $X += 1) {// X can't be zero for ($Y = 1; $Y -le 9; $Y += 1) { // Y can't be zero either. for ($Z = 0; $Z -le 9; $Z += 1) { $XY = $X * 10 + $Y; $YZZ = $Y * 100 + $Z * 10 + $Z if ($XY + $XY -eq $YZZ) { // XY + XY = YZZ Write-Host $XY + $XY = $YZZ } } } }
This outputs: X = 6, Y = 1, and Z = 2. You don’t need to write bruteforce algorithm to search for these 3 values because of a simple logics:
- X should be larger or equal than 5 otherwise the sum won’t be 3 digits.
- Y can only be 1 i.e. the maximum two digits 99 + 99 = 198.
- Y = 1 so Z = 2
- and X = 6
You may also like: 大白 + 大白 = 白胖胖
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading...
287 wordsloading...
Last Post: Software Engineer Interview Question - How to Improve Dynamic Programming Space Complexity?
Next Post: Chrome Extension to Switch between Simplified Chinese and Traditional Chinese Automatically