Skip to main content
Improved conditionals in code
Source Link

Python 2, 123 120 bytes

N=sorted(map(int,raw_input().split(' ')));print(''.join((''if n+1in N else'-'+`n`)if n-1in N else' '+`n`for n in N)[1:])

If the input can be a list as a function argument then (thanks mbomb007 and xnor for the conditionals)

93 9090 81 bytes

def f(N):print''.join((''if' '+`n`,`-n`*-~-(n+1in N else`-n`)if n)[n-1in N else' '+`n`forN]for n in sorted(N))[1:]

(77 bytes if leading whitespace is acceptable - drop the final [1:])

Python 2, 123 120 bytes

N=sorted(map(int,raw_input().split(' ')));print(''.join((''if n+1in N else'-'+`n`)if n-1in N else' '+`n`for n in N)[1:])

If the input can be a list as a function argument then

93 90 bytes

def f(N):print''.join((''if n+1in N else`-n`)if n-1in N else' '+`n`for n in sorted(N))[1:]

Python 2, 123 120 bytes

N=sorted(map(int,raw_input().split(' ')));print(''.join((''if n+1in N else'-'+`n`)if n-1in N else' '+`n`for n in N)[1:])

If the input can be a list as a function argument then (thanks mbomb007 and xnor for the conditionals)

93 90 81 bytes

def f(N):print''.join((' '+`n`,`-n`*-~-(n+1in N))[n-1in N]for n in sorted(N))[1:]

(77 bytes if leading whitespace is acceptable - drop the final [1:])

Golfed more
Source Link

Python 2, 123 120 bytes

N=sorted(map(int,raw_input().split(' ')));print(''.join((''if n+1in N else'-'+`n`)if n-1in N else' '+`n`for n in N)[1:])

If the input can be a list as a function argument then

9393 90 bytes

def f(N):print''.join((''if n+1in N else'else`-'+`n`n`)if n-1in N else' '+`n`for n in sorted(N))[1:]

Python 2, 123 120 bytes

N=sorted(map(int,raw_input().split(' ')));print(''.join((''if n+1in N else'-'+`n`)if n-1in N else' '+`n`for n in N)[1:])

If the input can be a list as a function argument then

93 bytes

def f(N):print''.join((''if n+1in N else'-'+`n`)if n-1in N else' '+`n`for n in sorted(N))[1:]

Python 2, 123 120 bytes

N=sorted(map(int,raw_input().split(' ')));print(''.join((''if n+1in N else'-'+`n`)if n-1in N else' '+`n`for n in N)[1:])

If the input can be a list as a function argument then

93 90 bytes

def f(N):print''.join((''if n+1in N else`-n`)if n-1in N else' '+`n`for n in sorted(N))[1:]
added 218 characters in body
Source Link

Python 2, 123 120 bytes

N=sorted(map(int,raw_input().split(' ')));print(''.join((''if n+1in N else'-'+`n`)if n-1in N else' '+`n`for n in N)[1:])

If the input can be a list as a function argument then

93 bytes

def f(N):print''.join((''if n+1in N else'-'+`n`)if n-1in N else' '+`n`for n in sorted(N))[1:]

Python 2, 123 120 bytes

N=sorted(map(int,raw_input().split(' ')));print(''.join((''if n+1in N else'-'+`n`)if n-1in N else' '+`n`for n in N)[1:])

Python 2, 123 120 bytes

N=sorted(map(int,raw_input().split(' ')));print(''.join((''if n+1in N else'-'+`n`)if n-1in N else' '+`n`for n in N)[1:])

If the input can be a list as a function argument then

93 bytes

def f(N):print''.join((''if n+1in N else'-'+`n`)if n-1in N else' '+`n`for n in sorted(N))[1:]
deleted 2 characters in body
Source Link
mbomb007
  • 23.5k
  • 7
  • 63
  • 135
Loading
Golfed code
Source Link
Loading
added "prettify" markup for readability
Source Link
mbomb007
  • 23.5k
  • 7
  • 63
  • 135
Loading
Source Link
Loading