82
\$\begingroup\$

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

74 Answers 74

24
\$\begingroup\$

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.

\$\endgroup\$
17
\$\begingroup\$

Python 3, 26 bytes

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

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

\$\endgroup\$
3
  • \$\begingroup\$ Had the same before I read existing answers. +1 \$\endgroup\$
    – ElPedro
    Commented May 24, 2017 at 20:08
  • \$\begingroup\$ It appears you could actually assume a tuple where it's always (younger,older) - just asked OP - wonder what he'll say. \$\endgroup\$
    – rm-vanda
    Commented May 25, 2017 at 16:07
  • \$\begingroup\$ @rm-vanda I asked earlier, you can't assume \$\endgroup\$
    – Stephen
    Commented May 26, 2017 at 17:28
16
\$\begingroup\$

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!

\$\endgroup\$
1
  • \$\begingroup\$ Noticed an obvious optimization. If you point it out before I edit, I'll still credit you! \$\endgroup\$ Commented Sep 4, 2017 at 0:02
15
\$\begingroup\$

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

C#, 22 bytes

n=>m=>n<m/2+7|m<n/2+7;
\$\endgroup\$
2
  • 1
    \$\begingroup\$ I'm not much of a C# programmer, but is the final semicolon required as part of the function? \$\endgroup\$ Commented May 27, 2017 at 19:02
  • 1
    \$\begingroup\$ @OlivierGrégoire It's just invalid syntax if it's omitted; this is an anonymous function \$\endgroup\$
    – cat
    Commented May 27, 2017 at 22:00
8
\$\begingroup\$

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!

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

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

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

R, 26 25 bytes

-1 byte thanks to @djhurio

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

Try it online!

\$\endgroup\$
0
6
\$\begingroup\$

Jelly, 6 bytes

H+7>ṚṀ

Try it online!

Seemingly different algorithm than Comrade's.

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

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.

\$\endgroup\$
5
\$\begingroup\$

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

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

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

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.

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

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

\$\endgroup\$
3
\$\begingroup\$

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");
    }
  }
}
\$\endgroup\$
2
  • 1
    \$\begingroup\$ +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?.. :) \$\endgroup\$ Commented May 26, 2017 at 10:22
  • 1
    \$\begingroup\$ 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. :) \$\endgroup\$ Commented May 26, 2017 at 10:40
3
\$\begingroup\$

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.

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

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)
\$\endgroup\$
3
\$\begingroup\$

Jq 1.5, 11 bytes

max/2+7>min

Try it online!

\$\endgroup\$
2
\$\begingroup\$

TI-Basic, 10 9 10 bytes

2min(Ans)-14≤max(Ans

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

\$\endgroup\$
0
2
\$\begingroup\$

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               *)
\$\endgroup\$
1
  • \$\begingroup\$ Save 2 bytes by taking the ages as a list: Max@#/2+7<Min@#& \$\endgroup\$
    – user61980
    Commented May 24, 2017 at 19:28
2
\$\begingroup\$

SAS, 77 bytes

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

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.

\$\endgroup\$
1
  • \$\begingroup\$ +1 for the %0 %2 %1 and bypassing interget aritmetic. \$\endgroup\$
    – stevefestl
    Commented May 28, 2017 at 12:38
2
\$\begingroup\$

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
}
\$\endgroup\$
2
\$\begingroup\$

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!

\$\endgroup\$
2
\$\begingroup\$

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!

\$\endgroup\$
1
  • \$\begingroup\$ you can remove the space in lambda *a \$\endgroup\$
    – Cyoce
    Commented Nov 30, 2017 at 23:37
2
\$\begingroup\$

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
\$\endgroup\$
2
\$\begingroup\$

Thunno 2 G, 5 bytes

½7+r<

Attempt This Online!

Port of Riley's 05AB1E answer.

Explanation

½7+r<  # Implicit input
½      # Halve each value
 7+    # Add seven to each
   r   # Reverse the list
    <  # Vectorised less than
       # Get the maximum
       # Implicit output
\$\endgroup\$
2
\$\begingroup\$

K (oK), 16 bytes

{(x&y)<7+-2!x|y}

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Uiua, 8 bytes

<+7÷2⊃↥↧

Try it online!

<+7÷2⊃↥↧    input: two ages as two separate stack items
     ⊃↥↧    push max and min of the two ages
 +7÷2       max / 2 + 7
<           is greater than min?
\$\endgroup\$
2
\$\begingroup\$

Nekomata + -e, 5 bytes

Ṁä7+≥

Attempt This Online!

Returns True for not creepy, False for creepy.

Ṁ        Get the maximum of the input
 ä       Divide it by 2
  7+     Add 7
    ≥    Is every element of the input greater than or equal to that?
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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