Skip to main content
Added a cut: see https://codegolf.meta.stackexchange.com/q/25112/16766
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

Brachylog, 78 bytes

⟦₁s.+?!

Try it online!

Explanation

⟦₁s.+?!∧ ⟦₁  Inclusive range from 1 to the input number s  A consecutive sublist (trying longest sublists first) .  is the output +  Its sum ?  is the input  ! Don't try any further possibilities  ∧ Break unification with the output 

Brachylog, 7 bytes

⟦₁s.+?∧ 

Try it online!

Explanation

⟦₁s.+?∧ ⟦₁ Inclusive range from 1 to the input number s A consecutive sublist (trying longest sublists first) . is the output + Its sum ? is the input ∧ Break unification with the output 

Brachylog, 8 bytes

⟦₁s.+?!

Try it online!

Explanation

⟦₁s.+?!∧ ⟦₁  Inclusive range from 1 to the input number s  A consecutive sublist (trying longest sublists first) .  is the output +  Its sum ?  is the input  ! Don't try any further possibilities  ∧ Break unification with the output 
Source Link
DLosc
  • 40.7k
  • 6
  • 87
  • 142

Brachylog, 7 bytes

⟦₁s.+?∧ 

Try it online!

Explanation

⟦₁s.+?∧ ⟦₁ Inclusive range from 1 to the input number s A consecutive sublist (trying longest sublists first) . is the output + Its sum ? is the input ∧ Break unification with the output