Is this relationship creepy?

73

4

According to this XKCD comic, there is a formula to determine whether or not the age gap in a relationship is "creepy". This formula is defined as:

(Age/2) + 7

being the minimum age of people you can date.

Therefore a relationship is creepy if either of the people in said relationship are younger than the minimum age of the other.

Given the age of two people, can you output whether or not that relationship is creepy?

Rules

  1. Your program should take two integers as input, the age of both people in the relationship. These can be taken in any reasonable format.

  2. Your program must then output a truthy or falsy value describiing whether or not the relationship is "creepy" (Truthy = Creepy).

  3. Standard loopholes are not allowed.
  4. This puzzle is Code Golf, so the answer with the shortest source code in bytes wins

Test Cases

40, 40    - Not Creepy
18, 21    - Not Creepy
80, 32    - Creepy
15, 50    - Creepy
47, 10000 - Creepy
37, 38    - Not Creepy
22, 18    - Not Creepy

Leo

Posted 2017-05-24T18:14:40.520

Reputation: 1 256

3How should age/2 be rounded? Probably up if the exact half is supposed to be the minimum? 17,21 would make a good test case. – Martin Ender – 2017-05-24T18:20:04.527

4@MartinEnder The value is a minimum, so do not round at all. It doesn't have to be an integer. – Leo – 2017-05-24T18:24:09.443

1@FishProHD can we require a certain input order (i.e. largest first) – Stephen – 2017-05-24T18:32:27.177

81You could also add 13, 13 - Creepy. – Greg Martin – 2017-05-24T19:20:00.760

1247, 10000 is an... interesting combination. I would also like to point out that according to this formula, it is creepy for Doctor Who to date any human. – David Conrad – 2017-05-26T15:01:33.853

8@DavidConrad - well yeah. its basically beastiality on his part.... – Batman – 2017-05-26T16:47:47.627

I hate to be a puritan about it but 17-20 is very-easily creepy. – Erik Reppen – 2017-05-27T05:53:03.213

Would you mind updating the accepted answer? – Okx – 2017-06-03T10:04:04.953

Done! Sorry about the delay didn't check it in a while. – Leo – 2017-06-03T10:07:24.480

An important test case is, for example, 21, 29 - Creepy. If you do integer division you get it wrong. – Max – 2017-10-13T17:16:56.737

1This post is like 5 months old @Max – Leo – 2017-10-13T17:18:08.840

Had to take a second look after seeing the title to make sure I wasn't on IPS... – FlipTack – 2017-11-20T18:18:49.503

Answers

6

Jelly, 6 bytes

H+7>ṚṀ

Try it online!

Seemingly different algorithm than Comrade's.

Erik the Outgolfer

Posted 2017-05-24T18:14:40.520

Reputation: 38 134

Well, its the same now... ;p – Draco18s no longer trusts SE – 2017-05-24T21:47:21.710

@Draco18s It was always the same with the earlier 05AB1E submission though. – Erik the Outgolfer – 2017-05-25T11:31:03.693

17

Python 3, 26 bytes

lambda x:max(x)/2+7>min(x)

Try it online!
The input is a list with both ages

Rod

Posted 2017-05-24T18:14:40.520

Reputation: 17 588

Had the same before I read existing answers. +1 – ElPedro – 2017-05-24T20:08:36.120

It appears you could actually assume a tuple where it's always (younger,older) - just asked OP - wonder what he'll say. – rm-vanda – 2017-05-25T16:07:11.677

@rm-vanda I asked earlier, you can't assume – Stephen – 2017-05-26T17:28:42.967

15

05AB1E, 8 6 bytes

;7+R‹Z

Try it online! or Try all test

         # Implicit Input: an array of the ages
;        # Divide both ages by 2
 7+      # Add 7 to both ages
   R     # Reverse the order of the ages
         #    this makes the "minimum age" line up with the partner's actual age
    ‹    # Check for less than the input (vectorized)
     Z   # Push largest value in the list

Riley

Posted 2017-05-24T18:14:40.520

Reputation: 11 345

3As a C programmer I agree that 2 is truthy. – gmatht – 2017-05-26T12:44:53.400

@gmatht This should always return either 0 or 1, never 2. – Riley – 2017-05-26T14:07:11.017

4[13,13] is doubly creepy. – gmatht – 2017-05-27T03:30:22.400

1@gmatht I guess that would be double. I didn't think about numbers that small. It's still truthy though. – Riley – 2017-05-27T04:13:02.670

@Riley 2 is not truthy, see this.

– Okx – 2017-06-02T17:40:52.093

@Okx 2 is not truthy, we shouldn't use __ to determine truthiness, we should use i1ë0}. – Erik the Outgolfer – 2017-06-03T11:11:08.343

@EriktheOutgolfer I don't understand. – Okx – 2017-06-03T11:14:28.987

@Okx Riley probably assumed 2 is truthy, or used __, while _ considers 2 to be truthy, while consensus says it must behave like truthy on if statements, so i1ë0} is the perfect truthiness checker to use here. – Erik the Outgolfer – 2017-06-03T11:16:14.887

