lundi 23 mai 2016

finding if a triangle is ISOSCELES in bash

How can this code could be summarized for when the triangle is ISOSCELES?

  1 #!/bin/bash
  2 
  3 read x y z
  4 
  5 if [[ x -eq z ]] && [[ x -eq y ]] && [[ y -eq z ]]; then
  6   echo EQUILATERAL
  7 elif [[ x -eq z ]] && [[ x -eq y ]]
  8 then
  9   echo ISOSCELES
 10 elif [[ y -eq z ]] && [[ y -eq x ]]
 11 then
 12   echo ISOSCELES
 13 elif [[ z -eq x ]] && [[ z -eq y ]]
 14 then
 15   echo ISOSCELES
 16 else
 17   echo SCALENE
 18 fi
~  

currently actually the code doesn't work:

$ ./triangle.sh 
4 4 6
SCALENE
$ ./triangle.sh 
4 5 5
SCALENE
$ ./triangle.sh 
4 5 3
SCALENE
$ ./triangle.sh 
4 4 4 
EQUILATERAL
$ ./triangle.sh 
2 9 1
SCALENE
$ ./triangle.sh 
2 3 2
SCALENE

Aucun commentaire:

Enregistrer un commentaire