g | x | w | all
Bytes Lang Time Link
036Japt S180824T155219ZShaggy
035Thunno 2 j230614T163829ZThe Thon
nan230315T083831ZThe Thon
060ARBLE171022T224558ZATaco
108Go221013T034809Zbigyihsu
nanFig221013T033141ZnaffetS
030Vyxal221013T024230ZDialFros
072Rust210209T030856ZAiden4
093Whispers v2210208T030750ZRazetime
028Jelly210208T154322Zcaird co
110Javascript140208T085837ZIsmael M
076Python 2.7 76 Characters140205T181753ZAbhijit
070JavaScript210208T104737Zuser1006
051Pyth210208T040714Zhakr14
041Husk190326T103316ZUnrelate
076JavaScript Node.js180824T153846Zuser8232
051APL Dyalog180518T231443ZH.PWiz
024Stax180519T001902Zrecursiv
066Petit Computer BASIC171023T214842Z12Me21
032Jelly171023T193415Zsporkl
05305AB1E171023T200433Zsporkl
092Axiom171023T080327Zuser5898
080Jq 1.5171023T033541Zjq170727
057OML171023T010658ZConor O&
052TIBASIC140205T164805ZTimtech
076R171021T194825ZRudier
080Tcl171021T144858Zsergiol
066c64 basic v2170913T210203Zpeterh
069Perl 5170913T204644ZXcali
056J170913T192923ZJonah
087Fortran 2008151024T041833ZTime Lai
077Haskell140418T141528ZThom Wig
091Bash with bc140418T103526Zuser1640
079Python 2140216T103517Zuser344
nan140217T153146Zyedidyak
073Ruby 2.1+140216T234447ZO-I
nanRuby140205T191339Zepson121
093JavaScript140206T102534ZEliseo D
098Javascript 98 characters/bytes140206T201258ZClaudia
nan140205T182957ZMerin Na
090Fortran140207T152601ZKyle Kan
065Golfscript140205T190413ZJoachim
155Java140206T155049ZSumedh
112Java140206T160809ZJames We
078F#140206T152602ZRik
046Sclipting140206T150416ZTimwi
103newLISP140206T124445Zcormulli
055dc140206T132136ZTomas
078Groovy 78 Characters140206T130845ZMicha
083JavaScript140206T105356ZFez Vras
079EcmaScript 6140205T171213ZFlorent
223Java140206T100720ZBeyondPr
nan140206T081125Zbela
111PowerShell140206T081404ZIszi
078AWK — 84140205T181106Zuser1525
nan140206T075226ZBrandon
nan140206T065134ZMika
7799C140205T164204ZJosh
1001C140205T232834Zuser1220
054dc140205T232252Zdaniero
097Javascript140205T215952Zelixenid
054APL140205T184254Zmarinus
074Perl 6 68140205T170459Znull
090C++140205T164630Zuser1076
080Python 2.7140205T170054ZAndrea C
074MATLAB140205T165456Zmmumboss
109Javascript140205T165445Zmicha

Japt -S, 37 36 bytes

`Tåó©«eåì   cght×1Âec`qc pUx²¬x3

Try it

Thunno 2 j, 35 bytes

ÆH3ȯ‘The hypotenuse of ċṠ Ṗṇ ġḳ is 

Attempt This Online!

4 bytes (ÆH3ȯ) for the main bit, and 31 bytes for the compressed string.

Explanation

ÆH3ȯ‘...  # Implicit input
ÆH        # Compute hypotenuse
  3ȯ      # Round to 3 d.p.s
    ‘...  # Push compressed string
          # Join the stack
          # Implicit output

Thunno Kj, \$ 46 \log_{256}(96) \approx \$ 37.86 bytes

AO3Zu"The hypotenuse of this right triangle is

Attempt This Online!

Not having string compression really hurts in challenges like these.

Explanation

           # Implicit input
AO         # Push the hypotenuse of the inputs (yes, this is a built-in)
  3Zu      # Round to three decimal places
     "...  # Push the string
           # Flags join the stack by spaces
           # Implicit output

ARBLE, 73 60 bytes

"The hypotenuse of this right triangle is %.3f"%(a^2+b^2)^.5