@EriktheOutgolfer May I say again that should use isn't in a golfer's dictionary? Whatever works, works. – Okx – 2017-06-03T11:19:23.650

@EriktheOutgolfer I'm not using __ to check for truthyness, I'm using it to translate 0->0, 1->1, and 2->1 which will make the output match the if statement definition of truthy/falsy. – Riley – 2017-06-03T16:58:58.787

@Riley I wasn't talking about the use of __ here. – Erik the Outgolfer – 2017-06-03T17:00:56.157

@EriktheOutgolfer Okay. I guess I'm just confused about what you guys are talking about. – Riley – 2017-06-03T17:11:44.033

@Riley We were talking about how you assumed 2 is truthy at first, and a potential way so that you never face the issue again. Coincidentally, it involved the use of __ too (since Ā was added after the challenge). – Erik the Outgolfer – 2017-06-03T17:13:22.747

@Riley Z or P works :P. – Magic Octopus Urn – 2017-09-03T21:35:20.270

13

NAND gates, 551

16-bit creepiness calculator Created with Logisim

Same principle as my other answer, but takes 2-byte signed inputs, so it can handle 47, 10000. Works for ALL test cases!

This is not optimal for the given test cases, as 10000 can be expressed with only 15 of the 16 bits, but it works for any ages in the range [-32768, 32768). Note that any negative age will return 1.

Inputs on left (no particular order, 1-bit on top). Output in lower right.

Khuldraeseth na'Barya

Posted 2017-05-24T18:14:40.520

Reputation: 2 608

10

NAND gates, 274 262

Original:

Better: Created with Logisim

This takes two inputs on the left as 1-byte signed integers, with the 1-bit at the top. Output is in the lower left; the truthy and falsey here should be obvious.

Works for all test cases except 47, 10000, so I guess this is technically not a valid answer. However, the oldest person on (reliable) record was 122, so 8 bits (max 127) will work for any scenario ever possible to this point. I'll post a new answer (or should I edit this one?) when I finish the 16-bit version.

16-bit version is done!

You'll notice some vertical sections of the circuit. The first one (from the left) determines which input is greater. The next two are multiplexers, sorting the inputs. I then add 11111001 (-7) to the lesser in the fourth section, and I conclude by comparing twice this to the greater input. If it is less, the relationship is creepy. Since I shift the bits to double, I must take into account the unused bit of lesser-7. If this is a 1, then lesser-7 is negative, and the younger of the two is no older than six. Creepy. I finish with an OR gate, so if either creepiness test returns 1, the entire circuit does.

If you look closely, you'll see that I used seven one constants (hardcoding the 11111011 and the trailing 0). I did this because Logisim requires at least one value going in for a logic gate to produce an output. However, each time a constant is used, two NAND gates ensure a 1 value regardless of the constant.

-12 gates thanks to me!

Khuldraeseth na'Barya

Posted 2017-05-24T18:14:40.520

Reputation: 2 608

Noticed an obvious optimization. If you point it out before I edit, I'll still credit you! – Khuldraeseth na'Barya – 2017-09-04T00:02:38.883

9

C#, 22 bytes

n=>m=>n<m/2+7|m<n/2+7;

TheLethalCoder

Posted 2017-05-24T18:14:40.520

Reputation: 6 930

1I'm not much of a C# programmer, but is the final semicolon required as part of the function? – Olivier Grégoire – 2017-05-27T19:02:59.107

1@OlivierGrégoire It's just invalid syntax if it's omitted; this is an anonymous function – cat – 2017-05-27T22:00:28.977

8

C, 29 bytes

#define f(a,b)a/2+7>b|b/2+7>a

How it works:

  • #define f(a,b) defines a macro function f that takes two untyped arguments.
  • a/2+7>b checks if the first age divided by two plus seven is larger than the second age.
  • b/2+7>a checks if the second age divided by two plus seven is larger than the first age.
  • If either of the above values are true, return 1 (creepy). Otherwise, return 0 (not creepy).

Try it online!

MD XF

Posted 2017-05-24T18:14:40.520

Reputation: 11 605

you should flip the comparison, it should be like >b not <b – Khaled.K – 2017-05-24T20:26:45.597

Quote "being the minimum age" means you have to check if age >= min, also you need AND instead of OR, since both sides has to satisfy in order for it to not be creepy, test case "47, 10000 - Creepy" – Khaled.K – 2017-05-24T20:40:03.533

okay I've fixed the error, but the logic is wrong, it return true, tio.run

– Khaled.K – 2017-05-24T20:42:58.820

@Khaled.K Hm, fixed. – MD XF – 2017-05-24T21:01:43.637

1

@Tas nope.

– MD XF – 2017-05-24T23:35:39.717

1Cheers, thanks for the link – Tas – 2017-05-24T23:39:47.480

7

JavaScript (ES6), 21 bytes

a=>b=>a<b/2+7|b<a/2+7

Returns 0 for not creepy, 1 for creepy.

f=a=>b=>a<b/2+7|b<a/2+7

console.log(f(40)(40));
console.log(f(18)(21));
console.log(f(80)(32));
console.log(f(15)(50));
console.log(f(47)(10000));
console.log(f(37)(38));
console.log(f(22)(18));

