Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Invariant is sort, not sum...
Source Link
Ven
  • 3.6k
  • 1
  • 20
  • 25

Pyth, 18 bytes

L?SIb0hys%L2>Bb1
y

Try it online!

-2 thanks to @Erik the Outgolfer.

The script has two line: the first one defines a function y, the second line calls y with the implicit Q (evaluated stdin) argument.

L?SIb0hys%L2>Bb1
L function y(b)
 ? if...
 SIb the Invariant b == sumsort(b) holds
 0 return 0
 h otherwise increment...
 y ...the return of a recursive call with:
 B the current argument "bifurcated", an array of:
 b - the original argument
 > 1 - same with the head popped off
 L map...
 % 2 ...take only every 2nd value in each array
 s and concat them back together

1

Pyth, 18 bytes

L?SIb0hys%L2>Bb1
y

Try it online!

-2 thanks to @Erik the Outgolfer.

The script has two line: the first one defines a function y, the second line calls y with the implicit Q (evaluated stdin) argument.

L?SIb0hys%L2>Bb1
L function y(b)
 ? if...
 SIb the Invariant b == sum(b) holds
 0 return 0
 h otherwise increment...
 y ...the return of a recursive call with:
 B the current argument "bifurcated", an array of:
 b - the original argument
 > 1 - same with the head popped off
 L map...
 % 2 ...take only every 2nd value in each array
 s and concat them back together

1

Pyth, 18 bytes

L?SIb0hys%L2>Bb1
y

Try it online!

-2 thanks to @Erik the Outgolfer.

The script has two line: the first one defines a function y, the second line calls y with the implicit Q (evaluated stdin) argument.

L?SIb0hys%L2>Bb1
L function y(b)
 ? if...
 SIb the Invariant b == sort(b) holds
 0 return 0
 h otherwise increment...
 y ...the return of a recursive call with:
 B the current argument "bifurcated", an array of:
 b - the original argument
 > 1 - same with the head popped off
 L map...
 % 2 ...take only every 2nd value in each array
 s and concat them back together

1

added 5 characters in body
Source Link
Ven
  • 3.6k
  • 1
  • 20
  • 25

Pyth, 18 bytes

L?SIb0hys%L2>Bb1
y

Try it online!

-2 thanks to @Erik the Outgolfer.

The script has two line: the first one defines a function y, the second line calls y with the implicit Q (evaluated stdin) argument.

L?SIb0hys%L2>Bb1
L function y(b)
 ? if...
 SIb the Invariant b == sum(b) holds
 0 return 0
 h otherwise increment...
 y ...the return of a recursive call with:
 B the current argument "bifurcated", an array of:
 b - the original argument
 > 1 - same with the head popped off
 L map...
 % 2 ...take only every 2nd value in each array
 s and concat them back together

1

Pyth, 18 bytes

L?SIb0hys%L2>Bb1
y

Try it online!

-2 thanks to @Erik the Outgolfer.

1

Pyth, 18 bytes

L?SIb0hys%L2>Bb1
y

Try it online!

-2 thanks to @Erik the Outgolfer.

The script has two line: the first one defines a function y, the second line calls y with the implicit Q (evaluated stdin) argument.

L?SIb0hys%L2>Bb1
L function y(b)
 ? if...
 SIb the Invariant b == sum(b) holds
 0 return 0
 h otherwise increment...
 y ...the return of a recursive call with:
 B the current argument "bifurcated", an array of:
 b - the original argument
 > 1 - same with the head popped off
 L map...
 % 2 ...take only every 2nd value in each array
 s and concat them back together

1

added 5 characters in body
Source Link
Ven
  • 3.6k
  • 1
  • 20
  • 25

Pyth, 18 bytes

L?SIb0hys%L2>Bb1
y

Try it online!

-2 thanks to @Erik the Outgolfer.

1

Pyth, 18 bytes

L?SIb0hys%L2>Bb1
y

Try it online!

-2 thanks to @Erik the Outgolfer.

Pyth, 18 bytes

L?SIb0hys%L2>Bb1
y

Try it online!

-2 thanks to @Erik the Outgolfer.

1

deleted 179 characters in body
Source Link
Ven
  • 3.6k
  • 1
  • 20
  • 25
Loading
added 1 character in body
Source Link
Ven
  • 3.6k
  • 1
  • 20
  • 25
Loading
deleted 47 characters in body
Source Link
Ven
  • 3.6k
  • 1
  • 20
  • 25
Loading
Source Link
Ven
  • 3.6k
  • 1
  • 20
  • 25
Loading

AltStyle によって変換されたページ (->オリジナル) /