Try it online!

Go, 108 bytes

import(."fmt";."math")
func f(a,b float64){Printf("The hypotenuse of the triangle is %.3f\n",Sqrt(a*a+b*b))}

Attempt This Online!

Fig, \$36\log_{256}(96)\approx\$ 29.632 bytes

+qDFQ$XS)s2lSXreS8x%twBEZ:x@KUX"mqS*

Try it online!

Vyxal, 32 30 bytes

∆/`λƛ h⁼Ǐ¢Ṗλ₇ of λ× ¬ẋ Ȧ⇩ is Π

Try it Online!

Rust, 72 bytes

|a,b|print!("The hypotenuse of this right triangle is {:.3}",a.hypot(b))

Try it online!

Woohoo, rust has built-ins for this. The hypot method calculates the hypotenuse between the numbers. Instead of the usual "{}" format substitution I used "{:.3}" which forces the number to display with three decimal places.

Whispers v2, 133, 93 bytes

> Input
> Input
> "The hypotenuse of this right triangle is %.3f"
>> 1⊿2
>> 3%4
>> Output 5

Try it online!

The major part of this program is calculating the decimal point's index and truncating to 3 digits. -40 bytes from Leo!

Jelly, 28 bytes

ÆḊær3“¡ÆC⁷⁺ɱSoṿȤç½?⁶Ẏtḍỵŀ»,K

Try it online!

How it works

ÆḊær3“¡ÆC⁷⁺ɱSoṿȤç½?⁶Ẏtḍỵŀ»,K - Main link. Takes a pair [a, b] as input
ÆḊ                           - Take the norm √(a²+b²)
  ær3                        - Round the 3 decimal places
     “¡ÆC⁷⁺ɱSoṿȤç½?⁶Ẏtḍỵŀ»   - "The hypotenuse of this right triangle is"
                          ,  - Pair the string with the norm
                           K - Insert a space between the two

Javascript, 110 bytes

function h(a,b){return a/1==a&&b/1==b?'The hypotenuse of this right triangle is '+(a*a+b*b||0).toFixed(3):!1;}

It's a monster!!!

But it can handle NaN and invalid numbers, like text, objects, 0/0 and other invalid numbers.

Python 2.7 - 76 Characters

print'The hypotenuse of this right triangle is %.3f'%abs(input()+1j*input())

Explanation

$$|a+bi| = \sqrt{a^2 + b^2} = c \\ \implies a^2 + b^2 = c^2$$

PJ on hypotenuse

Teacher: "Can you tell me, what is hypotenuse?"

LJ: "Hypotenuse, an easy question. If there's a high profile party last night, and you read it in the news paper, its called High Party News"

JavaScript, 70 bytes

(a,b)=>'The hypotenuse of the triangle is '+((a*a+b*b)**.5).toFixed(3)

The latter function rounds the number to 3 decimal places.

Pyth, 51 bytes

+." y¢ó³-.n?ãÜPŽýD'9¹i¾5ŠÁ«£¿9WhI‚".R@s^RJ2QJ3

Try it online!


The actual math only takes up 8 bytes.

Despite having built-in string compression capabilities, Pyth is pretty bad at compressing strings.

Husk, 41 bytes

+¨ΣŸṗ¤μe₀fı≤ṙ↔ẏ«G¹∫¨J"."msλ‰⁰i*⁰)1000√¤+□

Try it online!

With rounding being involved, I sure didn't pick the right language for the task...

+                              The concatenation of
 ¨...¨                         the compressed prefix for the output
          ms                   with the stringified elements of
            λ‰⁰   )1000        the divmod by 1000 of
                       √       the square root of 
                         +     the sum of
                        ¤ □    the squares of the two arguments
                *⁰             times 1000
               i               converted to an integer
      J"."                     with a period inserted between them.

Computing the actual length of the hypotenuse only takes four bytes, rounding to three decimal places takes seventeen bytes, and adding on The hypotenuse of this right triangle is to the output takes twenty bytes. 90.244% of this answer is just formatting!

JavaScript (Node.js), 76 bytes

a=>b=>'The hypotenuse of this right triangle is '+Math.hypot(a,b).toFixed(3)

Try it online!

Explanation

a => b => // the two arguments (curry method)
    `The hypotenuse of this right triangle is // write the text required
    ${Math.hypot(a,b)}` // and use JS Math.hypot function to calculate the hypotenuse. 

Alternately, if the you spare me the pain of writing this text.

f=Math.hypot // is also a valid answer

APL (Dyalog), 51 bytes

'The hypotenuse of this right triangle is',3⍕|0j1⊥⎕

Try it online!

0j1⊥⎕: Convert the input into base i. e.g a b -> b+ai

|: Magnitude

3⍕: Round to 3 decimal places

Stax, 24 bytes

╬Z.-êû$P¿[▐Ä√#╙δdr▼▀Ö☺┐ç

Run and debug it

Unpacked, ungolfed, and commented, it looks like this.

`1/yyH\fBXNR&X+{.SC`p   print "The hypotenuse of this right triangle is "
:J+                     square and add the inputs
|Q                      square root
3j                      round to 3 places
p                       print

Run this one

Petit Computer BASIC, 66 bytes

INPUT A,B?"The hypotenuse of this right triangle is ";SQR(A*A+B*B)

PTC only displays the first 3 decimal places when printing.

Jelly, 32 characters

,²S½ær3µ,“¡ÆC⁷⁺ɱSoṿȤç½?⁶Ẏtḍỵŀ»ṚK

Try it online!

There is probably a better string compression that allows me to get around needing to join with spaces but I was having trouble finding it.

Explanation:

,²S½ær3µ,“...»ṚK    Example inputs: 3, 4
,                   Pair the inputs. Result: [3, 4]
 ²                  Square them. Result: [9, 16]
  S                 Sum them. Result: 25
   ½                Get the square root of the sum. Result: 5
    ær3             Round to 3 decimal places. Result: 5
       µ            Take the result of that... Result: 5
         “...»       ...and  the compressed string Result: "The hypotenuse of this right triangle is"
        ,           And put them into a pair. Result: [5, "The hypotenuse of this right triangle is"]
              Ṛ     Reverse that. Result: ["The hypotenuse of this right triangle is", 5]
               k    Join it with spaces. Result: "The hypotenuse of this right triangle is 5.0"
                    Implicit output.

05AB1E, 53 characters

"The hypotenuse of this right triangle is "|nOt₄*ï₄/«

Try it online!

I could not figure out how to compress 05AB1E strings. :(

Explanation:

"..."|nOt₄*ï₄/«

     |             Push array of inputs.
      n            Square them.
       O           Get the sum.
        t          Get the square root.
         ₄*        Multiply by 1000
           ï       Convert to integer. This rounds it.
            ₄/     Divide by 1000
"..."         «    Append it to the string.
                   Implicit print.

Axiom, 92 bytes

g(a,b)=="The hypotenuse of this right triangle is "((round((a^2+b^2)^.5*1.e3)/1.e3)::String)

test

(4) -> g(12, 19)
   (4)  "The hypotenuse of this right triangle is 22.472"
                                                             Type: String

Jq 1.5, 80 bytes

"The hypotenuse of this right triangle is \(1e3*pow(map(.*.)|add;.5)|floor/1e3)"

Assumes input is [a,b]

Try it online at tio.run or jqplay.org

OML, 57 bytes

"The hypotenuse of this right triangle is "shnhn+A6`*N3eD

Try it online!

Part 1

This simply outputs the string

"The hypotenuse of this right triangle is "s

Part 2

hnhn+A6`*N3eD
hn              take input and square it
  hn            take another input and square it
    +           add them
     A6`        push 10^6
        *       multiply the sum with that number
         N      take integer square root
          3eD   output with three places of precision
                implicit output

TI-BASIC, 76 55 53 52 bytes

Input :Disp "THE HYPOTENUSE OF THIS RIGHT TRIANGLE IS
Fix 3:R▶Pr(X,Y

No, a closing parentheses is not required. Also, less bytes than that APL answer :)

R, 61 76 bytes

cat("The hypotenuse of this right triangle is",round(sqrt(sum(scan()^2)),3))

cat displays its content to STDOUT.

The scan() function takes user's input from keyboard. This input exists as a vector, on which the ^2 is applied (^function is vectorized), and the sum() sums the elements of the vector. sqrt outputs the square-root, which is rounded to 3 decimal places by round(,3)

Thanks to @caird coinheringaahing for noticing that the previous answer didn't round.

Tcl, 80 bytes

puts "The hypotenuse of this right triangle is [expr int(hypot($a,$b)*1e3)/1e3]"

Try it online!

c64 basic v2, 60 66 bytes

0inputa,b:?"The hypotenuse of this right triangle is";sQ(a*a+b*b)

Screenshot:

enter image description here

How to try it.

Perl 5, 69 bytes

printf"The hypotenuse of this right triangle is %.3f",sqrt<>**2+<>**2

Try it online!

J, 56 bytes

'The hypotenuse of this right triangle is '&,@":@(+&.*:)

explanation

J's "Under" verb &. is a nice fit here. It applies a transformation, executes a verb, and then applies the reverse transformation to the result. In this case, squaring is the transformation *:, its reverse is taking the square root, and the verb in question is addition. So we do addition "under" the square transformation. The rest is just formatting the number and cat'ing it onto the sentence.

Try it online!

Fortran 2008 (87 characters)

Based on the Fortran 90 solution, but now in Fortran 2008, HYPOT is an intrinsic function.

read(*,*)a,b;print'(a,f9.3)','The hypotenuse of this right triangle is ',hypot(a,b);end

Haskell, 77 characters

(\x y->print$"The hypotenuse of this right triangle is "++(show$sqrt$x^2+y^2))

Useage:

(\x y->print$"The hypotenuse of this right triangle is "++(show$sqrt$x^2+y^2)) 3.0 4.0
The hypotenuse of this right triangle is 5.0

Bash with bc, 91

No bash script yet?!

read a b
echo -n 'The hypotenuse of this right triangle is '
bc<<<"scale=3;sqrt($a^2+$b^2)"

There is no way this can win.

Python 2 (79)

def p(a,b):print'The hypotenuse of this right triangle is %.3d'%((a*a+b*b)**.5)

Prolog

h(A,B):-X is A*A+B*B, C is sqrt(X),format('The hypotenuse of this right triangle is ~3f',C).

Ruby 2.1+ (73 characters)

f=->a,b{puts"The hypotenuse of this right triangle is %.3f"%(a+b*1i).abs}

Ruby, 94 90 82 chars

p "The hypotenuse of this right triangle is %.3f"%(Math.sqrt(gets.to_i**2+gets.to_i**2))

Update (thanks for the comments):

p "The hypotenuse of this right triangle is %.3f"%(gets.to_i**2+gets.to_i**2)**0.5

JavaScript 118 106 93

Unlike @micha's solution, mine takes in two variables via function and sends the alert of the result.

function(a,b){m=Math;c=d=>d*d,e=1e3;alert("The hypotenuse of this right triangle is "+m.round(m.sqrt(c(a)+c(b))*e)/e)}

function(a,b){e=1e3;alert("The hypotenuse of this right triangle is "+Math.round(Math.sqrt(a*a+b*b)*e)/e)}

Fat arrow functions to the rescue!

h=(a,b,e=1e3)=>"The hypotenuse of this right triangle is "+Math.round(Math.sqrt(a*a+b*b)*e)/e

Javascript 98 characters/bytes

This is implemented as a browser alert in a function.

function p(a,b){alert('The hypotenuse of this right triangle is: '+Math.sqrt(a*a+b*b).toFixed(3))};

C#

Method Only (114)

void H(double a, double b)
{
    Console.Write("The hypotenuse of this right triangle is {0:N3}", Math.Sqrt(a * a + b * b)); 
}

Complete Program (171)

using System;
class P
{        
   static void H(double a, double b)
   {
     Console.Write("The hypotenuse of this right triangle is {0:N3}", Math.Sqrt(a * a + b * b));
   }                
   static void Main()
   {
    H(3, 4);
   }
}

Complete Program (without using method - 141)

using System;class P{static void Main(){double a=3,b=4;Console.Write("The hypotenuse of this right triangle is {0:N3}",Math.Sqrt(a*a+b*b));}}

Fortran (90)

read(*,*)a,b;print'(a,f9.3)',"The hypotenuse of this right triangle is ",sqrt(a*a+b*b);end

Uses implicit typing so that a,b are single precision reals.

Golfscript (69 67 66 65)

This would be much easier if floating point was actually supported without resorting to workarounds... :)

