- If you have a list of lists and first want to join each inner list by spaces, and then those space-delimited strings by newlines, the to-the-point approach would be
ðý»of course. However, the»already implicitly joins inner lists by spaces before joining by newlines, so theðýisn't necessary in this case: try it online. D(duplicate) andÐ(triplicate) in combination withs(swap) andŠ(triple-swapa,b,ctoc,a,b) are usually shorter than using©(save in global_variable) and®(push global_variable) inside loops. This saved a byte in this answer of mine, as well as two in this answer of mine.1⁄2(if 1, then increase counter_variable by 1) isn't necessary at the end of aμ(while counter_variable != a, do...), since it's done implicitly (saved a byte in this answer of mine)..Bimplicitly splits on new-lines. This was useful in this answer of mine when we were looking for an alternative for¡(split) while still keeping empty items (NOTE: Solution in the linked answer doesn't work when elements contain trailing spaces after splitting.) - Hopefully a builtin will be added to split but keep empty lines in the future.- [legacy version only]
SÖ(which of the digits of the input-integer can evenly divide the input-integer) will contain the number itself for the digits0(instead of divide-by-zero errors). For example,1053will result in[1,1053,0,1](1053 is divisible by 1 and 3; is not divisible by 5; and gives a division-by-zero error for 0). This was pretty useful in this answer of mine by taking the power of the list, since only1is truthy in 05AB1E and everything else is falsey.SÖPresulting in truthy (1) therefore means an input-integer is evenly divisible by each of its digits. - After seeing
û(palindromize a given string) I was surprised there isn't an is_palindrome builtin. But later on I realized only 2 bytes are needed to accomplish that, which areÂQ(whereÂis bifurcate, which is short forDR: Duplicate & Reverse copy; andQis to check if the top two values on the stack are equal). - When you want to filter a list by multiple things, it's usually cheaper to have multiple loose filters, rather than all combined in one filter. Because when you have two filters you'll need something along the lines of
Ds*(duplicate, swap, multiply to act as logical-AND) vs}ʒ(close first filter, filter again) when you use two filters. For example: in this challenge we have to list all numbers of four digits long, containing at least one0, and with a digit sum equal to9. Using a range[1000,10000]covers the number of four digits long, but then you are left with two more filters. Initially I used44°ŸʒD0åsSO9Q*(14 bytes), but by using two filters a byte can be saved:44°Ÿʒ0å}ʒSO9Q(13 bytes). (Which later got golfed to44°ŸεW°ö9Q(10 bytes) by @Grimmy.) - When you want to zip with integer
0as filler, you could use0ζ. One issue with this however is that the filler0will become a string"0", so if you later try to sort with mixed strings and integer, this will most likely not give the result you'd want. Here an example of how it will sort the zipped inner lists:0ζ€{. This can be fixed by adding an explicit cast to int (ï) after the zip, and only then sort:0ζï€{. However, using the3⁄4as constant0with the zip-filler, will cause it to remain an integer instead of a string during the zip. So3⁄4ζ€{will save a byte here. This tip was provided by @Mr.Xcoder to save a byte in this answer of mine. (The same applies toXinstead of1andYinstead of2.) - If you want to sum the digits of multiple numbers in a list, you could use
€SO. Shorter however is using1ö, which automatically vectorizes. This tip was provided by @Grimmy to save a byte here (and 2 bytes here). - If you're only dealing with non-negative integers, and you want to get a truthy value (
1) when the integer is either 0 or 1, you could of course use the obvious2‹. However, using!(factorial) will also only result in 1 (truthy) for0and1, and every other value will result in something higher (and thus falsey, since only1is truthy in 05AB1E). This tip was provided by @Grimmy to save a byte here. - If you want a list of all overlapping pairs (i.e.
[1,2,3,4,5,6,7,8,9]→[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9]]), most probably already knowü‚can be used (Try it online). But what if you want a list of overlapping triplets or quartets? The most obvious approach would seem to beŒ3ù(substrings & keep those of length 3 - Try it online). Butüactually has a (currently undocumented) feature as shortcut for thisü3(Try it online), which works with any integer given toü, including2to create overlapping pairs (Try it online). - If the stack is empty, some builtins will use the last value that was previously on the stack (and thus there is also no implicit input!), saving you on a potential duplicate. For example, in this 05AB1E answer the
×ばつwill use the9Llist twice, without a need to duplicate it first. And in this 05AB1E program theÿinside the string will use the11all three times, without the need to triplicate it first. - If we've used
|to get all (remaining) inputs, the nextIor implicit input will push this same list instead of the final input. Knowing this can sometimes save bytes, like in the top program of this answer of mine. - There is a flatten builtin
̃to flatten a multi-dimensional list to a single list: try it online. There is also a way to flatten a (potentially multi-dimensional) list of strings to a single list of characters withS: try it online. But what if we only want to flatten it down one level, instead of all the way? In that case,€`can be used if the order of items isn't important (try it online) orí€`if retaining the order of items is important (try it online). The unordered version is used pretty often in matrix-related challenges, like I used in this answer of mine. - You probably know how
δ(apply double-vectorized) can be used on two list arguments to execute it on every pair (e.g.δ‚will create pairs using the values in the two lists - try it online). You probably also know how it can be used as an apply-map with both a list and loose argument (e.g.0δKwill remove all 0s from each inner list, which is shorter than a regular mapε0K}- try it online). What you might nownot know, at least it was new to me, is when two integers are given as arguments, it implicitly uses their[1,n]ranged lists instead (e.g.δ‚again on two integer arguments will convert both to a list and applies the pairing to those - try it online). This saved two bytes in a couple of answers of mine (here and here for example).
- If you have a list of lists and first want to join each inner list by spaces, and then those space-delimited strings by newlines, the to-the-point approach would be
ðý»of course. However, the»already implicitly joins inner lists by spaces before joining by newlines, so theðýisn't necessary in this case: try it online. D(duplicate) andÐ(triplicate) in combination withs(swap) andŠ(triple-swapa,b,ctoc,a,b) are usually shorter than using©(save in global_variable) and®(push global_variable) inside loops. This saved a byte in this answer of mine, as well as two in this answer of mine.1⁄2(if 1, then increase counter_variable by 1) isn't necessary at the end of aμ(while counter_variable != a, do...), since it's done implicitly (saved a byte in this answer of mine)..Bimplicitly splits on new-lines. This was useful in this answer of mine when we were looking for an alternative for¡(split) while still keeping empty items (NOTE: Solution in the linked answer doesn't work when elements contain trailing spaces after splitting.) - Hopefully a builtin will be added to split but keep empty lines in the future.- [legacy version only]
SÖ(which of the digits of the input-integer can evenly divide the input-integer) will contain the number itself for the digits0(instead of divide-by-zero errors). For example,1053will result in[1,1053,0,1](1053 is divisible by 1 and 3; is not divisible by 5; and gives a division-by-zero error for 0). This was pretty useful in this answer of mine by taking the power of the list, since only1is truthy in 05AB1E and everything else is falsey.SÖPresulting in truthy (1) therefore means an input-integer is evenly divisible by each of its digits. - After seeing
û(palindromize a given string) I was surprised there isn't an is_palindrome builtin. But later on I realized only 2 bytes are needed to accomplish that, which areÂQ(whereÂis bifurcate, which is short forDR: Duplicate & Reverse copy; andQis to check if the top two values on the stack are equal). - When you want to filter a list by multiple things, it's usually cheaper to have multiple loose filters, rather than all combined in one filter. Because when you have two filters you'll need something along the lines of
Ds*(duplicate, swap, multiply to act as logical-AND) vs}ʒ(close first filter, filter again) when you use two filters. For example: in this challenge we have to list all numbers of four digits long, containing at least one0, and with a digit sum equal to9. Using a range[1000,10000]covers the number of four digits long, but then you are left with two more filters. Initially I used44°ŸʒD0åsSO9Q*(14 bytes), but by using two filters a byte can be saved:44°Ÿʒ0å}ʒSO9Q(13 bytes). (Which later got golfed to44°ŸεW°ö9Q(10 bytes) by @Grimmy.) - When you want to zip with integer
0as filler, you could use0ζ. One issue with this however is that the filler0will become a string"0", so if you later try to sort with mixed strings and integer, this will most likely not give the result you'd want. Here an example of how it will sort the zipped inner lists:0ζ€{. This can be fixed by adding an explicit cast to int (ï) after the zip, and only then sort:0ζï€{. However, using the3⁄4as constant0with the zip-filler, will cause it to remain an integer instead of a string during the zip. So3⁄4ζ€{will save a byte here. This tip was provided by @Mr.Xcoder to save a byte in this answer of mine. - If you want to sum the digits of multiple numbers in a list, you could use
€SO. Shorter however is using1ö, which automatically vectorizes. This tip was provided by @Grimmy to save a byte here (and 2 bytes here). - If you're only dealing with non-negative integers, and you want to get a truthy value (
1) when the integer is either 0 or 1, you could of course use the obvious2‹. However, using!(factorial) will also only result in 1 (truthy) for0and1, and every other value will result in something higher (and thus falsey, since only1is truthy in 05AB1E). This tip was provided by @Grimmy to save a byte here. - If you want a list of all overlapping pairs (i.e.
[1,2,3,4,5,6,7,8,9]→[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9]]), most probably already knowü‚can be used (Try it online). But what if you want a list of overlapping triplets or quartets? The most obvious approach would seem to beŒ3ù(substrings & keep those of length 3 - Try it online). Butüactually has a (currently undocumented) feature as shortcut for thisü3(Try it online), which works with any integer given toü, including2to create overlapping pairs (Try it online). - If the stack is empty, some builtins will use the last value that was previously on the stack (and thus there is also no implicit input!), saving you on a potential duplicate. For example, in this 05AB1E answer the
×ばつwill use the9Llist twice, without a need to duplicate it first. And in this 05AB1E program theÿinside the string will use the11all three times, without the need to triplicate it first. - If we've used
|to get all (remaining) inputs, the nextIor implicit input will push this same list instead of the final input. Knowing this can sometimes save bytes, like in the top program of this answer of mine. - There is a flatten builtin
̃to flatten a multi-dimensional list to a single list: try it online. There is also a way to flatten a (potentially multi-dimensional) list of strings to a single list of characters withS: try it online. But what if we only want to flatten it down one level, instead of all the way? In that case,€`can be used if the order of items isn't important (try it online) orí€`if retaining the order of items is important (try it online). The unordered version is used pretty often in matrix-related challenges, like I used in this answer of mine. - You probably know how
δ(apply double-vectorized) can be used on two list arguments to execute it on every pair (e.g.δ‚will create pairs using the values in the two lists - try it online). You probably also know how it can be used as an apply-map with both a list and loose argument (e.g.0δKwill remove all 0s from each inner list, which is shorter than a regular mapε0K}- try it online). What you might now know, at least it was new to me, is when two integers are given as arguments, it implicitly uses their[1,n]ranged lists instead (e.g.δ‚again on two integer arguments will convert both to a list and applies the pairing to those - try it online). This saved two bytes in a couple of answers of mine (here and here for example).
- If you have a list of lists and first want to join each inner list by spaces, and then those space-delimited strings by newlines, the to-the-point approach would be
ðý»of course. However, the»already implicitly joins inner lists by spaces before joining by newlines, so theðýisn't necessary in this case: try it online. D(duplicate) andÐ(triplicate) in combination withs(swap) andŠ(triple-swapa,b,ctoc,a,b) are usually shorter than using©(save in global_variable) and®(push global_variable) inside loops. This saved a byte in this answer of mine, as well as two in this answer of mine.1⁄2(if 1, then increase counter_variable by 1) isn't necessary at the end of aμ(while counter_variable != a, do...), since it's done implicitly (saved a byte in this answer of mine)..Bimplicitly splits on new-lines. This was useful in this answer of mine when we were looking for an alternative for¡(split) while still keeping empty items (NOTE: Solution in the linked answer doesn't work when elements contain trailing spaces after splitting.) - Hopefully a builtin will be added to split but keep empty lines in the future.- [legacy version only]
SÖ(which of the digits of the input-integer can evenly divide the input-integer) will contain the number itself for the digits0(instead of divide-by-zero errors). For example,1053will result in[1,1053,0,1](1053 is divisible by 1 and 3; is not divisible by 5; and gives a division-by-zero error for 0). This was pretty useful in this answer of mine by taking the power of the list, since only1is truthy in 05AB1E and everything else is falsey.SÖPresulting in truthy (1) therefore means an input-integer is evenly divisible by each of its digits. - After seeing
û(palindromize a given string) I was surprised there isn't an is_palindrome builtin. But later on I realized only 2 bytes are needed to accomplish that, which areÂQ(whereÂis bifurcate, which is short forDR: Duplicate & Reverse copy; andQis to check if the top two values on the stack are equal). - When you want to filter a list by multiple things, it's usually cheaper to have multiple loose filters, rather than all combined in one filter. Because when you have two filters you'll need something along the lines of
Ds*(duplicate, swap, multiply to act as logical-AND) vs}ʒ(close first filter, filter again) when you use two filters. For example: in this challenge we have to list all numbers of four digits long, containing at least one0, and with a digit sum equal to9. Using a range[1000,10000]covers the number of four digits long, but then you are left with two more filters. Initially I used44°ŸʒD0åsSO9Q*(14 bytes), but by using two filters a byte can be saved:44°Ÿʒ0å}ʒSO9Q(13 bytes). (Which later got golfed to44°ŸεW°ö9Q(10 bytes) by @Grimmy.) - When you want to zip with integer
0as filler, you could use0ζ. One issue with this however is that the filler0will become a string"0", so if you later try to sort with mixed strings and integer, this will most likely not give the result you'd want. Here an example of how it will sort the zipped inner lists:0ζ€{. This can be fixed by adding an explicit cast to int (ï) after the zip, and only then sort:0ζï€{. However, using the3⁄4as constant0with the zip-filler, will cause it to remain an integer instead of a string during the zip. So3⁄4ζ€{will save a byte here. This tip was provided by @Mr.Xcoder to save a byte in this answer of mine. (The same applies toXinstead of1andYinstead of2.) - If you want to sum the digits of multiple numbers in a list, you could use
€SO. Shorter however is using1ö, which automatically vectorizes. This tip was provided by @Grimmy to save a byte here (and 2 bytes here). - If you're only dealing with non-negative integers, and you want to get a truthy value (
1) when the integer is either 0 or 1, you could of course use the obvious2‹. However, using!(factorial) will also only result in 1 (truthy) for0and1, and every other value will result in something higher (and thus falsey, since only1is truthy in 05AB1E). This tip was provided by @Grimmy to save a byte here. - If you want a list of all overlapping pairs (i.e.
[1,2,3,4,5,6,7,8,9]→[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9]]), most probably already knowü‚can be used (Try it online). But what if you want a list of overlapping triplets or quartets? The most obvious approach would seem to beŒ3ù(substrings & keep those of length 3 - Try it online). Butüactually has a (currently undocumented) feature as shortcut for thisü3(Try it online), which works with any integer given toü, including2to create overlapping pairs (Try it online). - If the stack is empty, some builtins will use the last value that was previously on the stack (and thus there is also no implicit input!), saving you on a potential duplicate. For example, in this 05AB1E answer the
×ばつwill use the9Llist twice, without a need to duplicate it first. And in this 05AB1E program theÿinside the string will use the11all three times, without the need to triplicate it first. - If we've used
|to get all (remaining) inputs, the nextIor implicit input will push this same list instead of the final input. Knowing this can sometimes save bytes, like in the top program of this answer of mine. - There is a flatten builtin
̃to flatten a multi-dimensional list to a single list: try it online. There is also a way to flatten a (potentially multi-dimensional) list of strings to a single list of characters withS: try it online. But what if we only want to flatten it down one level, instead of all the way? In that case,€`can be used if the order of items isn't important (try it online) orí€`if retaining the order of items is important (try it online). The unordered version is used pretty often in matrix-related challenges, like I used in this answer of mine. - You probably know how
δ(apply double-vectorized) can be used on two list arguments to execute it on every pair (e.g.δ‚will create pairs using the values in the two lists - try it online). You probably also know how it can be used as an apply-map with both a list and loose argument (e.g.0δKwill remove all 0s from each inner list, which is shorter than a regular mapε0K}- try it online). What you might not know, at least it was new to me, is when two integers are given as arguments, it implicitly uses their[1,n]ranged lists instead (e.g.δ‚again on two integer arguments will convert both to a list and applies the pairing to those - try it online). This saved two bytes in a couple of answers of mine (here and here for example).
Kevin Cruijssen
- 136.2k
- 14
- 154
- 394
- If you have a list of lists and first want to join each inner list by spaces, and then those space-delimited strings by newlines, the to-the-point approach would be
ðý»of course. However, the»already implicitly joins inner lists by spaces before joining by newlines, so theðýisn't necessary in this case: try it online. D(duplicate) andÐ(triplicate) in combination withs(swap) andŠ(triple-swapa,b,ctoc,a,b) are usually shorter than using©(save in global_variable) and®(push global_variable) inside loops. This saved a byte in this answer of mine, as well as two in this answer of mine.1⁄2(if 1, then increase counter_variable by 1) isn't necessary at the end of aμ(while counter_variable != a, do...), since it's done implicitly (saved a byte in this answer of mine)..Bimplicitly splits on new-lines. This was useful in this answer of mine when we were looking for an alternative for¡(split) while still keeping empty items (NOTE: Solution in the linked answer doesn't work when elements contain trailing spaces after splitting.) - Hopefully a builtin will be added to split but keep empty lines in the future.- [legacy version only]
SÖ(which of the digits of the input-integer can evenly divide the input-integer) will contain the number itself for the digits0(instead of divide-by-zero errors). For example,1053will result in[1,1053,0,1](1053 is divisible by 1 and 3; is not divisible by 5; and gives a division-by-zero error for 0). This was pretty useful in this answer of mine by taking the power of the list, since only1is truthy in 05AB1E and everything else is falsey.SÖPresulting in truthy (1) therefore means an input-integer is evenly divisible by each of its digits. - After seeing
û(palindromize a given string) I was surprised there isn't an is_palindrome builtin. But later on I realized only 2 bytes are needed to accomplish that, which areÂQ(whereÂis bifurcate, which is short forDR: Duplicate & Reverse copy; andQis to check if the top two values on the stack are equal). - When you want to filter a list by multiple things, it's usually cheaper to have multiple loose filters, rather than all combined in one filter. Because when you have two filters you'll need something along the lines of
Ds*(duplicate, swap, multiply to act as logical-AND) vs}ʒ(close first filter, filter again) when you use two filters. For example: in this challenge we have to list all numbers of four digits long, containing at least one0, and with a digit sum equal to9. Using a range[1000,10000]covers the number of four digits long, but then you are left with two more filters. Initially I used44°ŸʒD0åsSO9Q*(14 bytes), but by using two filters a byte can be saved:44°Ÿʒ0å}ʒSO9Q(13 bytes). (Which later got golfed to44°ŸεW°ö9Q(10 bytes) by @Grimmy.) - When you want to zip with integer
0as filler, you could use0ζ. One issue with this however is that the filler0will become a string"0", so if you later try to sort with mixed strings and integer, this will most likely not give the result you'd want. Here an example of how it will sort the zipped inner lists:0ζ€{. This can be fixed by adding an explicit cast to int (ï) after the zip, and only then sort:0ζï€{. However, using the3⁄4as constant0with the zip-filler, will cause it to remain an integer instead of a string during the zip. So3⁄4ζ€{will save a byte here. This tip was provided by @Mr.Xcoder to save a byte in this answer of mine. - If you want to sum the digits of multiple numbers in a list, you could use
€SO. Shorter however is using1ö, which automatically vectorizes. This tip was provided by @Grimmy to save a byte here (and 2 bytes here). - If you're only dealing with non-negative integers, and you want to get a truthy value (
1) when the integer is either 0 or 1, you could of course use the obvious2‹. However, using!(factorial) will also only result in 1 (truthy) for0and1, and every other value will result in something higher (and thus falsey, since only1is truthy in 05AB1E). This tip was provided by @Grimmy to save a byte here. - If you want a list of all overlapping pairs (i.e.
[1,2,3,4,5,6,7,8,9]→[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9]]), most probably already knowü‚can be used (Try it online). But what if you want a list of overlapping triplets or quartets? The most obvious approach would seem to beŒ3ù(substrings & keep those of length 3 - Try it online). Butüactually has a (currently undocumented) feature as shortcut for thisü3(Try it online), which works with any integer given toü, including2to create overlapping pairs (Try it online). - If the stack is empty, some builtins will use the last value that was previously on the stack (and thus there is also no implicit input!), saving you on a potential duplicate. For example, in this 05AB1E answer the
×ばつwill use the9Llist twice, without a need to duplicate it first. And in this 05AB1E program theÿinside the string will use the11all three times, without the need to triplicate it first. - If we've used
|to get all (remaining) inputs, the nextIor implicit input will push this same list instead of the final input. Knowing this can sometimes save bytes, like in the top program of this answer of mine. - There is a flatten builtin
̃to flatten a multi-dimensional list to a single list: try it online. There is also a way to flatten a (potentially multi-dimensional) list of strings to a single list of characters withS: try it online. But what if we only want to flatten it down one level, instead of all the way? In that case,€`can be used if the order of items isn't important (try it online) orí€`if retaining the order of items is important (try it online). The unordered version is used pretty often in matrix-related challenges, like I used in this answer of mine this answer of mine . - You probably know how
δ(apply double-vectorized) can be used on two list arguments to execute it on every pair (e.g.δ‚will create pairs using the values in the two lists - try it online ). You probably also know how it can be used as an apply-map with both a list and loose argument (e.g.0δKwill remove all 0s from each inner list, which is shorter than a regular mapε0K}- try it online ). What you might now know, at least it was new to me, is when two integers are given as arguments, it implicitly uses their[1,n]ranged lists instead (e.g.δ‚again on two integer arguments will convert both to a list and applies the pairing to those - try it online ). This saved two bytes in a couple of answers of mine (here and here for example).
- If you have a list of lists and first want to join each inner list by spaces, and then those space-delimited strings by newlines, the to-the-point approach would be
ðý»of course. However, the»already implicitly joins inner lists by spaces before joining by newlines, so theðýisn't necessary in this case: try it online. D(duplicate) andÐ(triplicate) in combination withs(swap) andŠ(triple-swapa,b,ctoc,a,b) are usually shorter than using©(save in global_variable) and®(push global_variable) inside loops. This saved a byte in this answer of mine, as well as two in this answer of mine.1⁄2(if 1, then increase counter_variable by 1) isn't necessary at the end of aμ(while counter_variable != a, do...), since it's done implicitly (saved a byte in this answer of mine)..Bimplicitly splits on new-lines. This was useful in this answer of mine when we were looking for an alternative for¡(split) while still keeping empty items (NOTE: Solution in the linked answer doesn't work when elements contain trailing spaces after splitting.) - Hopefully a builtin will be added to split but keep empty lines in the future.- [legacy version only]
SÖ(which of the digits of the input-integer can evenly divide the input-integer) will contain the number itself for the digits0(instead of divide-by-zero errors). For example,1053will result in[1,1053,0,1](1053 is divisible by 1 and 3; is not divisible by 5; and gives a division-by-zero error for 0). This was pretty useful in this answer of mine by taking the power of the list, since only1is truthy in 05AB1E and everything else is falsey.SÖPresulting in truthy (1) therefore means an input-integer is evenly divisible by each of its digits. - After seeing
û(palindromize a given string) I was surprised there isn't an is_palindrome builtin. But later on I realized only 2 bytes are needed to accomplish that, which areÂQ(whereÂis bifurcate, which is short forDR: Duplicate & Reverse copy; andQis to check if the top two values on the stack are equal). - When you want to filter a list by multiple things, it's usually cheaper to have multiple loose filters, rather than all combined in one filter. Because when you have two filters you'll need something along the lines of
Ds*(duplicate, swap, multiply to act as logical-AND) vs}ʒ(close first filter, filter again) when you use two filters. For example: in this challenge we have to list all numbers of four digits long, containing at least one0, and with a digit sum equal to9. Using a range[1000,10000]covers the number of four digits long, but then you are left with two more filters. Initially I used44°ŸʒD0åsSO9Q*(14 bytes), but by using two filters a byte can be saved:44°Ÿʒ0å}ʒSO9Q(13 bytes). (Which later got golfed to44°ŸεW°ö9Q(10 bytes) by @Grimmy.) - When you want to zip with integer
0as filler, you could use0ζ. One issue with this however is that the filler0will become a string"0", so if you later try to sort with mixed strings and integer, this will most likely not give the result you'd want. Here an example of how it will sort the zipped inner lists:0ζ€{. This can be fixed by adding an explicit cast to int (ï) after the zip, and only then sort:0ζï€{. However, using the3⁄4as constant0with the zip-filler, will cause it to remain an integer instead of a string during the zip. So3⁄4ζ€{will save a byte here. This tip was provided by @Mr.Xcoder to save a byte in this answer of mine. - If you want to sum the digits of multiple numbers in a list, you could use
€SO. Shorter however is using1ö, which automatically vectorizes. This tip was provided by @Grimmy to save a byte here (and 2 bytes here). - If you're only dealing with non-negative integers, and you want to get a truthy value (
1) when the integer is either 0 or 1, you could of course use the obvious2‹. However, using!(factorial) will also only result in 1 (truthy) for0and1, and every other value will result in something higher (and thus falsey, since only1is truthy in 05AB1E). This tip was provided by @Grimmy to save a byte here. - If you want a list of all overlapping pairs (i.e.
[1,2,3,4,5,6,7,8,9]→[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9]]), most probably already knowü‚can be used (Try it online). But what if you want a list of overlapping triplets or quartets? The most obvious approach would seem to beŒ3ù(substrings & keep those of length 3 - Try it online). Butüactually has a (currently undocumented) feature as shortcut for thisü3(Try it online), which works with any integer given toü, including2to create overlapping pairs (Try it online). - If the stack is empty, some builtins will use the last value that was previously on the stack (and thus there is also no implicit input!), saving you on a potential duplicate. For example, in this 05AB1E answer the
×ばつwill use the9Llist twice, without a need to duplicate it first. And in this 05AB1E program theÿinside the string will use the11all three times, without the need to triplicate it first. - If we've used
|to get all (remaining) inputs, the nextIor implicit input will push this same list instead of the final input. Knowing this can sometimes save bytes, like in the top program of this answer of mine. - There is a flatten builtin
̃to flatten a multi-dimensional list to a single list: try it online. There is also a way to flatten a (potentially multi-dimensional) list of strings to a single list of characters withS: try it online. But what if we only want to flatten it down one level, instead of all the way? In that case,€`can be used if the order of items isn't important (try it online) orí€`if retaining the order of items is important (try it online). The unordered version is used pretty often in matrix-related challenges, like I used in this answer of mine.
- If you have a list of lists and first want to join each inner list by spaces, and then those space-delimited strings by newlines, the to-the-point approach would be
ðý»of course. However, the»already implicitly joins inner lists by spaces before joining by newlines, so theðýisn't necessary in this case: try it online. D(duplicate) andÐ(triplicate) in combination withs(swap) andŠ(triple-swapa,b,ctoc,a,b) are usually shorter than using©(save in global_variable) and®(push global_variable) inside loops. This saved a byte in this answer of mine, as well as two in this answer of mine.1⁄2(if 1, then increase counter_variable by 1) isn't necessary at the end of aμ(while counter_variable != a, do...), since it's done implicitly (saved a byte in this answer of mine)..Bimplicitly splits on new-lines. This was useful in this answer of mine when we were looking for an alternative for¡(split) while still keeping empty items (NOTE: Solution in the linked answer doesn't work when elements contain trailing spaces after splitting.) - Hopefully a builtin will be added to split but keep empty lines in the future.- [legacy version only]
SÖ(which of the digits of the input-integer can evenly divide the input-integer) will contain the number itself for the digits0(instead of divide-by-zero errors). For example,1053will result in[1,1053,0,1](1053 is divisible by 1 and 3; is not divisible by 5; and gives a division-by-zero error for 0). This was pretty useful in this answer of mine by taking the power of the list, since only1is truthy in 05AB1E and everything else is falsey.SÖPresulting in truthy (1) therefore means an input-integer is evenly divisible by each of its digits. - After seeing
û(palindromize a given string) I was surprised there isn't an is_palindrome builtin. But later on I realized only 2 bytes are needed to accomplish that, which areÂQ(whereÂis bifurcate, which is short forDR: Duplicate & Reverse copy; andQis to check if the top two values on the stack are equal). - When you want to filter a list by multiple things, it's usually cheaper to have multiple loose filters, rather than all combined in one filter. Because when you have two filters you'll need something along the lines of
Ds*(duplicate, swap, multiply to act as logical-AND) vs}ʒ(close first filter, filter again) when you use two filters. For example: in this challenge we have to list all numbers of four digits long, containing at least one0, and with a digit sum equal to9. Using a range[1000,10000]covers the number of four digits long, but then you are left with two more filters. Initially I used44°ŸʒD0åsSO9Q*(14 bytes), but by using two filters a byte can be saved:44°Ÿʒ0å}ʒSO9Q(13 bytes). (Which later got golfed to44°ŸεW°ö9Q(10 bytes) by @Grimmy.) - When you want to zip with integer
0as filler, you could use0ζ. One issue with this however is that the filler0will become a string"0", so if you later try to sort with mixed strings and integer, this will most likely not give the result you'd want. Here an example of how it will sort the zipped inner lists:0ζ€{. This can be fixed by adding an explicit cast to int (ï) after the zip, and only then sort:0ζï€{. However, using the3⁄4as constant0with the zip-filler, will cause it to remain an integer instead of a string during the zip. So3⁄4ζ€{will save a byte here. This tip was provided by @Mr.Xcoder to save a byte in this answer of mine. - If you want to sum the digits of multiple numbers in a list, you could use
€SO. Shorter however is using1ö, which automatically vectorizes. This tip was provided by @Grimmy to save a byte here (and 2 bytes here). - If you're only dealing with non-negative integers, and you want to get a truthy value (
1) when the integer is either 0 or 1, you could of course use the obvious2‹. However, using!(factorial) will also only result in 1 (truthy) for0and1, and every other value will result in something higher (and thus falsey, since only1is truthy in 05AB1E). This tip was provided by @Grimmy to save a byte here. - If you want a list of all overlapping pairs (i.e.
[1,2,3,4,5,6,7,8,9]→[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9]]), most probably already knowü‚can be used (Try it online). But what if you want a list of overlapping triplets or quartets? The most obvious approach would seem to beŒ3ù(substrings & keep those of length 3 - Try it online). Butüactually has a (currently undocumented) feature as shortcut for thisü3(Try it online), which works with any integer given toü, including2to create overlapping pairs (Try it online). - If the stack is empty, some builtins will use the last value that was previously on the stack (and thus there is also no implicit input!), saving you on a potential duplicate. For example, in this 05AB1E answer the
×ばつwill use the9Llist twice, without a need to duplicate it first. And in this 05AB1E program theÿinside the string will use the11all three times, without the need to triplicate it first. - If we've used
|to get all (remaining) inputs, the nextIor implicit input will push this same list instead of the final input. Knowing this can sometimes save bytes, like in the top program of this answer of mine. - There is a flatten builtin
̃to flatten a multi-dimensional list to a single list: try it online. There is also a way to flatten a (potentially multi-dimensional) list of strings to a single list of characters withS: try it online. But what if we only want to flatten it down one level, instead of all the way? In that case,€`can be used if the order of items isn't important (try it online) orí€`if retaining the order of items is important (try it online). The unordered version is used pretty often in matrix-related challenges, like I used in this answer of mine . - You probably know how
δ(apply double-vectorized) can be used on two list arguments to execute it on every pair (e.g.δ‚will create pairs using the values in the two lists - try it online ). You probably also know how it can be used as an apply-map with both a list and loose argument (e.g.0δKwill remove all 0s from each inner list, which is shorter than a regular mapε0K}- try it online ). What you might now know, at least it was new to me, is when two integers are given as arguments, it implicitly uses their[1,n]ranged lists instead (e.g.δ‚again on two integer arguments will convert both to a list and applies the pairing to those - try it online ). This saved two bytes in a couple of answers of mine (here and here for example).
- If you have a list of lists and first want to join each inner list by spaces, and then those space-delimited strings by newlines, the to-the-point approach would be
ðý»of course. However, the»already implicitly joins inner lists by spaces before joining by newlines, so theðýisn't necessary in this case: try it online. D(duplicate) andÐ(triplicate) in combination withs(swap) andŠ(triple-swapa,b,ctoc,a,b) are usually shorter than using©(save in global_variable) and®(push global_variable) inside loops. This saved a byte in this answer of mine, as well as two in this answer of mine.1⁄2(if 1, then increase counter_variable by 1) isn't necessary at the end of aμ(while counter_variable != a, do...), since it's done implicitly (saved a byte in this answer of mine)..Bimplicitly splits on new-lines. This was useful in this answer of mine when we were looking for an alternative for¡(split) while still keeping empty items (NOTE: Solution in the linked answer doesn't work when elements contain trailing spaces after splitting.) - Hopefully a builtin will be added to split but keep empty lines in the future.- [legacy version only]
SÖ(which of the digits of the input-integer can evenly divide the input-integer) will contain the number itself for the digits0(instead of divide-by-zero errors). For example,1053will result in[1,1053,0,1](1053 is divisible by 1 and 3; is not divisible by 5; and gives a division-by-zero error for 0). This was pretty useful in this answer of mine by taking the power of the list, since only1is truthy in 05AB1E and everything else is falsey.SÖPresulting in truthy (1) therefore means an input-integer is evenly divisible by each of its digits. - After seeing
û(palindromize a given string) I was surprised there isn't an is_palindrome builtin. But later on I realized only 2 bytes are needed to accomplish that, which areÂQ(whereÂis bifurcate, which is short forDR: Duplicate & Reverse copy; andQis to check if the top two values on the stack are equal). - When you want to filter a list by multiple things, it's usually cheaper to have multiple loose filters, rather than all combined in one filter. Because when you have two filters you'll need something along the lines of
Ds*(duplicate, swap, multiply to act as logical-AND) vs}ʒ(close first filter, filter again) when you use two filters. For example: in this challenge we have to list all numbers of four digits long, containing at least one0, and with a digit sum equal to9. Using a range[1000,10000]covers the number of four digits long, but then you are left with two more filters. Initially I used44°ŸʒD0åsSO9Q*(14 bytes), but by using two filters a byte can be saved:44°Ÿʒ0å}ʒSO9Q(13 bytes). (Which later got golfed to44°ŸεW°ö9Q(10 bytes) by @Grimmy.) - When you want to zip with integer
0as filler, you could use0ζ. One issue with this however is that the filler0will become a string"0", so if you later try to sort with mixed strings and integer, this will most likely not give the result you'd want. Here an example of how it will sort the zipped inner lists:0ζ€{. This can be fixed by adding an explicit cast to int (ï) after the zip, and only then sort:0ζï€{. However, using the3⁄4as constant0with the zip-filler, will cause it to remain an integer instead of a string during the zip. So3⁄4ζ€{will save a byte here. This tip was provided by @Mr.Xcoder to save a byte in this answer of mine. - If you want to sum the digits of multiple numbers in a list, you could use
€SO. Shorter however is using1ö, which automatically vectorizes. This tip was provided by @Grimmy to save a byte here (and 2 bytes here). - If you're only dealing with non-negative integers, and you want to get a truthy value (
1) when the integer is either 0 or 1, you could of course use the obvious2‹. However, using!(factorial) will also only result in 1 (truthy) for0and1, and every other value will result in something higher (and thus falsey, since only1is truthy in 05AB1E). This tip was provided by @Grimmy to save a byte here. - If you want a list of all overlapping pairs (i.e.
[1,2,3,4,5,6,7,8,9]→[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9]]), most probably already knowü‚can be used (Try it online). But what if you want a list of overlapping triplets or quartets? The most obvious approach would seem to beŒ3ù(substrings & keep those of length 3 - Try it online). Butüactually has a (currently undocumented) feature as shortcut for thisü3(Try it online), which works with any integer given toü, including2to create overlapping pairs (Try it online). - If the stack is empty, some builtins will use the last value that was previously on the stack (and thus there is also no implicit input!), saving you on a potential duplicate. For example, in this 05AB1E answer the
×ばつwill use the9Llist twice, without a need to duplicate it first. And in this 05AB1E program theÿinside the string will use the11all three times, without the need to triplicate it first. - If we've used
|to get all (remaining) inputs, the nextIor implicit input will push this same list instead of the final input. Knowing this can sometimes save bytes, like in the top program of this answer of mine . - There is a flatten builtin
̃to flatten a multi-dimensional list to a single list: try it online . There is also a way to flatten a (potentially multi-dimensional) list of strings to a single list of characters withS: try it online . But what if we only want to flatten it down one level, instead of all the way? In that case,€`can be used if the order of items isn't important (try it online ) orí€`if retaining the order of items is important (try it online ). The unordered version is used pretty often in matrix-related challenges, like I used in this answer of mine .
- If you have a list of lists and first want to join each inner list by spaces, and then those space-delimited strings by newlines, the to-the-point approach would be
ðý»of course. However, the»already implicitly joins inner lists by spaces before joining by newlines, so theðýisn't necessary in this case: try it online. D(duplicate) andÐ(triplicate) in combination withs(swap) andŠ(triple-swapa,b,ctoc,a,b) are usually shorter than using©(save in global_variable) and®(push global_variable) inside loops. This saved a byte in this answer of mine, as well as two in this answer of mine.1⁄2(if 1, then increase counter_variable by 1) isn't necessary at the end of aμ(while counter_variable != a, do...), since it's done implicitly (saved a byte in this answer of mine)..Bimplicitly splits on new-lines. This was useful in this answer of mine when we were looking for an alternative for¡(split) while still keeping empty items (NOTE: Solution in the linked answer doesn't work when elements contain trailing spaces after splitting.) - Hopefully a builtin will be added to split but keep empty lines in the future.- [legacy version only]
SÖ(which of the digits of the input-integer can evenly divide the input-integer) will contain the number itself for the digits0(instead of divide-by-zero errors). For example,1053will result in[1,1053,0,1](1053 is divisible by 1 and 3; is not divisible by 5; and gives a division-by-zero error for 0). This was pretty useful in this answer of mine by taking the power of the list, since only1is truthy in 05AB1E and everything else is falsey.SÖPresulting in truthy (1) therefore means an input-integer is evenly divisible by each of its digits. - After seeing
û(palindromize a given string) I was surprised there isn't an is_palindrome builtin. But later on I realized only 2 bytes are needed to accomplish that, which areÂQ(whereÂis bifurcate, which is short forDR: Duplicate & Reverse copy; andQis to check if the top two values on the stack are equal). - When you want to filter a list by multiple things, it's usually cheaper to have multiple loose filters, rather than all combined in one filter. Because when you have two filters you'll need something along the lines of
Ds*(duplicate, swap, multiply to act as logical-AND) vs}ʒ(close first filter, filter again) when you use two filters. For example: in this challenge we have to list all numbers of four digits long, containing at least one0, and with a digit sum equal to9. Using a range[1000,10000]covers the number of four digits long, but then you are left with two more filters. Initially I used44°ŸʒD0åsSO9Q*(14 bytes), but by using two filters a byte can be saved:44°Ÿʒ0å}ʒSO9Q(13 bytes). (Which later got golfed to44°ŸεW°ö9Q(10 bytes) by @Grimmy.) - When you want to zip with integer
0as filler, you could use0ζ. One issue with this however is that the filler0will become a string"0", so if you later try to sort with mixed strings and integer, this will most likely not give the result you'd want. Here an example of how it will sort the zipped inner lists:0ζ€{. This can be fixed by adding an explicit cast to int (ï) after the zip, and only then sort:0ζï€{. However, using the3⁄4as constant0with the zip-filler, will cause it to remain an integer instead of a string during the zip. So3⁄4ζ€{will save a byte here. This tip was provided by @Mr.Xcoder to save a byte in this answer of mine. - If you want to sum the digits of multiple numbers in a list, you could use
€SO. Shorter however is using1ö, which automatically vectorizes. This tip was provided by @Grimmy to save a byte here (and 2 bytes here). - If you're only dealing with non-negative integers, and you want to get a truthy value (
1) when the integer is either 0 or 1, you could of course use the obvious2‹. However, using!(factorial) will also only result in 1 (truthy) for0and1, and every other value will result in something higher (and thus falsey, since only1is truthy in 05AB1E). This tip was provided by @Grimmy to save a byte here. - If you want a list of all overlapping pairs (i.e.
[1,2,3,4,5,6,7,8,9]→[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9]]), most probably already knowü‚can be used (Try it online). But what if you want a list of overlapping triplets or quartets? The most obvious approach would seem to beŒ3ù(substrings & keep those of length 3 - Try it online). Butüactually has a (currently undocumented) feature as shortcut for thisü3(Try it online), which works with any integer given toü, including2to create overlapping pairs (Try it online). - If the stack is empty, some builtins will use the last value that was previously on the stack (and thus there is also no implicit input!), saving you on a potential duplicate. For example, in this 05AB1E answer the
×ばつwill use the9Llist twice, without a need to duplicate it first. And in this 05AB1E program theÿinside the string will use the11all three times, without the need to triplicate it first.
- If you have a list of lists and first want to join each inner list by spaces, and then those space-delimited strings by newlines, the to-the-point approach would be
ðý»of course. However, the»already implicitly joins inner lists by spaces before joining by newlines, so theðýisn't necessary in this case: try it online. D(duplicate) andÐ(triplicate) in combination withs(swap) andŠ(triple-swapa,b,ctoc,a,b) are usually shorter than using©(save in global_variable) and®(push global_variable) inside loops. This saved a byte in this answer of mine, as well as two in this answer of mine.1⁄2(if 1, then increase counter_variable by 1) isn't necessary at the end of aμ(while counter_variable != a, do...), since it's done implicitly (saved a byte in this answer of mine)..Bimplicitly splits on new-lines. This was useful in this answer of mine when we were looking for an alternative for¡(split) while still keeping empty items (NOTE: Solution in the linked answer doesn't work when elements contain trailing spaces after splitting.) - Hopefully a builtin will be added to split but keep empty lines in the future.- [legacy version only]
SÖ(which of the digits of the input-integer can evenly divide the input-integer) will contain the number itself for the digits0(instead of divide-by-zero errors). For example,1053will result in[1,1053,0,1](1053 is divisible by 1 and 3; is not divisible by 5; and gives a division-by-zero error for 0). This was pretty useful in this answer of mine by taking the power of the list, since only1is truthy in 05AB1E and everything else is falsey.SÖPresulting in truthy (1) therefore means an input-integer is evenly divisible by each of its digits. - After seeing
û(palindromize a given string) I was surprised there isn't an is_palindrome builtin. But later on I realized only 2 bytes are needed to accomplish that, which areÂQ(whereÂis bifurcate, which is short forDR: Duplicate & Reverse copy; andQis to check if the top two values on the stack are equal). - When you want to filter a list by multiple things, it's usually cheaper to have multiple loose filters, rather than all combined in one filter. Because when you have two filters you'll need something along the lines of
Ds*(duplicate, swap, multiply to act as logical-AND) vs}ʒ(close first filter, filter again) when you use two filters. For example: in this challenge we have to list all numbers of four digits long, containing at least one0, and with a digit sum equal to9. Using a range[1000,10000]covers the number of four digits long, but then you are left with two more filters. Initially I used44°ŸʒD0åsSO9Q*(14 bytes), but by using two filters a byte can be saved:44°Ÿʒ0å}ʒSO9Q(13 bytes). (Which later got golfed to44°ŸεW°ö9Q(10 bytes) by @Grimmy.) - When you want to zip with integer
0as filler, you could use0ζ. One issue with this however is that the filler0will become a string"0", so if you later try to sort with mixed strings and integer, this will most likely not give the result you'd want. Here an example of how it will sort the zipped inner lists:0ζ€{. This can be fixed by adding an explicit cast to int (ï) after the zip, and only then sort:0ζï€{. However, using the3⁄4as constant0with the zip-filler, will cause it to remain an integer instead of a string during the zip. So3⁄4ζ€{will save a byte here. This tip was provided by @Mr.Xcoder to save a byte in this answer of mine. - If you want to sum the digits of multiple numbers in a list, you could use
€SO. Shorter however is using1ö, which automatically vectorizes. This tip was provided by @Grimmy to save a byte here (and 2 bytes here). - If you're only dealing with non-negative integers, and you want to get a truthy value (
1) when the integer is either 0 or 1, you could of course use the obvious2‹. However, using!(factorial) will also only result in 1 (truthy) for0and1, and every other value will result in something higher (and thus falsey, since only1is truthy in 05AB1E). This tip was provided by @Grimmy to save a byte here. - If you want a list of all overlapping pairs (i.e.
[1,2,3,4,5,6,7,8,9]→[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9]]), most probably already knowü‚can be used (Try it online). But what if you want a list of overlapping triplets or quartets? The most obvious approach would seem to beŒ3ù(substrings & keep those of length 3 - Try it online). Butüactually has a (currently undocumented) feature as shortcut for thisü3(Try it online), which works with any integer given toü, including2to create overlapping pairs (Try it online). - If the stack is empty, some builtins will use the last value that was previously on the stack (and thus there is also no implicit input!), saving you on a potential duplicate. For example, in this 05AB1E answer the
×ばつwill use the9Llist twice, without a need to duplicate it first. And in this 05AB1E program theÿinside the string will use the11all three times, without the need to triplicate it first. - If we've used
|to get all (remaining) inputs, the nextIor implicit input will push this same list instead of the final input. Knowing this can sometimes save bytes, like in the top program of this answer of mine . - There is a flatten builtin
̃to flatten a multi-dimensional list to a single list: try it online . There is also a way to flatten a (potentially multi-dimensional) list of strings to a single list of characters withS: try it online . But what if we only want to flatten it down one level, instead of all the way? In that case,€`can be used if the order of items isn't important (try it online ) orí€`if retaining the order of items is important (try it online ). The unordered version is used pretty often in matrix-related challenges, like I used in this answer of mine .
Added `»` to the tips (joins inner lists by spaces before joining by newlines), since I noticed it was missing (and this feature is also not documented)
Kevin Cruijssen
- 136.2k
- 14
- 154
- 394
Loading
Loading
Loading
Added tip about how some builtins will use the last value that was on the stack, even if the stack is now empty.
Kevin Cruijssen
- 136.2k
- 14
- 154
- 394
Loading
Added undocumented feature `ün` (n being an integer) to create a list of substrings of length n
Kevin Cruijssen
- 136.2k
- 14
- 154
- 394
Loading
Loading
Kevin Cruijssen
- 136.2k
- 14
- 154
- 394
Loading
Kevin Cruijssen
- 136.2k
- 14
- 154
- 394
Loading
Loading
Added bullet-point about multiple loose filters vs single combined filter
Kevin Cruijssen
- 136.2k
- 14
- 154
- 394
Loading
Loading
Kevin Cruijssen
- 136.2k
- 14
- 154
- 394
Loading
Loading