| Bytes | Lang | Time | Link |
|---|---|---|---|
| 051 | Rust | 240813T180010Z | bzr |
| 018 | JavaScript Node.js | 240812T021839Z | l4m2 |
| 004 | UiuaSBCS | 240811T185155Z | Europe20 |
| 002 | Thunno 2 | 230610T133915Z | The Thon |
| nan | Fig | 221007T213243Z | Seggan |
| 014 | FALSE | 221007T162121Z | Joe |
| 011 | K ngn/k | 221007T142701Z | oeuf |
| 002 | Japt | 221006T122102Z | Shaggy |
| 002 | MathGolf | 221006T120131Z | Kevin Cr |
| 017 | K ngn/k | 220523T094922Z | oeuf |
| 101 | Batch | 220522T224107Z | Youserna |
| 031 | Desmos | 220522T184949Z | naffetS |
| 013 | Factor + projecteuler.common | 220522T110615Z | chunes |
| 002 | Risky | 210709T130817Z | xigoi |
| 002 | Vyxal | 210709T121213Z | emanresu |
| 007 | Julia | 210413T170146Z | MarcMush |
| 020 | PowerShell Core | 210413T003032Z | Julian |
| 002 | Arn s | 210412T222728Z | ZippyMag |
| 039 | Whispers v2 | 210411T152847Z | caird co |
| 020 | V vim | 210411T152058Z | Razetime |
| 015 | BRASCA | 210203T104955Z | SjoerdPe |
| 015 | GNU AWK | 201220T212417Z | Pedro Ma |
| 004 | APL Dyalog Extended | 201220T131041Z | Kamila S |
| 005 | GolfScript | 201020T001944Z | 2014MELO |
| 004 | Bound | 201019T223639Z | HoofedEa |
| 015 | Excel VBA | 170929T034839Z | Taylor R |
| 013 | Pari/GP | 170520T042131Z | alephalp |
| 006 | TIBasic TI84 Plus CE | 170518T012004Z | pizzapan |
| 005 | Jelly | 170519T140321Z | user6318 |
| 023 | JavaScript | 170519T044209Z | Paul |
| 022 | awk | 170518T202227Z | steve |
| 012 | Ruby | 170516T200950Z | Value In |
| 037 | brainfuck | 170518T183202Z | Business |
| 023 | Axiom | 170518T173707Z | user5898 |
| 095 | Fortran 95 gfortran | 170517T142707Z | wafflest |
| 1118 | Taxi | 170516T205154Z | Engineer |
| 138 | Swift | 170518T115458Z | Caleb Kl |
| 024 | Java | 170518T110519Z | Olivier |
| 038 | C | 170518T065853Z | Khaled.K |
| 9312 | Perl 5 | 170518T050928Z | Chris |
| 076 | C++ | 170516T235222Z | Tas |
| 006 | MATL | 170516T211227Z | Luis Men |
| 026 | Lua | 170517T215009Z | Felipe N |
| 038 | TSQL | 170517T180046Z | WORNG AL |
| 015 | Bash | 170517T170403Z | marcosm |
| 043 | C | 170517T162238Z | jdt |
| 078 | GNU Make | 170517T162225Z | eush77 |
| 005 | Chaincode | 170517T161352Z | Linnea G |
| 024 | C# | 170517T161204Z | TheLetha |
| 028 | C# | 170517T145250Z | TheLetha |
| 022 | REXX 22 Bytes | 170517T135904Z | theblitz |
| nan | BrainFlak | 170517T122320Z | Erik the |
| 023 | PHP | 170516T195537Z | Jör |
| 023 | JavaScript ES6 | 170517T092949Z | Dom Hast |
| 002 | Braingolf | 170517T090003Z | Mayube |
| 010 | Alice | 170517T085813Z | Leo |
| 004 | MATL | 170517T085736Z | Luis Men |
| 018 | R | 170517T085248Z | Sven Hoh |
| 024 | JavaScript ES6 | 170516T195604Z | Shaggy |
| 033 | C# | 170517T080018Z | Bojan B |
| 001 | Brachylog | 170517T041033Z | user6213 |
| 9110 | Perl 5 | 170517T042012Z | user6213 |
| 007 | J | 170517T035839Z | Conor O& |
| 004 | Pyth | 170517T032438Z | clapp |
| 020 | Bean | 170517T004821Z | Patrick |
| 003 | dc | 170516T205546Z | Digital |
| 002 | RProgN 2 | 170516T225242Z | ATaco |
| 035 | Befunge | 170516T212951Z | bwillsh |
| 020 | Ruby | 170516T212146Z | marmelad |
| 005 | Japt | 170516T210514Z | Luke |
| 063 | BrainFlak | 170516T203321Z | DJMcMayh |
| 016 | Alice | 170516T201032Z | Martin E |
| 013 | Mathematica | 170516T193849Z | Martin E |
| 030 | Fourier | 170516T194248Z | Beta Dec |
| 005 | CJam | 170516T194043Z | Business |
| 002 | 05AB1E | 170516T194013Z | Riley |
| 022 | Python 2 | 170516T193811Z | totallyh |
| 002 | Jelly | 170516T193902Z | Jonathan |
| 002 | 05AB1E | 170516T193854Z | Magic Oc |
| 024 | PowerShell | 170516T193539Z | colsw |
| 002 | Retina | 170516T193328Z | Martin E |
JavaScript (Node.js), 18 bytes
f=x=>x&&-~f(x/10n)
JavaScript (Node.js), 21 bytes
x=>(x+[-x]).length>>1
19 if input as string, but worse than Johan Karlsson's answer then
FALSE, 14 bytes
^45=[1+^~][]#.
Explanation: If first character is '-' (ascii code 45), then push -1. Else push 0. Add 1 to number on stack until EOF character is reached.
K (ngn/k), 11 bytes
{#($x)^"-"}
Easy.
Explanation:
{#($x)^"-"} Main function. Takes x as input
($x) x as string
^"-" Without string literal "-" (Remove negative symbol)
# Length
MathGolf, 2 bytes
±£
Input as integers.
I'm actually surprised builtin £ works on integers. I was expecting I would need an explicit cast, since that's the case with a lot of MathGolf's builtins.
Explanation:
± # Get the absolute value of the (implicit) input-integer
£ # Pop and get the length of this integer
# (after which the entire stack is output implicitly as result)
K (ngn/k), 17 bytes
{#$$[x<0;x*-1;x]}
Can't handle big numbers correctly, e.g. 33107638153846291829. Still decent though.
Batch, 101 bytes
@set/pi=
@set o=-1&if %i:~,1%==- set o=-2
:l
@set/ao+=1&if %i%. neq . set i=%i:~,-1%&goto:l
@echo %o%
89 bytes
@set/pi=
@if %i% lss 0 set/ai=-%i%
:l
@set/ao+=1&if %i% gtr 9 set/ai/=10&goto:l
@echo %o%
Only works for 32-bit numbers.
Whispers v2, 39 bytes
> Input
>> |1|
>> "2"
>> #3
>> Output 4
Boring answer. Get input, absolute value, convert to string, return length.
V (vim), 20 bytes
:s/-
C<C-r>=strlen(<C-r>")
<esc>
Remove minuses(if any), cut the line, and get its length.
Not sure if I need the <esc> at the end.
BRASCA, 15 bytes
iM:45S=[xx0]x!n
Explanation
i - Turn the ascii characters 0-9 to numbers
M:45S=[ 0] - Move the bottom of the stack to the front and check if it's a minus
xx - If so: remove the minus
x - Remove any excess items on the stack
!n - Print the length as a number
GNU AWK, 18 17 15 bytes
$1=gsub(/\w/,1)
Substitutes every number character (except for the minus sign) alphanumeric character of the input for another character (here, the number 1), and assigns the number of substitutions to the output.
Thanks for cnamejj and manatwork for helping me saving some bytes!
AWK, 17 bytes
$1=gsub(/[^-]/,1)
This is a previous answer, that should work on any Awk version, not only GNU's.
Bound, 4 bytes
ib_,
Explanation:
i # Get user input
b # Separate each digit of the top element into individual elements
_ # Put the total number of elements onto the stack
, # Remove all but the top element from the stack
Bound then prints the stack at the end of execution, so you can then see the result.
Excel VBA, 15 Bytes
Anonymous VBE immediate window function that takes input from [A1] and outputs to the VBE immediate window
?[Len(Abs(A1))]
TI-Basic (TI-84 Plus CE, OS 5.2+), 6 bytes
length(toString(abs(Ans
TI-Basic is a tokenized language; length( and toString( are two bytes each.
Ans is used as implicit input; the last (only) line's value is implicitly returned.
Pretty simple, takes the absolute value to get rid of a minus sign, converts to string, returns the length of the string.
A 6-byte mathematical approach that doesn't work for 0:
1+log(abs(Ans
JavaScript, 23 bytes
x=>`${x<0?-x:x}`.length
Ruby, 15 11+1 = 16 12 bytes
Uses the -n flag.
p~/$/-~/\d/
Explanation
# -n flag gets one line of input implicitly
p # Print
~/$/ # Position of end of line (aka string length) in input
- # minus
~/\d/ # Position of first digit (1 if negative number, 0 otherwise)
brainfuck, 37 bytes
-[+>+[+<]>+]>->,[-<->]<[>+>],[<+>,]<.
Output is by byte value.
Explanation
-[+>+[+<]>+]>-> Constant for 45 (from esolangs wiki)
, Read a byte of input
[-<->] Subtract that byte from 45
<[>+>] If the result is nonzero then increment a cell and move to the right
(0 means it was a minus; so not counted)
,[<+>,] Read a byte and increment the cell to its left until EOF is reached
<. Print the cell that was being incremented
Axiom, 23 Bytes
f(x)==#(abs(x)::String)
Fortran 95 (gfortran), 121 96 95 bytes
program c
character b
call get_command_argument(1,b,length=i)
print*,i-index(b,'-')
end program
Explanation:
Subtracts the index of the '-' sign from the length of the argument.
Arrays start at 1 in Fortran, and index() returns 0 if symbol not found.
Edit: Switched to implicit integer "i", also consolidated argument getter.
Edit: -1 byte thanks to @Tsathoggua
Taxi, 1118 bytes
1 is waiting at Starchild Numerology.Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to Chop Suey.Go to Chop Suey:n 1 r 1 l 4 r 1 l.Pickup a passenger going to Crime Lab.'-' is waiting at Writer's Depot.Go to Writer's Depot:n 1 l 3 l.Pickup a passenger going to Crime Lab.Go to Crime Lab:n 1 r 2 r 2 l.Switch to plan "n" if no one is waiting.-1 is waiting at Starchild Numerology.[n]0 is waiting at Starchild Numerology.Go to Starchild Numerology:s 1 r 1 l 1 l 2 l.Pickup a passenger going to Cyclone.Pickup a passenger going to Addition Alley.Go to Cyclone:e 1 l 2 r.[r]Pickup a passenger going to Cyclone.Pickup a passenger going to Addition Alley.Go to Zoom Zoom:n.Go to Addition Alley:w 1 l 1 r.Pickup a passenger going to Addition Alley.Go to Chop Suey:n 1 r 2 r.Switch to plan "f" if no one is waiting.Pickup a passenger going to Sunny Skies Park.Go to Sunny Skies Park:n 1 l 3 l 1 l.Go to Cyclone:n 1 l.Switch to plan "r".[f]Go to Addition Alley:n 1 l 2 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:n 1 r 1 r.Pickup a passenger going to Post Office.Go to Post Office:n 1 l 1 r.
Ungolfed:
1 is waiting at Starchild Numerology.
Go to Post Office: west 1st left 1st right 1st left.
Pickup a passenger going to Chop Suey.
Go to Chop Suey: north 1st right 1st left 4th right 1st left.
Pickup a passenger going to Crime Lab.
'-' is waiting at Writer's Depot.
Go to Writer's Depot: north 1st left 3rd left.
Pickup a passenger going to Crime Lab.
Go to Crime Lab: north 1st right 2nd right 2nd left.
Switch to plan "n" if no one is waiting.
-1 is waiting at Starchild Numerology.
[n]
0 is waiting at Starchild Numerology.
Go to Starchild Numerology: south 1st right 1st left 1st left 2nd left.
Pickup a passenger going to Cyclone.
Pickup a passenger going to Addition Alley.
Go to Cyclone: east 1st left 2nd right.
[r]
Pickup a passenger going to Cyclone.
Pickup a passenger going to Addition Alley.
Go to Zoom Zoom: north.
Go to Addition Alley: west 1st left 1st right.
Pickup a passenger going to Addition Alley.
Go to Chop Suey: north 1st right 2nd right.
Switch to plan "f" if no one is waiting.
Pickup a passenger going to Sunny Skies Park.
Go to Sunny Skies Park: north 1st left 3rd left 1st left.
Go to Cyclone: north 1st left.
Switch to plan "r".
[f]
Go to Addition Alley: north 1st left 2nd left.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery: north 1st right 1st right.
Pickup a passenger going to Post Office.
Go to Post Office: north 1st left 1st right.
Explanation:
Pickup the input and split it into individual characters
Pickup the value 1.
If the first character a hyphen, add -1. Otherwise, add 0.
Keep picking up characters and adding 1 until you're out.
Convert the running total to a string and print to stdout.
Swift, 138 bytes
You would think there would be an easier way to do this.
import Foundation;var d:(String)->Int={return $0.trimmingCharacters(in:CharacterSet(charactersIn:"0123456789").inverted).characters.count}
You can try it here
Un-golfed:
import Foundation // Import the Foundation module
var d:(String)->Int={ // Create a closure that takes in a String and returns an Int
return // Return the following
$0.trimmingCharacters(in: // Removes all characters in the following CharacterSet
CharacterSet(charactersIn:"0123456789").inverted // Create a CharacterSet with all characters that are not digits
).characters.count // Get the length of the resulting String
}
Java, 30 24 bytes
i->(""+i.abs()).length()
Assumes i is a BigInteger. Also, the type is contextualized, so no imports are required, as shown in the test code.
Test
// No imports
class Pcg120897 {
public static void main(String[] args) {
java.util.function.ToIntFunction<java.math.BigInteger> f =
// No full class declaration past here
i->(""+i.abs()).length()
// No full class declaration before here
;
System.out.println(f.applyAsInt(new java.math.BigInteger("-1267650600228229401496703205376"))); // -(2^100)
System.out.println(f.applyAsInt(new java.math.BigInteger("1267650600228229401496703205376"))); // (2^100)
}
}
Saves
- 30 -> 24 bytes : thanks to @cliffroot
Perl 5, 9 bytes + 3 for -F flag=12 bytes
say@F-/-/
Run like perl -F -E 'say@F-/-/'. Takes a single number from stdin without a trailing newline. Can add the -l flag at the cost of an extra byte if you would rather have it accept a trailing newline.
The -F flag auto splits stdin into the array @F. In scalar context, @F evaluates to the length of the array, which is the number of characters in $_ (which comes from stdin). /-/ in a numerical context evaluates to 1 if $_ has a minus sign in it or 0 if $_ does not have a minus sign in it, so @F-/-/ evaluates to the number of non-minus sign characters (i.e. the number of digit characters) read from stdin.
C++, 80 76 bytes
#include<string>
int main(int,char**c){printf("%d",strlen(c[1])-(*c[1]<46));}
Prints the length of the argument, minuses 1 if the first character is a minus because bool guarantees conversion to 1 if true or 0 if false
- 4 bytes thanks to @Squidy for pointing out I can use
<46instead of=='-', and to deference the array instead of[]
MATL, 6 bytes
nGU0<-
Explanation
n % Implicitly input a string. Push its length
G % Push input again
U % Convert to number (floating-point double). Although integers with absolute
% value exceeding 2^53 cannot be represented exactly, the sign is correct
0< % Is it negative?
- % Subtract. Implicitly display
Lua, 26 bytes
Replaces all occurrences of '-' with the empty string '' and get length with #.
print(#(...):gsub('-',''))
T-SQL, 38 bytes
CREATE PROC l @ BIGINT AS PRINT LEN(@)
Usage:
EXECUTE l @ = 9999999999
Bash, 15 bytes
wc -L<<<${1//-}
Deletes - from input as array, and otputs length of longest line (wc -c returns one char more than length)
GNU Make, 78 bytes
Imperative style:
$(eval T=$1)$(foreach D,$(shell seq 9),$(eval T=$(subst $D,? ,$T)))$(words $T)
Functional style, 113 bytes:
$(eval 2?=$(shell seq 9))$(if $2,$(call $0,$(subst $(word 1,$2),? ,$1),$(wordlist 2,$(words $2),$2)),$(words $1))
Pure Make, 83 bytes:
$(eval T=$1)$(foreach D,0 1 2 3 4 5 6 7 8 9,$(eval T=$(subst $D,? ,$T)))$(words $T)
C#, 28 bytes
s=>s.Replace("-","").Length;
REXX 22 Bytes
arg "-" a
say length(a)
Explanation: There is no distinction in Rexx between numbers and strings. The action you perform is what defines the type. The "typing" applies just to that action and can change at any time.
So, here the number (say -20) is treated as a string. The "arg" instruction (short for parse arg) tells Rexx to search for the first "-" and then put everything after it in the variable "a". If "-" is not found then everything goes in "a".
REXX functions and instructions
PHP, 23 Bytes
<?=-~log10(abs($argn));
log of base 10 of the absolute value plus one cast to int
for zero as input log10 gives back INF which is interpreted as false
The better way is to replace $argn with $argn?:1 +3 Bytes
PHP, 27 Bytes
<?=strlen($argn)-($argn<0);
string length minus boolean is lower then zero
+2 Bytes for string comparision $argn<"0"
PHP, 32 Bytes
<?=preg_match_all("#\d#",$argn);
Regex count all digits
35 Bytes
<?=strlen($argn)-strspn($argn,"-");
string length minus count -
Braingolf, 2 bytes
dl
Explaination:
dl
Implicit input from command-line args to stack
d Pop last item from stack, split it into digits, and push each digit to the stack
l Push length of stack to the end of the stack
Implicit output of last item on stack
Alice, 10 bytes (non-competing)
/d/
O@IHc
This is a non-competing solution, because at the time this challenge was posted the command c was bugged in the official (and only :D) interpreter. Martin Ender fixed it in the meanwhile, so this now works.
Explanation
The instruction pointer passes through the two mirrors (/) multiple times, so it may be a bit difficult to follow. I'll try to explain it as clearly as I can, using cardinal directions (e.g. N is up, SW is down to the left...).
I'll call /1 the leftmost mirror, and /2 the rightmost one.
Command Direction Comment
E Execution starts from the upper-left corner going right
/1 E → SE Passing through the mirror changes direction and switches
to ordinal mode (string operations)
I SE → NE Push the input string to the stack, then bounce against
the bottom of the code
/2 NE → S Back to cardinal mode (numeric operations)
H S Pop n, push abs(n). Execution wraps from bottom to top
/2 S → SE Ordinal mode again
c SE → NW Pop s, push each char of s separatedly. Bounce against
the bottom right corner
/2 NW → W Cardinal mode
d W Push the depth of the stack (which is now equal to
the number of characters in abs(input))
/1 W → NW → SW Pass through the mirror, then bounce agains the top
O SW → NE Output the result, then bounce on the bottom left corner
/1 NE → S Last mirror, I promise
@ S Terminate execution
MATL, 4 bytes
47>s
Inspired by Martin's Retina answer: count how many characters have code point exceeding 47 (this excludes the minus sign).
R, 18 bytes
nchar(abs(scan()))
JavaScript (ES6), 27 26 25 24 bytes
Takes input as a string.
s=>s.match(/\d/g).length
- Saved two bytes thanks to Arnauld.
C#, 33 bytes
i=>Math.Abs(i).ToString().Length;
Brachylog, 1 byte
l
Another builtin solution, but this one has the shortest name (unless someone finds a language which does this task in zero bytes). This should work in both Brachylog 1 and Brachylog 2.
This is a function submission (the TIO link contains a command-line argument that causes the interpreter to run an individual function rather than a whole program), partly because otherwise we'd have to spend bytes on output, partly because Brachylog's syntax for negative numbers is somewhat unusual and making this program a function resolves any potential arguments about input syntax.
It's often bothered me that most of Brachylog's builtins treat negative numbers like positive ones, but that fact ended up coming in handy here. I guess there are tradeoffs involved with every golfing language.
Perl 5, 9 + 1 = 10 bytes
$_=y/-//c
Run with -p (1 byte penalty).
Explanation
$_=y/-//c
{implicit from -p: for each line of input}
y/ // In {the input}, replace
c everything except
- '-'
$_= Store number of replacements back in $_
{implicit from -p: output $_}
We treat the input as a string in order to handle numbers outside the 64-bit range. One interesting trick here is that we don't have to specify what we're replacing the nonhyphens with; we can still count the number of replacements that occur.
The TIO link uses -l in order to let us run the program on multiple data without the newlines between them interfering. If the program only has to run once, we can do without it, so long as there's no final newline on the input.
J, 7 bytes
#@":@**
All the solutions I came up with:
0>.@>.10^.>:@(**)
[:#10&#.inv
#@-.&'-'
#@":@**
The first one is math, the second is base conversion, the third takes a string as input, and the shortest takes a number.
The current solution looks like this:
┌─ #
┌─ @ ─┴─ ":
┌─ @ ─┴─ *
──┴─ *
The parent root is a hook between the upper tine and the lower tine. The lower tine (*) is a monad that calculates magnitude. The upper tine is a composition:
┌─ #
┌─ @ ─┴─ ":
@ ─┴─ *
This composes the upper tine (another composition) with *, in this case, a dyad. This is the dyad for multiplication. In the last tine:
┌─ #
@ ─┴─ ":
This calculates format (":) then length (#).
In English form, this is "multiply x times the sign of x, then convert this to a string, then take the length of this string". Basically, abs.toString.length.
Bean, 20 bytes
Hexdump:
00000000: 2650 80d3 d080 a05d 2080 0921 8181 0020 &P.ÓÐ. ] ..!...
00000010: 8001 dc64 ..Üd
JavaScript equivalent:
a.match(/\d/g).length;
Explanation:
Implicitly takes input as a decimal string in a and implicitly outputs the length of the match, which is all the decimal digits in the string. Returns 1 for input of 0.
Bean, 22 bytes
Hexdump:
00000000: 2aa0 1f26 4ccc d3a0 8043 53a0 802d 2043 * .&LÌÓ .CS .- C
00000010: 9125 398b 253a .%9.%:
JavaScript equivalent:
with(Math)((log10(abs(A))^0)+1);
Explanation:
Implicitly takes input as a decimal integer in A, takes the absolute value, then log-base-10, XORs with 0, then adds 1.
When A is 0, the returned value of log10() is -Infinity, and -Infinity ^ 0 is 0 in JavaScript, so the returned value for 0 is 1.
dc, 3
?Zp
Note that normally dc requires negative numbers to be given with _ instead of the more usual -. However, in this case, either may be used. If - is given, then dc treats this as a subtraction on an empty stack, throws dc: stack empty, and then continues with the rest of the number; Thus the result is no different.
? # input
Z # measure length
p # print
Befunge, 35 bytes
77*~`!1+:v
~0`#@ ># !#. #- #2_1+
77*~`! add 49 to the stack and see if that is less than 50 (ascii for
'-')
1+:v if there is a -, don't count it. Add 1 so we don't
have a zero at the top of the stack. Move down.
># !#. #- #2_1+ move right and add one to the total. (Will remove later)
~0`#@ Loop back around and take an input and make sure it is not end of
the string (-1, so we make sure it is > 0)
># !#. #- #2_1+ check to see if there was an input. If there was, add one to the
total. If not, move left. Subtract 2 because we added 1 at two
different locations. Print output and end program.
Ruby, 20 bytes
->a{a.abs.to_s.size}
Japt, 5 bytes
a s l
Explanation
a s l
Ua s l
Ua # take the absolute value of the input
s # and turn it into a string
l # and return its length
Brain-Flak, 63 bytes
([({})]((((()()()()())){}{})){}{})((){[()](<{}>)}{})([{}][]<>)
This is 62 bytes of code and +1 byte for the -a flag.
I tried two other approaches, but unfortunately both of them were longer:
([]<({}[((((()()()()())){}{})){}{}]<>)((){[()](<{}>)}{})>)({}[{}])
([]<>)<>({}<>)((((([][]())){}{})){}{}[{}])((){[()](<{}>)}{})([{}]{})
This should be a very short answer. In fact, if we didn't have to support negative numbers, we could just do:
([]<>)
But we have to compare the first input with 45 (ASCII -) first, which is most of the byte count of this answer.
An arithmetic solution might be shorter.
Alice, 16 bytes
//; 'q<)e
o!@i -
Explanation
Finding a half-decent layout for this was quite tricky. I'm still not super happy with it because of the spaces, the < and the ;, but this is the best I could do for now.
String length is one of those very common built-ins that doesn't exist in Alice, because its input is a string and its output is an integer (and all Alice commands are strictly integers to integer or strings to strings). We can measure a string's length by writing it to the tape in Ordinal mode and then finding its end in Cardinal mode.
/ Reflect to SE. Switch to Ordinal. While in Ordinal mode, the IP will bounce
diagonally up and down through the code.
! Store an implicit empty string on the tape, does nothing.
; Discard an implicit empty string, does nothing.
i Read all input as a string.
'- Push "-".
< Set the horizontal component of the IP's direction to west, so we're bouncing
back now.
- Remove substring. This deletes the minus sign if it exists.
'i Push "i".
; Discard it again.
! Store the input, minus a potential minus sign, on the tape.
/ Reflect to W. Switch to Cardinal. The IP immediately wraps to the
last column.
e) Search the tape to the right for a -1, which will be found at the end
of the string we stored there.
< Does nothing.
q Push the tape head's position, which is equal to the string length.
'<sp> Push " ".
; Discard it again.
/ Reflect to NW. Switch to Ordinal. The IP immediately bounces off
the top boundary to move SW instead.
o Implicitly convert the string length to a string and print it.
IP bounces off the bottom left corner, moves back NE.
/ Reflect to S. Switch to Cardinal.
! Store an implicit 0 on the tape, irrelevant.
The IP wraps back to the first line.
/ Reflect to NE. Switch to Ordinal. The IP immediately bounces off
the top boundary to move SE instead.
@ Terminate the program.
I also tried taking care of the minus sign in Cardinal mode with H (absolute value), but the additional mode switch always ended up being more expensive in my attempts.
Mathematica, 13 bytes
IntegerLength
There's a built-in... returns 0 for 0.
Fourier, 30 bytes
I~S<0{1}{-2*S~S}S{0}{S^~S}SL^o
Fourier doesn't have strings, so it uses logs instead. Bytes are wasted on supporting zero and negative numbers.
CJam, 5 bytes
q'--,
String based.
9 bytes for a purely math-based solution:
riz)AmLm]
Or another 5 with base conversion:
riAb,
Jelly, 2 bytes
DL
This does literally what was asked:
DL - Main link number n e.g. -45
D - convert to a decimal list [-4,-5]
L - get the length 2
05AB1E, 2 bytes
þg
# Implicit input [a]...
þ # Only the digits in [a]...
g # length of [a]...
# Implicit output.
PowerShell, 24 Bytes
"$args"-replace'-'|% Le*
casts the "absolute" value of the input args to a string and gets the 'length' property of it.
1 byte shorter than "".Length
until someone finds a better way to get the abs of a number in PS this is probably as short as it will get.
Retina, 2 bytes
\d
Retina doesn't really know what numbers are, so the input is treated as a string and we simply count the digit characters.