~'The hypotenuse of this right triangle is '@.*@.*+2-1??+.'.'?4+<

A link to test it.

Java : 155

class A{A(int x,int y){System.out.printf("The hypotenuse of this right triangle is %.3f",Math.hypot(x,y));}public static void main(String[]s){new A(1,4);}}

Java, 112

(Also prints out a No Such Method error, though I'm not sure if this is against the rules)

class A{static{int a=1,b=1;System.out.printf("The hypotenuse of this right triangle is %.3f",Math.hypot(a,b));}}

Java, 149

(No error)

class A{static{int a=1,b=1;System.out.printf("The hypotenuse of this right triangle is %.3f",Math.hypot(a,b));}public static void main(String[] a){}}

F#, 78

let f a b=sqrt(a*a+b*b)|>printf"The hypotenuse of this right triangle is %.3f"

Sclipting, 46 characters

글坼各갠方終加감半方갾밈乘增貶껠矽녆둥긆둹댆뭴뉖멵댶넠닶눠덆둩댲걲늖덨덂건댦땡닦덬뉒걩댲밀⓶

Expects the input as two numbers (can be fractional!) separated by a space.

This is shorter than APL, despite having to use a few inconvenient tricks.

Explanation

글坼 | split at space
各 | for each...
  갠方 | to the power of two
終
加 | add
감半方 | to the power of one half
갾밈乘 | multiply by 1000
增貶 | increment, then decrement (kludge for rounding)
껠矽 | insert '.' at 4th-last character position
녆둥긆둹댆뭴뉖멵댶넠닶눠덆둩댲걲늖덨덂건댦땡닦덬뉒걩댲밀⓶ | "The hypotenuse..."

newLISP, 103 characters

(let(a 3.1 b 4)(println"The hypotenuse of this right triangle is "(round(pow(add(pow a)(pow b)).5)-3)))

The unspecified input method helps a lot... :)

