September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,4 @@
begin
% print some numbers in hex %
for i := 0 until 20 do write( intbase16( i ) )
end.

View file

@ -0,0 +1,40 @@
import Data.Monoid ((<>))
import Data.Array (Array, listArray, (!))
import Data.List (unfoldr, transpose, intercalate)
-- ARBITRARY RADICES ----------------------------------------------------------
bases :: [Int]
bases = abs <$> [2, 7, 8, 10, 12, 16, 32]
tableRows :: [[String]]
tableRows = ((([baseDigits] <*> bases) <*>) . return) <$> [1 .. 33]
digits :: Array Int Char
digits = listArray (0, 35) (['0' .. '9'] <> ['A' .. 'Z'])
baseDigits :: Int -> Int -> String
baseDigits base
| base > 36 = const "Needs glyphs beyond Z"
| otherwise = reverse . unfoldr remQuot
where
remQuot 0 = Nothing
remQuot n =
let (q, r) = quotRem n base
in Just (digits ! r, q)
-- TEST AND TABULATION---------------------------------------------------------
table :: String -> [[String]] -> [String]
table delim rows =
intercalate delim <$>
transpose
((\col ->
let width = maximum (length <$> col)
justifyRight n c s = drop (length s) (replicate n c <> s)
in justifyRight width ' ' <$> col) <$>
transpose rows)
main :: IO ()
main =
mapM_
putStrLn
(table " " (([(show <$>), (const "----" <$>)] <*> [bases]) <> tableRows))

View file

@ -1,4 +1,4 @@
rocedure main()
procedure main()
write("Non-decimal radices/Output")
every i := 255 | 2 | 5 | 16 do {
printf("%%d = %d\n",i) # integer format

View file

@ -0,0 +1,12 @@
// version 1.1.2
fun main(args: Array<String>) {
val bases = intArrayOf(2, 8, 10, 16, 19, 36)
for (base in bases) print("%6s".format(base))
println()
println("-".repeat(6 * bases.size))
for (i in 0..35) {
for (base in bases) print("%6s".format(i.toString(base)))
println()
}
}

View file

@ -0,0 +1,11 @@
# Project : Editing Non Decimal radices/Output
# Date : 2017/09/15
# Author : Gal Zsolt (~ CalmoSoft ~)
# Email : <calmosoft@gmail.com>
see string(0) + nl
see string(123456789) + nl
see string(-987654321) + nl
see upper(hex(43981)) + nl
see upper(hex(-1)) + nl

View file

@ -0,0 +1,3 @@
const N=16;
var fmt=[2..N].pump(String,"%%5.%dB".fmt); // %5.2B%5.3B%5.4B%5.5B ...
foreach n in (17){fmt.fmt(n.pump(N,List,n.fp(n)).xplode()).println()}

View file

@ -0,0 +1 @@
(100).toString(36) //-->"2s"

View file

@ -0,0 +1,3 @@
"%,.2B".fmt(1234567) //-->"1|0010|1101|0110|1000|0111"
"%,d".fmt(1234567) //-->"1,234,567"
"%,x".fmt(1234567) //-->"12|d6|87"