A lizard is present on one corner of cube, It wants to reach diagonally opposite corner of cube. You have to calculate minimum distance lizard has to cover to reach its destination.

Note : Lizard can’t fly, it moves along the wall.

You are given **a** representing side of cube.you have to calculate minimum distance lizard has to travel.

**Examples:**

Input : 5 Output :11.1803 Input :2 Output :4.47214

As we have to calculate the minimum distance from one corner to another diagonally opposite corner. if lizard able to fly then the shortest distance will be length of diagonal. But it can’t.

So, to calculate minimum distance, just open the cube, as describe in diagram.

Let us suppose, lizard is initially at point **E**.and it has to reach at point **A**(as A is diagonally opposite to E).Now we have to find **AE**.

Just use Pythagoras theorem, As

AC=a

CE=CD+DE=2a

## C++

`// CPP program to find minimum distance to be travlled ` `// by lizard. ` `#include <bits/stdc++.h> ` `#define ll long long int ` `using` `namespace` `std; ` `int` `main() ` `{ ` ` ` `// side of cube ` ` ` `ll a = 5; ` ` ` ` ` `// understand from diagram ` ` ` `ll AC = a; ` ` ` ` ` `// understand from diagram ` ` ` `ll CE = 2 * a; ` ` ` ` ` `// minimum distance ` ` ` `double` `shortestDistace = ` `sqrt` `(AC * AC + CE * CE); ` ` ` ` ` `cout << shortestDistace << endl; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`//Java program to find minimum ` `//distance to be travelled by lizard ` `import` `java.util.*; ` ` ` `class` `solution ` `{ ` `public` `static` `void` `main(String arr[]) ` `{ ` ` ` `// side of the cube ` ` ` `int` `a = ` `5` `; ` ` ` ` ` `// understand from diagram ` ` ` `int` `AC = a; ` ` ` ` ` `// understand from diagram ` ` ` `int` `CE = ` `2` `* a; ` ` ` ` ` `// minimum distance ` ` ` `double` `shortestDistace = Math.sqrt(AC * AC + CE * CE); ` ` ` ` ` `System.out.println(shortestDistace); ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find minimum ` `# distance to be travelled by lizard ` ` ` `import` `math ` ` ` `#side of cube ` `if` `__name__` `=` `=` `'__main__'` `: ` ` ` `a ` `=` `5` ` ` `#understand from diagram ` ` ` `AC ` `=` `a ` ` ` `#understand from diagram ` ` ` `CE ` `=` `2` `*` `a ` ` ` `#minimum distance ` ` ` `shortestDistace ` `=` `math.sqrt(AC ` `*` `AC ` `+` `CE ` `*` `CE) ` ` ` ` ` `print` `(shortestDistace) ` ` ` `#this code is Contributed by Shashank_Sharma ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find minimum ` `// distance to be travelled by lizard ` `using` `System; ` ` ` `class` `GFG ` `{ ` `public` `static` `void` `Main() ` `{ ` ` ` `// side of the cube ` ` ` `int` `a = 5; ` ` ` ` ` `// understand from diagram ` ` ` `int` `AC = a; ` ` ` ` ` `// understand from diagram ` ` ` `int` `CE = 2 * a; ` ` ` ` ` `// minimum distance ` ` ` `double` `shortestDistace = Math.Sqrt(AC * AC + CE * CE); ` ` ` ` ` `Console.Write(shortestDistace); ` `} ` `} ` ` ` `// This code is contributed by ita_c ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find minimum distance ` `// to be travlled by lizard. ` ` ` `// side of cube ` `$a` `= 5; ` ` ` `// understand from diagram ` `$AC` `= ` `$a` `; ` ` ` `// understand from diagram ` `$CE` `= 2 * ` `$a` `; ` ` ` `// minimum distance ` `$shortestDistance` `= (double)(sqrt(` `$AC` `* ` `$AC` `+ ` ` ` `$CE` `* ` `$CE` `)); ` ` ` `echo` `$shortestDistance` `. ` `"\n"` `; ` ` ` `// This code is contributed ` `// by Akanksha Rai ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

11.1803

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Puzzle | ( Distance, Time and Work)
- Puzzle | Find The Probability of Distance in a Square
- Puzzle 3 | (Calculate total distance travelled by bee)
- Puzzle 31 | (Minimum cut Puzzle)
- Find maximum and minimum distance between magnets
- Minimum distance to travel to cover all intervals
- Minimum distance to the corner of a grid from source
- Puzzle | Minimum planes to go around the world
- Puzzle | Minimum time required to make N Pancakes
- Puzzle | Minimum number steps to weigh 1 kg rice with 1gm weight
- Puzzle | Minimum colors required to color a chessboard with no two given pair threatening each other
- Minimum number of moves required to solve a Jigsaw Assembly Puzzle
- Count paths with distance equal to Manhattan distance
- Puzzle 51| Cheryl’s Birthday Puzzle and Solution
- Puzzle 15 | (Camel and Banana Puzzle)
- Puzzle 34 | (Prisoner and Policeman Puzzle)
- Puzzle 85 | Chain Link Puzzle
- Puzzle | 3 Priests and 3 devils Puzzle
- Puzzle 81 | 100 people in a circle with gun puzzle
- Distance of chord from center when distance between center and another equal length chord is given

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.