dc, 55

3k?d*?d*+v[The hypotenuse of this right triangle is ]Pp

Groovy : 78 Characters

a={x,y->printf"The hypotenuse of this right triangle is %.3f",Math.hypot(x,y)}

Assuming the task is just writing a method. If you need to take input parameters:

99 Characters

printf"The hypotenuse of this right triangle is %.3f",Math.hypot(args[0].toLong(),args[1].toLong())

I found two ways to it with the same length:

printf"The hypotenuse of this right triangle is %.3f",Math.sqrt(args.collect{it.toLong()**2}.sum())

JavaScript: 83

i=prompt,'The hypotenuse of this right triangle is '+Math.hypot(i(),i()).toFixed(3)

Currently the shortest JS implementation using stdin :D
Works only on Firefox 27.0+ (EcmaScript 6)

JavaScript: 78

If we can use just two variables (as lot of scripts do here):

a=2,b=3,'The hypotenuse of this right triangle is '+Math.hypot(a,b).toFixed(3)

EcmaScript 6, 82 79

f=(a,b)=>"The hypotenuse of this right triangle is "+Math.hypot(a,b).toFixed(3)

Usage:

f(3, 5)
> "The hypotenuse of this right triangle is 5"

Update: Switch to Math.hypot()

Java : 223

   class l {
        public static void main(String[] args) {      
          new l().H(2,4);
        }   
        void H(float a, float b)
    {
        System.out.printf("The hypotenuse of this right triangle is %.3f",Math.hypot(a,b));
    }
    }