Rick Hitchcock

Posted 2017-05-24T18:14:40.520

Reputation: 2 461

Save a byte with currying: a=>b=> instead of (a,b)=>, call with f(40)(40). – Stephen – 2017-05-24T19:30:50.377

@StephenS, thank you, learned something new! – Rick Hitchcock – 2017-05-24T19:32:18.293

No problem, I learned it when someone told me the same thing :) it only works with two parameters though, after that it's not worth it. – Stephen – 2017-05-24T19:33:43.717

7

R, 26 25 bytes

-1 byte thanks to @djhurio

any(rev(a<-scan())<a/2+7)

Try it online!

Giuseppe

Posted 2017-05-24T18:14:40.520

Reputation: 21 077

5

TI-Basic, 20 10 9 bytes

max(2Ans<14+max(Ans

-10 bytes by using a list and part of Timtech's suggestion

-1 byte using lirtosiast's suggestion

Takes in a list of two ages, "{40,42}:prgmNAME"

Returns 1 for 'creepy' and 0 for 'not creepy'.

pizzapants184

Posted 2017-05-24T18:14:40.520

Reputation: 3 174

Does TI-BASIC automatically close parentheses at a testing-symbol (< <= = != >= >)? – Zacharý – 2017-09-04T16:03:18.867

@Zacharý No, TI-Basic only closes parentheses at the end of a line or a colon. – pizzapants184 – 2017-09-04T16:16:57.497

Oh, whoops I forgot that the input was being taken as a list of numbers! – Zacharý – 2017-09-04T16:21:34.130

5

Retina, 20 bytes

O`.+
^1{7}(1+)¶1\1\1

Try it online!

Input is in unary with a linefeed between the two numbers. Output is 0 (not creepy) or 1 (creepy).

Explanation

O`.+

Sort the two numbers, so we know that the larger one is second.

^1{7}(1+)¶1\1\1

Call the smaller age a and the larger age b. We first capture a-7 in group 1. Then we try to match 2*(a-7)+1 in b, which means b >= 2*(a-7)+1 or b >= 2*(a-7) or b/2+7 > a which is the criterion for a creepy relationship.

Martin Ender

Posted 2017-05-24T18:14:40.520

Reputation: 184 808

4

Python 3, 74 45 bytes

First Code Golf, probably terrible.

29 byte reduction by @Phoenix

lambda a,b:0 if(a/2)+7>b or(b/2)+7>a else 1

KuanHulio

Posted 2017-05-24T18:14:40.520

Reputation: 883

Hi, please be sure to properly format your code using the markdown system. – Leo – 2017-05-24T18:47:22.647

don't worry, someone beat me to it, ill fix it though – KuanHulio – 2017-05-24T18:47:48.870

You can get rid of some of the spaces there :) – Beta Decay – 2017-05-24T18:47:57.463

Also, lambda a,b:0 if(a/2)+7>b or(b/2)+7>a else 1 should work and is shorter by a lot. – Pavel – 2017-05-24T18:55:35.577

i think the space before if can be left out as well as the one after else – Roman Gräf – 2017-05-25T12:40:22.040

lambda a,b:0if a/2+7>b or b/2+7>a else1... – Roman Gräf – 2017-05-25T12:41:20.370

1lambda a,b:a/2+7>b or b/2+7>a. Abandon the burden of those pesky 1s and 0s and embrace the power of True/False! – Value Ink – 2017-05-31T01:31:25.497

4

GNU APL 1.2, 23 bytes

Defines a function that takes two arguments and prints 1 if creepy, 0 if not.

∇A f B
(A⌊B)<7+.5×A⌈B
∇

Explanation

begins and ends the function
A f B is the function header; function is named f and takes two arguments, A and B (functions in APL can be monadic - taking one argument - or dyadic - taking two arguments)
A⌊B is min(A,B) and A⌈B is max(A,B)
APL is evaluated right-to-left, so parentheses are needed to ensure proper precedence

The other operators are self explanatory.

Code might be golf-able, I'm still new to code-golf.

Arc676

Posted 2017-05-24T18:14:40.520

Reputation: 301

1Welcome to the site! – OldBunny2800 – 2017-05-25T12:22:17.547

Wow, nice, GNU APL, haven't seen that in a while. – Zacharý – 2017-09-04T14:10:16.580

Also, it's possible to take the arguments as a list: f X then (⌊/X)<7+.5×⌈/X. IIRC you can remove the newline between the second and third lines. – Zacharý – 2017-09-04T14:11:49.910

@Zacharý Yes, anonymous lambdas are possible. They are not supported by this version of GNU APL and the newer one does not compile on Mac. Some of my other answers use APL 1.7 because I test them on Ubuntu. I have not used lambdas (might fix them later) because I'm still pretty new to APL. – Arc676 – 2017-09-04T14:14:13.713

Try out ngn-apl. It's open-source like GNU APL, but in all honesty it's better. – Zacharý – 2017-09-04T14:20:04.323

Doesn't GNU APL use UTF-8? Anyway, in Dyalog APL, you can write this tacitly as ⌊<7+.5×⌈

– Adám – 2017-10-14T23:55:05.490

@Adám I was not aware that you could give arguments implicitly; that’s pretty neat. – Arc676 – 2017-10-15T03:48:17.320

3

JavaScript (ES6), 27 bytes

f=a=>b=>b>a?f(b)(a):b>a/2+7

No currying (call like f(a,b) instead of f(a)(b))

f=(a,b)=>b>a?f(b,a):b>a/2+7

If b > a, swap parameters and retry. Otherwise, check. Currying doesn't save any bytes because of the recursive call.

f=a=>b=>b>a?f(b)(a):b>a/2+7

console.log(f(18)(22))
console.log(f(22)(18))
console.log(f(18)(21))

Stephen

Posted 2017-05-24T18:14:40.520

Reputation: 12 293

3

Excel, 26 24 Bytes

Cell formula that takes input as numbers from cell range A1:B1 and output a boolean value representing creepiness to the formula cell

=OR(A1/2+7>B1,B1/2+7>A1)

Old Version, 26 Bytes

=MAX(A1:B1)/2+7>MIN(A1:B1)

Taylor Scott

Posted 2017-05-24T18:14:40.520

Reputation: 6 709

3

Java, 21 bytes

a->b->a/2+7>b|b/2+7>a

Absolutely not original.

Testing

Try it online!

import java.util.function.*;

public class Pcg122520 {
  static IntFunction<IntPredicate> f = a->b->a/2+7>b|b/2+7>a;
  public static void main(String[] args) {
    int[][] tests = {
      {40, 40},
      {18, 21},
      {80, 32},
      {15, 50},
      {47, 10000},
      {37, 38},
      {22, 18}
    };
    for (int[] test: tests) {
      System.out.printf("%d, %d - %s%n", test[0], test[1], f.apply(test[0]).test(test[1]) ? "Creepy" : "Not creepy");
    }
  }
}

Olivier Grégoire

Posted 2017-05-24T18:14:40.520

Reputation: 10 647

1

+1 for mentioning "Absolutely not original.". Almost no one else does, while they are almost all the same. And I took the liberty of adding a TIO-link from your test code. Not sure why you always add a test code, but not a TIO-link?.. :)

