No Singles Allowed

-1

2

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.

Feathercrown

Posted 2017-03-31T12:37:59.090

Reputation: 121

Question was closed 2017-03-31T21:43:24.677

"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. – Martin Ender – 2017-03-31T12:45:49.387

you used variables with 1 character long, is that acceptable? – Felipe Nardi Batista – 2017-03-31T12:46:51.497

@FelipeNardiBatista Variables that are 1 character long are good to go, as long as it's not a function. – Feathercrown – 2017-03-31T12:47:32.350

@MartinEnder Oops, forgot the code-golf tag.... :P Parentheses do not count, I'll add that into my question. – Feathercrown – 2017-03-31T12:48:59.180

what about : ? – Felipe Nardi Batista – 2017-03-31T12:50:21.693

3@Feathercrown, questions like this are very hard to get right... What about "special operators"? You allow (), but what about @? ., :, = and so on? – Stewie Griffin – 2017-03-31T12:52:21.837

This seems awfully language specific. In CJam, . is a sort of meta-operator that combines with the next token into a single new operator, so that .- is element-wise subtraction. Is that one two-character symbol or are those two one-character symbols? – Martin Ender – 2017-03-31T12:52:23.027

4

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.

– AdmBorkBork – 2017-03-31T12:55:20.220

What about strings? "foo" – Felipe Nardi Batista – 2017-03-31T13:00:57.383

I've clarified those questions. @StewieGriffin The whole point is that special operators are restricted; no, those are not allowed. – Feathercrown – 2017-03-31T13:03:38.733

@MartinEnder The cjam example is interesting... I guess that would count as one two-character operator. – Feathercrown – 2017-03-31T13:04:09.407

i would like to add dist s t=sum(map(**2)(zipWith subtract s t))**0.5 but the on hold status seems to prevent me from doing that. – Roman Czyborra – 2017-03-31T13:08:47.547

@RomanCzyborra the = symbol is not allowed – Felipe Nardi Batista – 2017-03-31T13:16:40.533

2Are all strings allowed? In python: eval("a+b") it's a valid string, but it will be executed as code – Felipe Nardi Batista – 2017-03-31T13:56:44.703

2You 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. – Post Rock Garf Hunter – 2017-03-31T14:00:50.907

Bigram/Trigram allowed? – Matthew Roh – 2017-03-31T14:20:50.587

Well there goes every 2d esolang :( – MildlyMilquetoast – 2017-03-31T17:09:24.537

@WheatWizard Wait, the are? I thought they were their own thing. – Feathercrown – 2017-03-31T20:05:39.347

@FelipeNardiBatista Good catch. Eval is not allowed. – Feathercrown – 2017-03-31T20:06:00.777

Should've added a "no built-ins" restriction. Oh well. – Feathercrown – 2017-03-31T20:09:47.323

The list of things which are unclear is too long to write because I'd certainly miss a few, but includes: 1. What is a "symbol"? 2. Is -- allowed when it's two separate stack-based subtractions? In general it's not clear whether the rules are meant to apply on a syntax level or on a source level (although it is clear that you didn't think about any languages outside the ALGOL family) -- and in fact they seem to be mixed together. 3. It's not obvious why you need to explicitly allow "'([{<>}])'", given that it's a string. 4. The rules on input are rendered irrelevant by the ban on eval. – Peter Taylor – 2017-03-31T20:43:26.100

@PeterTaylor 1. A symbol is an operator. I've added that into the question for clarity. 2. -- as 2 -s is not allowed under this rule as it is 2 separate single-character operators, which are illegal in this challenge. 3. Not really a problem, since it's just another example of something that's valid, but I "fixed" it anyways. 4. I'm not sure I understand, please clarify. – Feathercrown – 2017-03-31T23:00:56.700

@WheatWizard It appears that you are right. Fixin' it. – Feathercrown – 2017-03-31T23:08:33.130

@ETHProductions, TaylorScott, DownChristopher, and powelles: Can you please explain what exactly is unclear? – Feathercrown – 2017-03-31T23:13:55.663

Answers

3

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!

Felipe Nardi Batista

Posted 2017-03-31T12:37:59.090

Reputation: 2 345

@nimi . and , are allowed, however = is not, which is going to be the hard part for most languages. – Feathercrown – 2017-03-31T13:05:07.097

@nini fixed it, as () and . are now allowed – Felipe Nardi Batista – 2017-03-31T13:07:44.843

2

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.

Greg Martin

Posted 2017-03-31T12:37:59.090

Reputation: 13 940

1

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']

Neil

Posted 2017-03-31T12:37:59.090

Reputation: 95 035

0

R, 33 bytes

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

Try it online!

R, 26 bytes

dist(rbind(scan(),scan()))

Steadybox

Posted 2017-03-31T12:37:59.090

Reputation: 15 798

0

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.

Stewie Griffin

Posted 2017-03-31T12:37:59.090

Reputation: 43 471