DELPHI / PASCAL

With indent (157)

program p;
{$APPTYPE CONSOLE}
var a,b:integer;
begin
     readln(a,b);
     writeln('the hypotenuse of this right triangle is',sqrt(b*b+a*a):2:3);
end.

PowerShell: 111

Golfed Code

1..2|%{sv $_ (read-host)};"The hypotenuse of this right triangle is $("{0:N3}"-f[math]::sqrt($1/1*$1+$2/1*$2))"

Walkthrough

1..2|%{sv $_ (read-host)}; Gets two inputs interactively from the user, and stores them in $1 and $2. Might be able to cut some length by using arguments or pipeline inputs instead.

"The hypotenuse of this right triangle is Required text in the output, per the challenge specifications.

$(...)" Encapsulated code block will be processed as script before being included in the output.

"{0:N3}"-f Formats output from the next bit of code as a number with exactly three digits after the decimal point.

[math]::sqrt(...) Gets the square root of the encapsulated value.

$1/1*$1+$2/1*$2 Serves as our "a^2+b^2". Multiplying a number by itself is the shortest way to square it in PowerShell, but the variables need to be divided by 1 first to force them to integers. Otherwise, they are treated as text and 3*3+4*4 would be 3334444 instead of 25.

AWK — 84 78 characters