– Kevin Cruijssen – 2017-05-26T10:22:54.090

1Thanks Kevin! I sometimes do add one, sometimes not. It depends on whether I have my IDE open or closed. It's as simple as that! :P Also, I show the test code in order for people to understand what makes this lambda valid. :) – Olivier Grégoire – 2017-05-26T10:40:45.930

3

Python 3, 31 bytes

lambda a,b:abs(a-b)>min(a,b)-14

Not much shorter than the other python submissions, but I found a slightly different way to check for creepiness. I noticed that the acceptable difference between ages is equal to min - 14. This follows from algebraically rearranging the formula.

min = (max/2) + 7
min - 7 = max/2
2*min - 14 = max

dif = max - min
max = dif + min

2*min - 14 = dif + min
min - 14 = dif

This let me solve without needing two constants, and also without needing to use both max and min, instead using abs(a-b). From a golfing perspective I only got one byte less than @nocturama's solution, but I used a slightly different formula to do it.

Delya Erricson

Posted 2017-05-24T18:14:40.520

Reputation: 81

Surely this fails on [37,53] (not in the test suite but) within the (x/2)+7 spirit of this fairway – Alexx Roche – 2017-10-15T12:32:08.627

@AlexxRoche Nope, when given [37,53] as [a,b], the calculation should become

abs(37 - 53) > min(37, 53) - 14 = abs(-16) > 37 - 14 = 16 > 23 = False

This is the correct answer, because according to (x/2) + 7, the minimum age for 53 is 53/2 + 7 = 26.5 + 7 = 33.5 – Delya Erricson – 2017-10-17T03:56:07.910

2

Mathics, 16 bytes

Max@#/2+7<Min@#&

Try it online!

-2 bytes thanks to @GregMartin

True for not creepy, false for creepy.

            (* Argument: A list of integers     *)
Max@#       (* The maximum of the input         *)
 /2+7       (* Divided by 2, plus 7             *)
  <         (* Is less than?                    *)
   Min@#    (* The minimum of the input         *)
    &       (* Anonymous function               *)

Pavel

Posted 2017-05-24T18:14:40.520

Reputation: 8 585

Save 2 bytes by taking the ages as a list: Max@#/2+7<Min@#& – ngenisis – 2017-05-24T19:28:29.840

2

TI-Basic, 10 9 10 bytes

