Skip to main content
Commonmark migration
Source Link

#K4, 13 12 11 bytes

K4, 13 12 11 bytes

Solution:

(*1?)\[0<;]

Examples:

q)k)(*1?)\[0<;] 100
100 77 30 17 12 2 0
q)k)(*1?)\[0<;] 100
100 37 28 20 2 0
q)k)(*1?)\[0<;] 100
100 77 61 55 53 6 2 0
q)k)(*1?)\[0<;] 100
100 12 1 0

Explanation:

Iterate over expression while x is greater than zero.

(*1?)\[0<;] / the solution
(   )\[0<;] / iterate over brackets whilst 0< evaluates true
  1?        / 1 choose (returns a 1-item list)
 *          / take the first

Bonus:

A 14 byte solution that also works in K (oK); this one is an if/else version of the same theme:

{$[x;*1?x;x]}\

Try it online!

#K4, 13 12 11 bytes

Solution:

(*1?)\[0<;]

Examples:

q)k)(*1?)\[0<;] 100
100 77 30 17 12 2 0
q)k)(*1?)\[0<;] 100
100 37 28 20 2 0
q)k)(*1?)\[0<;] 100
100 77 61 55 53 6 2 0
q)k)(*1?)\[0<;] 100
100 12 1 0

Explanation:

Iterate over expression while x is greater than zero.

(*1?)\[0<;] / the solution
(   )\[0<;] / iterate over brackets whilst 0< evaluates true
  1?        / 1 choose (returns a 1-item list)
 *          / take the first

Bonus:

A 14 byte solution that also works in K (oK); this one is an if/else version of the same theme:

{$[x;*1?x;x]}\

Try it online!

K4, 13 12 11 bytes

Solution:

(*1?)\[0<;]

Examples:

q)k)(*1?)\[0<;] 100
100 77 30 17 12 2 0
q)k)(*1?)\[0<;] 100
100 37 28 20 2 0
q)k)(*1?)\[0<;] 100
100 77 61 55 53 6 2 0
q)k)(*1?)\[0<;] 100
100 12 1 0

Explanation:

Iterate over expression while x is greater than zero.

(*1?)\[0<;] / the solution
(   )\[0<;] / iterate over brackets whilst 0< evaluates true
  1?        / 1 choose (returns a 1-item list)
 *          / take the first

Bonus:

A 14 byte solution that also works in K (oK); this one is an if/else version of the same theme:

{$[x;*1?x;x]}\

Try it online!

another byte shaved off.
Source Link
mkst
  • 5.2k
  • 12
  • 19

#K4, 13 1212 11 bytes

Solution:

(*1?)\[{x};]\[0<;]

Examples:

q)k)(*1?)\[{x};]\[0<;] 100
100 5177 2930 2517 1512 92 0
q)k)(*1?)\[{x};]\[0<;] 100
100 637 28 20 2 0
q)k)(*1?)\[{x};]\[0<;] 100
100 7277 1361 55 53 6 2 0
q)k)(*1?)\[{x};]\[0<;] 100
100 9 512 1 0

Explanation:

IteratesIterate over expression while x is notgreater than zero.

(*1?)\[{x};]\[0<;] / the solution
(   )\[{x};]\[0<;] / iterate over brackets whilst {x}0< evaluates true
  1?         / 1 choose (returns a 1-item list)
 *           / take the first

Bonus:

A 14 byte solution that also works in K (oK); this one is an if/else version of the same theme:

{$[x;*1?x;x]}\

Try it online!

#K4, 13 12 bytes

Solution:

(*1?)\[{x};]

Examples:

q)k)(*1?)\[{x};] 100
100 51 29 25 15 9 0
q)k)(*1?)\[{x};] 100
100 6 2 0
q)k)(*1?)\[{x};] 100
100 72 13 0
q)k)(*1?)\[{x};] 100
100 9 5 1 0

Explanation:

Iterates over expression while x is not zero.

(*1?)\[{x};] / the solution
(   )\[{x};] / iterate over brackets whilst {x} evaluates true
  1?         / 1 choose (returns a 1-item list)
 *           / take the first

Bonus:

A 14 byte solution that also works in K (oK); this one is an if/else version of the same theme:

{$[x;*1?x;x]}\

Try it online!

#K4, 13 12 11 bytes

Solution:

(*1?)\[0<;]

Examples:

q)k)(*1?)\[0<;] 100
100 77 30 17 12 2 0
q)k)(*1?)\[0<;] 100
100 37 28 20 2 0
q)k)(*1?)\[0<;] 100
100 77 61 55 53 6 2 0
q)k)(*1?)\[0<;] 100
100 12 1 0

Explanation:

Iterate over expression while x is greater than zero.

(*1?)\[0<;] / the solution
(   )\[0<;] / iterate over brackets whilst 0< evaluates true
  1?        / 1 choose (returns a 1-item list)
 *          / take the first

Bonus:

A 14 byte solution that also works in K (oK); this one is an if/else version of the same theme:

{$[x;*1?x;x]}\

Try it online!

Source Link
mkst
  • 5.2k
  • 12
  • 19

#K4, 13 12 bytes

Solution:

(*1?)\[{x};]

Examples:

q)k)(*1?)\[{x};] 100
100 51 29 25 15 9 0
q)k)(*1?)\[{x};] 100
100 6 2 0
q)k)(*1?)\[{x};] 100
100 72 13 0
q)k)(*1?)\[{x};] 100
100 9 5 1 0

Explanation:

Iterates over expression while x is not zero.

(*1?)\[{x};] / the solution
(   )\[{x};] / iterate over brackets whilst {x} evaluates true
  1?         / 1 choose (returns a 1-item list)
 *           / take the first

Bonus:

A 14 byte solution that also works in K (oK); this one is an if/else version of the same theme:

{$[x;*1?x;x]}\

Try it online!