-1
\$\begingroup\$

This is a fairly simple challenge.

Write a program that computes the distance between two points on a 2D plane. However, you can't use any functions or operators (referred to here as symbols) that are 1 character long.

Examples:

  • -=, +=, *=, /=, %=, etc. are allowed.
  • ||, &&, --, ++ are allowed as well.
  • +, -, /, * are not allowed.
  • f(x) is not allowed, but fn(x) is.
  • S 5 4 is not allowed, but SUM 5 4 is.
  • if(lol==lel) is allowed.
  • Simply putting two separate single-character operators one after the other is not allowed, eg. !!(true) isn't allowed.

Exceptions:

  • Single semicolons or the equivalent are allowed, e.g. foo();, as long as they are being used as an end-of-command symbol.
  • Commas (,) and periods (.) are allowed.
  • Parentheses (()) and other symbols that are used in such a way to require a second match are allowed. Examples:
    • foo(); is allowed, as is foo(x);.
    • [5,6] is allowed.
    • "strings" are allowed.
    • for(i+=5;;i++){} is allowed
    • if(1<2 && 2>3) is not allowed, as the symbols are being interpreted as greater than and less than symbols, and so do not require the other.
    • ([{<>}]) is allowed.
    • ][ is not allowed, as the symbols do not match.
    • Essentially, the interpreter/compiler/etc.(?) should recognize the symbols as matching.

Specifications:

  • Whitespace does not count for the single character rule, e.g. this == that and this ==that etc. are both allowed.
  • Standard rules for loopholes etc. apply.
  • Input can be in any reasonable format of two points. Examples:
    • [{x:0,y:0},{x:9,y:786}]*
    • [[5,4],[6,8]]
    • "54,37,68,9760"
    • new Point(0,0), new Point(5,6)
    • ["34,56","23,98657"]
    • etc.
  • Output should be a double or equivalent with 5 significant digits.
  • No eval!
  • This is code-golf, so shortest allowed and functioning code wins!

*You would have to construct the objects a different way, as colons are single symbols.

Good luck without being able to use the = operator! :P

Edit: Imaginary 5 kudo points for not using a built-in.

\$\endgroup\$

closed as unclear what you're asking by Peter Taylor, Taylor Scott, Christopher, powelles, ETHproductions Mar 31 '17 at 21:43

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ "f(x) is not allowed, but fn(x) is", aren't (, x and ) all one character long? You also seem to be missing a winning criterion. \$\endgroup\$ – Martin Ender Mar 31 '17 at 12:45
  • 3
    \$\begingroup\$ @Feathercrown, questions like this are very hard to get right... What about "special operators"? You allow (), but what about @? ., :, = and so on? \$\endgroup\$ – Stewie Griffin Mar 31 '17 at 12:52
  • 4
    \$\begingroup\$ Restricted source questions are notoriously difficult to get right, because the tend to make many language assumptions. For example here, the language Whitespace has no effective restrictions. For future challenges, I recommend posting to the Sandbox where you can get meaningful feedback and iron out details before posting a challenge to Main. \$\endgroup\$ – AdmBorkBork Mar 31 '17 at 12:55
  • 2
    \$\begingroup\$ Are all strings allowed? In python: eval("a+b") it's a valid string, but it will be executed as code \$\endgroup\$ – Felipe Nardi Batista Mar 31 '17 at 13:56
  • 2
    \$\begingroup\$ You say that semicolons are allowed as line ending symbols but for(i+=5;;i++){} is disallowed? The semicolons in a for loop are line ending symbols. Just because they commonly don't have a newline after them does not mean that they are some type of operator. \$\endgroup\$ – Wheat Wizard Mar 31 '17 at 14:00
3
\$\begingroup\$

Python 2, 35 bytes

print abs(input().__sub__(input()))

Example input for points (5,4) and (6,8):

5+4j
6+8j
4.12310562562

or:

complex(5,4)
complex(6,8)
4.12310562562

Try it online!

\$\endgroup\$
  • \$\begingroup\$ @nimi . and , are allowed, however = is not, which is going to be the hard part for most languages. \$\endgroup\$ – Feathercrown Mar 31 '17 at 13:05
  • \$\begingroup\$ @nini fixed it, as () and . are now allowed \$\endgroup\$ – Felipe Nardi Batista Mar 31 '17 at 13:07
2
\$\begingroup\$

Mathematica, 17 bytes

EuclideanDistance

A function invoked like EuclideanDistance[{5,4}, {6,8}]. Works in other dimensions as well.

Mathematica and its long command names thank you for your support.

\$\endgroup\$
1
\$\begingroup\$

JavaScript, 10 bytes

Math.hypot

Returns a function that does the job. For 13 bytes, I can do it using only paired puncutation:

Math['hypot']
\$\endgroup\$
0
\$\begingroup\$

R, 33 bytes

cd<-function(a,b)dist(rbind(a,b))

Try it online!

R, 26 bytes

dist(rbind(scan(),scan()))
\$\endgroup\$
0
\$\begingroup\$

Octave, 20 bytes

abs(diff(input('')))

Takes input on the form: [5+4j, 6+8j].

Anonymous functions can't be used since @ is a single character. It takes a vector with two complex numbers as input, calculated the difference, and takes the absolute value.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.