How many threes?

Clash Royale CLAN TAG#URR8PPP
up vote
16
down vote
favorite
In this task your code will be given an integer $n$ as input. Your code should then output the greatest number of multiples of $3$ that can be concatenated (in base $10$) to form $3n$ (with no leading zeros). For example if you were given $26042$ as input,
$26042times3=78126$
and $78126$ can be made by concatenating $78$, $12$ and $6$, so you output $3$.
Any standard forms of IO are permitted. Answers should aim to minimize the number of bytes in their code.
Here are the first $6562$ entries in this sequence starting with zero:
1,1,1,1,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,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2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2
code-golf sequence
add a comment |Â
up vote
16
down vote
favorite
In this task your code will be given an integer $n$ as input. Your code should then output the greatest number of multiples of $3$ that can be concatenated (in base $10$) to form $3n$ (with no leading zeros). For example if you were given $26042$ as input,
$26042times3=78126$
and $78126$ can be made by concatenating $78$, $12$ and $6$, so you output $3$.
Any standard forms of IO are permitted. Answers should aim to minimize the number of bytes in their code.
Here are the first $6562$ entries in this sequence starting with zero:
1,1,1,1,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2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,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2
code-golf sequence
8
It would be great to have some examples on the formn -> f(n), wheref(n)is the answer. As it is now, I can't even tell if your 6561 entries are 0-indexed or 1-indexed.
â maxb
Sep 27 at 13:34
@maxb There are too many examples to do that format. My list is zero indexed.
â W W
Sep 27 at 13:35
2
Of course, but some select few would be great, in addition to the first example. And from what I can see, we are allowed to split the number $3n$ any way we want? So a brute force implementation would be required (in some languages) to find the maximum number of multiples of 3? Also, do you define 0 as a multiple of 3? From your question it seems like it.
â maxb
Sep 27 at 13:38
@maxb There are two tricks that can be used to get solutions in shorter and faster ways. (hint 3 is special) and yes 0 is a multiple of 3. I dont know how else it could be.
â W W
Sep 27 at 13:54
add a comment |Â
up vote
16
down vote
favorite
up vote
16
down vote
favorite
In this task your code will be given an integer $n$ as input. Your code should then output the greatest number of multiples of $3$ that can be concatenated (in base $10$) to form $3n$ (with no leading zeros). For example if you were given $26042$ as input,
$26042times3=78126$
and $78126$ can be made by concatenating $78$, $12$ and $6$, so you output $3$.
Any standard forms of IO are permitted. Answers should aim to minimize the number of bytes in their code.
Here are the first $6562$ entries in this sequence starting with zero:
1,1,1,1,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,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2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2
code-golf sequence
In this task your code will be given an integer $n$ as input. Your code should then output the greatest number of multiples of $3$ that can be concatenated (in base $10$) to form $3n$ (with no leading zeros). For example if you were given $26042$ as input,
$26042times3=78126$
and $78126$ can be made by concatenating $78$, $12$ and $6$, so you output $3$.
Any standard forms of IO are permitted. Answers should aim to minimize the number of bytes in their code.
Here are the first $6562$ entries in this sequence starting with zero:
1,1,1,1,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2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,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2
code-golf sequence
code-golf sequence
edited Sep 28 at 9:03
ngn
6,30812358
6,30812358
asked Sep 27 at 13:26
W W
33.9k10150354
33.9k10150354
8
It would be great to have some examples on the formn -> f(n), wheref(n)is the answer. As it is now, I can't even tell if your 6561 entries are 0-indexed or 1-indexed.
â maxb
Sep 27 at 13:34
@maxb There are too many examples to do that format. My list is zero indexed.
â W W
Sep 27 at 13:35
2
Of course, but some select few would be great, in addition to the first example. And from what I can see, we are allowed to split the number $3n$ any way we want? So a brute force implementation would be required (in some languages) to find the maximum number of multiples of 3? Also, do you define 0 as a multiple of 3? From your question it seems like it.
â maxb
Sep 27 at 13:38
@maxb There are two tricks that can be used to get solutions in shorter and faster ways. (hint 3 is special) and yes 0 is a multiple of 3. I dont know how else it could be.
â W W
Sep 27 at 13:54
add a comment |Â
8
It would be great to have some examples on the formn -> f(n), wheref(n)is the answer. As it is now, I can't even tell if your 6561 entries are 0-indexed or 1-indexed.
â maxb
Sep 27 at 13:34
@maxb There are too many examples to do that format. My list is zero indexed.
â W W
Sep 27 at 13:35
2
Of course, but some select few would be great, in addition to the first example. And from what I can see, we are allowed to split the number $3n$ any way we want? So a brute force implementation would be required (in some languages) to find the maximum number of multiples of 3? Also, do you define 0 as a multiple of 3? From your question it seems like it.
â maxb
Sep 27 at 13:38
@maxb There are two tricks that can be used to get solutions in shorter and faster ways. (hint 3 is special) and yes 0 is a multiple of 3. I dont know how else it could be.
â W W
Sep 27 at 13:54
8
8
It would be great to have some examples on the form
n -> f(n), where f(n) is the answer. As it is now, I can't even tell if your 6561 entries are 0-indexed or 1-indexed.â maxb
Sep 27 at 13:34
It would be great to have some examples on the form
n -> f(n), where f(n) is the answer. As it is now, I can't even tell if your 6561 entries are 0-indexed or 1-indexed.â maxb
Sep 27 at 13:34
@maxb There are too many examples to do that format. My list is zero indexed.
â W W
Sep 27 at 13:35
@maxb There are too many examples to do that format. My list is zero indexed.
â W W
Sep 27 at 13:35
2
2
Of course, but some select few would be great, in addition to the first example. And from what I can see, we are allowed to split the number $3n$ any way we want? So a brute force implementation would be required (in some languages) to find the maximum number of multiples of 3? Also, do you define 0 as a multiple of 3? From your question it seems like it.
â maxb
Sep 27 at 13:38
Of course, but some select few would be great, in addition to the first example. And from what I can see, we are allowed to split the number $3n$ any way we want? So a brute force implementation would be required (in some languages) to find the maximum number of multiples of 3? Also, do you define 0 as a multiple of 3? From your question it seems like it.
â maxb
Sep 27 at 13:38
@maxb There are two tricks that can be used to get solutions in shorter and faster ways. (hint 3 is special) and yes 0 is a multiple of 3. I dont know how else it could be.
â W W
Sep 27 at 13:54
@maxb There are two tricks that can be used to get solutions in shorter and faster ways. (hint 3 is special) and yes 0 is a multiple of 3. I dont know how else it could be.
â W W
Sep 27 at 13:54
add a comment |Â
21 Answers
21
active
oldest
votes
up vote
9
down vote
Haskell, 51 bytes
f n=sum[1|x<-scanr(:)"0".show$3*n,read x`mod`3<1]-1
Try it online!
The key idea is the following: given a multiple of 3 (call it $3n$), the best way to write it as the juxtaposition of multiples of 3 is to start from the end (or the beginning) and select multiples of 3 greedily. For instance, if $3n=78126$, then we get (starting from the end) a $6$, then a $12$, and finally a $78$: $78|12|6$. Note that this is possible because a number is a multiple of 3 iff the sum of its digits is a multiple of 3. Also note that if we concatenate two multiples of 3, we get another multiple of 3, so $6,12|6,78|12|6$ are all multiples of 3.
Thus the answer can be found by considering the list of suffixes of $3n$ (e.g. $[78126,8126,126,26,6]$) and counting the multiples of 3.
add a comment |Â
up vote
9
down vote
Retina, 11 bytes of Latin-1
v`.3*[012ö]
Try it online!
Retina works on strings rather than integers, so I'm taking the number as it'd appear in a file (digits followed by a newline).
Algorithm
Almost all the solutions here have a multiplication by 3, but I thought it'd be interesting to try to solve the problem without it. We already know from the algorithm most people are using that we need to identify the number of suffixes of 3n that are divisible by 3. Now, given a suffix of n (say s), 3s will appear as a suffix of 3n if the multiplication sÃÂ3 does not carry into the digit before the suffix. Meanwhile, if the multiplication sÃÂ3 does carry, then the corresponding suffix of 3n will not be divisible by 3 (as the digital root of 3*s* is divisible by 3 â 3 divides (10-1) and we're working in base 10 â and the corresponding suffix of 3*n* will be equal to 3*s* but without a leading 1 or 2, neither of which is divisible by 3).
We do need to adjust for the possibility that 3*n* has more digits than n, thus meaning that 3*n* has an extra suffix that doesn't correspond to any suffix of n. This suffix is trivially the whole number 3*n*, and will always be divisible by 3 (for obvious reasons). Thus, if the multiplication nÃÂ3 carries, we have to add 1 to the result. We can note that if nÃÂ3 doesn't carry, it will contribute 1 to the result using a naive algorithm, whereas if it does, it won't; and thus we can do this adjustment simply by counting the "suffix that represents the whole number n" unconditionally, rather than checking for a carry. Equivalently (and slightly more tersely), we can unconditionally not count this suffix, and count some other suffix instead (the empty suffix is convenient), as it'll come to the same total.
How do we determine if a multiplication by 3 would carry? Well, if the first digit of the number is greater than 3, it must; if it's less than 3, it can't. If it's 3, whether it carries or not will depend on the next digit of the number in the same way. If the number consists entirely of 3s, the multiplication won't carry (it'll stop just short at a number consisting entirely of 9s). Thus, the algorithm we want is "count the number of proper suffixes that start with 0 or more 3s, followed by 0, 1, 2, or the end of the string; plus one extra suffix".
Explanation
This algorithm ends up longer than the consensus algorithm in most languages, so I'm submitting it in Retina, a language where it turns out to be shorter than the more usual method (and a similar length to golfing languages).
v`.3*[012ö]
v` Count the number of points within the input from which you can
. ignore one character,
3* and skip past any number (including zero) of 3s,
[012ö] to find 0, 1, 2, or the newline at the end of the input.
The requirement to ignore one character before we start looking means that the improper suffix consisting of the whole number cannot be counted (as the suffixes that we actually look at will be the ones starting one character to the right of where Retina starts, and thus not at the first character). However, the improper suffix consisting only of the newline at the end of the number will always be counted, thus giving us the one extra suffix we need.
This was the algorithm I had in mind when I wrote the question. I'm glad to see someone used it!
â W W
Sep 28 at 3:48
@WW: This answer was more a case of "this is an interesting algorithm, let's find a language where it's efficient" than "this is an interesting language, let's find the best algorithm in it". (Although Retina is an interesting language anyway, as it happens!) I guess this is a weird side effect of the "competition per-language"; it means that you can make an answer "better", in some sense, by translating it to a language which doesn't deal with translations of competing answers well.
â ais523
Sep 28 at 5:08
I believe[¶-2]saves a byte since you should be able to assume the input consists only of numeric digits and the newline.
â FryAmTheEggman
Oct 2 at 3:16
add a comment |Â
up vote
7
down vote
Husk, 9 bytes
#oæ3dṫd*3
Try it online or verify the first 2188 terms!
Explanation
#(æ3d)ṫd*3 -- example: 42
*3 -- times 3: 126
d -- digits: [1,2,6]
ṫ -- tails: [[1,2,6],[2,6],[6]]
#( ) -- count values that are truthy when
d -- | undigits: [126,26,6]
æ3 -- | divisible by 3: [42,0,2]
-- : 2
add a comment |Â
up vote
3
down vote
Perl 6, 54 28 bytes
-14 bytes thanks to nwellnhof!
+grep *%%3,[~] .combo*ÃÂ3
Try it online!
This counts how many prefixes of the number times three are divisible by 3.
Explanation:
o*ÃÂ3 # Pass the input times 3 into the code block
[~] .comb # Get all the prefixes of the number
grep , # Filter from that
*%%3 # All numbers divisible by 3
+ # Return the length of the list
Shaved off another byte.
â nwellnhof
Sep 27 at 16:50
@nwellnhof I didn't realise you could combine with Whatever code. Neat!
â Jo King
Sep 27 at 16:59
add a comment |Â
up vote
3
down vote
05AB1E, 14 12 7 6 bytes
3*÷3ÃÂO
-5 bytes creating a port of @BMO's Husk answer.
-1 byte thanks to @Nitrodon by changing suffixes to prefixes.
Try it online or verify the first 1000 items.
Explanation:
3* # Multiply the (implicit) input by 3
# i.e. 26042 â 78126
÷ # List of prefixes
# i.e. 78126 â ["7","78","781","7812","78126"]
3ÃÂ # Check for each if its divisible by 3
# i.e. ["7","78","781","7812","78126"] â [0,1,0,1,1]
O # And take the sum (which is implicitly output)
# i.e. [0,1,0,1,1] â 3
Old 12-bytes answer:
3*.Ã
ÂÃÂ3ÃÂP}â¬gÃÂ
Or alternatively â¬gàcan be éøg.
Try it online or verify the first 1000 items
Explanation:
3* # Multiply the (implicit) input by 3
# i.e. 26042 â 78126
.Ã
 # Take all possible partitions of this number
# i.e. 78126 â [["7","8","1","2","6"],["7","8","1","26"],["7","8","12","6"],
# ...,["781","26"],["7812","6"],["78126"]]
ÃÂ } # Filter these partitions by:
3ÃÂP # Only keep partitions where every number is divisible by 3
# i.e. ["7","8","1","2","6"] â [0,0,0,0,1] â 0
# i.e. ["78","12","6"] â [1,1,1] â 1
#(option 1:)
â¬g # Take the length of each remaining partition
# i.e. [["78","12","6"],["78","126"],["7812","6"],["78126"]] â [3,2,2,1]
ÃÂ # And take the max (which we output implicitly)
# i.e. [3,2,2,1] â 3
#(option 2:)
é # Sort the remaining partitions by length
# i.e. [["78","12","6"],["78","126"],["7812","6"],["78126"]]
# â [["78126"],["78","126"],["7812","6"],["78","12","6"]]
ø # Take the last one (the longest)
# i.e. [["78126"],["78","126"],["7812","6"],["78","12","6"]]
# â ["78","12","6"]
g # And take its length (which we output implicitly)
# i.e. ["78","12","6"] â 3
1
Using prefixes instead of suffixes gives the same result in one fewer byte.
â Nitrodon
Sep 27 at 18:32
@Nitrodon Thanks! :) I knew about the 1-byte prefixes builtin, but didn't realize the challenge works by using prefixes instead of suffixes as well.
â Kevin Cruijssen
Sep 27 at 18:39
add a comment |Â
up vote
2
down vote
Python 2, 99 88 bytes
lambda n:g(`3*n`)
g=lambda n:int(n)%3<1and 1+max([g(n[i:])for i in range(1,len(n))]+[0])
Try it online!
add a comment |Â
up vote
2
down vote
APL (Dyalog Unicode), 14 bytes
+/0=3|+âÂÂèâÂÂ3ÃÂâÂÂ
Try it online! or verify the first 1000
Explanaition
+/0=3|+âÂÂèâÂÂ3ÃÂâÂÂ
â â prompt for input
3àâ multiply by 3
âÂÂèâ â convert the number to a vector of digits
+ â take the cumulative sum
3| â find each term modulo 3
+/0= â count those that equal 0
This works because a number is divisible by three if and only if the sum of its digits is divisible by three
add a comment |Â
up vote
2
down vote
JavaScript (ES6), 41 bytes
f=(n,i=10)=>!(n*3%i%3)+(n*3>i&&f(n,i*10))
Try it online!
add a comment |Â
up vote
2
down vote
Haskell, 44 bytes
g.(*3).max 1
g 0=0
g n=0^mod n 3+g(div n 10)
Try it online!
Uses Delfad0r's observation that the output is the number of suffixes (equivalently, prefixes) of 3n that are multiples of 3. This method finds the prefixes arithmetically by repeatedly floor-dividing by 10 rather than using the string representation. The 0^ is a short arithmetic way to produce 1 if the exponent mod n 3 is zero, and produce 0 otherwise.
The first line is the main function, which triples the input before passing it to the helper function g which is defined recursively. The max 1 is a hack to make f(0) equal 1, since we're required to handle zero like the string '0' rather than the empty string.
add a comment |Â
up vote
2
down vote
MathGolf, 15 14 bytes
3*âÂÂ0ÃÂç_3÷;]ã
Try it online!
-1 byte thanks to JoKing
Explanation
3* Multiply the input by 3
â Convert to a list of digits
0 Push a zero and swap the top two elements
ÃÂ Execute the next 5 characters for each block
ç Concatenate
_ Duplicate
3÷ Check divisibility by 3 (returns 0 or 1)
Swap top two elements
; Discard TOS (the last swap
]ã Wrap the entire stack in an array and output its sum
I don't know if this is the correct solution to the problem but it mimics the JS solution by Arnauld. If I'm incorrect, I'll try to fix it.
14 bytes
â Jo King
Sep 28 at 4:45
@JoKing I'll have do figure out what your code does, then I'll update with an explanation (I know what it does, but not why it works)
â maxb
Sep 28 at 6:04
add a comment |Â
up vote
1
down vote
Pyth, 16 15 bytes
lef!.E%vT3./`*3
Try it online here.
lef!.E%vT3./`*3Q Implicit: Q=eval(input())
Trailing Q inferred
`*3Q Input * 3
` Convert to string
./ Take divisions into disjoint substrings
f Filter the above using:
vT Convert each back to integer
% 3 Mod 3
.E Are any non-0?
! Logical NOT
le Take the length of the last value
As the substring sets are generated in order of number of
substrings, the last value is guaranteed to be the longest
add a comment |Â
up vote
1
down vote
Shakespeare Programming Language, 376 bytes
T.Ajax,.Page,.Act I:x.Scene I:x[Enter Ajax and Page]Ajax:Listen tothy!You be the sum ofthe sum ofyou you you!Scene V:x.Page:You be the sum ofyou the quotient betweena cat the sum ofa cat the remainder of the quotient betweenI the sum ofa big cat a cat!Ajax:You be the quotient betweenyou twice the sum ofa big big cat a cat!Be you nicer zero?If solet usscene V.Page:Open heart
Try it online!
I wonder if the 1/(1+I/3) trick is better than a control flow.
You don't need thexafter scenes. Try it online!
â Jo King
Sep 27 at 17:28
add a comment |Â
up vote
1
down vote
Java 10, 66 bytes
n->int m=1,r=n<1?1:0;for(n*=3;m<n;m*=10)r+=n%m%3<1?1:0;return r;
Try it online.
Explanation:
Uses a combination of @BMO's Husk answer (checking how many prefixex are divisible by 3) and @Arnauld's JavaScript (ES6) answer (multiplying an integer by 10 every iteration, and get the prefixes with a modulo of this integer).
n-> // Method with integer as both parameter and return-type
int m=1, // Modulo-integer, starting at 1
r= // Result-integer, starting at:
n<1? // If the input is the edge-case 0:
1 // Start it at 1
: // Else:
0; // Start it at 0
for(n*=3; // Multiply the input by 3
m<n; // Loop as long as `m` is still smaller than `n`
m*=10) // After every iteration: Multiply `m` by 10
r+=n%m // If `n` modulo-`m` (to get a suffix),
%3<1? // is divisible by 3:
1 // Increase the result-sum by 1
: // Else:
0; // Leave the result-sum the same by adding 0
return r; // Return the result-sum
add a comment |Â
up vote
1
down vote
Retina, 35 32 bytes
.+
$.(*3*
Lv$`.+
<$&*->
<(---)*>
Try it online! Explanation:
.+
$.(*3*
Multiply the input by 3.
Lv$`.+
<$&*->
Convert each suffix to unary.
<(---)*>
Count the multiples of three.
add a comment |Â
up vote
1
down vote
K (ngn/k), 16 bytes
+/~3!+.:'$3*x
Try it online!
add a comment |Â
up vote
1
down vote
Python 2, 48 bytes
n=input()*3;p=n<1
while n:p+=n%3<1;n/=10
print p
Try it online!
Similar to ovs's answer, but takes the whole prefix mod 3 without accumulating rather than the last digit. Outputs True as 1 on input of 0.
Python 3, 42 bytes
f=lambda n:n>=1and(n%1<1/3)+f(n/10)or n==0
Try it online!
Uses ideas from ais523's very nice solution. Repeatedly floor-divides the input by 10 until it's zero, and counts how many times the fractional part is less than 1/3. On very large inputs float precision will eventually be a problem. The n=0 case is handled with or n==0 making it return True for 1. The code can work in Python 2 if the input is a float, if we rewrite n%1<1/3 as n%1*3<1 which is the same length.
add a comment |Â
up vote
1
down vote
Jelly, 7 bytes
ÃÂ3DÃÂ3á¸ÂS
Try it online!
How it works
ÃÂ3DÃÂ3á¸ÂS Main link. Argument: n
ÃÂ3 Compute 3n.
D Decimal; convert 3n to the array of its digits in base 10.
ÃÂ Accumulate; take the cumulative sum.
Note that an integer and its digit sum are congruent modulo 3.
3ḠTest each partial digit sum for divisibility by 3.
S Take the sum of the Booleans, counting the multiples of 3.
add a comment |Â
up vote
0
down vote
Stax, 8 bytes
ñNÃÂâ â 1d}
Run and debug it
Unpacked, ungolfed, and commented, it looks like this.
3* triple input
E convert to array of decimal digits
:+ get all prefix sums
F for each prefix sum
3%! is it a multiple of 3?
+ add to running total
Run this one
add a comment |Â
up vote
0
down vote
Japt -x, 12 bytes
*3 s ÃÂ¥+ îðv3
Try it or view results for0-1000
add a comment |Â
up vote
0
down vote
J, 20 bytes
1#.0=[:(3|".)3":@*]
Try it online!
add a comment |Â
up vote
0
down vote
Python 2, 56 bytes
n=input()*3;k=p=0
while n:k+=n%10;n/=10;p+=k%3<1
print p
Try it online!
add a comment |Â
21 Answers
21
active
oldest
votes
21 Answers
21
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
9
down vote
Haskell, 51 bytes
f n=sum[1|x<-scanr(:)"0".show$3*n,read x`mod`3<1]-1
Try it online!
The key idea is the following: given a multiple of 3 (call it $3n$), the best way to write it as the juxtaposition of multiples of 3 is to start from the end (or the beginning) and select multiples of 3 greedily. For instance, if $3n=78126$, then we get (starting from the end) a $6$, then a $12$, and finally a $78$: $78|12|6$. Note that this is possible because a number is a multiple of 3 iff the sum of its digits is a multiple of 3. Also note that if we concatenate two multiples of 3, we get another multiple of 3, so $6,12|6,78|12|6$ are all multiples of 3.
Thus the answer can be found by considering the list of suffixes of $3n$ (e.g. $[78126,8126,126,26,6]$) and counting the multiples of 3.
add a comment |Â
up vote
9
down vote
Haskell, 51 bytes
f n=sum[1|x<-scanr(:)"0".show$3*n,read x`mod`3<1]-1
Try it online!
The key idea is the following: given a multiple of 3 (call it $3n$), the best way to write it as the juxtaposition of multiples of 3 is to start from the end (or the beginning) and select multiples of 3 greedily. For instance, if $3n=78126$, then we get (starting from the end) a $6$, then a $12$, and finally a $78$: $78|12|6$. Note that this is possible because a number is a multiple of 3 iff the sum of its digits is a multiple of 3. Also note that if we concatenate two multiples of 3, we get another multiple of 3, so $6,12|6,78|12|6$ are all multiples of 3.
Thus the answer can be found by considering the list of suffixes of $3n$ (e.g. $[78126,8126,126,26,6]$) and counting the multiples of 3.
add a comment |Â
up vote
9
down vote
up vote
9
down vote
Haskell, 51 bytes
f n=sum[1|x<-scanr(:)"0".show$3*n,read x`mod`3<1]-1
Try it online!
The key idea is the following: given a multiple of 3 (call it $3n$), the best way to write it as the juxtaposition of multiples of 3 is to start from the end (or the beginning) and select multiples of 3 greedily. For instance, if $3n=78126$, then we get (starting from the end) a $6$, then a $12$, and finally a $78$: $78|12|6$. Note that this is possible because a number is a multiple of 3 iff the sum of its digits is a multiple of 3. Also note that if we concatenate two multiples of 3, we get another multiple of 3, so $6,12|6,78|12|6$ are all multiples of 3.
Thus the answer can be found by considering the list of suffixes of $3n$ (e.g. $[78126,8126,126,26,6]$) and counting the multiples of 3.
Haskell, 51 bytes
f n=sum[1|x<-scanr(:)"0".show$3*n,read x`mod`3<1]-1
Try it online!
The key idea is the following: given a multiple of 3 (call it $3n$), the best way to write it as the juxtaposition of multiples of 3 is to start from the end (or the beginning) and select multiples of 3 greedily. For instance, if $3n=78126$, then we get (starting from the end) a $6$, then a $12$, and finally a $78$: $78|12|6$. Note that this is possible because a number is a multiple of 3 iff the sum of its digits is a multiple of 3. Also note that if we concatenate two multiples of 3, we get another multiple of 3, so $6,12|6,78|12|6$ are all multiples of 3.
Thus the answer can be found by considering the list of suffixes of $3n$ (e.g. $[78126,8126,126,26,6]$) and counting the multiples of 3.
edited Sep 27 at 14:57
answered Sep 27 at 14:35
Delfad0r
773213
773213
add a comment |Â
add a comment |Â
up vote
9
down vote
Retina, 11 bytes of Latin-1
v`.3*[012ö]
Try it online!
Retina works on strings rather than integers, so I'm taking the number as it'd appear in a file (digits followed by a newline).
Algorithm
Almost all the solutions here have a multiplication by 3, but I thought it'd be interesting to try to solve the problem without it. We already know from the algorithm most people are using that we need to identify the number of suffixes of 3n that are divisible by 3. Now, given a suffix of n (say s), 3s will appear as a suffix of 3n if the multiplication sÃÂ3 does not carry into the digit before the suffix. Meanwhile, if the multiplication sÃÂ3 does carry, then the corresponding suffix of 3n will not be divisible by 3 (as the digital root of 3*s* is divisible by 3 â 3 divides (10-1) and we're working in base 10 â and the corresponding suffix of 3*n* will be equal to 3*s* but without a leading 1 or 2, neither of which is divisible by 3).
We do need to adjust for the possibility that 3*n* has more digits than n, thus meaning that 3*n* has an extra suffix that doesn't correspond to any suffix of n. This suffix is trivially the whole number 3*n*, and will always be divisible by 3 (for obvious reasons). Thus, if the multiplication nÃÂ3 carries, we have to add 1 to the result. We can note that if nÃÂ3 doesn't carry, it will contribute 1 to the result using a naive algorithm, whereas if it does, it won't; and thus we can do this adjustment simply by counting the "suffix that represents the whole number n" unconditionally, rather than checking for a carry. Equivalently (and slightly more tersely), we can unconditionally not count this suffix, and count some other suffix instead (the empty suffix is convenient), as it'll come to the same total.
How do we determine if a multiplication by 3 would carry? Well, if the first digit of the number is greater than 3, it must; if it's less than 3, it can't. If it's 3, whether it carries or not will depend on the next digit of the number in the same way. If the number consists entirely of 3s, the multiplication won't carry (it'll stop just short at a number consisting entirely of 9s). Thus, the algorithm we want is "count the number of proper suffixes that start with 0 or more 3s, followed by 0, 1, 2, or the end of the string; plus one extra suffix".
Explanation
This algorithm ends up longer than the consensus algorithm in most languages, so I'm submitting it in Retina, a language where it turns out to be shorter than the more usual method (and a similar length to golfing languages).
v`.3*[012ö]
v` Count the number of points within the input from which you can
. ignore one character,
3* and skip past any number (including zero) of 3s,
[012ö] to find 0, 1, 2, or the newline at the end of the input.
The requirement to ignore one character before we start looking means that the improper suffix consisting of the whole number cannot be counted (as the suffixes that we actually look at will be the ones starting one character to the right of where Retina starts, and thus not at the first character). However, the improper suffix consisting only of the newline at the end of the number will always be counted, thus giving us the one extra suffix we need.
This was the algorithm I had in mind when I wrote the question. I'm glad to see someone used it!
â W W
Sep 28 at 3:48
@WW: This answer was more a case of "this is an interesting algorithm, let's find a language where it's efficient" than "this is an interesting language, let's find the best algorithm in it". (Although Retina is an interesting language anyway, as it happens!) I guess this is a weird side effect of the "competition per-language"; it means that you can make an answer "better", in some sense, by translating it to a language which doesn't deal with translations of competing answers well.
â ais523
Sep 28 at 5:08
I believe[¶-2]saves a byte since you should be able to assume the input consists only of numeric digits and the newline.
â FryAmTheEggman
Oct 2 at 3:16
add a comment |Â
up vote
9
down vote
Retina, 11 bytes of Latin-1
v`.3*[012ö]
Try it online!
Retina works on strings rather than integers, so I'm taking the number as it'd appear in a file (digits followed by a newline).
Algorithm
Almost all the solutions here have a multiplication by 3, but I thought it'd be interesting to try to solve the problem without it. We already know from the algorithm most people are using that we need to identify the number of suffixes of 3n that are divisible by 3. Now, given a suffix of n (say s), 3s will appear as a suffix of 3n if the multiplication sÃÂ3 does not carry into the digit before the suffix. Meanwhile, if the multiplication sÃÂ3 does carry, then the corresponding suffix of 3n will not be divisible by 3 (as the digital root of 3*s* is divisible by 3 â 3 divides (10-1) and we're working in base 10 â and the corresponding suffix of 3*n* will be equal to 3*s* but without a leading 1 or 2, neither of which is divisible by 3).
We do need to adjust for the possibility that 3*n* has more digits than n, thus meaning that 3*n* has an extra suffix that doesn't correspond to any suffix of n. This suffix is trivially the whole number 3*n*, and will always be divisible by 3 (for obvious reasons). Thus, if the multiplication nÃÂ3 carries, we have to add 1 to the result. We can note that if nÃÂ3 doesn't carry, it will contribute 1 to the result using a naive algorithm, whereas if it does, it won't; and thus we can do this adjustment simply by counting the "suffix that represents the whole number n" unconditionally, rather than checking for a carry. Equivalently (and slightly more tersely), we can unconditionally not count this suffix, and count some other suffix instead (the empty suffix is convenient), as it'll come to the same total.
How do we determine if a multiplication by 3 would carry? Well, if the first digit of the number is greater than 3, it must; if it's less than 3, it can't. If it's 3, whether it carries or not will depend on the next digit of the number in the same way. If the number consists entirely of 3s, the multiplication won't carry (it'll stop just short at a number consisting entirely of 9s). Thus, the algorithm we want is "count the number of proper suffixes that start with 0 or more 3s, followed by 0, 1, 2, or the end of the string; plus one extra suffix".
Explanation
This algorithm ends up longer than the consensus algorithm in most languages, so I'm submitting it in Retina, a language where it turns out to be shorter than the more usual method (and a similar length to golfing languages).
v`.3*[012ö]
v` Count the number of points within the input from which you can
. ignore one character,
3* and skip past any number (including zero) of 3s,
[012ö] to find 0, 1, 2, or the newline at the end of the input.
The requirement to ignore one character before we start looking means that the improper suffix consisting of the whole number cannot be counted (as the suffixes that we actually look at will be the ones starting one character to the right of where Retina starts, and thus not at the first character). However, the improper suffix consisting only of the newline at the end of the number will always be counted, thus giving us the one extra suffix we need.
This was the algorithm I had in mind when I wrote the question. I'm glad to see someone used it!
â W W
Sep 28 at 3:48
@WW: This answer was more a case of "this is an interesting algorithm, let's find a language where it's efficient" than "this is an interesting language, let's find the best algorithm in it". (Although Retina is an interesting language anyway, as it happens!) I guess this is a weird side effect of the "competition per-language"; it means that you can make an answer "better", in some sense, by translating it to a language which doesn't deal with translations of competing answers well.
â ais523
Sep 28 at 5:08
I believe[¶-2]saves a byte since you should be able to assume the input consists only of numeric digits and the newline.
â FryAmTheEggman
Oct 2 at 3:16
add a comment |Â
up vote
9
down vote
up vote
9
down vote
Retina, 11 bytes of Latin-1
v`.3*[012ö]
Try it online!
Retina works on strings rather than integers, so I'm taking the number as it'd appear in a file (digits followed by a newline).
Algorithm
Almost all the solutions here have a multiplication by 3, but I thought it'd be interesting to try to solve the problem without it. We already know from the algorithm most people are using that we need to identify the number of suffixes of 3n that are divisible by 3. Now, given a suffix of n (say s), 3s will appear as a suffix of 3n if the multiplication sÃÂ3 does not carry into the digit before the suffix. Meanwhile, if the multiplication sÃÂ3 does carry, then the corresponding suffix of 3n will not be divisible by 3 (as the digital root of 3*s* is divisible by 3 â 3 divides (10-1) and we're working in base 10 â and the corresponding suffix of 3*n* will be equal to 3*s* but without a leading 1 or 2, neither of which is divisible by 3).
We do need to adjust for the possibility that 3*n* has more digits than n, thus meaning that 3*n* has an extra suffix that doesn't correspond to any suffix of n. This suffix is trivially the whole number 3*n*, and will always be divisible by 3 (for obvious reasons). Thus, if the multiplication nÃÂ3 carries, we have to add 1 to the result. We can note that if nÃÂ3 doesn't carry, it will contribute 1 to the result using a naive algorithm, whereas if it does, it won't; and thus we can do this adjustment simply by counting the "suffix that represents the whole number n" unconditionally, rather than checking for a carry. Equivalently (and slightly more tersely), we can unconditionally not count this suffix, and count some other suffix instead (the empty suffix is convenient), as it'll come to the same total.
How do we determine if a multiplication by 3 would carry? Well, if the first digit of the number is greater than 3, it must; if it's less than 3, it can't. If it's 3, whether it carries or not will depend on the next digit of the number in the same way. If the number consists entirely of 3s, the multiplication won't carry (it'll stop just short at a number consisting entirely of 9s). Thus, the algorithm we want is "count the number of proper suffixes that start with 0 or more 3s, followed by 0, 1, 2, or the end of the string; plus one extra suffix".
Explanation
This algorithm ends up longer than the consensus algorithm in most languages, so I'm submitting it in Retina, a language where it turns out to be shorter than the more usual method (and a similar length to golfing languages).
v`.3*[012ö]
v` Count the number of points within the input from which you can
. ignore one character,
3* and skip past any number (including zero) of 3s,
[012ö] to find 0, 1, 2, or the newline at the end of the input.
The requirement to ignore one character before we start looking means that the improper suffix consisting of the whole number cannot be counted (as the suffixes that we actually look at will be the ones starting one character to the right of where Retina starts, and thus not at the first character). However, the improper suffix consisting only of the newline at the end of the number will always be counted, thus giving us the one extra suffix we need.
Retina, 11 bytes of Latin-1
v`.3*[012ö]
Try it online!
Retina works on strings rather than integers, so I'm taking the number as it'd appear in a file (digits followed by a newline).
Algorithm
Almost all the solutions here have a multiplication by 3, but I thought it'd be interesting to try to solve the problem without it. We already know from the algorithm most people are using that we need to identify the number of suffixes of 3n that are divisible by 3. Now, given a suffix of n (say s), 3s will appear as a suffix of 3n if the multiplication sÃÂ3 does not carry into the digit before the suffix. Meanwhile, if the multiplication sÃÂ3 does carry, then the corresponding suffix of 3n will not be divisible by 3 (as the digital root of 3*s* is divisible by 3 â 3 divides (10-1) and we're working in base 10 â and the corresponding suffix of 3*n* will be equal to 3*s* but without a leading 1 or 2, neither of which is divisible by 3).
We do need to adjust for the possibility that 3*n* has more digits than n, thus meaning that 3*n* has an extra suffix that doesn't correspond to any suffix of n. This suffix is trivially the whole number 3*n*, and will always be divisible by 3 (for obvious reasons). Thus, if the multiplication nÃÂ3 carries, we have to add 1 to the result. We can note that if nÃÂ3 doesn't carry, it will contribute 1 to the result using a naive algorithm, whereas if it does, it won't; and thus we can do this adjustment simply by counting the "suffix that represents the whole number n" unconditionally, rather than checking for a carry. Equivalently (and slightly more tersely), we can unconditionally not count this suffix, and count some other suffix instead (the empty suffix is convenient), as it'll come to the same total.
How do we determine if a multiplication by 3 would carry? Well, if the first digit of the number is greater than 3, it must; if it's less than 3, it can't. If it's 3, whether it carries or not will depend on the next digit of the number in the same way. If the number consists entirely of 3s, the multiplication won't carry (it'll stop just short at a number consisting entirely of 9s). Thus, the algorithm we want is "count the number of proper suffixes that start with 0 or more 3s, followed by 0, 1, 2, or the end of the string; plus one extra suffix".
Explanation
This algorithm ends up longer than the consensus algorithm in most languages, so I'm submitting it in Retina, a language where it turns out to be shorter than the more usual method (and a similar length to golfing languages).
v`.3*[012ö]
v` Count the number of points within the input from which you can
. ignore one character,
3* and skip past any number (including zero) of 3s,
[012ö] to find 0, 1, 2, or the newline at the end of the input.
The requirement to ignore one character before we start looking means that the improper suffix consisting of the whole number cannot be counted (as the suffixes that we actually look at will be the ones starting one character to the right of where Retina starts, and thus not at the first character). However, the improper suffix consisting only of the newline at the end of the number will always be counted, thus giving us the one extra suffix we need.
answered Sep 28 at 3:28
community wiki
ais523
This was the algorithm I had in mind when I wrote the question. I'm glad to see someone used it!
â W W
Sep 28 at 3:48
@WW: This answer was more a case of "this is an interesting algorithm, let's find a language where it's efficient" than "this is an interesting language, let's find the best algorithm in it". (Although Retina is an interesting language anyway, as it happens!) I guess this is a weird side effect of the "competition per-language"; it means that you can make an answer "better", in some sense, by translating it to a language which doesn't deal with translations of competing answers well.
â ais523
Sep 28 at 5:08
I believe[¶-2]saves a byte since you should be able to assume the input consists only of numeric digits and the newline.
â FryAmTheEggman
Oct 2 at 3:16
add a comment |Â
This was the algorithm I had in mind when I wrote the question. I'm glad to see someone used it!
â W W
Sep 28 at 3:48
@WW: This answer was more a case of "this is an interesting algorithm, let's find a language where it's efficient" than "this is an interesting language, let's find the best algorithm in it". (Although Retina is an interesting language anyway, as it happens!) I guess this is a weird side effect of the "competition per-language"; it means that you can make an answer "better", in some sense, by translating it to a language which doesn't deal with translations of competing answers well.
â ais523
Sep 28 at 5:08
I believe[¶-2]saves a byte since you should be able to assume the input consists only of numeric digits and the newline.
â FryAmTheEggman
Oct 2 at 3:16
This was the algorithm I had in mind when I wrote the question. I'm glad to see someone used it!
â W W
Sep 28 at 3:48
This was the algorithm I had in mind when I wrote the question. I'm glad to see someone used it!
â W W
Sep 28 at 3:48
@WW: This answer was more a case of "this is an interesting algorithm, let's find a language where it's efficient" than "this is an interesting language, let's find the best algorithm in it". (Although Retina is an interesting language anyway, as it happens!) I guess this is a weird side effect of the "competition per-language"; it means that you can make an answer "better", in some sense, by translating it to a language which doesn't deal with translations of competing answers well.
â ais523
Sep 28 at 5:08
@WW: This answer was more a case of "this is an interesting algorithm, let's find a language where it's efficient" than "this is an interesting language, let's find the best algorithm in it". (Although Retina is an interesting language anyway, as it happens!) I guess this is a weird side effect of the "competition per-language"; it means that you can make an answer "better", in some sense, by translating it to a language which doesn't deal with translations of competing answers well.
â ais523
Sep 28 at 5:08
I believe
[¶-2] saves a byte since you should be able to assume the input consists only of numeric digits and the newline.â FryAmTheEggman
Oct 2 at 3:16
I believe
[¶-2] saves a byte since you should be able to assume the input consists only of numeric digits and the newline.â FryAmTheEggman
Oct 2 at 3:16
add a comment |Â
up vote
7
down vote
Husk, 9 bytes
#oæ3dṫd*3
Try it online or verify the first 2188 terms!
Explanation
#(æ3d)ṫd*3 -- example: 42
*3 -- times 3: 126
d -- digits: [1,2,6]
ṫ -- tails: [[1,2,6],[2,6],[6]]
#( ) -- count values that are truthy when
d -- | undigits: [126,26,6]
æ3 -- | divisible by 3: [42,0,2]
-- : 2
add a comment |Â
up vote
7
down vote
Husk, 9 bytes
#oæ3dṫd*3
Try it online or verify the first 2188 terms!
Explanation
#(æ3d)ṫd*3 -- example: 42
*3 -- times 3: 126
d -- digits: [1,2,6]
ṫ -- tails: [[1,2,6],[2,6],[6]]
#( ) -- count values that are truthy when
d -- | undigits: [126,26,6]
æ3 -- | divisible by 3: [42,0,2]
-- : 2
add a comment |Â
up vote
7
down vote
up vote
7
down vote
Husk, 9 bytes
#oæ3dṫd*3
Try it online or verify the first 2188 terms!
Explanation
#(æ3d)ṫd*3 -- example: 42
*3 -- times 3: 126
d -- digits: [1,2,6]
ṫ -- tails: [[1,2,6],[2,6],[6]]
#( ) -- count values that are truthy when
d -- | undigits: [126,26,6]
æ3 -- | divisible by 3: [42,0,2]
-- : 2
Husk, 9 bytes
#oæ3dṫd*3
Try it online or verify the first 2188 terms!
Explanation
#(æ3d)ṫd*3 -- example: 42
*3 -- times 3: 126
d -- digits: [1,2,6]
ṫ -- tails: [[1,2,6],[2,6],[6]]
#( ) -- count values that are truthy when
d -- | undigits: [126,26,6]
æ3 -- | divisible by 3: [42,0,2]
-- : 2
answered Sep 27 at 15:48
BMO
9,97921774
9,97921774
add a comment |Â
add a comment |Â
up vote
3
down vote
Perl 6, 54 28 bytes
-14 bytes thanks to nwellnhof!
+grep *%%3,[~] .combo*ÃÂ3
Try it online!
This counts how many prefixes of the number times three are divisible by 3.
Explanation:
o*ÃÂ3 # Pass the input times 3 into the code block
[~] .comb # Get all the prefixes of the number
grep , # Filter from that
*%%3 # All numbers divisible by 3
+ # Return the length of the list
Shaved off another byte.
â nwellnhof
Sep 27 at 16:50
@nwellnhof I didn't realise you could combine with Whatever code. Neat!
â Jo King
Sep 27 at 16:59
add a comment |Â
up vote
3
down vote
Perl 6, 54 28 bytes
-14 bytes thanks to nwellnhof!
+grep *%%3,[~] .combo*ÃÂ3
Try it online!
This counts how many prefixes of the number times three are divisible by 3.
Explanation:
o*ÃÂ3 # Pass the input times 3 into the code block
[~] .comb # Get all the prefixes of the number
grep , # Filter from that
*%%3 # All numbers divisible by 3
+ # Return the length of the list
Shaved off another byte.
â nwellnhof
Sep 27 at 16:50
@nwellnhof I didn't realise you could combine with Whatever code. Neat!
â Jo King
Sep 27 at 16:59
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Perl 6, 54 28 bytes
-14 bytes thanks to nwellnhof!
+grep *%%3,[~] .combo*ÃÂ3
Try it online!
This counts how many prefixes of the number times three are divisible by 3.
Explanation:
o*ÃÂ3 # Pass the input times 3 into the code block
[~] .comb # Get all the prefixes of the number
grep , # Filter from that
*%%3 # All numbers divisible by 3
+ # Return the length of the list
Perl 6, 54 28 bytes
-14 bytes thanks to nwellnhof!
+grep *%%3,[~] .combo*ÃÂ3
Try it online!
This counts how many prefixes of the number times three are divisible by 3.
Explanation:
o*ÃÂ3 # Pass the input times 3 into the code block
[~] .comb # Get all the prefixes of the number
grep , # Filter from that
*%%3 # All numbers divisible by 3
+ # Return the length of the list
edited Sep 27 at 16:58
answered Sep 27 at 13:51
Jo King
16.9k24193
16.9k24193
Shaved off another byte.
â nwellnhof
Sep 27 at 16:50
@nwellnhof I didn't realise you could combine with Whatever code. Neat!
â Jo King
Sep 27 at 16:59
add a comment |Â
Shaved off another byte.
â nwellnhof
Sep 27 at 16:50
@nwellnhof I didn't realise you could combine with Whatever code. Neat!
â Jo King
Sep 27 at 16:59
Shaved off another byte.
â nwellnhof
Sep 27 at 16:50
Shaved off another byte.
â nwellnhof
Sep 27 at 16:50
@nwellnhof I didn't realise you could combine with Whatever code. Neat!
â Jo King
Sep 27 at 16:59
@nwellnhof I didn't realise you could combine with Whatever code. Neat!
â Jo King
Sep 27 at 16:59
add a comment |Â
up vote
3
down vote
05AB1E, 14 12 7 6 bytes
3*÷3ÃÂO
-5 bytes creating a port of @BMO's Husk answer.
-1 byte thanks to @Nitrodon by changing suffixes to prefixes.
Try it online or verify the first 1000 items.
Explanation:
3* # Multiply the (implicit) input by 3
# i.e. 26042 â 78126
÷ # List of prefixes
# i.e. 78126 â ["7","78","781","7812","78126"]
3ÃÂ # Check for each if its divisible by 3
# i.e. ["7","78","781","7812","78126"] â [0,1,0,1,1]
O # And take the sum (which is implicitly output)
# i.e. [0,1,0,1,1] â 3
Old 12-bytes answer:
3*.Ã
ÂÃÂ3ÃÂP}â¬gÃÂ
Or alternatively â¬gàcan be éøg.
Try it online or verify the first 1000 items
Explanation:
3* # Multiply the (implicit) input by 3
# i.e. 26042 â 78126
.Ã
 # Take all possible partitions of this number
# i.e. 78126 â [["7","8","1","2","6"],["7","8","1","26"],["7","8","12","6"],
# ...,["781","26"],["7812","6"],["78126"]]
ÃÂ } # Filter these partitions by:
3ÃÂP # Only keep partitions where every number is divisible by 3
# i.e. ["7","8","1","2","6"] â [0,0,0,0,1] â 0
# i.e. ["78","12","6"] â [1,1,1] â 1
#(option 1:)
â¬g # Take the length of each remaining partition
# i.e. [["78","12","6"],["78","126"],["7812","6"],["78126"]] â [3,2,2,1]
ÃÂ # And take the max (which we output implicitly)
# i.e. [3,2,2,1] â 3
#(option 2:)
é # Sort the remaining partitions by length
# i.e. [["78","12","6"],["78","126"],["7812","6"],["78126"]]
# â [["78126"],["78","126"],["7812","6"],["78","12","6"]]
ø # Take the last one (the longest)
# i.e. [["78126"],["78","126"],["7812","6"],["78","12","6"]]
# â ["78","12","6"]
g # And take its length (which we output implicitly)
# i.e. ["78","12","6"] â 3
1
Using prefixes instead of suffixes gives the same result in one fewer byte.
â Nitrodon
Sep 27 at 18:32
@Nitrodon Thanks! :) I knew about the 1-byte prefixes builtin, but didn't realize the challenge works by using prefixes instead of suffixes as well.
â Kevin Cruijssen
Sep 27 at 18:39
add a comment |Â
up vote
3
down vote
05AB1E, 14 12 7 6 bytes
3*÷3ÃÂO
-5 bytes creating a port of @BMO's Husk answer.
-1 byte thanks to @Nitrodon by changing suffixes to prefixes.
Try it online or verify the first 1000 items.
Explanation:
3* # Multiply the (implicit) input by 3
# i.e. 26042 â 78126
÷ # List of prefixes
# i.e. 78126 â ["7","78","781","7812","78126"]
3ÃÂ # Check for each if its divisible by 3
# i.e. ["7","78","781","7812","78126"] â [0,1,0,1,1]
O # And take the sum (which is implicitly output)
# i.e. [0,1,0,1,1] â 3
Old 12-bytes answer:
3*.Ã
ÂÃÂ3ÃÂP}â¬gÃÂ
Or alternatively â¬gàcan be éøg.
Try it online or verify the first 1000 items
Explanation:
3* # Multiply the (implicit) input by 3
# i.e. 26042 â 78126
.Ã
 # Take all possible partitions of this number
# i.e. 78126 â [["7","8","1","2","6"],["7","8","1","26"],["7","8","12","6"],
# ...,["781","26"],["7812","6"],["78126"]]
ÃÂ } # Filter these partitions by:
3ÃÂP # Only keep partitions where every number is divisible by 3
# i.e. ["7","8","1","2","6"] â [0,0,0,0,1] â 0
# i.e. ["78","12","6"] â [1,1,1] â 1
#(option 1:)
â¬g # Take the length of each remaining partition
# i.e. [["78","12","6"],["78","126"],["7812","6"],["78126"]] â [3,2,2,1]
ÃÂ # And take the max (which we output implicitly)
# i.e. [3,2,2,1] â 3
#(option 2:)
é # Sort the remaining partitions by length
# i.e. [["78","12","6"],["78","126"],["7812","6"],["78126"]]
# â [["78126"],["78","126"],["7812","6"],["78","12","6"]]
ø # Take the last one (the longest)
# i.e. [["78126"],["78","126"],["7812","6"],["78","12","6"]]
# â ["78","12","6"]
g # And take its length (which we output implicitly)
# i.e. ["78","12","6"] â 3
1
Using prefixes instead of suffixes gives the same result in one fewer byte.
â Nitrodon
Sep 27 at 18:32
@Nitrodon Thanks! :) I knew about the 1-byte prefixes builtin, but didn't realize the challenge works by using prefixes instead of suffixes as well.
â Kevin Cruijssen
Sep 27 at 18:39
add a comment |Â
up vote
3
down vote
up vote
3
down vote
05AB1E, 14 12 7 6 bytes
3*÷3ÃÂO
-5 bytes creating a port of @BMO's Husk answer.
-1 byte thanks to @Nitrodon by changing suffixes to prefixes.
Try it online or verify the first 1000 items.
Explanation:
3* # Multiply the (implicit) input by 3
# i.e. 26042 â 78126
÷ # List of prefixes
# i.e. 78126 â ["7","78","781","7812","78126"]
3ÃÂ # Check for each if its divisible by 3
# i.e. ["7","78","781","7812","78126"] â [0,1,0,1,1]
O # And take the sum (which is implicitly output)
# i.e. [0,1,0,1,1] â 3
Old 12-bytes answer:
3*.Ã
ÂÃÂ3ÃÂP}â¬gÃÂ
Or alternatively â¬gàcan be éøg.
Try it online or verify the first 1000 items
Explanation:
3* # Multiply the (implicit) input by 3
# i.e. 26042 â 78126
.Ã
 # Take all possible partitions of this number
# i.e. 78126 â [["7","8","1","2","6"],["7","8","1","26"],["7","8","12","6"],
# ...,["781","26"],["7812","6"],["78126"]]
ÃÂ } # Filter these partitions by:
3ÃÂP # Only keep partitions where every number is divisible by 3
# i.e. ["7","8","1","2","6"] â [0,0,0,0,1] â 0
# i.e. ["78","12","6"] â [1,1,1] â 1
#(option 1:)
â¬g # Take the length of each remaining partition
# i.e. [["78","12","6"],["78","126"],["7812","6"],["78126"]] â [3,2,2,1]
ÃÂ # And take the max (which we output implicitly)
# i.e. [3,2,2,1] â 3
#(option 2:)
é # Sort the remaining partitions by length
# i.e. [["78","12","6"],["78","126"],["7812","6"],["78126"]]
# â [["78126"],["78","126"],["7812","6"],["78","12","6"]]
ø # Take the last one (the longest)
# i.e. [["78126"],["78","126"],["7812","6"],["78","12","6"]]
# â ["78","12","6"]
g # And take its length (which we output implicitly)
# i.e. ["78","12","6"] â 3
05AB1E, 14 12 7 6 bytes
3*÷3ÃÂO
-5 bytes creating a port of @BMO's Husk answer.
-1 byte thanks to @Nitrodon by changing suffixes to prefixes.
Try it online or verify the first 1000 items.
Explanation:
3* # Multiply the (implicit) input by 3
# i.e. 26042 â 78126
÷ # List of prefixes
# i.e. 78126 â ["7","78","781","7812","78126"]
3ÃÂ # Check for each if its divisible by 3
# i.e. ["7","78","781","7812","78126"] â [0,1,0,1,1]
O # And take the sum (which is implicitly output)
# i.e. [0,1,0,1,1] â 3
Old 12-bytes answer:
3*.Ã
ÂÃÂ3ÃÂP}â¬gÃÂ
Or alternatively â¬gàcan be éøg.
Try it online or verify the first 1000 items
Explanation:
3* # Multiply the (implicit) input by 3
# i.e. 26042 â 78126
.Ã
 # Take all possible partitions of this number
# i.e. 78126 â [["7","8","1","2","6"],["7","8","1","26"],["7","8","12","6"],
# ...,["781","26"],["7812","6"],["78126"]]
ÃÂ } # Filter these partitions by:
3ÃÂP # Only keep partitions where every number is divisible by 3
# i.e. ["7","8","1","2","6"] â [0,0,0,0,1] â 0
# i.e. ["78","12","6"] â [1,1,1] â 1
#(option 1:)
â¬g # Take the length of each remaining partition
# i.e. [["78","12","6"],["78","126"],["7812","6"],["78126"]] â [3,2,2,1]
ÃÂ # And take the max (which we output implicitly)
# i.e. [3,2,2,1] â 3
#(option 2:)
é # Sort the remaining partitions by length
# i.e. [["78","12","6"],["78","126"],["7812","6"],["78126"]]
# â [["78126"],["78","126"],["7812","6"],["78","12","6"]]
ø # Take the last one (the longest)
# i.e. [["78126"],["78","126"],["7812","6"],["78","12","6"]]
# â ["78","12","6"]
g # And take its length (which we output implicitly)
# i.e. ["78","12","6"] â 3
edited Sep 27 at 18:38
answered Sep 27 at 13:54
Kevin Cruijssen
31.1k553168
31.1k553168
1
Using prefixes instead of suffixes gives the same result in one fewer byte.
â Nitrodon
Sep 27 at 18:32
@Nitrodon Thanks! :) I knew about the 1-byte prefixes builtin, but didn't realize the challenge works by using prefixes instead of suffixes as well.
â Kevin Cruijssen
Sep 27 at 18:39
add a comment |Â
1
Using prefixes instead of suffixes gives the same result in one fewer byte.
â Nitrodon
Sep 27 at 18:32
@Nitrodon Thanks! :) I knew about the 1-byte prefixes builtin, but didn't realize the challenge works by using prefixes instead of suffixes as well.
â Kevin Cruijssen
Sep 27 at 18:39
1
1
Using prefixes instead of suffixes gives the same result in one fewer byte.
â Nitrodon
Sep 27 at 18:32
Using prefixes instead of suffixes gives the same result in one fewer byte.
â Nitrodon
Sep 27 at 18:32
@Nitrodon Thanks! :) I knew about the 1-byte prefixes builtin, but didn't realize the challenge works by using prefixes instead of suffixes as well.
â Kevin Cruijssen
Sep 27 at 18:39
@Nitrodon Thanks! :) I knew about the 1-byte prefixes builtin, but didn't realize the challenge works by using prefixes instead of suffixes as well.
â Kevin Cruijssen
Sep 27 at 18:39
add a comment |Â
up vote
2
down vote
Python 2, 99 88 bytes
lambda n:g(`3*n`)
g=lambda n:int(n)%3<1and 1+max([g(n[i:])for i in range(1,len(n))]+[0])
Try it online!
add a comment |Â
up vote
2
down vote
Python 2, 99 88 bytes
lambda n:g(`3*n`)
g=lambda n:int(n)%3<1and 1+max([g(n[i:])for i in range(1,len(n))]+[0])
Try it online!
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Python 2, 99 88 bytes
lambda n:g(`3*n`)
g=lambda n:int(n)%3<1and 1+max([g(n[i:])for i in range(1,len(n))]+[0])
Try it online!
Python 2, 99 88 bytes
lambda n:g(`3*n`)
g=lambda n:int(n)%3<1and 1+max([g(n[i:])for i in range(1,len(n))]+[0])
Try it online!
edited Sep 27 at 14:01
answered Sep 27 at 13:43
TFeld
12k2833
12k2833
add a comment |Â
add a comment |Â
up vote
2
down vote
APL (Dyalog Unicode), 14 bytes
+/0=3|+âÂÂèâÂÂ3ÃÂâÂÂ
Try it online! or verify the first 1000
Explanaition
+/0=3|+âÂÂèâÂÂ3ÃÂâÂÂ
â â prompt for input
3àâ multiply by 3
âÂÂèâ â convert the number to a vector of digits
+ â take the cumulative sum
3| â find each term modulo 3
+/0= â count those that equal 0
This works because a number is divisible by three if and only if the sum of its digits is divisible by three
add a comment |Â
up vote
2
down vote
APL (Dyalog Unicode), 14 bytes
+/0=3|+âÂÂèâÂÂ3ÃÂâÂÂ
Try it online! or verify the first 1000
Explanaition
+/0=3|+âÂÂèâÂÂ3ÃÂâÂÂ
â â prompt for input
3àâ multiply by 3
âÂÂèâ â convert the number to a vector of digits
+ â take the cumulative sum
3| â find each term modulo 3
+/0= â count those that equal 0
This works because a number is divisible by three if and only if the sum of its digits is divisible by three
add a comment |Â
up vote
2
down vote
up vote
2
down vote
APL (Dyalog Unicode), 14 bytes
+/0=3|+âÂÂèâÂÂ3ÃÂâÂÂ
Try it online! or verify the first 1000
Explanaition
+/0=3|+âÂÂèâÂÂ3ÃÂâÂÂ
â â prompt for input
3àâ multiply by 3
âÂÂèâ â convert the number to a vector of digits
+ â take the cumulative sum
3| â find each term modulo 3
+/0= â count those that equal 0
This works because a number is divisible by three if and only if the sum of its digits is divisible by three
APL (Dyalog Unicode), 14 bytes
+/0=3|+âÂÂèâÂÂ3ÃÂâÂÂ
Try it online! or verify the first 1000
Explanaition
+/0=3|+âÂÂèâÂÂ3ÃÂâÂÂ
â â prompt for input
3àâ multiply by 3
âÂÂèâ â convert the number to a vector of digits
+ â take the cumulative sum
3| â find each term modulo 3
+/0= â count those that equal 0
This works because a number is divisible by three if and only if the sum of its digits is divisible by three
edited Sep 27 at 15:17
answered Sep 27 at 15:11
jslip
71118
71118
add a comment |Â
add a comment |Â
up vote
2
down vote
JavaScript (ES6), 41 bytes
f=(n,i=10)=>!(n*3%i%3)+(n*3>i&&f(n,i*10))
Try it online!
add a comment |Â
up vote
2
down vote
JavaScript (ES6), 41 bytes
f=(n,i=10)=>!(n*3%i%3)+(n*3>i&&f(n,i*10))
Try it online!
add a comment |Â
up vote
2
down vote
up vote
2
down vote
JavaScript (ES6), 41 bytes
f=(n,i=10)=>!(n*3%i%3)+(n*3>i&&f(n,i*10))
Try it online!
JavaScript (ES6), 41 bytes
f=(n,i=10)=>!(n*3%i%3)+(n*3>i&&f(n,i*10))
Try it online!
edited Sep 27 at 16:55
answered Sep 27 at 13:42
Arnauld
65.9k583278
65.9k583278
add a comment |Â
add a comment |Â
up vote
2
down vote
Haskell, 44 bytes
g.(*3).max 1
g 0=0
g n=0^mod n 3+g(div n 10)
Try it online!
Uses Delfad0r's observation that the output is the number of suffixes (equivalently, prefixes) of 3n that are multiples of 3. This method finds the prefixes arithmetically by repeatedly floor-dividing by 10 rather than using the string representation. The 0^ is a short arithmetic way to produce 1 if the exponent mod n 3 is zero, and produce 0 otherwise.
The first line is the main function, which triples the input before passing it to the helper function g which is defined recursively. The max 1 is a hack to make f(0) equal 1, since we're required to handle zero like the string '0' rather than the empty string.
add a comment |Â
up vote
2
down vote
Haskell, 44 bytes
g.(*3).max 1
g 0=0
g n=0^mod n 3+g(div n 10)
Try it online!
Uses Delfad0r's observation that the output is the number of suffixes (equivalently, prefixes) of 3n that are multiples of 3. This method finds the prefixes arithmetically by repeatedly floor-dividing by 10 rather than using the string representation. The 0^ is a short arithmetic way to produce 1 if the exponent mod n 3 is zero, and produce 0 otherwise.
The first line is the main function, which triples the input before passing it to the helper function g which is defined recursively. The max 1 is a hack to make f(0) equal 1, since we're required to handle zero like the string '0' rather than the empty string.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Haskell, 44 bytes
g.(*3).max 1
g 0=0
g n=0^mod n 3+g(div n 10)
Try it online!
Uses Delfad0r's observation that the output is the number of suffixes (equivalently, prefixes) of 3n that are multiples of 3. This method finds the prefixes arithmetically by repeatedly floor-dividing by 10 rather than using the string representation. The 0^ is a short arithmetic way to produce 1 if the exponent mod n 3 is zero, and produce 0 otherwise.
The first line is the main function, which triples the input before passing it to the helper function g which is defined recursively. The max 1 is a hack to make f(0) equal 1, since we're required to handle zero like the string '0' rather than the empty string.
Haskell, 44 bytes
g.(*3).max 1
g 0=0
g n=0^mod n 3+g(div n 10)
Try it online!
Uses Delfad0r's observation that the output is the number of suffixes (equivalently, prefixes) of 3n that are multiples of 3. This method finds the prefixes arithmetically by repeatedly floor-dividing by 10 rather than using the string representation. The 0^ is a short arithmetic way to produce 1 if the exponent mod n 3 is zero, and produce 0 otherwise.
The first line is the main function, which triples the input before passing it to the helper function g which is defined recursively. The max 1 is a hack to make f(0) equal 1, since we're required to handle zero like the string '0' rather than the empty string.
answered Sep 27 at 23:40
xnor
87.3k17181432
87.3k17181432
add a comment |Â
add a comment |Â
up vote
2
down vote
MathGolf, 15 14 bytes
3*âÂÂ0ÃÂç_3÷;]ã
Try it online!
-1 byte thanks to JoKing
Explanation
3* Multiply the input by 3
â Convert to a list of digits
0 Push a zero and swap the top two elements
ÃÂ Execute the next 5 characters for each block
ç Concatenate
_ Duplicate
3÷ Check divisibility by 3 (returns 0 or 1)
Swap top two elements
; Discard TOS (the last swap
]ã Wrap the entire stack in an array and output its sum
I don't know if this is the correct solution to the problem but it mimics the JS solution by Arnauld. If I'm incorrect, I'll try to fix it.
14 bytes
â Jo King
Sep 28 at 4:45
@JoKing I'll have do figure out what your code does, then I'll update with an explanation (I know what it does, but not why it works)
â maxb
Sep 28 at 6:04
add a comment |Â
up vote
2
down vote
MathGolf, 15 14 bytes
3*âÂÂ0ÃÂç_3÷;]ã
Try it online!
-1 byte thanks to JoKing
Explanation
3* Multiply the input by 3
â Convert to a list of digits
0 Push a zero and swap the top two elements
ÃÂ Execute the next 5 characters for each block
ç Concatenate
_ Duplicate
3÷ Check divisibility by 3 (returns 0 or 1)
Swap top two elements
; Discard TOS (the last swap
]ã Wrap the entire stack in an array and output its sum
I don't know if this is the correct solution to the problem but it mimics the JS solution by Arnauld. If I'm incorrect, I'll try to fix it.
14 bytes
â Jo King
Sep 28 at 4:45
@JoKing I'll have do figure out what your code does, then I'll update with an explanation (I know what it does, but not why it works)
â maxb
Sep 28 at 6:04
add a comment |Â
up vote
2
down vote
up vote
2
down vote
MathGolf, 15 14 bytes
3*âÂÂ0ÃÂç_3÷;]ã
Try it online!
-1 byte thanks to JoKing
Explanation
3* Multiply the input by 3
â Convert to a list of digits
0 Push a zero and swap the top two elements
ÃÂ Execute the next 5 characters for each block
ç Concatenate
_ Duplicate
3÷ Check divisibility by 3 (returns 0 or 1)
Swap top two elements
; Discard TOS (the last swap
]ã Wrap the entire stack in an array and output its sum
I don't know if this is the correct solution to the problem but it mimics the JS solution by Arnauld. If I'm incorrect, I'll try to fix it.
MathGolf, 15 14 bytes
3*âÂÂ0ÃÂç_3÷;]ã
Try it online!
-1 byte thanks to JoKing
Explanation
3* Multiply the input by 3
â Convert to a list of digits
0 Push a zero and swap the top two elements
ÃÂ Execute the next 5 characters for each block
ç Concatenate
_ Duplicate
3÷ Check divisibility by 3 (returns 0 or 1)
Swap top two elements
; Discard TOS (the last swap
]ã Wrap the entire stack in an array and output its sum
I don't know if this is the correct solution to the problem but it mimics the JS solution by Arnauld. If I'm incorrect, I'll try to fix it.
edited Sep 28 at 8:18
answered Sep 27 at 13:58
maxb
1,6481621
1,6481621
14 bytes
â Jo King
Sep 28 at 4:45
@JoKing I'll have do figure out what your code does, then I'll update with an explanation (I know what it does, but not why it works)
â maxb
Sep 28 at 6:04
add a comment |Â
14 bytes
â Jo King
Sep 28 at 4:45
@JoKing I'll have do figure out what your code does, then I'll update with an explanation (I know what it does, but not why it works)
â maxb
Sep 28 at 6:04
14 bytes
â Jo King
Sep 28 at 4:45
14 bytes
â Jo King
Sep 28 at 4:45
@JoKing I'll have do figure out what your code does, then I'll update with an explanation (I know what it does, but not why it works)
â maxb
Sep 28 at 6:04
@JoKing I'll have do figure out what your code does, then I'll update with an explanation (I know what it does, but not why it works)
â maxb
Sep 28 at 6:04
add a comment |Â
up vote
1
down vote
Pyth, 16 15 bytes
lef!.E%vT3./`*3
Try it online here.
lef!.E%vT3./`*3Q Implicit: Q=eval(input())
Trailing Q inferred
`*3Q Input * 3
` Convert to string
./ Take divisions into disjoint substrings
f Filter the above using:
vT Convert each back to integer
% 3 Mod 3
.E Are any non-0?
! Logical NOT
le Take the length of the last value
As the substring sets are generated in order of number of
substrings, the last value is guaranteed to be the longest
add a comment |Â
up vote
1
down vote
Pyth, 16 15 bytes
lef!.E%vT3./`*3
Try it online here.
lef!.E%vT3./`*3Q Implicit: Q=eval(input())
Trailing Q inferred
`*3Q Input * 3
` Convert to string
./ Take divisions into disjoint substrings
f Filter the above using:
vT Convert each back to integer
% 3 Mod 3
.E Are any non-0?
! Logical NOT
le Take the length of the last value
As the substring sets are generated in order of number of
substrings, the last value is guaranteed to be the longest
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Pyth, 16 15 bytes
lef!.E%vT3./`*3
Try it online here.
lef!.E%vT3./`*3Q Implicit: Q=eval(input())
Trailing Q inferred
`*3Q Input * 3
` Convert to string
./ Take divisions into disjoint substrings
f Filter the above using:
vT Convert each back to integer
% 3 Mod 3
.E Are any non-0?
! Logical NOT
le Take the length of the last value
As the substring sets are generated in order of number of
substrings, the last value is guaranteed to be the longest
Pyth, 16 15 bytes
lef!.E%vT3./`*3
Try it online here.
lef!.E%vT3./`*3Q Implicit: Q=eval(input())
Trailing Q inferred
`*3Q Input * 3
` Convert to string
./ Take divisions into disjoint substrings
f Filter the above using:
vT Convert each back to integer
% 3 Mod 3
.E Are any non-0?
! Logical NOT
le Take the length of the last value
As the substring sets are generated in order of number of
substrings, the last value is guaranteed to be the longest
edited Sep 27 at 14:08
answered Sep 27 at 13:55
Sok
3,041722
3,041722
add a comment |Â
add a comment |Â
up vote
1
down vote
Shakespeare Programming Language, 376 bytes
T.Ajax,.Page,.Act I:x.Scene I:x[Enter Ajax and Page]Ajax:Listen tothy!You be the sum ofthe sum ofyou you you!Scene V:x.Page:You be the sum ofyou the quotient betweena cat the sum ofa cat the remainder of the quotient betweenI the sum ofa big cat a cat!Ajax:You be the quotient betweenyou twice the sum ofa big big cat a cat!Be you nicer zero?If solet usscene V.Page:Open heart
Try it online!
I wonder if the 1/(1+I/3) trick is better than a control flow.
You don't need thexafter scenes. Try it online!
â Jo King
Sep 27 at 17:28
add a comment |Â
up vote
1
down vote
Shakespeare Programming Language, 376 bytes
T.Ajax,.Page,.Act I:x.Scene I:x[Enter Ajax and Page]Ajax:Listen tothy!You be the sum ofthe sum ofyou you you!Scene V:x.Page:You be the sum ofyou the quotient betweena cat the sum ofa cat the remainder of the quotient betweenI the sum ofa big cat a cat!Ajax:You be the quotient betweenyou twice the sum ofa big big cat a cat!Be you nicer zero?If solet usscene V.Page:Open heart
Try it online!
I wonder if the 1/(1+I/3) trick is better than a control flow.
You don't need thexafter scenes. Try it online!
â Jo King
Sep 27 at 17:28
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Shakespeare Programming Language, 376 bytes
T.Ajax,.Page,.Act I:x.Scene I:x[Enter Ajax and Page]Ajax:Listen tothy!You be the sum ofthe sum ofyou you you!Scene V:x.Page:You be the sum ofyou the quotient betweena cat the sum ofa cat the remainder of the quotient betweenI the sum ofa big cat a cat!Ajax:You be the quotient betweenyou twice the sum ofa big big cat a cat!Be you nicer zero?If solet usscene V.Page:Open heart
Try it online!
I wonder if the 1/(1+I/3) trick is better than a control flow.
Shakespeare Programming Language, 376 bytes
T.Ajax,.Page,.Act I:x.Scene I:x[Enter Ajax and Page]Ajax:Listen tothy!You be the sum ofthe sum ofyou you you!Scene V:x.Page:You be the sum ofyou the quotient betweena cat the sum ofa cat the remainder of the quotient betweenI the sum ofa big cat a cat!Ajax:You be the quotient betweenyou twice the sum ofa big big cat a cat!Be you nicer zero?If solet usscene V.Page:Open heart
Try it online!
I wonder if the 1/(1+I/3) trick is better than a control flow.
answered Sep 27 at 17:07
user202729
13k12549
13k12549
You don't need thexafter scenes. Try it online!
â Jo King
Sep 27 at 17:28
add a comment |Â
You don't need thexafter scenes. Try it online!
â Jo King
Sep 27 at 17:28
You don't need the
x after scenes. Try it online!â Jo King
Sep 27 at 17:28
You don't need the
x after scenes. Try it online!â Jo King
Sep 27 at 17:28
add a comment |Â
up vote
1
down vote
Java 10, 66 bytes
n->int m=1,r=n<1?1:0;for(n*=3;m<n;m*=10)r+=n%m%3<1?1:0;return r;
Try it online.
Explanation:
Uses a combination of @BMO's Husk answer (checking how many prefixex are divisible by 3) and @Arnauld's JavaScript (ES6) answer (multiplying an integer by 10 every iteration, and get the prefixes with a modulo of this integer).
n-> // Method with integer as both parameter and return-type
int m=1, // Modulo-integer, starting at 1
r= // Result-integer, starting at:
n<1? // If the input is the edge-case 0:
1 // Start it at 1
: // Else:
0; // Start it at 0
for(n*=3; // Multiply the input by 3
m<n; // Loop as long as `m` is still smaller than `n`
m*=10) // After every iteration: Multiply `m` by 10
r+=n%m // If `n` modulo-`m` (to get a suffix),
%3<1? // is divisible by 3:
1 // Increase the result-sum by 1
: // Else:
0; // Leave the result-sum the same by adding 0
return r; // Return the result-sum
add a comment |Â
up vote
1
down vote
Java 10, 66 bytes
n->int m=1,r=n<1?1:0;for(n*=3;m<n;m*=10)r+=n%m%3<1?1:0;return r;
Try it online.
Explanation:
Uses a combination of @BMO's Husk answer (checking how many prefixex are divisible by 3) and @Arnauld's JavaScript (ES6) answer (multiplying an integer by 10 every iteration, and get the prefixes with a modulo of this integer).
n-> // Method with integer as both parameter and return-type
int m=1, // Modulo-integer, starting at 1
r= // Result-integer, starting at:
n<1? // If the input is the edge-case 0:
1 // Start it at 1
: // Else:
0; // Start it at 0
for(n*=3; // Multiply the input by 3
m<n; // Loop as long as `m` is still smaller than `n`
m*=10) // After every iteration: Multiply `m` by 10
r+=n%m // If `n` modulo-`m` (to get a suffix),
%3<1? // is divisible by 3:
1 // Increase the result-sum by 1
: // Else:
0; // Leave the result-sum the same by adding 0
return r; // Return the result-sum
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Java 10, 66 bytes
n->int m=1,r=n<1?1:0;for(n*=3;m<n;m*=10)r+=n%m%3<1?1:0;return r;
Try it online.
Explanation:
Uses a combination of @BMO's Husk answer (checking how many prefixex are divisible by 3) and @Arnauld's JavaScript (ES6) answer (multiplying an integer by 10 every iteration, and get the prefixes with a modulo of this integer).
n-> // Method with integer as both parameter and return-type
int m=1, // Modulo-integer, starting at 1
r= // Result-integer, starting at:
n<1? // If the input is the edge-case 0:
1 // Start it at 1
: // Else:
0; // Start it at 0
for(n*=3; // Multiply the input by 3
m<n; // Loop as long as `m` is still smaller than `n`
m*=10) // After every iteration: Multiply `m` by 10
r+=n%m // If `n` modulo-`m` (to get a suffix),
%3<1? // is divisible by 3:
1 // Increase the result-sum by 1
: // Else:
0; // Leave the result-sum the same by adding 0
return r; // Return the result-sum
Java 10, 66 bytes
n->int m=1,r=n<1?1:0;for(n*=3;m<n;m*=10)r+=n%m%3<1?1:0;return r;
Try it online.
Explanation:
Uses a combination of @BMO's Husk answer (checking how many prefixex are divisible by 3) and @Arnauld's JavaScript (ES6) answer (multiplying an integer by 10 every iteration, and get the prefixes with a modulo of this integer).
n-> // Method with integer as both parameter and return-type
int m=1, // Modulo-integer, starting at 1
r= // Result-integer, starting at:
n<1? // If the input is the edge-case 0:
1 // Start it at 1
: // Else:
0; // Start it at 0
for(n*=3; // Multiply the input by 3
m<n; // Loop as long as `m` is still smaller than `n`
m*=10) // After every iteration: Multiply `m` by 10
r+=n%m // If `n` modulo-`m` (to get a suffix),
%3<1? // is divisible by 3:
1 // Increase the result-sum by 1
: // Else:
0; // Leave the result-sum the same by adding 0
return r; // Return the result-sum
answered Sep 27 at 18:36
Kevin Cruijssen
31.1k553168
31.1k553168
add a comment |Â
add a comment |Â
up vote
1
down vote
Retina, 35 32 bytes
.+
$.(*3*
Lv$`.+
<$&*->
<(---)*>
Try it online! Explanation:
.+
$.(*3*
Multiply the input by 3.
Lv$`.+
<$&*->
Convert each suffix to unary.
<(---)*>
Count the multiples of three.
add a comment |Â
up vote
1
down vote
Retina, 35 32 bytes
.+
$.(*3*
Lv$`.+
<$&*->
<(---)*>
Try it online! Explanation:
.+
$.(*3*
Multiply the input by 3.
Lv$`.+
<$&*->
Convert each suffix to unary.
<(---)*>
Count the multiples of three.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Retina, 35 32 bytes
.+
$.(*3*
Lv$`.+
<$&*->
<(---)*>
Try it online! Explanation:
.+
$.(*3*
Multiply the input by 3.
Lv$`.+
<$&*->
Convert each suffix to unary.
<(---)*>
Count the multiples of three.
Retina, 35 32 bytes
.+
$.(*3*
Lv$`.+
<$&*->
<(---)*>
Try it online! Explanation:
.+
$.(*3*
Multiply the input by 3.
Lv$`.+
<$&*->
Convert each suffix to unary.
<(---)*>
Count the multiples of three.
edited Sep 27 at 21:26
answered Sep 27 at 16:04
Neil
75.9k744172
75.9k744172
add a comment |Â
add a comment |Â
up vote
1
down vote
K (ngn/k), 16 bytes
+/~3!+.:'$3*x
Try it online!
add a comment |Â
up vote
1
down vote
K (ngn/k), 16 bytes
+/~3!+.:'$3*x
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
K (ngn/k), 16 bytes
+/~3!+.:'$3*x
Try it online!
K (ngn/k), 16 bytes
+/~3!+.:'$3*x
Try it online!
answered Sep 28 at 9:06
ngn
6,30812358
6,30812358
add a comment |Â
add a comment |Â
up vote
1
down vote
Python 2, 48 bytes
n=input()*3;p=n<1
while n:p+=n%3<1;n/=10
print p
Try it online!
Similar to ovs's answer, but takes the whole prefix mod 3 without accumulating rather than the last digit. Outputs True as 1 on input of 0.
Python 3, 42 bytes
f=lambda n:n>=1and(n%1<1/3)+f(n/10)or n==0
Try it online!
Uses ideas from ais523's very nice solution. Repeatedly floor-divides the input by 10 until it's zero, and counts how many times the fractional part is less than 1/3. On very large inputs float precision will eventually be a problem. The n=0 case is handled with or n==0 making it return True for 1. The code can work in Python 2 if the input is a float, if we rewrite n%1<1/3 as n%1*3<1 which is the same length.
add a comment |Â
up vote
1
down vote
Python 2, 48 bytes
n=input()*3;p=n<1
while n:p+=n%3<1;n/=10
print p
Try it online!
Similar to ovs's answer, but takes the whole prefix mod 3 without accumulating rather than the last digit. Outputs True as 1 on input of 0.
Python 3, 42 bytes
f=lambda n:n>=1and(n%1<1/3)+f(n/10)or n==0
Try it online!
Uses ideas from ais523's very nice solution. Repeatedly floor-divides the input by 10 until it's zero, and counts how many times the fractional part is less than 1/3. On very large inputs float precision will eventually be a problem. The n=0 case is handled with or n==0 making it return True for 1. The code can work in Python 2 if the input is a float, if we rewrite n%1<1/3 as n%1*3<1 which is the same length.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Python 2, 48 bytes
n=input()*3;p=n<1
while n:p+=n%3<1;n/=10
print p
Try it online!
Similar to ovs's answer, but takes the whole prefix mod 3 without accumulating rather than the last digit. Outputs True as 1 on input of 0.
Python 3, 42 bytes
f=lambda n:n>=1and(n%1<1/3)+f(n/10)or n==0
Try it online!
Uses ideas from ais523's very nice solution. Repeatedly floor-divides the input by 10 until it's zero, and counts how many times the fractional part is less than 1/3. On very large inputs float precision will eventually be a problem. The n=0 case is handled with or n==0 making it return True for 1. The code can work in Python 2 if the input is a float, if we rewrite n%1<1/3 as n%1*3<1 which is the same length.
Python 2, 48 bytes
n=input()*3;p=n<1
while n:p+=n%3<1;n/=10
print p
Try it online!
Similar to ovs's answer, but takes the whole prefix mod 3 without accumulating rather than the last digit. Outputs True as 1 on input of 0.
Python 3, 42 bytes
f=lambda n:n>=1and(n%1<1/3)+f(n/10)or n==0
Try it online!
Uses ideas from ais523's very nice solution. Repeatedly floor-divides the input by 10 until it's zero, and counts how many times the fractional part is less than 1/3. On very large inputs float precision will eventually be a problem. The n=0 case is handled with or n==0 making it return True for 1. The code can work in Python 2 if the input is a float, if we rewrite n%1<1/3 as n%1*3<1 which is the same length.
answered Sep 28 at 22:58
xnor
87.3k17181432
87.3k17181432
add a comment |Â
add a comment |Â
up vote
1
down vote
Jelly, 7 bytes
ÃÂ3DÃÂ3á¸ÂS
Try it online!
How it works
ÃÂ3DÃÂ3á¸ÂS Main link. Argument: n
ÃÂ3 Compute 3n.
D Decimal; convert 3n to the array of its digits in base 10.
ÃÂ Accumulate; take the cumulative sum.
Note that an integer and its digit sum are congruent modulo 3.
3ḠTest each partial digit sum for divisibility by 3.
S Take the sum of the Booleans, counting the multiples of 3.
add a comment |Â
up vote
1
down vote
Jelly, 7 bytes
ÃÂ3DÃÂ3á¸ÂS
Try it online!
How it works
ÃÂ3DÃÂ3á¸ÂS Main link. Argument: n
ÃÂ3 Compute 3n.
D Decimal; convert 3n to the array of its digits in base 10.
ÃÂ Accumulate; take the cumulative sum.
Note that an integer and its digit sum are congruent modulo 3.
3ḠTest each partial digit sum for divisibility by 3.
S Take the sum of the Booleans, counting the multiples of 3.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Jelly, 7 bytes
ÃÂ3DÃÂ3á¸ÂS
Try it online!
How it works
ÃÂ3DÃÂ3á¸ÂS Main link. Argument: n
ÃÂ3 Compute 3n.
D Decimal; convert 3n to the array of its digits in base 10.
ÃÂ Accumulate; take the cumulative sum.
Note that an integer and its digit sum are congruent modulo 3.
3ḠTest each partial digit sum for divisibility by 3.
S Take the sum of the Booleans, counting the multiples of 3.
Jelly, 7 bytes
ÃÂ3DÃÂ3á¸ÂS
Try it online!
How it works
ÃÂ3DÃÂ3á¸ÂS Main link. Argument: n
ÃÂ3 Compute 3n.
D Decimal; convert 3n to the array of its digits in base 10.
ÃÂ Accumulate; take the cumulative sum.
Note that an integer and its digit sum are congruent modulo 3.
3ḠTest each partial digit sum for divisibility by 3.
S Take the sum of the Booleans, counting the multiples of 3.
answered Sep 29 at 5:11
Dennisâ¦
182k32292725
182k32292725
add a comment |Â
add a comment |Â
up vote
0
down vote
Stax, 8 bytes
ñNÃÂâ â 1d}
Run and debug it
Unpacked, ungolfed, and commented, it looks like this.
3* triple input
E convert to array of decimal digits
:+ get all prefix sums
F for each prefix sum
3%! is it a multiple of 3?
+ add to running total
Run this one
add a comment |Â
up vote
0
down vote
Stax, 8 bytes
ñNÃÂâ â 1d}
Run and debug it
Unpacked, ungolfed, and commented, it looks like this.
3* triple input
E convert to array of decimal digits
:+ get all prefix sums
F for each prefix sum
3%! is it a multiple of 3?
+ add to running total
Run this one
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Stax, 8 bytes
ñNÃÂâ â 1d}
Run and debug it
Unpacked, ungolfed, and commented, it looks like this.
3* triple input
E convert to array of decimal digits
:+ get all prefix sums
F for each prefix sum
3%! is it a multiple of 3?
+ add to running total
Run this one
Stax, 8 bytes
ñNÃÂâ â 1d}
Run and debug it
Unpacked, ungolfed, and commented, it looks like this.
3* triple input
E convert to array of decimal digits
:+ get all prefix sums
F for each prefix sum
3%! is it a multiple of 3?
+ add to running total
Run this one
answered Sep 27 at 18:30
recursive
4,4961220
4,4961220
add a comment |Â
add a comment |Â
up vote
0
down vote
Japt -x, 12 bytes
*3 s ÃÂ¥+ îðv3
Try it or view results for0-1000
add a comment |Â
up vote
0
down vote
Japt -x, 12 bytes
*3 s ÃÂ¥+ îðv3
Try it or view results for0-1000
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Japt -x, 12 bytes
*3 s ÃÂ¥+ îðv3
Try it or view results for0-1000
Japt -x, 12 bytes
*3 s ÃÂ¥+ îðv3
Try it or view results for0-1000
edited Sep 27 at 20:10
answered Sep 27 at 18:11
Shaggy
17k21662
17k21662
add a comment |Â
add a comment |Â
up vote
0
down vote
J, 20 bytes
1#.0=[:(3|".)3":@*]
Try it online!
add a comment |Â
up vote
0
down vote
J, 20 bytes
1#.0=[:(3|".)3":@*]
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
J, 20 bytes
1#.0=[:(3|".)3":@*]
Try it online!
J, 20 bytes
1#.0=[:(3|".)3":@*]
Try it online!
answered Sep 28 at 7:56
Galen Ivanov
5,0171929
5,0171929
add a comment |Â
add a comment |Â
up vote
0
down vote
Python 2, 56 bytes
n=input()*3;k=p=0
while n:k+=n%10;n/=10;p+=k%3<1
print p
Try it online!
add a comment |Â
up vote
0
down vote
Python 2, 56 bytes
n=input()*3;k=p=0
while n:k+=n%10;n/=10;p+=k%3<1
print p
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Python 2, 56 bytes
n=input()*3;k=p=0
while n:k+=n%10;n/=10;p+=k%3<1
print p
Try it online!
Python 2, 56 bytes
n=input()*3;k=p=0
while n:k+=n%10;n/=10;p+=k%3<1
print p
Try it online!
answered Sep 28 at 20:47
ovs
17.6k21058
17.6k21058
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%2f172910%2fhow-many-threes%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
8
It would be great to have some examples on the form
n -> f(n), wheref(n)is the answer. As it is now, I can't even tell if your 6561 entries are 0-indexed or 1-indexed.â maxb
Sep 27 at 13:34
@maxb There are too many examples to do that format. My list is zero indexed.
â W W
Sep 27 at 13:35
2
Of course, but some select few would be great, in addition to the first example. And from what I can see, we are allowed to split the number $3n$ any way we want? So a brute force implementation would be required (in some languages) to find the maximum number of multiples of 3? Also, do you define 0 as a multiple of 3? From your question it seems like it.
â maxb
Sep 27 at 13:38
@maxb There are two tricks that can be used to get solutions in shorter and faster ways. (hint 3 is special) and yes 0 is a multiple of 3. I dont know how else it could be.
â W W
Sep 27 at 13:54