text:
Increment base-36 strings
This is a code golf version of a similar question I asked on stack earlier but thought it'd be an interesting puzzle.
Given a string of length 10 which represents a base 36 number, increment it by one and return the resulting string.
This means the strings will only contain digits from 0 to 9 and letters from a to z.
Base 36 works as follows:
The right most digit is incremented, first by using 0 to 9

0000000000 > 9 iterations > 0000000009

and after that a to z is used:

000000000a > 25 iterations > 000000000z

If z needs to be incremented it loops back to zero and the digit to its left is incremented:

000000010

Further rules:

You may use upper case or lower case letters.
You may not drop leading zeros. Both input and output are strings of length 10.
You do not need to handle zzzzzzzzzz as input.

Test Cases:
"0000000000" -> "0000000001"
"0000000009" -> "000000000a"
"000000000z" -> "0000000010"
"123456zzzz" -> "1234570000"
"00codegolf" -> "00codegolg"

@JoKing Code-golf, cool ideas, and efficiency I guess.

@JoKing I just edited the question to explain the golf puzzle a bit better, the aim is to create the function or "cycler" to turn one string into the next, the i = i + 1 part of a for loop.

@JoKing changed to bytes.

I like the idea of implementing just the increment operation because it has the potential for strategies other than base-converting there and back.

@xnor I was thinking the same, I am trying to do the puzzle now and I was thinking of the ability to use it in a for-loop or while. for (i = "000"; i == "zzz"; i = up(i)) {} or something.

@JoKing you can use uppercase, you can add to the base-X as much as you want, it just has to be an iterating function that works with string AND integer, capital or not. And no you cannot truncate leading 0's. Will explain the bonus better now.

Welcome to PPCG! This is a nice challenge idea, however as some comments have pointed out, some parts of the specification are unclear. For the future I recommend using our sandbox where you can get feedback on a challenge before posting it.

suggest you add something like "0zzzzzzzzz" (modify the most signficant digit) as a test case. It tripped up my C solution because of an off-by-one-error.

Is there a codegolf style that gives points for readability?

"increment it by one and return the resulting string." <- is an in-place operation ok as well?

added an entry assuming it's ok -- a C entry already does it as well.

@FelixPalmen yes :D

Do I have to return leading zeros?

@MagicOctopusUrn "You may not drop leading zeros."

05AB1E, 10 bytes
Input is in uppercase.
Code
1ì36ö>36B¦

Explanation
1ì           # Prepend a 1 to the number
  36ö        # Convert from base 36 to decimal
     >       # Increment by 1
      36B    # Convert from decimal to base 36
         ¦   # Remove the first character

Uses the 05AB1E encoding. Try it online! or Verify all test cases.

Can be 8 bytes in the new version of 05AB1E.

JavaScript (ES6), 45 bytes
Saved 4 bytes thanks to @O.O.Balance
s=>(parseInt(1+s,36)+1).toString(36).slice(1)

Try it online!

You're insane, good one. +1

45 bytes: https://bit.ly/2K5tjw0

I don't think ES8 anymore after latest golf...

@Downgoat Thanks! You're right. Updated.

Haskell, 58 bytes
d=['0'..'9']
f s=snd(span(<s)$mapM(\_->d++['a'..'z'])d)!!1

Try it online!
A very brute-force strategy: generate all the length-10 base-36 strings in order, and find the one that comes after the input in the list. Take an enormous amount of time on strings far from the start of the list.

Haskell, 60 bytes
q '9'='a'
q c=succ c
f(h:t)|any(<'z')t=h:f t|r<-'0'<$t=q h:r

Try it online!
Reads the string left to right until it reaches a character followed by a suffix of all z's, which may be empty. Increments that character, and replaces the z's with 0's.

Japt, 13 bytes
n36 Ä s36 ù0A

Try it online! and Verify test cases
Takes input as a string
Explanation
n36            converts input to base 36
    Ä           +1
      s36       to base 36 string
          ù0A   left-pad with 0 to length 10

Welcome to Japt! :)

C (gcc), 50 48 bytes
An explicit carry flag wasn't necessary after restructuring the loop to end as soon as no carry would happen. The 9->A adjustment is performed during the loop check.
Thanks to ceilingcat for the suggestion.
f(char*s){for(s+=9;(*s+=*s-57?1:8)>90;*s--=48);}

Try it online!

Original version: 71 57 bytes
This version uses a carry flag to propagate updates: I set it to truthy to begin the increment. The string is modified in-place and only accepts 0-9, A-Z. The tricky part was making sure that 9->A got handled correctly on carries.
Edit: I repurposed the input pointer as the carry flag.
f(s){for(char*t=s+9;s;)*t--+=(s=++*t>90)?-43:7*!(*t-58);}

Try it online!

C, 82 81 53 50 bytes
f(char*s){for(s+=10;*--s>89;)*s=48;*s+=*s-57?1:8;}

Directly modifies the input string; input and output is in upper case. Try it online here. Thanks to Arnauld for golfing 24 bytes and to ceilingcat for golfing 3 more bytes.
Ungolfed:
f(char *s) { // function taking a string argument
     for(s += 10; *--s > 89; ) // skip to the least significant digit, and step through the string until you hit something other than a 'Z' (90 is the ASCII code for 'Z') ...
         *s = 48; // ... replacing each digit with a zero (48 is the ASCII code for '0')
         *s += // the next digit has to be incremented:
         *s - 57 // if it's not a '9' (ASCII code 57) ...
         ? 1 // ... that is straightforward ...
         : 8; // ... otherwise it has to be replaced with an 'A' (ASCII code 65 = 57 + 8)
 }

I think this should be safe: 60 bytes

Actually, you don't really need another pointer: 57 bytes (it does assume that the byte stored immediately before the string is NUL but ... well, it works ^^)

@Arnauld You can't assume a zero byte before the string...

@Jakob I'm not 100% sure about that. We define languages by their implementations. This is C (gcc) running on a TIO VM, where the memory can be -- I think -- assumed to be initially cleared. (I've seen other C answers that make similar assumptions.)

@Arnauld I don't think you can make that assumption – even if the memory is initially cleared, you can't make any assumptions about the memory layout of the program calling the function. But I think your golf is valid regardless, because you stop when a character is smaller than 90 – so it can never read past the start of the string.

By including the testing environment in the 'implementation', I may be taking it a stage too far indeed. But you may still use the 60-byte version which does not rely on any memory assumption.

@Arnauld I've golfed another 4 bytes. It really should be safe, since we don't have to handle ZZZZZZZZZZ. ErikF's answer does the same, but even shorter: https://codegolf.stackexchange.com/a/169468/79343

Stax, 7 bytes
ûæ≥╡►N▀

Run and debug it
Explanation:
|3^|3A|z Full program, implicit input
|3       Convert from base 36
  ^      Increment
   |3    Convert to base 36
     A|z Fill with "0" to length 10
         Implicit output

6502 (NMOS*) machine code routine, 26 bytes
A0 09 F3 FB B1 FB C9 5B 90 07 A9 30 91 FB 88 10 F1 C9 3A D0 04 A9 41 91 FB 60

*) uses an "illegal" opcode ISB/0xF3, works on all original NMOS 6502 chips, not on later CMOS variants.
Expects a pointer to a 10-character string in $fb/$fc which is expected to be a base-36 number. Increments this number in-place.
Doesn't do anything sensible on invalid input (like e.g. a shorter string) -- handles ZZZZZZZZZZ "correctly" by accident ;)
Commented disassembly
; function to increment base 36 number as 10 character string
;
; input:
;   $fb/$fc: address of string to increment
; clobbers:
;   A, Y
 .inc36:
A0 09       LDY #$09            ; start at last character
 .loop:
F3 FB       ISB ($FB),Y         ; increment character ("illegal" opcode)
B1 FB       LDA ($FB),Y         ; load incremented character
C9 5B       CMP #$5B            ; > 'z' ?
90 07       BCC .checkgap       ; no, check for gap between numbers and letters
A9 30       LDA #$30            ; load '0'
91 FB       STA ($FB),Y         ; and store in string
88          DEY                 ; previous position
10 F1       BPL .loop           ; and loop
 .checkgap:
C9 3A       CMP #$3A            ; == '9' + 1 ?
D0 04       BNE .done           ; done if not
A9 41       LDA #$41            ; load 'a'
91 FB       STA ($FB),Y         ; and store in string
 .done:
60          RTS

Example C64 assembler program using the routine:
Online demo

Code in ca65 syntax:
.import inc36   ; link with routine above

.segment "BHDR" ; BASIC header
                .word   $0801           ; load address
                .word   $080b           ; pointer next BASIC line
                .word   2018            ; line number
                .byte   $9e             ; BASIC token "SYS"
                .byte   "2061",$0,$0,$0 ; 2061 ($080d) and terminating 0 bytes

.bss
b36str:         .res    11

.data
prompt:         .byte   "> ", $0

.code
                lda     #<prompt        ; display prompt
                ldy     #>prompt
                jsr     $ab1e

                lda     #<b36str        ; read string into buffer
                ldy     #>b36str
                ldx     #$b
                jsr     readline

                lda     #<b36str        ; address of array to $fb/fc
                sta     $fb
                lda     #>b36str
                sta     $fc
                jsr     inc36           ; call incrementing function

                lda     #<b36str        ; output result
                ldy     #>b36str
                jmp     $ab1e

; read a line of input from keyboard, terminate it with 0
; expects pointer to input buffer in A/Y, buffer length in X
.proc readline
                dex
                stx     $fb
                sta     $fc
                sty     $fd
                ldy     #$0
                sty     $cc             ; enable cursor blinking
                sty     $fe             ; temporary for loop variable
getkey:         jsr     $f142           ; get character from keyboard
                beq     getkey
                sta     $2              ; save to temporary
                and     #$7f
                cmp     #$20            ; check for control character
                bcs     checkout        ; no -> check buffer size
                cmp     #$d             ; was it enter/return?
                beq     prepout         ; -> normal flow
                cmp     #$14            ; was it backspace/delete?
                bne     getkey          ; if not, get next char
                lda     $fe             ; check current index
                beq     getkey          ; zero -> backspace not possible
                bne     prepout         ; skip checking buffer size for bs
checkout:       lda     $fe             ; buffer index
                cmp     $fb             ; check against buffer size
                beq     getkey          ; if it would overflow, loop again
prepout:        sei                     ; no interrupts
                ldy     $d3             ; get current screen column
                lda     ($d1),y         ; and clear
                and     #$7f            ;   cursor in
                sta     ($d1),y         ;   current row
output:         lda     $2              ; load character
                jsr     $e716           ;   and output
                ldx     $cf             ; check cursor phase
                beq     store           ; invisible -> to store
                ldy     $d3             ; get current screen column
                lda     ($d1),y         ; and show
                ora     #$80            ;   cursor in
                sta     ($d1),y         ;   current row
                lda     $2              ; load character
store:          cli                     ; enable interrupts
                cmp     #$14            ; was it backspace/delete?
                beq     backspace       ; to backspace handling code
                cmp     #$d             ; was it enter/return?
                beq     done            ; then we're done.
                ldy     $fe             ; load buffer index
                sta     ($fc),y         ; store character in buffer
                iny                     ; advance buffer index
                sty     $fe
                bne     getkey          ; not zero -> ok
done:           lda     #$0             ; terminate string in buffer with zero
                ldy     $fe             ; get buffer index
                sta     ($fc),y         ; store terminator in buffer
                sei                     ; no interrupts
                ldy     $d3             ; get current screen column
                lda     ($d1),y         ; and clear
                and     #$7f            ;   cursor in
                sta     ($d1),y         ;   current row
                inc     $cc             ; disable cursor blinking
                cli                     ; enable interrupts
                rts                     ; return
backspace:      dec     $fe             ; decrement buffer index
                bcs     getkey          ; and get next key
.endproc

65C02 version can discard the ISB, then use INC after the LDA (), Y (and .done moves up by one line) and be shorter by one byte.

@peterferrie does the 65C02 have an INC for the accu?

@peterferrie ok, it does, nice -- that's what I was missing in the first place on the 6502 :)

