Longest Increasing Substring
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
Given a list of positive integers, write code that finds the length of longest contiguous sub-list that is increasing (not strictly). That is the longest sublist such that each element is greater than or equal to the last.
For example if the input was:
$[1,1,2,1,1,4,5,3,2,1,1]$
The longest increasing sub-list would be $[1,1,4,5]$, so you would output $4$.
Your answer will be scored by taking its source as a list of bytes and then finding the length of the longest increasing sub-list of that list. A lower score is the goal. Ties are broken in favor of programs with fewer overall bytes.
code-challenge source-layout
add a comment |Â
up vote
4
down vote
favorite
Given a list of positive integers, write code that finds the length of longest contiguous sub-list that is increasing (not strictly). That is the longest sublist such that each element is greater than or equal to the last.
For example if the input was:
$[1,1,2,1,1,4,5,3,2,1,1]$
The longest increasing sub-list would be $[1,1,4,5]$, so you would output $4$.
Your answer will be scored by taking its source as a list of bytes and then finding the length of the longest increasing sub-list of that list. A lower score is the goal. Ties are broken in favor of programs with fewer overall bytes.
code-challenge source-layout
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Given a list of positive integers, write code that finds the length of longest contiguous sub-list that is increasing (not strictly). That is the longest sublist such that each element is greater than or equal to the last.
For example if the input was:
$[1,1,2,1,1,4,5,3,2,1,1]$
The longest increasing sub-list would be $[1,1,4,5]$, so you would output $4$.
Your answer will be scored by taking its source as a list of bytes and then finding the length of the longest increasing sub-list of that list. A lower score is the goal. Ties are broken in favor of programs with fewer overall bytes.
code-challenge source-layout
Given a list of positive integers, write code that finds the length of longest contiguous sub-list that is increasing (not strictly). That is the longest sublist such that each element is greater than or equal to the last.
For example if the input was:
$[1,1,2,1,1,4,5,3,2,1,1]$
The longest increasing sub-list would be $[1,1,4,5]$, so you would output $4$.
Your answer will be scored by taking its source as a list of bytes and then finding the length of the longest increasing sub-list of that list. A lower score is the goal. Ties are broken in favor of programs with fewer overall bytes.
code-challenge source-layout
code-challenge source-layout
asked 1 hour ago
W W
33.9k10150354
33.9k10150354
add a comment |Â
add a comment |Â
5 Answers
5
active
oldest
votes
up vote
1
down vote
Husk, 5 bytes, score = 2
00000000: bc6d 4cdc 14 â²mLáâÂÂ¥
Try it online!
It's unlikely to get a score lower than 2 with Husk because á
1 has a really high codepoint and there needs to be something before it to get the maximum and length. An attempt could be made with trying to use multiple functions but n
would be before any helper functions which has a really low codepoint so anything after it would create an increasing byte-sequence of at least length 2.
1: This seems like the best way to use for the comparison operators would need to follow the various split functions like âÂÂ
(span
).
Explanation
â²mLáâÂÂ¥ -- example input: [1,1,2,1,1,4,5,3,2,1,1]
áâÂÂ¥ -- group elements by geq: [[1,1,2],[1,1,4,5],[3],[2],[1,1]]
mL -- map length: [3,4,1,1,2]
â² -- maximum: 4
add a comment |Â
up vote
0
down vote
Jelly, 8 bytes, score 2
There is probably a score 1 solution somehow...
IṠõṣ-ZLâÂÂ
Try it online!
Source code as a list of byte values:
[73, 205, 9, 223, 45, 90, 76, 252]
How?
IṠõṣ-ZLâ - Link: list of integers e.g. [ 1, 1, 2, 1, 1, 4, 5, 3, 2, 1, 1]
I - increments [ 0, 1,-1, 0, 3, 1,-2,-1,-1, 0]
á¹ - sign [ 0, 1,-1, 0, 1, 1,-1,-1,-1, 0]
õ - start a new monadic chain (a low byte to stop score being 3)
- - literal minus one -1
á¹£ - split at [[0, 1], [0, 1, 1], , , [0]]
Z - transpose [[0, 0, 0], [1, 1], 1]
L - length 3
â - increment 4
add a comment |Â
up vote
0
down vote
Retina 0.8.2, 40 bytes, score 3
d+
$*
(?<=(1+)),(?!1)
ö
T`1`_
^O`
G,?
Try it online! Link includes itself as byte codes as input. Explanation:
d+
$*
Convert to unary.
(?<=(1+)),(?!1)
ö
Split on decreasing pairs.
T`1`_
Delete the digits.
^O`
Sort the commas in reverse order. (I would normally write this as O^
but can't do that here for obvious reasons.)
G,?
Count the longest comma run, and add one to include the final number.
add a comment |Â
up vote
0
down vote
MATL, score 2, 13 bytes
d0< ~Y'w)X>sQ
Uses ASCII encoding. Code points are 100, 48, 60, 32, 126, 89, 39, 119, 41, 88, 62, 115, 81
.
Input can be:
- An array of numbers.
- A string enclosed with single quotes. Single quotes within the string are escaped by duplicating.
Try it online!
add a comment |Â
up vote
0
down vote
Pyth, score 2 (8 bytes)
lefSIT.:
Try it here!
Code points [108, 101, 102, 83, 73, 84, 46, 58]
. Another shorter solution, leSI#.:
scores 3, but its code points are [108, 101, 83, 73, 35, 46, 58]
, which are very close to a score of 1, actually. Rearranging a bit may help Nevermind, the substrings built-in is .:
which cannot be rearranged, so the lowest score must be 2 if the program makes use of it.
How?
lefSIT.: Full program. Accepts either a list or a string from STDIN.
.: Substrings.
f T Only keep those that are...
SI Sorting-Invariant.
le Length of the last item.
add a comment |Â
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Husk, 5 bytes, score = 2
00000000: bc6d 4cdc 14 â²mLáâÂÂ¥
Try it online!
It's unlikely to get a score lower than 2 with Husk because á
1 has a really high codepoint and there needs to be something before it to get the maximum and length. An attempt could be made with trying to use multiple functions but n
would be before any helper functions which has a really low codepoint so anything after it would create an increasing byte-sequence of at least length 2.
1: This seems like the best way to use for the comparison operators would need to follow the various split functions like âÂÂ
(span
).
Explanation
â²mLáâÂÂ¥ -- example input: [1,1,2,1,1,4,5,3,2,1,1]
áâÂÂ¥ -- group elements by geq: [[1,1,2],[1,1,4,5],[3],[2],[1,1]]
mL -- map length: [3,4,1,1,2]
â² -- maximum: 4
add a comment |Â
up vote
1
down vote
Husk, 5 bytes, score = 2
00000000: bc6d 4cdc 14 â²mLáâÂÂ¥
Try it online!
It's unlikely to get a score lower than 2 with Husk because á
1 has a really high codepoint and there needs to be something before it to get the maximum and length. An attempt could be made with trying to use multiple functions but n
would be before any helper functions which has a really low codepoint so anything after it would create an increasing byte-sequence of at least length 2.
1: This seems like the best way to use for the comparison operators would need to follow the various split functions like âÂÂ
(span
).
Explanation
â²mLáâÂÂ¥ -- example input: [1,1,2,1,1,4,5,3,2,1,1]
áâÂÂ¥ -- group elements by geq: [[1,1,2],[1,1,4,5],[3],[2],[1,1]]
mL -- map length: [3,4,1,1,2]
â² -- maximum: 4
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Husk, 5 bytes, score = 2
00000000: bc6d 4cdc 14 â²mLáâÂÂ¥
Try it online!
It's unlikely to get a score lower than 2 with Husk because á
1 has a really high codepoint and there needs to be something before it to get the maximum and length. An attempt could be made with trying to use multiple functions but n
would be before any helper functions which has a really low codepoint so anything after it would create an increasing byte-sequence of at least length 2.
1: This seems like the best way to use for the comparison operators would need to follow the various split functions like âÂÂ
(span
).
Explanation
â²mLáâÂÂ¥ -- example input: [1,1,2,1,1,4,5,3,2,1,1]
áâÂÂ¥ -- group elements by geq: [[1,1,2],[1,1,4,5],[3],[2],[1,1]]
mL -- map length: [3,4,1,1,2]
â² -- maximum: 4
Husk, 5 bytes, score = 2
00000000: bc6d 4cdc 14 â²mLáâÂÂ¥
Try it online!
It's unlikely to get a score lower than 2 with Husk because á
1 has a really high codepoint and there needs to be something before it to get the maximum and length. An attempt could be made with trying to use multiple functions but n
would be before any helper functions which has a really low codepoint so anything after it would create an increasing byte-sequence of at least length 2.
1: This seems like the best way to use for the comparison operators would need to follow the various split functions like âÂÂ
(span
).
Explanation
â²mLáâÂÂ¥ -- example input: [1,1,2,1,1,4,5,3,2,1,1]
áâÂÂ¥ -- group elements by geq: [[1,1,2],[1,1,4,5],[3],[2],[1,1]]
mL -- map length: [3,4,1,1,2]
â² -- maximum: 4
edited 14 mins ago
answered 27 mins ago
BMO
10.1k21774
10.1k21774
add a comment |Â
add a comment |Â
up vote
0
down vote
Jelly, 8 bytes, score 2
There is probably a score 1 solution somehow...
IṠõṣ-ZLâÂÂ
Try it online!
Source code as a list of byte values:
[73, 205, 9, 223, 45, 90, 76, 252]
How?
IṠõṣ-ZLâ - Link: list of integers e.g. [ 1, 1, 2, 1, 1, 4, 5, 3, 2, 1, 1]
I - increments [ 0, 1,-1, 0, 3, 1,-2,-1,-1, 0]
á¹ - sign [ 0, 1,-1, 0, 1, 1,-1,-1,-1, 0]
õ - start a new monadic chain (a low byte to stop score being 3)
- - literal minus one -1
á¹£ - split at [[0, 1], [0, 1, 1], , , [0]]
Z - transpose [[0, 0, 0], [1, 1], 1]
L - length 3
â - increment 4
add a comment |Â
up vote
0
down vote
Jelly, 8 bytes, score 2
There is probably a score 1 solution somehow...
IṠõṣ-ZLâÂÂ
Try it online!
Source code as a list of byte values:
[73, 205, 9, 223, 45, 90, 76, 252]
How?
IṠõṣ-ZLâ - Link: list of integers e.g. [ 1, 1, 2, 1, 1, 4, 5, 3, 2, 1, 1]
I - increments [ 0, 1,-1, 0, 3, 1,-2,-1,-1, 0]
á¹ - sign [ 0, 1,-1, 0, 1, 1,-1,-1,-1, 0]
õ - start a new monadic chain (a low byte to stop score being 3)
- - literal minus one -1
á¹£ - split at [[0, 1], [0, 1, 1], , , [0]]
Z - transpose [[0, 0, 0], [1, 1], 1]
L - length 3
â - increment 4
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Jelly, 8 bytes, score 2
There is probably a score 1 solution somehow...
IṠõṣ-ZLâÂÂ
Try it online!
Source code as a list of byte values:
[73, 205, 9, 223, 45, 90, 76, 252]
How?
IṠõṣ-ZLâ - Link: list of integers e.g. [ 1, 1, 2, 1, 1, 4, 5, 3, 2, 1, 1]
I - increments [ 0, 1,-1, 0, 3, 1,-2,-1,-1, 0]
á¹ - sign [ 0, 1,-1, 0, 1, 1,-1,-1,-1, 0]
õ - start a new monadic chain (a low byte to stop score being 3)
- - literal minus one -1
á¹£ - split at [[0, 1], [0, 1, 1], , , [0]]
Z - transpose [[0, 0, 0], [1, 1], 1]
L - length 3
â - increment 4
Jelly, 8 bytes, score 2
There is probably a score 1 solution somehow...
IṠõṣ-ZLâÂÂ
Try it online!
Source code as a list of byte values:
[73, 205, 9, 223, 45, 90, 76, 252]
How?
IṠõṣ-ZLâ - Link: list of integers e.g. [ 1, 1, 2, 1, 1, 4, 5, 3, 2, 1, 1]
I - increments [ 0, 1,-1, 0, 3, 1,-2,-1,-1, 0]
á¹ - sign [ 0, 1,-1, 0, 1, 1,-1,-1,-1, 0]
õ - start a new monadic chain (a low byte to stop score being 3)
- - literal minus one -1
á¹£ - split at [[0, 1], [0, 1, 1], , , [0]]
Z - transpose [[0, 0, 0], [1, 1], 1]
L - length 3
â - increment 4
edited 23 mins ago
answered 37 mins ago
Jonathan Allan
48.8k534161
48.8k534161
add a comment |Â
add a comment |Â
up vote
0
down vote
Retina 0.8.2, 40 bytes, score 3
d+
$*
(?<=(1+)),(?!1)
ö
T`1`_
^O`
G,?
Try it online! Link includes itself as byte codes as input. Explanation:
d+
$*
Convert to unary.
(?<=(1+)),(?!1)
ö
Split on decreasing pairs.
T`1`_
Delete the digits.
^O`
Sort the commas in reverse order. (I would normally write this as O^
but can't do that here for obvious reasons.)
G,?
Count the longest comma run, and add one to include the final number.
add a comment |Â
up vote
0
down vote
Retina 0.8.2, 40 bytes, score 3
d+
$*
(?<=(1+)),(?!1)
ö
T`1`_
^O`
G,?
Try it online! Link includes itself as byte codes as input. Explanation:
d+
$*
Convert to unary.
(?<=(1+)),(?!1)
ö
Split on decreasing pairs.
T`1`_
Delete the digits.
^O`
Sort the commas in reverse order. (I would normally write this as O^
but can't do that here for obvious reasons.)
G,?
Count the longest comma run, and add one to include the final number.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Retina 0.8.2, 40 bytes, score 3
d+
$*
(?<=(1+)),(?!1)
ö
T`1`_
^O`
G,?
Try it online! Link includes itself as byte codes as input. Explanation:
d+
$*
Convert to unary.
(?<=(1+)),(?!1)
ö
Split on decreasing pairs.
T`1`_
Delete the digits.
^O`
Sort the commas in reverse order. (I would normally write this as O^
but can't do that here for obvious reasons.)
G,?
Count the longest comma run, and add one to include the final number.
Retina 0.8.2, 40 bytes, score 3
d+
$*
(?<=(1+)),(?!1)
ö
T`1`_
^O`
G,?
Try it online! Link includes itself as byte codes as input. Explanation:
d+
$*
Convert to unary.
(?<=(1+)),(?!1)
ö
Split on decreasing pairs.
T`1`_
Delete the digits.
^O`
Sort the commas in reverse order. (I would normally write this as O^
but can't do that here for obvious reasons.)
G,?
Count the longest comma run, and add one to include the final number.
answered 22 mins ago
Neil
76k744172
76k744172
add a comment |Â
add a comment |Â
up vote
0
down vote
MATL, score 2, 13 bytes
d0< ~Y'w)X>sQ
Uses ASCII encoding. Code points are 100, 48, 60, 32, 126, 89, 39, 119, 41, 88, 62, 115, 81
.
Input can be:
- An array of numbers.
- A string enclosed with single quotes. Single quotes within the string are escaped by duplicating.
Try it online!
add a comment |Â
up vote
0
down vote
MATL, score 2, 13 bytes
d0< ~Y'w)X>sQ
Uses ASCII encoding. Code points are 100, 48, 60, 32, 126, 89, 39, 119, 41, 88, 62, 115, 81
.
Input can be:
- An array of numbers.
- A string enclosed with single quotes. Single quotes within the string are escaped by duplicating.
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
MATL, score 2, 13 bytes
d0< ~Y'w)X>sQ
Uses ASCII encoding. Code points are 100, 48, 60, 32, 126, 89, 39, 119, 41, 88, 62, 115, 81
.
Input can be:
- An array of numbers.
- A string enclosed with single quotes. Single quotes within the string are escaped by duplicating.
Try it online!
MATL, score 2, 13 bytes
d0< ~Y'w)X>sQ
Uses ASCII encoding. Code points are 100, 48, 60, 32, 126, 89, 39, 119, 41, 88, 62, 115, 81
.
Input can be:
- An array of numbers.
- A string enclosed with single quotes. Single quotes within the string are escaped by duplicating.
Try it online!
edited 20 mins ago
answered 27 mins ago
Luis Mendo
73k885285
73k885285
add a comment |Â
add a comment |Â
up vote
0
down vote
Pyth, score 2 (8 bytes)
lefSIT.:
Try it here!
Code points [108, 101, 102, 83, 73, 84, 46, 58]
. Another shorter solution, leSI#.:
scores 3, but its code points are [108, 101, 83, 73, 35, 46, 58]
, which are very close to a score of 1, actually. Rearranging a bit may help Nevermind, the substrings built-in is .:
which cannot be rearranged, so the lowest score must be 2 if the program makes use of it.
How?
lefSIT.: Full program. Accepts either a list or a string from STDIN.
.: Substrings.
f T Only keep those that are...
SI Sorting-Invariant.
le Length of the last item.
add a comment |Â
up vote
0
down vote
Pyth, score 2 (8 bytes)
lefSIT.:
Try it here!
Code points [108, 101, 102, 83, 73, 84, 46, 58]
. Another shorter solution, leSI#.:
scores 3, but its code points are [108, 101, 83, 73, 35, 46, 58]
, which are very close to a score of 1, actually. Rearranging a bit may help Nevermind, the substrings built-in is .:
which cannot be rearranged, so the lowest score must be 2 if the program makes use of it.
How?
lefSIT.: Full program. Accepts either a list or a string from STDIN.
.: Substrings.
f T Only keep those that are...
SI Sorting-Invariant.
le Length of the last item.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Pyth, score 2 (8 bytes)
lefSIT.:
Try it here!
Code points [108, 101, 102, 83, 73, 84, 46, 58]
. Another shorter solution, leSI#.:
scores 3, but its code points are [108, 101, 83, 73, 35, 46, 58]
, which are very close to a score of 1, actually. Rearranging a bit may help Nevermind, the substrings built-in is .:
which cannot be rearranged, so the lowest score must be 2 if the program makes use of it.
How?
lefSIT.: Full program. Accepts either a list or a string from STDIN.
.: Substrings.
f T Only keep those that are...
SI Sorting-Invariant.
le Length of the last item.
Pyth, score 2 (8 bytes)
lefSIT.:
Try it here!
Code points [108, 101, 102, 83, 73, 84, 46, 58]
. Another shorter solution, leSI#.:
scores 3, but its code points are [108, 101, 83, 73, 35, 46, 58]
, which are very close to a score of 1, actually. Rearranging a bit may help Nevermind, the substrings built-in is .:
which cannot be rearranged, so the lowest score must be 2 if the program makes use of it.
How?
lefSIT.: Full program. Accepts either a list or a string from STDIN.
.: Substrings.
f T Only keep those that are...
SI Sorting-Invariant.
le Length of the last item.
answered 16 mins ago
Mr. Xcoder
30.6k758195
30.6k758195
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f173586%2flongest-increasing-substring%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password