# Is this relationship creepy?

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

• How 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. May 24, 2017 at 18:20
• @MartinEnder The value is a minimum, so do not round at all. It doesn't have to be an integer.
– Leo
May 24, 2017 at 18:24
• You could also add 13, 13 - Creepy. May 24, 2017 at 19:20
• 47, 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. May 26, 2017 at 15:01
• @DavidConrad - well yeah. its basically beastiality on his part.... May 26, 2017 at 16:47

# Python 3, 26 bytes

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


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

• It appears you could actually assume a tuple where it's always (younger,older) - just asked OP - wonder what he'll say. May 25, 2017 at 16:07
• @rm-vanda I asked earlier, you can't assume May 26, 2017 at 17:28

# 05AB1E, 8 6 bytes

;7+R‹Z

         # 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

• As a C programmer I agree that 2 is truthy. May 26, 2017 at 12:44
• @gmatht This should always return either 0 or 1, never 2. May 26, 2017 at 14:07
• [13,13] is doubly creepy. May 27, 2017 at 3:30
• @gmatht I guess that would be double. I didn't think about numbers that small. It's still truthy though. May 27, 2017 at 4:13
• @Riley 2 is not truthy, see this.
– Okx
Jun 2, 2017 at 17:40

# NAND gates, 551

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.

# 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!

• Noticed an obvious optimization. If you point it out before I edit, I'll still credit you! Sep 4, 2017 at 0:02

# C#, 22 bytes

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

• I'm not much of a C# programmer, but is the final semicolon required as part of the function? May 27, 2017 at 19:02
• @OlivierGrégoire It's just invalid syntax if it's omitted; this is an anonymous function
– cat
May 27, 2017 at 22:00

# 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!

• you should flip the comparison, it should be like >b not <b May 24, 2017 at 20:26
• 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" May 24, 2017 at 20:40
• okay I've fixed the error, but the logic is wrong, it return true, tio.run May 24, 2017 at 20:42
• @Tas nope. May 24, 2017 at 23:35
• Cheers, thanks for the link
– Tas
May 24, 2017 at 23:39

# 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));

• Save a byte with currying: a=>b=> instead of (a,b)=>, call with f(40)(40). May 24, 2017 at 19:30
• @StephenS, thank you, learned something new! May 24, 2017 at 19:32
• 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. May 24, 2017 at 19:33

# R, 26 25 bytes

-1 byte thanks to @djhurio

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


Try it online!

# Jelly, 6 bytes

H+7>ṚṀ


Try it online!

• Well, its the same now... ;p May 24, 2017 at 21:47
• @Draco18s It was always the same with the earlier 05AB1E submission though. May 25, 2017 at 11:31

## 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.

# TI-Basic, 2010 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'.

• Does TI-BASIC automatically close parentheses at a testing-symbol (< <= = != >= >)? Sep 4, 2017 at 16:03
• @Zacharý No, TI-Basic only closes parentheses at the end of a line or a colon. Sep 4, 2017 at 16:16
• Oh, whoops I forgot that the input was being taken as a list of numbers! Sep 4, 2017 at 16:21

# 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.

• Welcome to the site! May 25, 2017 at 12:22
• Wow, nice, GNU APL, haven't seen that in a while. Sep 4, 2017 at 14:10
• 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. Sep 4, 2017 at 14:11
• @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. Sep 4, 2017 at 14:14
• Try out ngn-apl. It's open-source like GNU APL, but in all honesty it's better. Sep 4, 2017 at 14:20

# 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

• Hi, please be sure to properly format your code using the markdown system.
– Leo
May 24, 2017 at 18:47
• don't worry, someone beat me to it, ill fix it though May 24, 2017 at 18:47
• You can get rid of some of the spaces there :) May 24, 2017 at 18:47
• 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. May 24, 2017 at 18:55
• lambda 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! May 31, 2017 at 1:31

# 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))

# 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");
}
}
}

• +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?.. :) May 26, 2017 at 10:22
• Thanks 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. :) May 26, 2017 at 10:40

# 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.

• Surely this fails on [37,53] (not in the test suite but) within the (x/2)+7 spirit of this fairway Oct 15, 2017 at 12:32
• @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 Oct 17, 2017 at 3:56

# 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)


# TI-Basic, 109 10 bytes

2min(Ans)-14≤max(Ans


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

# 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               *)

• Save 2 bytes by taking the ages as a list: Max@#/2+7<Min@#& May 24, 2017 at 19:28

## SAS, 77 bytes

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


# 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 }  # 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! # 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! • you can remove the space in lambda *a Nov 30, 2017 at 23:37 # 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. • It doesn't need to output a string like that, can be truthy or falsy – Leo May 24, 2017 at 18:26 • Nice golf. That was quick. May 24, 2017 at 18:38 # PHP, 29 Bytes prints 1 for creepy, nothing for Not creepy <?=max($_GET)/2+7>min($_GET);  Try it online! • As I understand the rules this fails on [34,19] Oct 15, 2017 at 12:43 # 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.  # 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  # 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  • 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! May 25, 2017 at 2:53 • @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. May 25, 2017 at 3:04 • @Jordan you should see some of the other more complex J-uby answers. They're quite something. May 25, 2017 at 3:21 # 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  # 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!