2min(Ans)-14≤max(Ans

List input from Ans, outputs 1 if "creepy" or 0 otherwise.

Timtech

Posted 2017-05-24T18:14:40.520

Reputation: 12 038

2

SAS, 77 bytes

%macro t(a,b);%put%eval(%sysfunc(max(&a,&b))/2+7>%sysfunc(min(&a,&b)));%mend;

J_Lard

Posted 2017-05-24T18:14:40.520

Reputation: 351

2

Röda, 16 bytes

{sort|[_<_/2+7]}

Try it online!

This is an anonymous function that takes input as two literals (not an array) from the input stream.

Explanation

{sort|[_<_/2+7]}                 Anonymous function
 sort                            Sorts the numbers in the input stream
     |[       ]                  And push
       _<                        whether the smaller value  is less than
         _/2+7                   the greater value / 2 + 7

user41805

Posted 2017-05-24T18:14:40.520

Reputation: 16 320

2

Crystal, 44 27 bytes

-17 from looking at daniero's answer in Ruby.

def a(a)7+a.max/2>a.min end

Try it online!

TitusLucretius

Posted 2017-05-24T18:14:40.520

Reputation: 121

2

Perl 6, 15 bytes

{.max/2+7>.min}

Try it

Expanded

{ # bare block lambda with implicit parameter 「$_」
  # (input is a List)

  .max / 2 + 7
  >
  .min
}

Brad Gilbert b2gills

Posted 2017-05-24T18:14:40.520

Reputation: 12 713

2

Python 3 - 32 27 bytes

Unable to comment, but I got a slightly shorter answer than the other Python 3 solution:

lambda *a:min(a)<max(a)/2+7

-5 thanks to @Cyoce!

nocturama

Posted 2017-05-24T18:14:40.520

Reputation: 111

you can remove the space in lambda *a – Cyoce – 2017-11-30T23:37:34.737

1

Fourier, 37 bytes

oI~AI~B>A{1}{A~SA~BS~B}A/2+7>B{1}{@o}

Try it on FourIDE!

Takes two numbers as input. Will golf later.

Beta Decay

Posted 2017-05-24T18:14:40.520

Reputation: 21 478

It doesn't need to output a string like that, can be truthy or falsy – Leo – 2017-05-24T18:26:18.623

Nice golf. That was quick. – MD XF – 2017-05-24T18:38:32.837

1

Japt, 11 bytes

Returns true for "creepy" and false for not.

wV /2+7>UmV

Try it online


Explanation

      :Implicit input of first integer U
wV    :Get the maximum of U and the second integer V
/2+7  :Divide by 2 & add 7
>     :Check if the result is greater than...
UmV   :the minimum of the two integers.

Shaggy

Posted 2017-05-24T18:14:40.520

Reputation: 24 623

1

PHP, 29 Bytes

prints 1 for creepy, nothing for Not creepy

<?=max($_GET)/2+7>min($_GET);

Try it online!

Jörg Hülsermann

Posted 2017-05-24T18:14:40.520

Reputation: 13 026

As I understand the rules this fails on [34,19] – Alexx Roche – 2017-10-15T12:43:32.810

1

J, 10 bytes

<.<7+2%~>.

Outputs 1 for not creepy, 0 for creepy

Explanation

<.          NB. the minimum
  >         NB. is greater than
    7+2%~>. NB. half the maximum + 7

Cyoce

Posted 2017-05-24T18:14:40.520

Reputation: 2 690

1

J-uby, 25 bytes

:>%[:min,:max|~:/&2|:+&7]

Call like f^[80,32]. Gives true for not creepy, false for creepy.

Explanation

    :min                  # the minimum
:>%[    ,               ] # is greater than
         :max|            # the maximum...
              ~:/&2|        # over two...
                    :+&7    # plus 7 

Cyoce

Posted 2017-05-24T18:14:40.520

Reputation: 2 690

This is a beautiful language. I spent a long time trying to accomplish similar ends with Ruby (I called it "Blurb"), but leaning heavily on method_missing led to too much complexity. This approach is clean and elegant. Congrats! – Jordan – 2017-05-25T02:53:09.127

@Jordan thanks! I can't take all the credit, as this was heavily inspired by J (hence the name). I'm open to suggestions from a fellow Ruby programmer if you have any. – Cyoce – 2017-05-25T03:04:41.713

@Jordan you should see some of the other more complex J-uby answers. They're quite something. – Cyoce – 2017-05-25T03:21:00.897

1

AWK, 26 bytes

{$0=$1/2+7>$2||$2/2+7>$1}1

Try it online!

Outputs 1 for "Creepy" and 0 for "Not Creepy". Could save 3 bytes if no-output could be consider a falsy value, via:

$0=$1/2+7>$2||$2/2+7>$1

Robert Benson

Posted 2017-05-24T18:14:40.520

Reputation: 1 339

1

Swift - 33 bytes

var f={max($0,$1)/2+7>min($0,$1)}

A lambda-function's equivalent in Swift, but unfortunately cannot take an array :((. Outputs true for truthy and false for falsy. If one must not count the declaration of the function (Python doesn't) the byte count would be 27. Usage: print(f(age1,age2))

Check it out!

Mr. Xcoder

Posted 2017-05-24T18:14:40.520

Reputation: 39 774

1

Batch, 50 bytes

@if %1 gtr %2 %0 %2 %1
@cmd/cset/a"%1*2-14-%2>>31

Outputs -1 for creepy, 0 for not creepy.

Since Batch only has integer arithmetic I have to work in units of half years.

Neil

Posted 2017-05-24T18:14:40.520

Reputation: 95 035

+1 for the %0 %2 %1 and bypassing interget aritmetic. – stevefestl – 2017-05-28T12:38:40.100