Perl 6, 34 32 30 bytes
Thanks to nwellnhof for -2 bytes through the use of the o operator to combine functions
{S/.//}o{base :36(1~$_)+1: 36}

Try it online!
Function that converts the argument to base 36, adds 1, converts back and then formats it. Now uses the same tactic as Adnan's answer to preserve the leading zeroes.

{S/.//}o{base :36(1~$_)+1: 36} for 30 bytes.

@nwellnhof Neat! I haven't ever thought to use o when golfing before, but I can see where it might be useful!

Ah, it's a pity that .succ (increment by one) doesn't work

Online Turing Machine Simulator, 745 bytes
init:0
accept:2
0,0
0,0,>
0,1
0,1,>
0,2
0,2,>
0,3
0,3,>
0,4
0,4,>
0,5
0,5,>
0,6
0,6,>
0,7
0,7,>
0,8
0,8,>
0,9
0,9,>
0,a
0,a,>
0,b
0,b,>
0,c
0,c,>
0,d
0,d,>
0,e
0,e,>
0,f
0,f,>
0,g
0,g,>
0,h
0,h,>
0,i
0,i,>
0,j
0,j,>
0,k
0,k,>
0,l
0,l,>
0,m
0,m,>
0,n
0,n,>
0,o
0,o,>
0,p
0,p,>
0,q
0,q,>
0,r
0,r,>
0,s
0,s,>
0,t
0,t,>
0,u
0,u,>
0,v
0,v,>
0,w
0,w,>
0,x
0,x,>
0,y
0,y,>
0,z
0,z,>
0,_
1,_,<
1,0
2,1,-
1,1
2,2,-
1,2
2,3,-
1,3
2,4,-
1,4
2,5,-
1,5
2,6,-
1,6
2,7,-
1,7
2,8,-
1,8
2,9,-
1,9
2,a,-
1,a
2,b,-
1,b
2,c,-
1,c
2,d,-
1,d
2,e,-
1,e
2,f,-
1,f
2,g,-
1,g
2,h,-
1,h
2,i,-
1,i
2,j,-
1,j
2,k,-
1,k
2,l,-
1,l
2,m,-
1,m
2,n,-
1,n
2,o,-
1,o
2,p,-
1,p
2,q,-
1,q
2,r,-
1,r
2,s,-
1,s
2,t,-
1,t
2,u,-
1,u
2,v,-
1,v
2,w,-
1,w
2,x,-
1,x
2,y,-
1,y
2,z,-
1,z
1,0,<

Online interpreter

brainfuck, 109 bytes
,[>>,]<+[++++<[<--->>-<-]-[<->>+<---]<[[-]>-------<]+>>[[+<+>]<<+[>+<------]>>]-[<+>-----]<++++<]<[<<]>>[.>>]

Try it online!

This is what I was keen to see!

MATL, 12 bytes
36ZAQ5M10&YA

Try it online!
           % Implicit input
36ZA       % convert from base 36 to decimal
Q          % increment by 1
5M         % bring the 36 back on stack (done this way to avoid needing space separator after this)
10         % = minimum length of output string
&YA        % convert back to base 36 with those arguments
           % Implicit output

JavaScript (ES6), 89 bytes
This one is not nearly as byte-efficient as the other JavaScript entry, but I made this without noticing this rule:

Given a string of length 10

So this isn't a serious entry - just for fun! It works with strings of general length, such as 0abc, and prepends a 1 when the first digit is z, e.g. zzz -> 1000. Input must be lowercase.
s=>(l=s[s.length-1],r=s.slice(0,-1),l=='z'?f(r||'0')+0:r+(parseInt(l,36)+1).toString(36))

Explanation
The expression (A, B, C) actually means "do A, then do B, then return C", which I make use of to declare some variables I reuse in the code. s stands for "string", l means "last", r means "rest".
/*1*/ s=>(
/*2*/   l=s[s.length-1],
/*3*/   r=s.slice(0,-1),
/*4*/   l=='z'
/*5*/     ? f(r||'0')+0
/*6*/     : r+(parseInt(l,36)+1).toString(36))

This is a recursive function. For a typical string like aza, it will just increment the last character (see line 6) - azb. But for a string that ends with z, like h0gz, it will run itself on everything up to the last character (the z) and substitute a 0 in place of it (see line 5) - f(h0gz) = f(h0g) + 0 = h0h0.
The ||'0' in line 5 is so that the function works when it's called on a 1-length string (i.e. the string 'z'). Without it, f('') is called (since 'z'.slice(0, -1) is ''), which has undefined behavior (literally - try it yourself), and that's no good. The expected result of f('z') is '10', which is what we get from f('0') + 0, so we use ||'0'. (||'0' is particularly useful because it doesn't get in the way of the usual case - r being at least 1-length (s at least 2-length) - because strings are falsey only when they are 0-length.)
The method for incrementing a string is the same as used in the other JS entry: convert the base-36 "number" into an actual number, add 1, then convert it back to base-36. We don't need to worry about the 1 from incrementing 'z' ('z' -> '10'), since we never actually increment 'z' (see line 4 and 6: the last character is only incremented if it is not 'z').
Also, we never risk discarding leading zeroes, because we don't ever actually manipulate more than a single character at a time - only ever the last character in the string. The rest of the characters are cleanly sliced off as you slice any string and prepended afterwords.

Haskell, 63 bytes
r.f.r
f('9':r)='a':r
f('z':r)='0':f r
f(c:r)=succ c:r
r=reverse

Try it online! Reverses the string and checks the first character:

A 9 is replaced by an a.
A z is replaced by a 0 and recursively the next character is checked.
All other characters are incremented using succ, the successor function which can be used on Chars because they are an instance of the Enum class.

Finally the resulting string is reversed again.

Java 8, 90 76 56 bytes
s->Long.toString(Long.valueOf(1+s,36)+1,36).substring(1)

Accepts both upper-case and lower-case letters for input. Output is always in lower case.
Thanks to Okx for golfing 18 bytes.
Try it online here.
Ungolfed:
s -> // lambda taking a String argument and returning a String
    Long.toString(Long.valueOf(1+s,36)+1,36) // prefix input with '1' to ensure leading zeros, convert to Long using base 36, increment, then convert back to String in base 36
    .substring(1) // remove the leading '1'

Nice! For future reference in older Java you can pad with something like "".format("%10s",t).replace(' ','0')

@Jakob Thanks, that's what I was looking for.

It's shorter to use the approach of adding a 1 at the start then removing it: s->Long.toString(Long.valueOf("1"+s,36)+1,36).substring(1)

@Okx Nice approach. 2 more bytes: "1"+s => 1+s

PHP, 69 64 bytes
lame version:
printf("%010s",base_convert(1+base_convert($argn,36,10),10,36));

Run as pipe with -R. Input case insensitive, output lowercase.
first approach, 69 bytes:
<?=str_pad(base_convert(1+base_convert($argn,36,10),10,36),10,'0',0);

Run as pipe with -F
looping version, also 69 bytes:
for($n=$argn;~$c=$n[$i-=1];)$f||$f=$n[$i]=$c!=9?$c>Y?0:++$c:A;echo$n;

PHP 7.1 only: older PHP does not understand negative string indexes,
younger PHP will yield warnings for undefined constants.
requires uppercase input. Replace Y and A with lowercase letters for lowercase input.

Run as pipe with -nR
... or try them online.

68 bytes: Try it online!

Another 68 bytes version: Try it online! You can use your -R and call this one 66 bytes as well.

@Night2 Good approach; but it can be done even shorter: printf('%010s',($b=base_convert)(1+$b($argn,36,10),10,36)); - 59 bytes

Nice one. Didn't know that we could call a function like this: ($b=base_convert)(a,b,c). I'm learning from you a lot.

Apl (Dyalog Unicode), 30 28 24 bytes
Thanks to ngn for the hint to save some bytes.
(f⍣¯1)1+f←36⊥1,(⎕D,⎕A)⍳⊢

Try it online!

Requires ⎕IO of 0
Uses upper case

why not go one step further and make '1', part of f? then 1↓ will become part of its inverse

even shorter: (⎕D,⎕A)⍳'1', -> 1,(⎕D,⎕A)⍳

one final improvement - it can be rewritten as a train: (f⍣¯1)1+f←36⊥1,(⎕D,⎕A)⍳⊢

Charcoal, 14 bytes
×0⁹←⮌⍘⊕⍘Ｓ³⁶¦³⁶

Try it online! Link is to verbose version of code. Explanation:
×0⁹

Print 9 0s. This serves to pad the result.
←⮌⍘⊕⍘Ｓ³⁶¦³⁶

Convert the input from base 36, incremented it, then convert back to base 36. Then, reverse the result and print it leftwards.

Retina 0.8.2, 12 bytes
T`zo`dl`.z*$

Try it online! Explanation: The dl part of the substitution destination expands to 0-9a-z while the o copies that to the source, resulting in z0-9a-z (although the second z gets ignored as it can never match). This increments the matched digits. The .z*$ part of the pattern matches the last non-z digit plus all trailing zs, thus handling the carry from their increment to 0.

Ruby, 40 bytes
->s{(s.to_i(36)+1).to_s(36).rjust 10,?0}

Try it online!

Convert the string to an integer interpreting it as base 36
Add 1
Convert back to base 36 string
Left pad with 0s

"zzzzzzzzzz" returns an 11-long string

Perl 5 + -pl, 31 bytes
Thanks to @DLosc for saving 3 bytes in the regex!
A different approach to @Xcali in their answer.
s/.z*$/$&=~y!0-9a-z!1-9a-z0!r/e
Try it online!
Explanation
Replaces any character, followed by 0 or more zs, with the result of transliterating 0-9a-z to 1-9a-z0.

@DLosc Thank you! Iterated around the regex a bit and didn't spot that in the end

R, 152 123 bytes
function(x)f(utf8ToInt(x),10)
f=function(x,n,y=x[n]){x[n]=y+(y==57)*39+(y==122)*(-75)+1
"if"(y==122,f(x,n-1),intToUtf8(x))}

Try it online!
A completely different approach. Get the ASCII code points and recursively "increment" the right-most code point (making 0 (57) jump to to a (97) and z (122) go back to 0 (48)) until you run out of zs. Convert back to string.
Old version
function(s,w=gsub("(z)(?=\\1*$)","0",s,,T),x=regexpr(".0*$",w)[1],y=substr(w,x,x),z=chartr("0-9a-z","1-9a-z0",y))sub(p(y,"(0*$)"),p(z,"\\1"),w)
p=paste0

Try it online!
This is all text manipulation, which is does not go hand-in-hand with R code golfing.
Replace all z at end of strings with 0. Find location of last element before the newly minted trailing 0s. Find the next base 36 digit. Make the change. Be glad to have barely beaten the Online Turing Machine Simulator solution.

You can do way better than this!! I think I have 72 bytes, if you can find the right built-in...

Oops...thought this challenge was code bowling!

Well the built-in is strtoi to get you started; there are a couple more golfing tricks to get it down to 72.

strtoi is limited to rather small numbers though? I gave up on it a while ago.

Oh I see. Didn't realize the int restriction was so problematic. Bummer! For posterity, this was my failed solution: Try it online!

Python 2, 88 bytes
def f(s):L,R=s[:-1],s[-1:];return s and[[L+chr(ord(R)+1),f(L)+'0'][R>'y'],L+'a'][R=='9']

Try it online!
Increments the string "by hand".

Clean, 89 84  bytes
import StdEnv
@['9':t]=['a':t]
@['z':t]=['0': @t]
@[c:t]=[inc c:t]
r=reverse

r o@o r

Try it online!
A shorter solution thanks to Laikoni.
Clean, 115 bytes
I love it when I get to use limit(iterate...
import StdEnv
@'9'='a'
@c=inc c
?[h,'{':t]=[@h,'0': ?t]
?[h:t]=[h: ?t]
?e=e
$l=limit(iterate?(init l++[@(last l)]))

Try it online!
Produces the answer without converting bases using list matching.

? :: [Char] -> [Char] performs forward carrying.
@ :: Char -> Char increments by one, accounting for the gap between '9' and 'z'.
$ :: [Char] -> [Char] increments the last character and applies ? until the value stabilizes.

Less fancy, but quite a bit shorter: Try it online!

@Laikoni Edited in, thanks!

Wolfram Language (Mathematica), 39 bytes
IntegerString[#~FromDigits~36+1,36,10]&

Try it online!

Starry, 325 bytes
     + , , , , , , , , , ,     +      +   +   +`* +          + +* + +**      + * +* * '    +           + +* +* +* +*      +* `     +  + +                + +  *       +* *  '    +      +*           + +* +* +*  `   +   +           + +* +  *  **   +  + +'    +    +   ` +           + +* +  *    * .           + +* +  *   * +   '

Try it online!
Explanation:
Put-a-zero-at-the-base-of-the-stack
|     +
Read-10-digits
| , , , , , , , , , ,
Initialise-next-stack
|     +
Initialise-carry-bit
|      +
|   +   +
Do
|`
    Top-of-stack:-[output-stack]-[carry-bit]-[next-value]
    Add-Carry-bit-to-digit
    |*

    Compare-with-58-("9"=57)
    | +
    5-double-triple-sub1-double
    |          + +* + +**      + * +*
    Take-difference
    | *
    If-one-above-"9"
    | '
        set-to-"a"=97=6-double-double-double-double-add1
        |    +
        |           + +* +* +* +*      +*
    | `

    Initialise-next-carry-bit
    |     +
    |  +

    Compare-with-123-("z"=122)
    | +
    11-squared-add2
    |                + +  *       +*
    Take-difference
    | *
    If-one-above-"z"
    |  '
        Delete-current-value
        |    +
        set-carry-bit
        |      +*
        Set-to-"0"=48
        |           + +* +* +*
    |  `

    Push-value-to-stack
    |   +   +
    |           + +* +  *
    |  **

    |   +  +
While-next-value-is-not-null
| +'

Pop-carry-bit-and-null-string-terminator
|    +    +
Do
|   `
    Get-top-value
    | +
    |           + +* +  *
    |    *

    Print-it
    | .

    Pop-the-value-off-the-stack
    |           + +* +  *
    |   *
While-stack-is-not-null
| +   '

Zsh, 41 36 bytes
echo ${(l:10::0:)$(([##36]36#$1+1))}

Try it online!

TypeScript’s type system, 145 bytes
type F<N>=N extends[...infer S,infer D]?"0123456789abcdedghijklmnopqrstuvwxyz"extends`${any}${D&string}${infer I}${any}`?[...S,I]:[...F<S>,"0"]:S

Try it at the TS playground
This is a generic type F<N> which takes a tuple type of characters and returns a type in the same format.
Explanation:
In the input tuple type N, match the last digit D and the rest S.
N extends[...infer S,infer D]

Match 0-9a-z against: anything + D + match the next character as I + anything.
"0123456789abcdedghijklmnopqrstuvwxyz"extends`${any}${D&string}${infer I}${any}`

If the match succeeded, return S + I.
?[...S,I]

Otherwise, recurse with S as the input, and append 0.
:[...F<S>,"0"]

This isn’t tail recursive, but that’s okay because the input is guaranteed to be 10 digits and the recursion limit for non tail-recursive TS types is 50.

Ruby -p, 39 36 bytes
Port of Dom Hastings’ Perl 5 answer; give them an upvote.
-3 bytes thanks to DLosc
sub(/.z*$/){$&.tr"0-9a-z","1-9a-z0"}

Attempt This Online!

@DLosc Well caught. Thanks!

Python 3.6+ and gmpy2, 62 bytes
from gmpy2 import*;f=lambda s:f'{digits(mpz(s,36)+1,36):0>10}'

Try it online!
(Note that gmpy2 isn't part of Python standard library and requires separated installation)

I don't think you need the f=. Anonymous functions are usually considered find in code golf.

Pyke, 11 bytes
? b!!R+bhbt

Try it here!
? b         - Change default base of `base` command to 36
            -  This is kind of clever because it modifies the list of characters
            -  the command uses to exactly the same as it was originally, whilst
            -  forcing an overwrite from the default settings of 10.
            -  The default setup works for base 36, you just have to specify it
            -  time when using the command.
            -  Literally `b.contents = modify(b.contents, func=lambda: noop)`
   !!       - The previous command returns `0123456789abcdefghijklmnopqrstuvwxyz`
            -  So we convert it into a 1 with (not not ^) for the following command:
     R+     -     "1"+input
       b    -    base(^, 36)
        h   -   ^ + 1
         b  -  base(^, 36)
          t - ^[1:]

Could be 2 bytes shorter with the following language change: If hex mode is used, change all base_36 and base_10 usages to base_92 (which isn't really base 92 in that context anyway)

Perl 5 -F, 47 bytes
($_=/z/?0:/9/?a:++$_)&&last for reverse@F;say@F

Try it online!

sed, 94 bytes
s/$/#:0123456789abcdefghijklmnopqrstuvwxyz#0/
:l
s/\(.\)#\(.*:.*\1\)\(#*.\)/\3\2\3/
tl
s/:.*//

Try it online!
Sed suffers a lot for having to change the characters by lookup.

Powershell, 79 78 82 bytes
+4 bytes: z and 9 inside an argument string fixed
$i=1
"$args"[9..0]|%{$r=([char]($i+$_)+'0a')[2*($i*$_-eq57)+($i*=$_-eq'z')]+$r};$r

Less golfed test script:
$f = {

$i=1                    # increment = 1
"$args"[9..0]|%{        # for chars in positions 0..9 in the argument string (in reverse order)
    $c=[char]($i+$_)    # Important! A Powershell calculates from left to right
                        # Therefore the subexpression ($i+$_) gets a value before the subexpression ($i=$_-eq122)
    $j=2*($i*$_-eq57)+  # j = 2 if the current char is '9' and previous i is 1
        ($i*=$_-eq122)  # j = 1 if the current char is 'z' and previous i is 1
                        # j = 0 othewise
                        # side effect is: i = 1 if the current char is 'z' and previous i is 1, i = 0 othewise
    $c=($c+'0a')[$j]    # get element with index j from the array
    $r=$c+$r            # accumulate the result string
}
$r                      # push the result to a pipe

}

@(
    ,("09fizzbuzz" , "09fizzbv00")
    ,("0000000000" , "0000000001")
    ,("0000000009" , "000000000a")
    ,("000000000z" , "0000000010")
    ,("123456zzzz" , "1234570000")
    ,("00codegolf" , "00codegolg")
) | % {
    $s,$expected = $_
    $result = &$f $s
    "$($result-eq$expected): $result"
}

Output:
True: 09fizzBv00
True: 0000000001
True: 000000000a
True: 0000000010
True: 1234570000
True: 00codegolg

C# (.NET Core), 125 bytes
a=>{var x="";for(int i=9;;i--){var y=a[i]==90?'0':a[i]==57?'A':(char)(a[i]+1);x=y+x;a=a.Remove(i);if(y>48)break;}return a+x;}

Try it online!
Ungolfed:
a => {
    var x = "";                 // initialize x
    for (int i = 9; ; i--)      // starting at 9 (length of string minus one) and decrementing i indefinitely
    {
        var y = a[i] == 90 ?        // if the last character of a is 'Z'
            '0' :                       // y = '0'
            a[i] == 57 ?                // if the last character of a is '9'
                'A':                        // y = 'A'
                (char)(a[i] + 1);           // y = the ascii value of last character plus 1
        x = y + x;                  // prepend y to x
        a = a.Remove(i);            // remove the last character of a
        if (y > 48)                 // if y is a character other than '0',
            break;                      // break from the loop
    }
    return a + x;               // return the remainder of a, with x appended
}

Vyxal r, 61 bitsv1, 7.625 bytes
36~β›R↳›

Try it Online!
TIL a) 36β uses the alphabet 0-9a-z, b) β is type aware and c) ↳ pads one string to the length of another.
Explained
36~β›R↳›
36~β      # Convert input from base 36, leaving the 36 on the stack
    ›     # Increment
     R    # and convert to base 36 using the alphabet `0-9A-Z`
      ↳   # pad left to length of input string
       ›  # and replace spaces with 0s

Japt, 9 bytes
n36ÈÄÃùUA

Try it (includes all test cases)
n36ÈÄÃùTA     :Implicit input of string U
n36           :Convert from base 36
   È          :Pass through the following function and convert back
    Ä         :  Add 1
     Ã        :End function
      ùU      :Left pad with original U
        A     :  To length 10

Interesting that in this case, it's shorter to define a function than use the automatic function calling.

Uiua,  74 44 37 34 32 characters
-2 thanks to noodle man
i←|1⊂⟨++1×39=@9.|@0i◌⟩=@z.°⊂
⍜⇌i

Try it here!
Give input by putting it after the code. The part ⍜⇌i is basically indiscernible from a function in Uiua so I think this counts.
Uiua, 74 characters
a←"0123456789abcdefghijklmnopqrstuvwxyz0"
i←|1⊂⟨∘|⊙i⟩=@0.⊡:a+1⊗:a⊢:↘1.
⍜⇌i

For this one, i didn't know you could add 1 to characters yet.
Other changes were the discovery of un join, and using one switch and some math instead of three switches.

Wish I knew about un join, that's cool

You can save 2 characters by changing ⟨+1|@a◌⟩=@9. to ++1×39=@9. (adding 40 to @9 gives @a)

35 character version, which fits on one line, using do instead of recursion: ⊂⇌⊂++1×39=@9.⍢(⊙(⊂@0)◌)(=@z.°⊂):""⇌

Python 3.8 (pre-release), 96 93 84 bytes
-9 bytes thanx to xnor
lambda a:''.join(chr((n:=-~int(a,36)//36**i%36)+48+39*(n>9))for i in range(9,-1,-1))

Try it online!

It looks like you don't need to walrus b since you're only referring to it once: TIO

You're absolutely right! Outgolfed the Python 2 answer by 4 bytes now :)

Elixir, 70 bytes
fn x->"1"<>x=Integer.to_string 1+String.to_integer("1"<>x,36),36;x end

Explanation:
Prepends 1 to the input, converts it to an integer in base 36, increments it, converts it to a string in base 36, and matches it to "1" <> x (reverse concatenation), then returns x.
Try it online!

Jelly, 21 bytes
ØBḊiⱮḅ‘bɗ36Ż9¡ṫ-9‘ịØB

Try it online!
Uses uppercase. TIO link allows for lower/mixed case too.


text:
Let's practice the scoring rules of 421!
421 is a rather popular dice game in France and some other European countries. It is mostly played in bars and pubs to determine who's going to buy the next round of drinks. The full game is usually played in two rounds, with tokens that each player tries to get rid of, but this is irrelevant here. (Wikipedia page in French.)
The game is played with 3 standard cube dice.
Task
Your task is to sort a non-empty list of distinct 3-dice rolls [ X,Y,Z ] from highest to lowest, by applying the scoring rules of this game.
Basic scoring

4,2,1 is the highest possible combination. Depending on the rules, it may score 8, 10 or 11 points. Because we are sorting the rolls rather than counting the points, the exact value doesn't matter.
Three Aces: 1,1,1 is the second highest combination and scores 7 points.
Two-Aces: X,1,1 (where X is 2 to 6) scores X points.
Three-of-a-Kind: X,X,X (where X is 2 to 6) scores X points.
Straights: X,X+1,X+2 scores 2 points.
All other rolls score 1 point.

Settling ties
Whenever two rolls give the same number of points, the following rules apply:

A Two-Aces is better than a Three-of-a-Kind. Example: 5,1,1 beats 5,5,5.
The Three-of-a-Kind 2,2,2 is better than a straight. Example: 2,2,2 beats 4,5,6.
Straights are ordered from lowest to highest. Example: 4,5,6 beats 2,3,4.
All other rolls are settled by sorting the dice from highest to lowest. Example: 6,5,2 beats 6,4,3. (Therefore, the lowest possible combination in the game is 2,2,1.)

Below are the 56 possible distinct rolls ordered from highest to lowest:
421 111 611 666 511 555 411 444 311 333 211 222 654 543 432 321
665 664 663 662 661 655 653 652 651 644 643 642 641 633 632 631
622 621 554 553 552 551 544 542 541 533 532 531 522 521 443 442
441 433 431 422 332 331 322 221

Challenge rules

You may take the rolls in any reasonable format, such as a list of lists [[3,2,1],[4,2,1]], a list of strings ["321","421"], a list of integers [321,421], etc. However, each die must be clearly identifiable with a value from 1 to 6.
For each roll, you can assume that the dice are sorted either from lowest to highest or from highest to lowest, as long as it is consistent. Please state in your answer which order you're expecting, if any.
The shortest answer in bytes wins!

Test cases
Using lists of strings with the dice sorted from highest to lowest:
Inputs
[ "321", "654" ]
[ "222", "321", "211" ]
[ "333", "311", "331", "111" ]
[ "111", "222", "333", "444" ]
[ "321", "421", "521", "621" ]
[ "422", "221", "442", "421", "222" ]
[ "222", "111", "421", "211", "651", "652", "543" ]

Expected outputs
[ "654", "321" ]
[ "211", "222", "321" ]
[ "111", "311", "333", "331" ]
[ "111", "444", "333", "222" ]
[ "421", "321", "621", "521" ]
[ "421", "222", "442", "422", "221" ]
[ "421", "111", "211", "222", "543", "652", "651" ]

Should the sort be stable?

@EriktheOutgolfer All rolls are distinct and two rolls can always be sorted according to the ties rules.

Would it be OK to take each die as 0-5 instead of 1-6 (e.g. 012 instead of 123)?

@wastl I'm going to say no. The format is flexible but the dice values must be in [1...6].

You carry dice to the pub?

@BetaDecay The dice rolling tray is made available by the bartender. This is not as popular as it used to be, though, and you'll only find that kind of games in a few establishments -- usually not the most sophisticated ones.

Python, 93 bytes
lambda a:sorted(a,key=lambda x:(x!=421,x>111,-(x%100<12)*x-(x%111<1)*x*.9,(x%111==99)*-x,-x))

Try it online!

What makes this specific to Python 2?

@SolomonUcko Nothing, but I guess it's marked as Python 2 because it was auto-generated by the Code Golf Submission template from TIO.

You can save 2 bytes by using the fact that 111=37*3 (and only xxx triples among all the possible triplets are divisible by 37) Try it online!

You can lose 2 bytes by sorting in place with the sort method.

Jelly,  37  34 bytes
;Ø1,ẋ3$)Ẏṙ-;‘r’Ɗ€;œċ3$Ṇ63¦
6RṚÇiµÞ

A monadic link accepting a list of lists of dice rolls (each sorted descending) which yields the sorted rolls descending.
Try it online! Or see a test-suite ...or try all rolls sorted lexicographically
How?
This method builds a list of all rolls from highest to lowest*, replacing [4,2,1] with 0 (an invalid input roll), in order to rank each roll using Jelly's first-index-of atom, i.
* The list also includes repeats and redundant entries which wont affect the behaviour:
[[1,1,1],[6,1,1],[6,6,6],[5,1,1],[5,5,5],[4,1,1],[4,4,4],[3,1,1],[3,3,3],[2,1,1],[2,2,2],[1,1,1],[7,6,5],[6,5,4],[5,4,3],[4,3,2],[3,2,1],[2,1,0],[6,6,6],[6,6,5],[6,6,4],[6,6,3],[6,6,2],[6,6,1],[6,5,5],[6,5,4],[6,5,3],[6,5,2],[6,5,1],[6,4,4],[6,4,3],[6,4,2],[6,4,1],[6,3,3],[6,3,2],[6,3,1],[6,2,2],[6,2,1],[6,1,1],[5,5,5],[5,5,4],[5,5,3],[5,5,2],[5,5,1],[5,4,4],[5,4,3],[5,4,2],[5,4,1],[5,3,3],[5,3,2],[5,3,1],[5,2,2],[5,2,1],[5,1,1],[4,4,4],[4,4,3],[4,4,2],[4,4,1],[4,3,3],[4,3,2],[4,3,1],[4,2,2],0,[4,1,1],[3,3,3],[3,3,2],[3,3,1],[3,2,2],[3,2,1],[3,1,1],[2,2,2],[2,2,1],[2,1,1],[1,1,1]]

;Ø1,ẋ3$)Ẏṙ-;‘r’Ɗ€;œċ3$Ṇ63¦ - Link 1, build rolls: descending pips, P  e.g. [6,5,4,3,2,1]
       )                   - for each:       e.g. X=5
 Ø1                        -   literal [1,1]
;                          -   concatenate        [5,1,1]
      $                    -   last two links as a monad (f(X)):
     3                     -     literal 3
    ẋ                      -     repeat           [5,5,5]
   ,                       -   pair               [[5,1,1],[5,5,5]]
        Ẏ                  - tighten (to a list of rolls rather than pairs of rolls)
          -                - literal -1
         ṙ                 - rotate left by (make rightmost [1,1,1] the leftmost entry)
               Ɗ€          - for €ach: last three links as a monad (f(X)):
            ‘              -   increment  -> X+1
              ’            -   decrement  -> X-1
             r             -   range      -> [X+1,X,X-1]
                           -   ...note: [7,6,5] and [2,1,0] are made but are redundant
           ;               - concatenate
                     $     - last two links as a monad (f(P)):
                    3      -   literal 3
                  œċ       -   combinations with replacement -> [[6,6,6],[6,6,5],...,[6,6,1],[6,5,5],...,[1,1,1]]
                 ;         - concatenate
                         ¦ - sparse application...
                       63  - ...to indices: 63
                      Ṇ    - ...what: NOT   -> replaces the [4,2,1] entry with a 0

6RṚÇiµÞ - Main Link: list of rolls
     µÞ - sort by the monadic link:
6       -   six
 R      -   range -> [1,2,3,4,5,6]
  Ṛ     -   reverse -> [6,5,4,3,2,1]
   Ç    -   call the last link as a monad -> [[1,1,1],[6,1,1],[6,6,6],[5,1,1],...]
    i   -   first index of (e.g.: [1,1,1]->1 or [6,1,1]->2 or [4,2,1]->0)

Retina 0.8.2, 67 bytes
O$#^`(421|111)|(\d)((11)|\2\2)|(654|543|432|321)|\d{3}
$1$2$#4$#5$&

Try it online! Link includes test cases. Explanation: The numeric sort key is generated as follows:
421     42100421
111     11100111
611-211   610611-  210211
666-222   600666-  600222
654-321    01654-   01321
653-221    00653-   00221

@Arnauld Sorry, I hadn't realised I'd mixed up those cases. Fortunately I think I've been able to fix it for the same byte count.

Now it's looking fine indeed.

R, 73 bytes
(x=scan())[order(x!=421,x>111,-(x%%100<12)*x-(!x%%37)*x*.9,x%%37!=25,-x)]

Try it online!

Full program taking a list of integer from stdin and returning them in
descending order (i.e. 421 ... 221)
Started as partially inspired by @Lynn answer, now is basically a porting of it... so credits to @Lynn ;)
Saved 2 bytes getting division remainder x % 37 instead of 111

Explanation :
For each of the numbers 5 keys are computed and used hierarchically to sort the array :
key1 = 0 if equal to 421, 1 otherwise
key2 = 0 if equal to 111, 1 otherwise
key3 = 0
       - 1.0*x if number is x11 numbers (2 aces)
       - 0.9*x if number is xxx numbers (3 of a kind)
key4 = 0 if number is a straight, 1 otherwise
key5 = -x

Then the array is sorted by key1 first, then by key2 in case of tie and so on...

05AB1E, 76 48 45 bytes
421X3∍6LR©vy11«y3∍}®vy>y<ŸJ})D®3ãJsм)˜©IΣ®sk>

This turned out to be a lot longer than expected, but at least it's easy to implement. Will see if I can find a better solution.. Made the list by hand now, but still a bit long.
Try it online or verify all test cases.
Explanation:
421             # Push 421 to the stack
X3∍             # ('1' lengthened to size 3) Push 111 to the stack
6LR             # Take the range [6, 1]
   ©            # Save this range in the register so we can re-use it
   v    }       # Loop over this range:
    y11«        #  Merge '11' with the current number `y`, and push it to the stack
    y3∍         #  Lengthen the current number `y` to size 3, and push it to the stack
   ®v      }    # Load the range [6, 1] from the register, and loop over it again:
     y>y<Ÿ      #  Take the range [`y+1`, `y-1`]
          J     #  And join them together to single 3-digit numbers
)               # Push everything that's now on the stack to a single list
 D              # Duplicate this list
  ®             # Load the range [6, 1] from the register again
   3ã           # Take the cartesian repeated three times
     R          # Reverse this list
      J         # Join every inner list to a single 3-digit number
 s              # Swap, so the duplicate list of above is at the top of the stack again
  м             # And remove all those items from the cartesian list
   )            # Combine both lists (as list of lists)
    ˜           # Flatten it
     ©          # Store this full completed list (now equal to the challenge description,
                #  with some additional values we can ignore) in the register