awk '{printf"The hypotenuse of this right triangle is %.3f\n",($1^2+$2^2)^.5}'

Thanks to Wasi for suggesting ^ operator and removing ()!

e.g.

$ echo 3 4 | awk '{printf"The hypotenuse of this right triangle is %.3f\n",($1^2+$2^2)^.5}'
The hypotenuse of this right triangle is 5.000

Powershell

Just to see if i could...

echo "The hypotenuse of this right triangle is " ([math]::round([math]::sqrt(([math]::pow(([double](Read-Host -p "A")),2) + [math]::pow(([double](Read-Host -p "B")),2))),3))

Scala (95c)

import Math._;val x=sqrt(pow(a,2)+pow(b,2));f"The hypotenuse of this right triangle is $x%1.3g"

C, 77 or 99

77 characters if input can just be the function arguments:

f(a,b){printf("The hypotenuse of this right triangle is %.3f\n",hypot(a,b));}

99 if input must be read from stdin:

a,b;f(){scanf("%d %d",&a,&b);printf("The hypotenuse of this right triangle is %.3f\n",hypot(a,b));}

A big thanks to @Yimin Rong!

C, 100 chars (beats the other C solution by 1!)

A ridiculously inefficient algorithm.

x;f(a,b){for(;x-a*a-b*b;x=rand());printf("The hypotenuse of this right triangle is %.3f",sqrt(x));}

dc 54

Tangents the score of the APL answer!

2^r2^+3kv[The hypotenuse of this right triangle is ]Pp

Test:

$ dc
3 4
2^r2^+3kv[The hypotenuse of this right triangle is ]Pp
The hypotenuse of this right triangle is 5.000

Javascript (97)

x=prompt;a=x(),b=x();x('The hypotenuse of this right triangle is '+Math.sqrt(a*a+b*b).toFixed(3))

APL (54)

'The hypotenuse of this right triangle is',3⍕.5*⍨+/⎕*2

Test:

      'The hypotenuse of this right triangle is',3⍕.5*⍨+/⎕*2
⎕:
      9 10
The hypotenuse of this right triangle is 13.454

Explanation:

Perl 6 (68 74 bytes)

{printf "The hypotenuse of this right triangle is %.3f
",sqrt [+] @_ X**2}

{} declares a lambda function. [+] is sum operator, X** is cross power operator (for example, 1, 2 X+ 10, 20 gives 11, 21, 12, 22). In this case, cross power operator takes one argument, so the result has the same length as @_. @_ contains all function arguments.

If it's disallowed to have function that may take wrong number of arguments (unsafe), it's possible to replace [+] @_ X**2 with $^a**2+$^b**2, where $^a and $^b are placeholder arguments.

C++ - 90

void h(int a,int b){printf("The hypotenuse of this right triangle is %.3f\n",hypot(a,b));}

Python 2.7 - 80 chars

print'The hypotenuse of this right triangle is %.3f'%(input()**2+input()**2)**.5

MATLAB 79 74

@(a,b)sprintf('The hypotenuse of this right triangle is %.3f',norm([a b]))

Javascript, 109

A=1,B=1,s=1e3,console.log("The hypotenuse of this right triangle is " + (Math.round(Math.sqrt(A*A+B*B)*s)/s))

Fiddledee