1

Ruby, 21 bytes

->*x{x.max/2+7>x.min}

Yup.

f = ->*x{x.max/2+7>x.min}
f[18,21]  #=> false
f[80,32]  #=> true

daniero

Posted 2017-05-24T18:14:40.520

Reputation: 17 193

1

z-shell (zsh), 38 bytes

n=(${(no)@});echo $((n[2]/2+7-n[1]>0))

${(no)@} is a numeric sort of the argument array

gsker

Posted 2017-05-24T18:14:40.520

Reputation: 11

1

Perl 5, 34 + 2 (-ap) = 36 bytes

$_=$F[0]/2+7>$F[1]|$F[1]/2+7>$F[0]

Try it online!

Xcali

Posted 2017-05-24T18:14:40.520

Reputation: 7 671

1

FORTH 96 Bytes

: C 2DUP > -1 = IF SWAP THEN 2 /  7 +  SWAP > -1 = IF ."  CREEPY " ELSE ." NOT CREEPY " THEN ;

Output:

40 40 c NOT CREEPY  ok
18 21 c
18 21 c NOT CREEPY  ok
80 32 c
80 32 c  CREEPY  ok
15 50 c
15 50 c  CREEPY  ok
47 10000 c
47 10000 c  CREEPY  ok
37 38 c
37 38 c NOT CREEPY  ok
22 18 c
22 18 c NOT CREEPY  ok

panicmore

Posted 2017-05-24T18:14:40.520

Reputation: 51

0

Excel VBA, 28 Bytes

Anonymous immediate window function that tTakes age inputs from cells [A1] and [B1] as expected type Integer and outputs a Boolean value representing creepyness to the VBE immediate window

?[B1]/2+7>[A1]|[A1]/2+7>[B1]

Taylor Scott

Posted 2017-05-24T18:14:40.520

Reputation: 6 709

1Can't you just write this as a formula in a cell? – Neil – 2017-05-24T18:53:37.367

@Neil, yes I <s>could</s> have, though my particular purpose in golfing with VBA is more to keep some level of practice up with the language, rather than optimizing for the byte count – Taylor Scott – 2017-05-25T13:10:30.047

Ah yes, VBA is a slightly different language. – Neil – 2017-05-25T13:26:33.640

0

shortC, 21 bytes

D(a,b)a/2+7<b|b/2+7<a

MD XF

Posted 2017-05-24T18:14:40.520

Reputation: 11 605

0

QBIC, 30 bytes

~:>:|c=a┘d=b\c=b┘d=a]?d>=c/2+7

Explanation

           First, we mustsort the input parameters
~:>:       IF a (from cmd line) > b (from cmd line)
|c=a┘d=b   THEN set c and d
\c=b┘d=a   ELSE set c and d in the other way
]          END IF
?d>=c/2+7  PRINT -1 if d is higher than c's lower bound, 0 for creepy

steenbergh

Posted 2017-05-24T18:14:40.520

Reputation: 7 772

0

Pyth, 17 16 13 12 bytes

>+7/.)JSQ2hJ

Takes a list. Outputs True for creepy, False for not creepy.

Try it!

explanation

>+7/.)JSQ2hJ
      JSQ        # Sort the input list (Q) and store the result in J
    .)           # pop the last/largest element from J (lets call it x)
          hJ     # the first/only element of J (lets call it y)
>+7/     2       # 7 + x/2 > y

old approach, 13 bytes

s.b<Y+7/N2_QQ

Takes a list. Outputs 1 for creepy, 0 for not-creepy.

Try it!

explanation

s.b<Y+7/N2_QQ
 .b       _QQ        # map over the list and it's reversal (variables: Y,N)
   <Y+7/N2           # Y < N/2 + 7
s                    # sum: False + False = 0; True + False = 1 (; True + True = 2 can never occur, because one of the ages is always larger or equal) 

KarlKastor

Posted 2017-05-24T18:14:40.520

Reputation: 2 352

0

CJam, 10 bytes

q~$~2d/7+<

Takes input as a list.

Try it online!

Explanation

q~          e# Read and eval input.
  $         e# Sort the list.
   ~        e# Dump the list on the stack.
    2d/7+   e# Apply age/2+7 to the greater age.
         <  e# Check if the other age is less than that.

Business Cat

Posted 2017-05-24T18:14:40.520

Reputation: 8 927

Do you need the d? all the test cases work without it. – Esolanging Fruit – 2017-05-24T20:41:41.833

@Challenger5 OP said not to round if the age is an odd number, so I assume so. – Business Cat – 2017-05-24T23:04:00.390

0

Actually, 12 bytes

;RZ⌠i½7+≤⌡Mπ

Try it online, or run all test cases!

Outputs 1 if it's not creepy, and 0 if it is.

Explanation:

;RZ⌠i½7+≤⌡Mπ  implicit input: [a, b]
;RZ           zip input with its reverse ([[a,b], [b,a]])
   ⌠i½7+≤⌡M   for each pair:
    i           flatten
     ½7+        half of one plus 7
        ≤       is less than or equal to the other?
           π  product (acts as a boolean AND)

Mego