I               # Take the input-list
 Σ              # Sort it by:
  ®             #  The list we generated above
   sk           #  Take the 0-indexed indices
     >          #  And increase it by 1 (because apparently 0 is placed at the back,
                #  so '421' would always be at the end)

Here is the actual list the first part of the code generates:
['421','111','611','666','511','555','411','444','311','333','211','222','111','111','765','654','543','432','321','210','','665','664','663','662','661','656','655','','653','652','651','646','645','644','643','642','641','636','635','634','633','632','631','626','625','624','623','622','621','616','615','614','613','612','','566','565','564','563','562','561','556','','554','553','552','551','546','545','544','','542','541','536','535','534','533','532','531','526','525','524','523','522','521','516','515','514','513','512','','466','465','464','463','462','461','456','455','454','453','452','451','446','445','','443','442','441','436','435','434','433','','431','426','425','424','423','422','','416','415','414','413','412','','366','365','364','363','362','361','356','355','354','353','352','351','346','345','344','343','342','341','336','335','334','','332','331','326','325','324','323','322','','316','315','314','313','312','','266','265','264','263','262','261','256','255','254','253','252','251','246','245','244','243','242','241','236','235','234','233','232','231','226','225','224','223','','221','216','215','214','213','212','','166','165','164','163','162','161','156','155','154','153','152','151','146','145','144','143','142','141','136','135','134','133','132','131','126','125','124','123','122','121','116','115','114','113','112','']

