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\$ 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
    May 24, 2017 at 18:24
  • 86
    \$\begingroup\$ You could also add 13, 13 - Creepy. \$\endgroup\$ 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\$ May 26, 2017 at 15:01
  • 9
    \$\begingroup\$ @DavidConrad - well yeah. its basically beastiality on his part.... \$\endgroup\$
    – Batman
    May 26, 2017 at 16:47

74 Answers 74

1
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ It doesn't need to output a string like that, can be truthy or falsy \$\endgroup\$
    – Leo
    May 24, 2017 at 18:26
  • \$\begingroup\$ Nice golf. That was quick. \$\endgroup\$
    – MD XF
    May 24, 2017 at 18:38
1
\$\begingroup\$

PHP, 29 Bytes

prints 1 for creepy, nothing for Not creepy

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

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ As I understand the rules this fails on [34,19] \$\endgroup\$ Oct 15, 2017 at 12:43
1
\$\begingroup\$

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

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

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 
\$\endgroup\$
3
  • \$\begingroup\$ 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! \$\endgroup\$
    – Jordan
    May 25, 2017 at 2:53
  • \$\begingroup\$ @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. \$\endgroup\$
    – Cyoce
    May 25, 2017 at 3:04
  • \$\begingroup\$ @Jordan you should see some of the other more complex J-uby answers. They're quite something. \$\endgroup\$
    – Cyoce
    May 25, 2017 at 3:21
1
\$\begingroup\$

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

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!

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

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

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

z-shell (zsh), 38 bytes

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

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

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

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

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

Try it online!

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

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)

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

ARBLE, 25 bytes

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

Try it online!

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

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!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – FlipTack
    Nov 20, 2017 at 20:59
1
\$\begingroup\$

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

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

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

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

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]
\$\endgroup\$
2
  • \$\begingroup\$ I see no output when I run it. \$\endgroup\$ Aug 16, 2023 at 7:24
  • \$\begingroup\$ @TheEmptyStringPhotographer That's because it's an anonymous function. You need to actually call it to get output, which you can do with the -i flag: Try it online! \$\endgroup\$ Aug 16, 2023 at 11:39
1
\$\begingroup\$

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

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

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

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

Vyxal, 8 bytes

sh½7+⁰t≥

Try it Online!

Inputs are a 2 element list.

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

Husk, 8 bytes

F·>o+7½O

Takes input as a 2-element list

F·>o+7½O
       O  sort
F         fold / apply following binary function to the elements
 · o+7½   apply this to the second argument
      ½   halve
   o+7    then add 7
  >       compare          

Try it online!

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

Arturo, 20 bytes

$=>[>7+0.5*do sort&]

Try it!

$=>[       ; a function where input is assigned to &
    sort&  ; sort input
    do     ; dump both ages from input list onto the stack
    0.5*   ; multiply TOS (the higher age) by 0.5
    +7     ; add 7 to TOS
    >      ; is NOS greater than TOS?
]          ; end function
\$\endgroup\$
1
\$\begingroup\$

PowerShell, 60 bytes

$c={param($a,$b)[math]::max($a,$b)/2+7-gt[math]::min($a,$b)}

Try it online!

No doubt could be improved upon!

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

PowerShell, 42 bytes

    $c={param($a,$b)$a/2+7-gt$b-or$b/2+7-gt$a}

Rather than using [math]::min and ::max, I'm trying both $a vs $b and $b vs $a then -or the result.

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

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]
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Can't you just write this as a formula in a cell? \$\endgroup\$
    – Neil
    May 24, 2017 at 18:53
  • \$\begingroup\$ @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 \$\endgroup\$ May 25, 2017 at 13:10
  • \$\begingroup\$ Ah yes, VBA is a slightly different language. \$\endgroup\$
    – Neil
    May 25, 2017 at 13:26
0
\$\begingroup\$

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

shortC, 21 bytes

D(a,b)a/2+7<b|b/2+7<a
\$\endgroup\$
0
0
\$\begingroup\$

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.
\$\endgroup\$
2
  • \$\begingroup\$ Do you need the d? all the test cases work without it. \$\endgroup\$ May 24, 2017 at 20:41
  • \$\begingroup\$ @Challenger5 OP said not to round if the age is an odd number, so I assume so. \$\endgroup\$ May 24, 2017 at 23:04
0
\$\begingroup\$

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) 
\$\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.