Posted 2017-05-24T18:14:40.520

Reputation: 32 998

0

q/kdb+, 17 16 bytes

Solution:

{(x&y)<7+.5*x|y}

Try it online! (oK rather than q/kdb+)

Examples:

q){(x&y)<7+.5*x|y}[22;18]
0b
q){(x&y)<7+.5*x|y}[22;17]
1b

Explanation:

Outputs creepy as boolean 1b (true, creepy) or 0b (false, not creepy)

{(x&y)<7+.5*x|y} / solution
{              } / lambda function with implicit parameters x and y
            x|y  / max of x and y
         .5*     / multiply by 0.5 (aka divide by 2)
       7+        / add 7
      <          / less than?
 (x&y)           / min of x and y

Notes:

Polyglot in:

  • q/kdb+
  • K
  • oK (see TIO link)

streetster

Posted 2017-05-24T18:14:40.520

Reputation: 3 635

0

Alice, 21 18 bytes

/o
\i@/sh2:-6-.H+n

Try it online!

-3 bytes thanks to Martin Ender.

Input is in any format that includes exactly two integers. Output is 1 if creepy and 0 if not creepy.

Explanation

ish2:-6-.H+no

i                Input numbers
 s               Sort the two ages
  h2:            Divide larger age by 2 rounded up
     -           Subtract from smaller age
      6-         Subtract 6
        .H+      Determine whether result is negative
           n     Push 1 if was negative, 0 otherwise
            o    Output

Nitrodon

Posted 2017-05-24T18:14:40.520

Reputation: 9 181

Would it be possible to shorten the formula by sorting the inputs with s (which puts the max on top and the min below)? – Martin Ender – 2017-05-30T09:15:50.690

0

tcl, 59

scan $argv %d\ %d x y
puts [expr max($x,$y)/2+7>min($x,$y)]

demo

To try, type

tclsh main.tcl Age1 Age2

on the green area.

sergiol

Posted 2017-05-24T18:14:40.520

Reputation: 3 055

0

Tcl, 44

I was losing to answers implementing it as a function, so I had to make mine into a function also:

proc c x\ y {expr max($x,$y)/2+7>min($x,$y)}

demo — You just have to press on the "Execute" button and see the 0 and 1 digits on the green area matching the question's creepiness values.

sergiol

Posted 2017-05-24T18:14:40.520

Reputation: 3 055

0

Wolfram Language, 16 bytes

Min@#<Max@#/2+7&

Takes input as a list.

Scott Milner

Posted 2017-05-24T18:14:40.520

Reputation: 1 806

0

S.I.L.O.S, 64 bytes

readIO
j=i
readIO
x=i/2+7-j
y=j/2+7-i
if x c
if y c
print k
lblc

Try it online!

It prints out the letter "k" if the relationship is ok, otherwise it prints out nothing. I couldn't figure out any mathemagical way with standard mathematical operators to do an if x>0 pr y>0 to save bytes.


Alternatively, we can create an "or gate" by exploiting the fact that x^.5 will error out if the number is negative.This removes the need for a conditional, but lengthens our code. This version outputs 0 for creepy and some positive number for not creepy.

S.I.L.O.S, 67 bytes

readIO
j=i
readIO
x=0-i/2-7+j
y=0-j/2-7+i
a=x^.5+y^.5+1
printInt a

Try it online!

Rohan Jhunjhunwala

Posted 2017-05-24T18:14:40.520

Reputation: 2 569

0

Python 3, 115 bytes

Edit : Bugfix according to @Alexx Roche

a=int(input())
b=int(input())
c=a
d=b
if b < a:
 c=b
 d=a
if not c < d/2.0+7:
 print("Not ",end='')
print("Creepy")

Try it online!

LMD

Posted 2017-05-24T18:14:40.520

Reputation: 377

This answer is far from golfed. For example, you can right your if statements all on one line, remove excess whitespace in all your comparisons, take the input as simply a,b=eval(input()). Furthermore there are many changes in the algorithm you're using that could make it shorter. – FlipTack – 2017-11-20T20:59:49.873

0

MATL, 10 bytes

tEP-X>-14>

My first ever solution. :) Try it online!

Explainer:

t    % push the input array [a b] (possibly redundant)
EP   % push the flipped(P)+doubled(E) array [2b 2a]
-    % subtract to get [a-2b b-2a]
X>   % take the maximum
-14> % if either exceeds -14, then it is creepy af bro!

DrQuarius

Posted 2017-05-24T18:14:40.520

Reputation: 562

0

Ly, 8 bytes

a2/7+Lfp

Try it online!

Explanation:

a2/7+Lfp

a        # sort (implicit input)
 2/7+    # halve and add 7
     L   # less than?
      fp # pop value, leaving just the result
         # implicit output

LyricLy

Posted 2017-05-24T18:14:40.520

Reputation: 3 313

0

C, C++, Java, C#, D, 56 bytes

-1 byte thanks to Zacharý

int c(int a,int b){return((a>b?a:b)/2+7)>(a>b?b:a)?1:0;}

C, C++, D optimization : 52 bytes