Try it online.
As you can see it contains empty items; numbers like 765 or 210; and numbers in the range [216, 112]. But we can all ignore these, because the items we want to actually sort are in the correct order.

Original 76 bytes solution:
Σ•X˜„Éε´õñ€9Ú ù?ä0₅9úd5àPÎøŒccuĆYÑ,o¾eíË¿¼À8@gID=vÆOΣxjF¨O‡J₃^εR™\èv•667вsk>

Try it online or verify all test cases (no test suite because there is still a bug with sort-by with compressed numbers not seeing the closing bracket to stop the sort).
Explanation:
Σ             # Sort by:
 •...•667в    #  The correctly sorted list of all possible rolls from the challenge
 sk           #  Take the 0-indexed indices
   >          #  And increase it by 1 (because apparently 0 is placed at the back,
              #  so '421' would always be at the end)

Explanation •X˜„Éε´õñ€9Ú ù?ä0₅9úd5àPÎøŒccuĆYÑ,o¾eíË¿¼À8@gID=vÆOΣxjF¨O‡J₃^εR™\èv•667в:
Everything between the two • is a compressed number that is generated with the following program:
Z>β 255B

Try it online.

Z>: Take the max of the list + 1 (667 in this case)
β: Convert the list from Base-667 to a single number
255B: And convert that single number to base 255 (using 05AB1E's code page), so we have our compressed number.

By using 667в it converts this compressed number back to the original list.

JavaScript (ES7), 96 bytes
d=>d.sort((a,b,g=(n,[x,y,z]=n)=>n**=n-421?y*z-1?x-y|y-z?~y%x|~z%y?1:2:3:x-1?3.1:5:5)=>g(b)-g(a))

Sorts rolls by adhering closely to the rules of scoring.
Expects an array of strings with individual rolls in descending order of
value, e.g. ["654"]
Try it online!
Explanation
Categories of rolls are raised to the following exponents:
421                 5
Three Aces          5
Two Aces            3.1
Three-of-a-Kind     3
Straights           2
Other               1

Ungolfed
Mentally unwrapping the conditional checks gives me a headache, and I'm certain it can somehow be further golfed....
var f =
d => d.sort(
    (
     a, b,
     g = (n, [x, y, z] = n) =>               // destructure rolls, e.g. "321" => ["3","2","1"]
        n **=                                // differentiate scores by raising to the exponent corresponding to its category in the table above
                                             // all conditionals check for a falsy value
            n - 421
                ? y * z - 1                  // ends with "11"
                    ? x - y | y - z          // three-of-a-kind
                        ? ~y % x | ~z % y    // straights, with operators chosen to correctly convert strings to numbers
                            ? 1
                            : 2
                        : 3
                    : x - 1                  // three aces
                        ? 3.1
                        : 5
                : 5
    ) =>
    g(b) - g(a)
)

Javascript, 101 chars, 116 bytes (UTF-8)
a=>(r=d=>(i="ƥoɣʚǿȫƛƼķōÓÞʎȟưŁ".indexOf(String.fromCharCode(d)),i<0?700-d:i),a.sort((a,b)=>r(a)-r(b)))

Takes an array of numbers representing the rolls like [ 321, 654 ].
Try it online!
Explanation:
I took the first 16 of the 56 possible distinct rolls (the ones that don't really follow any order) and I encoded them as a string: "ƥoɣʚǿȫƛƼķōÓÞʎȟưŁ". Each character of this string corresponds the the first 16 possible rolls (ƥ is 421, o is 111, ...). Now for each two elements a and b of the array we just check their index from the string, if they are included the index is used, otherwise (the index is -1) we use the roll number itself (we substract it from 700 to inverse the order of the ones not included, i.e. to sort them in a decreasing order).

NB: Unless otherwise specified, code length is always measured in bytes. The number of chars may sometimes be relevant, but I don't think it is here. Relevant meta answer.

@Arnauld Yeah! BTW I'm the one who asked that meta question ;-)

D'oh! I missed this detail entirely... :D

Clean, 169 102 bytes
All octal escapes are counted as one byte, as the Clean compiler will happily take them that way, but TIO and SE won't because they aren't well-formed UTF-8.
import StdEnv
$l=[e\\c<-:"\245\157\143\232\377\53\233\274\67\115\323\336\216\37\260\101\231\230\227\226\225\217\215\214\213\204\203\202\201\171\170\167\156\155\52\51\50\47\40\36\35\25\24\23\n\11\273\272\271\261\257\246\114\113\102\335",e<-l|c==toChar e]

Try it online!
Uses the fact that all the dice rolls, as integers modulo 256, are unique.
Conveniently, Char is treated (mostly) as a modulo 256 integer.

Pyth, 48 bytes
oxs[]j421T]j7 2_sm+Ld,,ddjT9tS6_m_+LdS3 4.C_S6 3

Expects input as a nested array, each element ordered descending. Try it online here, or verify all the test cases at once here.
oxs[]j421T]j7 2_sm+Ld,,ddjT9tS6_m_+LdS3 4.C_S6 3)NQ   Final 3 tokens inferred from context
                                                      Implicit: Q=eval(input()), T=10
    ]j421T                                            Convert 421 to base 10, wrap in array -> [[4,2,1]]
          ]j7 2                                       Convert 7 to base 2, wrap in array -> [[1,1,1]]
                 m          tS6                       Map d in [2,3,4,5,6] using:
                      ,dd                               [d,d]
                         jT9                            Convert 10 to base 9 -> [1,1]
                  +Ld,                                  Prepend d to each of the above
               _s                                     Flatten and reverse -> [[6,1,1],[6,6,6]...[2,2,2]]
                                m       4             Map d in [0,1,2,3] using:
                                  +LdS3                 [d+1,d+2,d+3]
                                 _                      Reverse the above
                               _                      Reverse the result -> [[6,5,4]...[3,2,1]]
                                           _S6        [6,5,4,3,2,1]
                                         .C    3      All 3-element combinations of the above, respecting order
  s[                                            )     Wrap the 5 previous sections in an array, concatenate
