Template:Str len/core: Difference between revisions

From Alternate History Worlds
Jump to navigation Jump to search
(Created page with "{{{{{|safesubst:}}}#ifeq: x{{{{{|safesubst:}}}#if:x|{{{1|}}}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| 500 }} <noinclude><!-- str >= 500 --></noinclude> | 500 | {{{{{|safesu...")
 
No edit summary
 
Line 1: Line 1:
{{{{{|safesubst:}}}#ifeq: x{{{{{|safesubst:}}}#if:x|{{{1|}}}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| 500 }}   <noinclude><!-- str >= 500 --></noinclude>
{{{{{|safesubst:}}}#switch: {{{3|}}}
| 500
 
| {{{{{|safesubst:}}}str len/core  <noinclude><!-- xx0-xx9 --></noinclude>
| hundreds =  <noinclude><!-- 0xx-4xx, using linear search since most strings will probably be less than 100 bytes. --></noinclude>
  |{{{{{|safesubst:}}}#if:x|{{{1|}}}}}
{{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| 100 }} <noinclude><!--str >= x--></noinclude>
   | {{{{{|safesubst:}}}str len/core  <noinclude><!-- x0x-x9x --></noinclude>
| {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| 200 }}
    |{{{{{|safesubst:}}}#if:x|{{{1|}}}}}
   | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| 300 }}
     | {{{{{|safesubst:}}}str len/core  <noinclude><!-- 0xx-4xx --></noinclude>
     | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| 400 }}
      |{{{{{|safesubst:}}}#if:x|{{{1|}}}}}
       | 4
       | | hundreds
      | 3
       }}| tens
       }}
     }}| ones
    | 2
     }}
  | 1
   }}
   }}
|  <noinclude><!-- Don't return 0, since tens and ones don't want a leading 0 in parameter 2. --></noinclude>
}}
| tens =  <noinclude><!-- x0x-x9x, using linear search for 0x-3x, binary search for 4x-9x, since most strings will probably be 0-39 bytes. --></noinclude>
{{{2|}}}{{
{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}10 }}  <noinclude><!--str >= x--></noinclude>
| {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}20 }}
  | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}30 }}
    | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}40 }}
      | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}60 }}
        | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}80 }}
          | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}90 }}
            | 9
            | 8
            }}
          | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}70 }}
            | 7
            | 6
            }}
          }}
        | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}50 }}
          | 5
          | 4
          }}
        }}
      | 3
      }}
    | 2
    }}
  | 1
  }}
| {{{{{|safesubst:}}}#if:{{{2|}}}|0}}  <noinclude><!-- Only return 0 if >=100, since ones don't want a leading 0 in parameter 2. --></noinclude>
}}
| ones =  <noinclude><!-- xx0-xx9, using binary search. --></noinclude>
{{{2|}}}{{
{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}4 }}  <noinclude><!--str >= x--></noinclude>
| {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}6 }}
  | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}8 }}
    | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}9 }}
      | 9
      | 8
      }}
    | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}7 }}
      | 7
      | 6
      }}
    }}
  | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}5 }}
    | 5
    | 4
    }}
  }}
| {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}2 }}
  | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}3 }}
    | 3
    | 2
    }}
  | {{{{{|safesubst:}}}#ifeq: x{{{1|}}} | x{{{{{|safesubst:}}}padleft:{{{1|}}}| {{{2|}}}1 }}
    | 1
    | 0
    }}
  }}
}}
}}<noinclude>
}}<noinclude>



Latest revision as of 12:29, 14 January 2017