int c(int a,int b){return((a>b?a:b)/2+7)>(a>b?b:a);}
  • C++ convert bool object to int implicitly ( false = 0, true = 1 )
  • In C, booleans are represented by integers values, where 0 is false, and 1 is true.
  • I barely know how to print something in D, so i won't comment about boolean to int conversions in this language Zacharý just informed me that D bool to int conversion works exactly like in C/C++
  • Unfortunately, Java and C# can't convert an integer to a boolean, so we need to use ternary operator.

HatsuPointerKun

Posted 2017-05-24T18:14:40.520

Reputation: 1 891

0

Dyalog APL, 11 bytes

⌊<(⌊7+.5×⌈)

Try it online!

Zacharý

Posted 2017-05-24T18:14:40.520

Reputation: 5 710

0

Sakura, 7 bytes

>Ƣ+ħ⓪7ƣ

Takes input as an array and outputs -1 if creepy and 0 otherwise.

Explanation:

>                     >
 Ƣ      max(         )
  +                +
   ħ             /2
    ⓪       input
     7              7
      ƣ                min(     )
                           input

TuxCrafting

Posted 2017-05-24T18:14:40.520

Reputation: 4 547

0

Jq 1.5, 11 bytes

max/2+7>min

Try it online!

jq170727

Posted 2017-05-24T18:14:40.520

Reputation: 411

0

BASH, 135 bytes

I dabbled in this area a few years ago. I think that Greg Martin's point should factor in, and wonder how he picked 13 and not, (for example) 12 as 13 is the upper bound of x < x/2+7. Leo what is the test cases for [14,21], [15,15] and [16,21]?

#!/bin/bash
[ $1 -lt $2 ]&&./$0 $2 $1&&exit
[ $(($1+$2)) -ge $(((($1-$2)/2)**2)) ]&&[ $((((($2*10)+5)/19)+7)) -lt $2 ]&&echo -n 'Not ';echo Creepy

(could save bytes by using ✗ for "Creepy" and ✓ for "Not Creepy" or exit codes)

Alexx Roche

Posted 2017-05-24T18:14:40.520

Reputation: 101

0

ARBLE, 25 bytes

lt(min(a,b),max(a,b)/2+7)

Try it online!

ATaco

Posted 2017-05-24T18:14:40.520

Reputation: 7 898

0

><>, 14 Bytes

:{:{(?r2,7+)n;

Pretty simple, but I don't see any obvious ways to cut down on characters.

Explanation:

               | Assume input is on the stack
:{:{           | Duplicate items on the stack (we pop them for inequality testing)
    (?r        | Sort them, so that the larger is on top of the stack
       2,7+    | Divide top item by 2 and add 7
           )n; | Print the truthy value of younger > (older/2) + 7

Prints 1 for non-creepy relationships, 0 for creepy ones

Bolce Bussiere

Posted 2017-05-24T18:14:40.520

Reputation: 970

0

Add++, 8 bytes

L,#2/7+>

Try it online!

2 bytes off Jelly just feels weird

How it works

L,   - Lambda function
     - Example arguments: [15 50]
  #  - Sort;      STACK = [15 50]
  2/ - Halve;     STACK = [15 25]
  7+ - Add 7;     STACK = [15 32]
  >  - Greater;   STACK = [1]

caird coinheringaahing

Posted 2017-05-24T18:14:40.520

Reputation: 13 702

0

Befunge, 28 bytes

&:&:00p`00g\> #0 #\_\7-2*`.@

Try It Online

Since Befunge uses integer math, I flipped it and added 7 to the minimum then multiplied by 2. 1 = Creepy, 0 = Not creepy

Jo King

Posted 2017-05-24T18:14:40.520

Reputation: 38 234

0

Pyt, 7 bytes

Đ↔₂7+≥Π

Try it online!

Takes input as an array of integers

Explanation:

       Implicit input [x,y]
Đ      Duplicate the array  [x,y],[x,y]
↔      Flip the top array   [x,y],[y,x]
₂      Divide the top of the stack by 2    [x,y],[y/2,x/2]
7+     Add 7 to each element of the top of the stack    [x,y],[y/2+7,x/2+7]
≥      Is the second on the stack greater than or equal to the top elementwise [x>=y/2+7,y>=x/2+7]
Π      Take the product (auto-casts to integers)
       Implicit print

mudkip201

Posted 2017-05-24T18:14:40.520

Reputation: 833

0

Stax, 6 bytes

Æ╠àá;╚

Run and debug online

Here's the ungolfed ascii representation of the same program.

oE  sort inputs and push each to stack, now the larger age is on top of the stack
^h  increment larger age and integer divide by 2
7+  add 7
<   is the first number less than the second?

Run this one

recursive

Posted 2017-05-24T18:14:40.520

Reputation: 8 616

0

Japt, 10 bytes

n v <U/2+7

Try it online!

Takes a 2-element array as input.

How it works

Un v <U/2+7

Un  Sort the input
v   Pop the first element (smaller one)
<   less than...
U/2+7  Implicitly cast the remaining 1-length array to number (larger one)
       then calculate /2+7

Bubbler

Posted 2017-05-24T18:14:40.520

Reputation: 16 616