ox                                               NQ   Order Q using each element's index in the above list

05AB1E, 24 bytes
Σ5βËyθyP‚yнÃ6βyË_y¥PΘy)(

Try it online!
Overall algorithm:
Σ          )( # sort by the following, in decreasing priority:
 5βË          # 1 for 421, 0 otherwise
 yθyP‚yнÃ6β   # 7 for 111, X for XXX and X11, 0 otherwise
 yË_          # 0 for XXX, 1 otherwise
 y¥PΘ         # 1 for sequences, 0 otherwise
 y            # the roll itself

Details:
5β          # parse the roll as a base-5 number
  Ë         # are all digits equal? (base-5 421 is 111)

yθ          # last die (equal to the 1st die iff we have XXX)
  yP        # product of dice (equal to the 1st die iff we have X11)
    ‚       # wrap the two in an array
     yнÃ    # keep only those that are equal to the 1st die
        6β  # parse as a base-6 number (111 -> [1, 1] -> 7)

yË          # are all dice equal?
  _         # boolean negation

y¥          # deltas ([a, b, c] -> [b - a, c - b])
  P         # product
   Θ        # 1 if it's equal to 1, 0 otherwise

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Split a list into sized chunks, but not counting items failing predicate
Motivation: Sometimes certain items in a list don't count towards your totals. For example, counting plane passengers in rows, where babies sit on a parent's laps.
Challenge: write a program to split a list of items into chunks. Each chunk (except possibly the last) is the same size, where size is defined as the number of items passing a predicate function.
Rules:

Your program must take

a list of items
a positive integer chunk size
a predicate function (takes an item, and returns true or false)

You must return the input list split into chunks
Each chunk is a list of items
Overall the items must remain in the same order, with none disgarded
The number of items passing predicate in each chunk (except possibly the last) should match the input chunk size.
items failing the predicate should not count toward this size
Items failing the predicate are

still included in the output chunks
allocated to the earliest chunk, in the case that a chunk is "full" but the next items are ones failing the predicate

thus the final chunk may not consist solely of items failing the predicate

The final chunk may be of size less than the chunk size because all the items have been accounted for.

Non exhaustive examples:
The simplest example is to consider 1s and 0s, where the predicate function is x ==> x > 0. In this case, the sum of each chunk must match the chunk size.

items: [], size: 2, predicate: x > 0 --> either [] or [[]]
items: [0, 0, 0, 0, 0, 0], size: 2, predicate: x > 0 --> [[0, 0, 0, 0, 0, 0]]
items: [0, 1, 1, 0], size: 2, predicate: x > 0 --> [[0, 1, 1, 0]]
items: [0, 1, 1, 0, 1, 0, 0], size: 2, predicate: x > 0 --> [[0, 1, 1, 0], [1, 0, 0]]
items: [0, 1, 0, 0, 1, 0, 1, 1, 0], size: 2, predicate: x > 0 --> [[0, 1, 0, 0, 1, 0], [1, 1, 0]]

And let's finish with the plane passengers where babies sit on a parent's lap example. A for adult, b for baby, plane row is 3 seats wide, adult always listed before their baby:

items: [A, b, A, b, A, A, A, b, A, b, A, A, b], size: 3, predicate: x => x == A --> [[A, b, A, b, A], [A, A, b, A, b], [A, A, b]]

This looks like a good question, but currently it's lacking a winning criterion. I suggest using [tag:code-golf].

Can we assume the list items are single characters? Or, say, numbers?

[tag:chunking] sounds interesting, though could maybe be replaced by [tag:set-partitions].

@Laikoni tagged [tag:code-golf]

@xnor list items can be any basic data-type like strings or numbers

@JonathanFrech [tag:set-partitions] are not appropriate as the order must be maintained

@ChasBrown also hoping this can be opened! I don't think there's any point in empty chunks, but either [] or [[]] would meet the criteria, I'll update the example.

"The final chunk may be of size less than the chunk size" -> What are the two sizes? We're given the chunk size, but the implication is that there's a different, other size.

@Ourous I've added "because all the items have been accounted for", i.e. the last chunk doesn't get a chance to get "full up", because that's just the end of the input items.

When dealing with string items, can we assume that they are not empty?

@Arnauld, no I think the items aren't restricted like that. They can be 0, 0.0, "", or any other basic data type.

Can we give an empty/falsey output for when input is [], instead of [] or [[]]?

General question, has there been a consensus on how to do these "blackbox predicate function" challenges in languages that don't have user-defined functions, for eg., MATL? I tried to search meta for this, but my search-fu seems weak today.

@sundar: here's some meta.

@nimi That answer still assumes the language has user-defined functions, just not first-class ones. MATL has only builtin functions, no user-defined functions whether first class or not. There's a workaround to call out to the surrounding environment though, so I've posted an answer using that. Thanks for the link though!

Jelly, 10 bytes
vⱮTm⁵ḊœṖŒṘ

A full program taking the monadic black-box function as the first optional argument, the list as the second optional argument and the chunk size as the third optional argument which prints a Python representation of the resulting list of lists (to avoid Jelly's implicit smashing of lists containing characters).
Try it online! (note that a list of characters is passed to a Jelly program by formatting it as a Python quoted string)
How?
vⱮTm⁵ḊœṖŒṘ - Main Link: B, L, S
 Ɱ         - map across second argument with (i.e. for X in L):
v          -   evaluate as a monad with input (i.e. B(X))
  T        - truthy indices (e.g. [0,0,1,0,1,1,1,0,0,0,1,0,0]T -> [3,5,6,7,10])
    ⁵      - 3rd optional argument = S
   m       - modulo slice   (e.g. [3,4,7,9,12,15,16,18,19,20]m3 -> [[3,4,7],[9,12,15],[16,18,19],[20]]
     Ḋ     - dequeue        (e.g. [[3,4,7],[9,12,15],[16,18,19],[20]]Ḋ -> [[9,12,15],[16,18,19],[20]]
      œṖ   - partition right (L) at the indices in that
        ŒṘ - print Python representaion

Brachylog, 37 bytes
hW&t~c.k{↰₂ˢl}ᵐ;WxĖ∧.bhᵐ↰₂ᵐ∧.t↰₂ˢl≤W∧

Try it online!
I was pleasantly surprised to find that this - pretty much a restatement of the question - successfully terminates and produces correct output.
Assumes the predicate is present as predicate 2 below this code. Outputs a list of lists ("chunks"), or false for an empty input.
Explanation:
hW&               % First input is W, the expected "weight" of each chunk
                  %  (i.e. the number of items passing predicate in each chunk)

t                 % Take the second input, the list of items
 ~c.              % Output is a partition of this list
    k{    }ᵐ      % For each partition (chunk) except the last,
      ↰₂ˢ         %   Select the items in the chunk that pass the predicate
         l        %   Get the length of that
                  % (So now we have the list of the "weights" of each chunk)
            ;Wx   % Remove the input expected weight from this list, and
               Ė  %  the result of this should be empty.
                  %  This verifies that the list of weights is either
                  %  composed of all W-values, or is empty (when input is [0 0 0] for eg.)

    ∧.bhᵐ↰₂ᵐ      % And, the first element of each chunk (except the first) should
                  %  pass the predicate. This is another way of saying:
                  %  "Items failing the predicate are allocated to the earliest chunk"

    ∧.t↰₂ˢl≤W     % And, the final chunk (which we haven't constrained so far)
                  %  should have weight ≤ the input expected weight
                  %  This disallows putting everything in the final chunk and calling it a day!

    ∧             % (no further constraints on output)

Apl (Dyalog Unicode) 17 16 bytes (SBCS)
Thanks to Adám for saving me 1 byte.
w⊆⍨⌈⎕÷⍨1⌈+\⎕¨w←⎕

Try it online!
for explaination purposes I will leave up the 17 byte solution.
{⍵⊆⍨⌈⍺÷⍨1⌈+\⍺⍺¨⍵}

⍺⍺¨⍵ aplies the predicate to the list returning a boolean vector
+\ generates a running total
1⌈ replaces leading 0s with 1s
⌈⍺÷⍨ divides each element by the chunk size and rounds up
⍵⊆⍨ partitions the original vector by this

That's impressive! And I like the output display, appropriate visual for the problem.

Save a byte by converting to program (tradfn body): w⊆⍨⌈⎕÷⍨1⌈+\⎕¨w←⎕

Clean, 96 92 bytes
Uses a named function f :: a -> Bool allowed according to meta consensus.
import StdEnv,StdLib
$l n|l>[]=last[[i: $t n]\\i<-inits l&t<-tails l|n>=sum[1\\e<-i|f e]]=[]

Try it online!
Expanded (with default highlighting to make comments show up):
$ l n // define function $ on `l` and `n`
 | l > [] // if `l` is not the empty list
  = last [ // the last element of ...
                   \\ i <- inits l // prefixes of `l`
                    & t <- tails l // matching suffixes of `l`
                    | n >= // where n is greater than or equal to
                           sum [1 \\ e <- i | f e] // the number of matching elements in the prefix
          [i: $t n] // prepend that prefix to the application of $ to the rest of the list
         ]
 = [] // if `l` is empty, return empty

Java 10, 207 186 159 148 145 bytes
a->n->{var r=new java.util.Stack();for(int l=a.size(),c=0,j=0,i=-1;i++<l;)if(i==l||f(a.get(i))&&++c>n&i>0)r.add(a.subList(j,j=i*=c=1));return r;}

Java is definitely not the right language for this challenge (or any codegolf-challenge of course..)
-21 bytes thanks to @O.O.Balance
-3 bytes thanks to @ceilingcat
Try it online.
Explanation:
a->n->{                   // Method with List & int parameters and List of Lists return
  var r=new java.util.Stack();
                          //  Result-list, starting empty
  for(int l=a.size(),     //  Size of the input-List
          c=0,            //  Count-integer, starting at 0
          j=0,            //  Range-integer, starting at 0
          i=-1;++i<l;)    //  Loop `i` in the range (-1, `l`]:
    if(i==l||             //   If this is the last iteration
       f(a.get(i))        //   Or if the black-box function is true for the current item
       &&++c              //    Increase the counter by 1
         >n&              //    If the counter is now larger than the size
         &i>0)            //    and it's not the first item of the List
      a.subList(j,j=i     //     Add a sub-List to the result from range [`j`, `i`)
                          //     And set `j` to `i` at the same time
                  *=c=1));//     And reset `c` to 1 at the same time as well
  return r;}              //  Return the List of Lists as result

Black box input format:
Assumes a named function boolean f(Object i) is present, which is allowed according to this meta answer.
I have an abstract class Test containing the default function f(i), as well as the lambda above:
abstract class Test{
  boolean f(Object i){
    return true;
  }

  public java.util.function.Function<java.util.List, java.util.function.Function<Integer, java.util.List<java.util.List>>> c =
    a->n->{var r=new java.util.Stack();for(int l=a.size(),c=0,j=0,i=-1;i++<l;)if(i==l||f(a.get(i))&&++c>n&i>0)r.add(a.subList(j,j=i*=c=1));return r;}
  ;
}

For the test cases, I overwrite this function f. For example, the last test case is called like this:
System.out.println(new Test(){
  @Override
  boolean f(Object i){
    return (char)i == 'A';
  }
}.c.apply(new java.util.ArrayList(java.util.Arrays.asList('A','b','A','b','A','A','A','b','A','b','A','A','b'))).apply(3));

"(or any codegolf-challenge of course..)" ehh I dunno, you've beaten out my Clean answers in at least a few cases. Anyway, I always look forward to your answers.

@Οurous It's more of a meme that Java is not suitable for codegolf in any way, which I guess applies to Clean as well if we compare it to actual golf languages like Jelly, 05AB1E, etc. I still enjoy solving all these codegolf-challenges in Java though (and you in Clean as well I assume). And once in a (long) while, Java is able to beat Python. ;) And I was once a leading answer with Java, until bash ruined it (and R golfed further). xD

186 bytes if you return a List of arrays: https://bit.ly/2mSjCIc

@O.O.Balance Thanks! Smart use of Arrays.copyOfRange!

@O.O.Balance been able to golf a bit more by using taking the input as List and using .sublist. Your functionality remains the same apart from that, but it saves a lot of bytes and removes the import. (And now it also works for the test-case with characters instead of integers.)

R, 58 bytes
function(v,g,n,a=(cumsum(Map(g,v))-1)%/%n)split(v,a*(a>0))

Try it online!

-5 bytes thanks to @Giuseppe

58 bytes

Haskell, 72 bytes
p#s|let l@(h:t)!a|sum[1|e<-h:a,p e]>s=a:l![]|n<-a++[h]=t!n;_!a=[a]=(![])

Try it online!
p#s     = (![])         -- main function that takes a predicate function 'p',
                        -- a size 's' and a input list without a name that is
                        -- directly passed as the first argument to function '!'
  let  l@(h:t)!a        -- function '!' is a local function (so that 'p' and 's'
                        -- are in scope). Takes a list 'l' of at least one element
                        -- 'h' (and 't' being the rest of the list) and an
                        -- accumulator 'a'
   |sum[1|e<-h:a,p e]>s -- if 'p' holds for more than 's' elements in 'h' and 'a'
     =a:l![]            --   put 'a' in front of a recursive call with the same list
                        --   'l' and an empty accumulator
   |n<-a++[h]           -- else bind 'n' to 'h' appended to 'a' and
     =t!n               --   call '!' again with 't' and 'n'
  _!a=[a]               -- base case for '!'. If the input list is empty, return
                        --   a singleton list with 'a'

C (gcc), 70 66 bytes
I use a structure to note the start of a sub-list, as C doesn't know about such things.
Thanks to ceilingcat for the suggestions.
t;f(a,s,c)l*a;int(*c)();{for(;a->v;a++)(t+=c(a->v))>s?t=++a->s:0;}

Try it online!

MATL, 19 bytes
HyX$Ysi/Xk1y>+!w7XQ

Based on jslip's excellent APL answer.
MATL doesn't really have user-defined functions as such, but it does have a way to call out to the environment it's running on (MATLAB/Octave), so this uses that for the predicate function. Usage would be something like this, but that functionality is disabled online for security reasons, so here's a version that uses a hardcoded isodd predicate function instead: Try it on MATL Online.
H    % Push the function name to be called, assumed to be
     %  stored in the H clipboard
y    % Take the first input, push copies of it both below and above the
     %  function name
X$   % Call the function (say 'isupper') with the input as argument
     %  returns a boolean vector
Ys   % Cumulative sum
i/   % Take the chunk size and divide each element by it
Xk   % ceil
1y>+ % Turn the (initial) 0s to 1s
!    % Transpose. Now we have a column vector specifying which chunk
     %  each input element should go into
w    % Bring the other copy of the input on top
7    % Code for this function: '@(x){x.'}'
     %  i.e. place each chunk in a row vector and enclose it in a cell
XQ   % 'accumarray' - split the input into chunks based on
     %   the given column vector, apply the given function to each chunk
     %   (which here just wraps it up as a cell), and accumulate the results
     %   in an array.
     % implicit output

JavaScript (ES6), 69 bytes
Saved 3 bytes thanks to @tsh
Takes input in currying syntax (size)(predicate)(array).
s=>p=>g=a=>a.every(x=>p(x)?k--:++j,j=k=s)?[a]:[a.splice(0,j),...g(a)]

Try it online!

s=>p=>g=a=>a.every(x=>p(x)?k--:++j,j=k=s)?[a]:[a.splice(0,j),...g(a)]

@tsh Nice optimization. Thanks!

Ruby, 57 bytes
->a,n,g{c=-1;a.group_by{|x|[0,c+=g[x]?1:0].max/n}.values}

Try it online!
Anonymous lambda accepting input array a, chunk size n, and predicate g. Maintains a counter c of items matching predicate and groups items by the number of chunks already used up. Unfortunately, the initial value -1/n doesn't round up to 0, so we have to spend a few bytes to fix it.

R, 100 bytes
function(L,K,P,s=sapply(L,P),y=cut(cumsum(s),seq(0,sum(s),K),,T))for(l in levels(y))cat(L[y==l],"
")

Try it online!
outgolfed handily by digEmAll

I don't know if named lists as output are ok (and if I missed some edge cases...):
65 bytes

Hmm well I'd post that as a separate answer!

Python 2, 92 bytes
lambda a,c,p:reduce(lambda r,v:[r[:-1]+[r[-1]+[v]],r+[[v]]][sum(map(p,r[-1]+[v]))>c],a,[[]])

Try it online!

JavaScript (Node.js), 90 bytes
(s,p,r=[l=[]],n=s+1)=>g=a=>0 in a?g(a,(n=(n||s)-p(v=a.shift()))||r.push(l=[]),l.push(v)):r

Try it online!
Invoke as F(2, x => x > 0)([0, 1, 1, 0])

Mathematica, 82 bytes
f[l_,s_,p_]:=Last@Reap[i=t=-1;Do[If[p@e,If[++i~Mod~s==0&&i>0,t++]];e~Sow~t,{e,l}]]

Ungolfed:
f[l_,s_,p_] :=                (* define a function that takes three    *)
                              (* arguments                             *)

  Last@Reap[                  (* collect and return results which were *)
                              (* gathered by the procedural loop below *)

    i=t=-1;                   (* initialize two counters               *)

    Do[                       (* start iterating over the list         *)

      If[p@e,                 (* if element passes predicate           *)
        If[                   (* then if preincremented i is 0 modulo  *)
          ++i~Mod~s==0&&i>0,  (* chunk size and i > 0                  *)
          t++                 (* increment t                           *)
        ]
      ];e~Sow~t,              (* finally sow the element tagged with   *)
                              (* the current value of t                *)

    {e,l}]                    (* e references current element of list  *)
                              (* l is the list itself                  *)
  ]

l is the input list; s is chunk size; p is an unnamed/anonymous/pure/lambda function that returns true/false operating on elements of the list.
Last@Reap[...] returns a list of lists of every element that was Sow-n inside of .... They are grouped into sublists by the second argument of e~Sow~t which is shorthand for Sow[e, t].
I had to initialize counters to -1 to handle a chunk size of 1, otherwise I would need to check Mod[i, s] (i~Mod~s) equal to 1, which could never happen.
The rest of the code is explained in the ungolfed block.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Display percent battery remaining
Display the remaining battery charge, as a percentage of maximum charge
Remember if you can't run your code on a phone, calculator, etc, you can probably install your environment on a laptop at least. If you absolutely can't run on a device that has a battery, then unfortunately your language isn't eligible since you have no useful value to print.
You must display the results on the screen. This is theoretically supposed to be a handy utility for the user to check the battery. Writing battery percent to a file is too clunky, requiring the user to then check the file. Displaying on-screen is therefore a part of the specification that can't be overridden by default IO. That said, you can assume nothing is preventing things like STDOUT from being displayed on screen in the usual way.
If the battery percent is already displayed on screen all the time by the OS, like on many phones, that does not mean you've got a zero-byte solution. You must assume that built-in display doesn't exist, and display the battery percent again somewhere else.
Edit: The output format is being opened up. You are free to display as little as just the digits of the percent, or the digits with some extra output as well.
Edit2: The digits representing the percent must appear in a known location within the output, not more than 50 lines from the end of the output, and that location shouldn't change between invocations. The digits representing the percent must be separated from other output by at least one non-digit character on each side.
For reference here is the old output format from before the change:
Remaining battery is ddd%
or
Remaining battery is ddd percent

This is a uniqueish challenge because the language chosen depends largely on the environment and the best golf is going to rely greatly on the api presented in that environment. Not sure if that's good or bad, ha

Turns out javascript has (had) the Battery Status API for this (currently available in chrome).

What if the program writes the percent to a file and then opens the file to display it?

What is battery percentage defined as?  I'm not really familiar with how the hardware works but I was always under the impression that battery percentage was some kind of hueristic in terms of predicted use.

Why is the output format so strict?

@WW I think I've heard of phones displaying that as the 'percent'. They shouldn't, of course, that's just misleading and condescending to the user. But short of asking people to golf a new hardware-level device driver, I'm willing to accept any % that the OS or system-level API gives.

@Okx Poke pointed out that if output doesn't have to be formatted, some solutions will simply be the relevant API call and nothing else, and the winner might simply be who has the shorter API call. I'm open to suggestions on the particular formatting required, though.

@mbomb007 I suppose that's alright. Displaying on screen is required, but any way you do that is allowed.

@WW https://electronics.stackexchange.com/questions/144914/how-does-a-smart-phone-measure-the-battery-power --> if I understood correctly, it has nothing to do with usage.

@JaredK Can we assume that the battery has 100% capacity? (i.e., it's a new battery)

Also: Does the output need to be zero left-padded?

@user202729 no it must check the current current battery charge, whatever it may be. And no, it doesn't need padding.

@JaredK I can't see how does the strict output makes the challenge better. Even Poke didn't claim the simple calls were problematic, and we do have a few catalogue challenges here. As I see the answers, it simply adds a printing command with the aforementioned text for each, which looks a bit like a clutter over the basic solution. That said, the original task is pretty good as a challenge on this site IMO.

@Uriel Good points. I think we can open up the output format and let this be a catalog challenge.

@JaredK Could you update the challenge then? Rules made in the comments don't count.

@user202729 That electronics.SE answer is about the internal measurement, but what's exposed to the user is often a doctored number - Li-ion batteries drain faster the more charge they have (or is it the other way around?), but the device (usually) adjusts for that to show a somewhat linear change in battery percentage since that feels more predictable to us users.

@sundar That's not really a problem. The real problem is that it's hard to tell whether an answer is correct (display the "original" number, not the "edited" one)

You should require the output to be consistent, with the only thing that changes is the number indicating the charge percentage.

I don't understand why this question is getting so much flak. I think it's a great question bringing a bit of diversity to the site.

Bash, 70 67 50 46 43 16 bytes
`</*/*/*/B*/c*y`

Outputs: <battery 0-100>: command not found
Reads the file /sys/class/power_supply/BAT1/capacity.
Tested using Ubuntu 18.04 on a LENOVO ideapad 500.
Takes a while (since it searches the entire filesystem) - but it saves a byte!
Old answer:
echo Remaining battery is `</*/*/*/B*/c*y`%

Takes a while (since it searches the entire filesystem) - but it saves a byte! - that's code golf for you!

Hm, I'm not sure if it can be guaranteed that there isn't a file called /so/apes/yadayada/Brunch/calamity.

@EriktheOutgolfer I'm told I can assume a fresh install.

@EriktheOutgolfer I'm so glad Brunch is served before the world ends.

Why do you need the B? It works for me without it (not 18.04 though).

@Ruslan Without it, it outputs: -bash: /*/*/*/*/c*y: ambiguous redirect. Though I am not using a clean install.

@Okx Considering the rule change, why not do cat /*/*/*/*/*? Sure, it might print a huge chunk of files on the system and take forever, but the battery string is there. Somewhere. Eventually.

@algmyr That's bending the rules quite a bit, and I doubt it will even be consistent output.

"You are free to display as little as just the digits of the percent, or as much output as you would like."
Who says we need consistent output? Also, isn't bending (but not breaking) the rules in the spirit of code golf?

@algmyr At that point I might as well do echo {0.100}

@Okx That is exactly why I dislike the change of rules. It allows solutions that doesn't follow the spirit of the challenge.

JavaScript (browser), 78 77 50 bytes
(-1 byte thanks to Benoit Esnard)
(-27 bytes since the output format is flexible now)

navigator.getBattery().then(b=>alert(b.level*100))

JavaScript (browser), 46 bytes, by returning a promise
(Suggested by Shaggy, requires a header and footer)

f=
_=>navigator.getBattery().then(b=>b.level*100)
f().then(alert)

Note: Only works on Google Chrome >= 38 (desktop and Android) or any other browser that supports Battery API. FireFox has removed this API due to privacy concerns.
Example on Android (old output format):

Example on a Windows laptop (old output format):

You can save one byte by using ES6 string templates: \Remaining battery is ${b.level*100}%``

@Benoit Esnard: Nice idea! Thanks ...

I never realised you can get a user's battery level in a webpage. I can't think of when that feature would actually be useful to a user though.

@numbermaniac Back in the days, PoC featured websites that included a low-power mode based on the battery level of the device. Too bad they didn't think all of this could also be used to track you without the need of cookies.

@numbermaniac: One of the usages is to auto save a form when user's battery is low. But there can be many misuses for it and that is why FireFox has removed it.

You can return a promise from a function so you could save a few bytes with _=>navigator.getBattery().then(b=>'Remaining battery is ${b.level*100}%') (replacing single quotes with backticks), which you would then call with f().then(console.log).

@Shaggy: The questions specifies that "You must display the results on the screen." and later on they say it cannot be overridden by default IO. That is why I used an alert.

If you have your browser's console ope or you use (e.g.) JSBin, it will be displayed on screen ;) Or, if you prefer, just replace console.log in my code above with alert.

@AlexisFacques Wow, I didn't realize I could be fingerprinted basically just by my Flash plugin--thanks for the informative link!

PowerShell, 28 bytes
-26 (!) thanks to AdmBorkBork. Previous version -3 thanks to colsw.
((gwmi win32_battery)|% e*g)

gwmi is short for Get-WmiObject
|% takes the pattern e*g and finds the only matching property; estimatedChargeRemaining

Using this tip, you can golf down the lengthy property name -- ((gwmi win32_battery)|% e*g).

@AdmBorkBork Thank you again. As you can tell, I'm not a Powershell golfer (or even user). Just used a bit of Google-fu…

If the device has more than one battery, it displays something like Remaining battery is 98 96%

@VasilyAlexeev OP sounds like we may choose an appropriate device.

Change "abc"+(def)+"ghi" to "abc$(def)ghi" to save some more.

@Adám only 10 more bytes and we beat bash! I'm not exactly hopeful.

You can now update this to remove the text "Remaining battery is ... %"

@immibis Thanks. Done.

Well it seems I've 172% left. Nice.

Bash+acpi, 43 4 bytes
New rules
acpi

output on form
Battery 0: Charging, 92%, 00:05:37 until charged

not sure if the rule change makes things more interesting, couldn't you dump any text that contains all strings 0 to 100 which would be valid output? Seems to lose the original intent if so.
Old rules
set `acpi`;echo Remaining battery is ${4%,}

output on form
Remaining battery is 92%

Don't ask me why set works like this, but it does.

What did you test this on? Ubuntu or similar I'm guessing? It doesn't work on Mac, for example.

Works on fedora, but it depends heavily on the syntax of the output (what is it on mac for reference? @numbermaniac )?

I assume it's the one available for most linux distros. Is the acpi output format different on mac perhaps (is acpi even available there)?

@Wilf acpi simply isn't there on Mac it seems.

It can to be installed separately on some linux distros, mac likely has its own built in equivalent drivers and commands.

Dumping all digits 0-100 would be hard-coding the output I think.

Python 3.6 + psutil, 80 bytes
import psutil
print(f"Remaining battery is {psutil.sensors_battery().percent}%")

Try it online!
If the machine has no battery (like on TIO), the program will throw an error, because psutil.sensors_battery() returns None.
This requires Python 3.6 for string interpolation.

Idk. It's included on TIO. I'll include a link to the module.

I Googled and found the same library but my Python 2 answer was not as smart as yours with string interpolation. Note to self: must get into Python 3.6 and answer faster. +1

C (win32, gcc i686-w64-mingw32), 78 bytes
#include<windows.h>
main(s){GetSystemPowerStatus(&s);printf("%hhu",s>>16);}

Abuses the win32 API by letting GetSystemPowerStatus() write "somewhere" on the stack, the interesting member is in the third byte, according to the SYSTEM_POWER_STATUS struct.
Unfortunately, the #include seems to be needed, probably because of calling conventions.
Example output:
> bat.exe
90

Displays 255 on systems without a battery.

What happens if you omit the include?

@Ruslan the linker doesn't find the symbol in kernel32.dll. That's why I think it's the calling convention, win32 API functions don't use the "standard" cdecl. So even if I could trick the linker somehow, the code probably wouldn't work anyways.

Did you try compiling with /Gz (default to __stdcall)?

@Neil no, does gcc/mingw have a similar option or do I have to use msvc for that? And wouldn't that break the printf() without a prototype?

Sorry, I hadn't read your header carefully enough. I think the mingw version is -mrtd, but I don't know what would happen to printf(); maybe there's a shorter include for it?

Excel VBA, 150 bytes
Restricted to 32-Bit Windows Installs of office, because the windows Kernel32 call is not 64-bit pointer safe.
Outputs to the cell A1 on the ActiveSheet.
Declare Sub GetSystemPowerStatus Lib"kernel32"(f As t)
Type t
i As Integer
b As Byte
End Type
Sub d
Dim e As t
GetSystemPowerStatus e
[A1]=e.b
End Sub

-26 bytes thanks to flexible output
-7 bytes thanks to @Neil for using an Int instead of 2 bytes

Not 64-bit pointer safe? What? That's ridiculous, Microsoft.

@immibis it has do do with a difference between the versions - if you are using a 64 bit install of Office then the call just changes to be Declare PtrSafe Sub GetSystemPowerStatus Lib"kernel32"(f As t)

Can you not use a byte array instead of a structure?

@Neil - unfortunately not, the Lib call assigns f to a pointer of the _SYSTEM_POWER_STATUS structure, which holds both byte and dword values, meaning that, in this case, the structure has to be emulated from within vba, and a byte array cannot be used.

If you can't use an array, can you not at least use a two-byte type as your padding instead of two single bytes?

@Neil - I hadn't even considered that - and it works fantastically! Great suggestion

QPython for Android, 133 bytes
from androidhelper import*
d=Android()
d.batteryStartMonitoring()
d.dialogCreateAlert(str(d.batteryGetLevel()[1])+"%")
d.dialogShow()

The +"%" isn't strictly necessary since it uses the newer more flexible output format anyway, but it makes for slightly nicer output at just +4 bytes.

[d.notify (create notification alert) would have been much shorter than creating and displaying the dialog, but for some reason it doesn't work, at least on my device (possibly, it hasn't been updated for newer Android APIs).]

This works for 130 bytes.

Emacs Lisp, 9 bytes
(battery)

Shows current battery status in mini-buffer at the bottom (or to stdout when using --batch) in format such as: Power N/A, battery Unknown (99.1% load, remaining time N/A).
Should work on Windows, OSX, BSD , and Linux.

Java, 546 bytes (Windows XP or Higher)
The powercfg utility came into play for WindowsXP, I have no idea what utilities were available prior to this. I must also be run as administrator. This is god-awful and I didn't make an extreme golfing attempt...
import java.io.*;import java.util.Scanner;public class J {public static void main(String[] args)throws Exception{Process p=Runtime.getRuntime().exec("powercfg energy");p.waitFor();Scanner s=new Scanner(new File("C:\\windows\\system32\\energy-report.html"));String x;double a=0,b=0;while(s.hasNextLine()){x=s.nextLine();if(x.contains("Design Capacity")){s.nextLine();b=Integer.parseInt(s.nextLine().replaceAll("\\D+",""));}else if(x.contains("Last Full Charge")){s.nextLine();a=Integer.parseInt(s.nextLine().replaceAll("\\D+",""));}}System.out.print(a/b*100);}}

Formatted / commented...
import java.io.*;
import java.util.Scanner;

public class J {
    public static void main(String[] args) throws Exception {
        Process p = Runtime.getRuntime().exec("powercfg energy"); // Run CMD sys32 app.
        p.waitFor();                                              // Wait for it.
        Scanner s = new Scanner(new File(
                "C:\\windows\\system32\\energy-report.html"));    // Read output.
        String x;
        double a = 0, b = 0;
        while (s.hasNextLine()) {
            x = s.nextLine();
            if (x.contains("Design Capacity")) {                   // Find max capacity.
                s.nextLine();
                b = Integer.parseInt(s.nextLine().replaceAll("\\D+", ""));
            } else if (x.contains("Last Full Charge")) {           // Find current capacity.
                s.nextLine();
                a = Integer.parseInt(s.nextLine().replaceAll("\\D+", ""));
            }
        }
        System.out.print(a / b * 100); // Calculate %.
    }
}

Honestly I was more interested to see if it was even possible in Java.

Having to call an external command like that, then read the results of the external command from a file... then having to calculate the percentage yourself. And so verbose. It's awful I love it. I'm glad people try these things in ill-suited languages it's so fun. +1

@JaredK I enjoy Java "golfing", but only on questions where people think, "oh god no, what moron would ever try this in Java? It just wouldn't make sense." Sort of ironic.

Sometimes I think Java ought to get a golfing version like how Japt was made for golfing Javascript.

@JaredK look into Groovy or Clojure, could probably turn this into a 100 byte groovy answer if I tried super hard.

@JaredK here's an approximation of this same answer in groovy: {Runtime.getRuntime().exec("powercfg energy").waitFor();x=new XMLSlurper(new File("C:\\windows\\system32\\energy-report.html"));x.html.table.tr[#].span[0] as int/x.html.table.tr[#].span[0] as int}

Japt, 60 bytes
Ox`nàÀÓ&.getBÂjry().È(x=>O.q("Rà@°á ßMy  "+L*x.¤vel+"%"))

Test it


text:
Calculate power series result
Related: Calculate Power Series Coefficients
Given a positive integer \$X\$ and a max exponent (Also a positive integer too) \$N\$ calculate the result of a power series. Example:
$$X^0+X^1+X^2+\cdots +X^N$$

Assume \$(X + N)  \le 100\$

Test Cases
1 2  => 3
2 3  => 15
3 4  => 121
2 19 => 1048575

Standard code-golf rules apply.

It would open up some more possibilities if we could assume that $ x\neq 1$, then we could use $ 1 + x + x^2 + \ldots + x^n = \frac{x^{n+1}-1}{x-1}$, but it is probably too late for that =)

I definitely remember this challenge appearing previously but I don't have time to look for a dupe now.

"Assume 0 ≤ (X + N) ..." - but X & N are positive integers, so should that read "Assume 0 < (X + N) ..." or should X & N be non-negative integers?

@JonathanAllan Most non-mathematicians would probably class zero as a positive integer

@BetaDecay really? Most non-mathematicians would probably class it as a "number" :p

This is the potential dupe I was thinking of, with a difference being that it goes to n*n-1 rather than n. Since my vote hammers, I'll wait for others to say if this is dupe-worthy.

@BetaDecay Most of the world considers 0 to be neither positive nor negative. A couple of places (like France) don't consider positive to mean strictly positive, and treat 0 as both positive and negative.

This is a simply stated challenge with a clear title. Perhaps the other challenge with the irrelevant backstory and the confusing title should get the dupe label retroactively!

@ngm, I don't find the title of this question clear, whereas the other title references a classic question that I've seen in printed puzzle books. However, if you want to propose flipping the duplicate closure relationship the place to do it is a [meta-tag:specific-question] [meta-tag:discussion] question on meta.

R, 25 bytes
function(x,n)sum(x^(0:n))

Try it online!

I love the way vectors work in R

@BetaDecay maybe we should nominate R for the language of the month!

@giuseppe I've been thinking about that for a while now... let's target September? I'll post an answer in Meta.

@JayCe yeah, sounds good. We should open up the R chatroom again (for the third time; I've twice opened one and both times it has died due to inactivity); I'm sure I'd love to add to whatever description you end up going with on the submission :-)

Haskell, 21 bytes
The straightforward approach:
x#n=sum$map(x^)[0..n]

For the case \$ x \neq 1 \$ we alternatively could use following function with the same length:
x#n=div(x*x^n-1)$x-1

This uses the fact that
\$ 1 + x + x^2 + \ldots + x^n = \frac{x^{n+1} -1}{x-1} \forall x \neq 1.\$
Try it online!

also 21 bytes: x#0=1;x#n=x^n+x#(n-1).

@nimi Oh that is clever:)

JavaScript (ES6), 22 bytes
Saved 1 byte thanks to @tsh
x=>g=n=>~n&&x*g(n-1)+1

Try it online!

Non-recursive (ES7), 23 bytes
Using the direct formula mentioned by @flawr:
x=>n=>~-(x**++n)/~-x||n

Try it online!

x=>g=n=>n?g(n-1)*x+1:1

05AB1E, 3 bytes
ÝmO

Try it online!
Explanation:
Input: 4, 3
Ý    [0..input] - [0, 1, 2, 3, 4]
m    Vectorized exponent - [1, 3, 9, 27, 81]
O    Sum - 121

Jelly, 4 bytes
*Ż}S

Try it online!

Not sure it's worth another answer to post this other 4 byter: *ⱮS‘

@JonathanAllan I actually edited that away (note: I do this pretty often), but, eh, a grace period exists. :P (It was actually me forgetting about vectorization of *...)

Python 3, 40 bytes
lambda x,n:sum(x**k for k in range(n+1))

Try it online!
lambda x,n:sum(map(x.__pow__,range(n+1))) is cool too but it's 1 byte longer lol.

PowerShell, 53 46 bytes
param($x,$n)0..$n|%{$o+=[math]::pow($x,$_)};$o

Try it online!
Not bad for needing a .NET call for pow.
-7 bytes thanks to mazzy.

It's stupid, but this param($x,$n)$s=0;0..$n|%{$s+=[math]::pow($x,$_)};$s is shorter. I don't sure about $s=0;: this expression is needed on a second run. Perhaps, it better to append ;rv s to the end.

2 bytes less: param($x,$n,$s)0..$n|%{$s+=[math]::pow($x,$_)};$s. A caller still sends 2 parameters.

@mazzy Thanks! There's no need to re-initialize $s if it's run as a full program (e.g., how it's done on Try It Online), so that saves a few more bytes.

MATL, 4 bytes
:^sQ

Try it online!
Takes input as N then X.

Noether, 17 bytes
I~xI(ax!i^+~ai)aP

Try it online!
Explanation
I~x               - Store the input in the variable x
   I(         )   - Loop until the top of the stack equals the input n
     a            - Push a
      x           - Push x
       !i         - Increment i
         ^        - Calculate the value of x^i
          +~a     - Add x^i to a and store in a
             i    - Push i
               aP - Print the value of a

Python,  35  32 bytes
-1 Thanks to tsh (f(x,n-1)+x**n -> f(x,n-1)*x+1)
Port of Arnauld's Javascript answer - not sure if it is the first, so do shout if you know who deserves the credit!
f=lambda x,n:~n and f(x,n-1)+x**n

A recursive function which sums the terms right-to-left, with a base case of zero when n reaches -1 (since ~(-1) is -1 - (-1) which is 0 which is falsey).
Try it online!

My previous 35 byter:
lambda x,n:x^1and~-x**-~n/~-x or-~n

Try it online!
How?
The ^ operator is bitwise-xor, so x^1 is zero when x is one and non-zero otherwise.
In Python non-zeros are truthy, so the right of the logical and is executed when x is not one, but not executed when x is one, whereupon the right of the logical or is executed instead.
So, when x is one we execute
-~n which is equivalent to
-1 * ~n which is equivalent to
-1 * (-1 - n) which is equivalent to
1 + n...
...and when x is not one we execute
~-x**-~n/~-x which, adding parentheses to signify precedence, is
(~-(x**(-~n)))/(~-x) which is equivalent to
(-1 - -1 * (x ** (-1 * (-1 - n))))/(-1 - -x) which is equivalent to
((x ** (n + 1)) - 1)/(x - 1)

The same to JS answer: +x**n -> *x+1 save 1 byte.

Brachylog, 11 bytes
t⟦R&h;Rz^ᵐ+

Try it online!
Nothing particularly interesting, construct the range 0 to n, raise x to the power of each number in it.
And since I wanted to learn how ᵃccumulate works, here's a slightly longer version that uses that:
15 bytes
,1↺⟨t×{bh}⟩ᵃ⁾k+

Try it online!
Form array [1, x], and do this n times, accumulating the results into that array after each iteration: multiply the last element of the array, by the second element of the array (i.e. x). Since this calculates [1, x, x^2, ... x^n, x^(n+1)], knife off the last value and add the rest of them up as the output.

Ruby, 26 bytes
->x,n{(0..n).sum{|i|x**i}}

Try it online!

Python 3, 42 bytes
lambda x,n:n+1if x<2else(x**(n+1)-1)/(x-1)

Try it online!

Since x is guaranteed to be positive, I believe you can do if x<2.

@MarDev, ah yes that’s right. Thanks.

cQuents, 6 bytes
$0;A^$

Try it online!
Explanation
        Implicit inputs: A and n
$0      Zero indexing
  ;     Output sum of first n terms in sequence
   A^$  Each term is A to the power of the current index

Python, 31 bytes
f=lambda x,n:n<1or x*f(x,n-1)+1

Try it online!

Python 2, 33 bytes
lambda x,n:1/x*-~n or~-x**-~n/~-x

Try it online!

J, 8 7 bytes
#.1$~>:

Try it online!
How it works
#.1$~>:  Left argument = X, Right argument = N
  1$~>:  Generate a list of N+1 ones
#.       Interpret as base X digits and convert to single integer

You can save 1 byte by using  >: instead of 1+]
7 bytes

Octave, 19 bytes
@(x,n)sum(x.^(0:n))

Try it online!
Just learnt Octave 15 minutes ago for this challenge... Hoping it is already optimized.

APL (Dyalog), 7 bytes
+/1,*∘⍳

Try it online!

Stax, 8 bytes
à╕F¬f£ù╞

Run and debug it

Python 2,  44  34 bytes
Here's my naive and simple solution.
f=lambda x,n:n>=0and x**n+f(x,n-1)

Try it online!

r is redundant, so f=lambda x,n:n>=0and x**n+f(x,n-1) is 34, although golfing that with n>=0 -> ~n  we get my port of 33 bytes.

Clean, 38 bytes
import StdEnv
$x n=sum[x^i\\i<-[0..n]]

Try it online!

Pure Bash (no external utilities), 32
echo $[`eval echo +$1**{0..$2}`]

Try it online!

Bash with GNU utilities, 23
seq -s+ -f$1^%g 0 $2|bc

Try it online!

Perl 6, 19 bytes
{sum $^a X**0..$^b}

Try it online!
Explanation:
{                 }  # Anonymous code block
 sum    # Get the sum of
         X**   # The cross product with the meta operator exponential
     $^a            # With the first parameter
            0..$^b  # And the range of 0 to the second parameter

CJam, 8 bytes
l~),f#:+

Try it online! Or verify all test cases.
Explanation
l      e# Read a line from STDIN
~      e# Evaluate: pushes x, then n
)      e# Add 1 to n
,      e# Range: gives [0 1 ... n]
f#     e# Map with extra parameter: gives [x^0 x^1 ... x^n]
:+     e# Fold addition over array: gives x^0 + x^1 + ... + x^n
       e# Implicit display in STDOUT

CJam... Now that's a name I haven't heard in a while

@BetaDecay Judge me by my age, do you?

Pari/GP, 21 bytes
(x,n)->sum(i=0,n,x^n)

Try it online!

You can take input via currying  to save 1 byte. Demo.

Java 8, 78 59 40 bytes
x->n->x>1?~-(int)Math.pow(x,n+1)/~-x:n+1

Uses the approach mentioned by @flawr.
Try it online.
Explanation:
x->n->                     // Method with two integer parameters and integer return-type
  x>1?                     //  If `x` is larger than 1:
   ~-(int)Math.pow(x,n+1)  //   Return `x` to the power of `n+1` - 1
   /~-x                    //   integer-divided by `x-1`
  :                        //  Else:
   n+1                     //   Return `n+1` as result instead

APL (Dyalog Classic), 8 bytes
⊣⊥1⍴⍨1+⊢

Try it online!

Prolog (SWI), 49 bytes
Throws errors, but still works I guess.
f(_,0,1).
f(X,N,Y):-M is N-1,f(X,M,Z),Y is Z+X^N.

Try it online!

C (gcc), 51 bytes
Your usual, everyday recursive solution.
f(b,e,t,i){for(t=1,i=e;i--;t*=b);t=e--?t+f(b,e):1;}

Try it online!

f(x,n,v){for(v=1;n--;v=v*x+1);x=v;}

f(b,e){b=e?pow(b,e--)+f(b,e):1;}

Charcoal, 9 7 bytes
Ｉ↨ＮＥ⊕Ｎ¹

Try it online! Link is to verbose version of code. Uses @Bubbler's algorithm. Explanation:
     Ｎ  Second input as a number
    ⊕   Increment
   Ｅ  ¹ Make list of `1`s of that length
  Ｎ     First input as a number
 ↨      Base conversion
Ｉ       Cast to string
        Implicitly print

Pyth, 14 13 bytes
AQVhH=+Z^GN)Z

Try it online!
How it works
assign('Q',eval_input())
assign('[G,H]',Q)
for N in num_to_range(head(H)):
 assign('Z',plus(Z,Ppow(G,N)))
imp_print(Z)

Batch, 61 bytes
@set s=0
@for /l %%i in (0,1,%2)do @set/as=s*%1+1
@echo %s%

Using @tsh's algorithm.

Swift 4.0, 100 bytes
func a(x:Int,n:Int)->Int{return(0...n).reduce(0,{p,q in p+(q>=1 ?(1...q).reduce(1,{a,_ in a*x}):1)})}

Try it online!
Ungolfed
func a(x:Int, n:Int) -> Int {
  return (0...n).reduce(0,        // For 0 to n
    { p, q in                     // p is result of last cycle, q the current element
      p +                         // Add p to
      ( q > 0 ?                   // If current element is not 0
        (1...q).reduce(1, { a, _ in a*x } ) // pow(x, n) *
        : 1                       // Otherwise, 1
      )
    }
  )
}

* The reduce is shorter than:
import Foundation
[...] Int(pow(Double(x),Double(q)))

First golf I do, so could be much more golfable, but finally the super-verbose Swift has a chance to be used!