Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
2
Task/Show-ASCII-table/00-META.yaml
Normal file
2
Task/Show-ASCII-table/00-META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Show_ASCII_table
|
||||
7
Task/Show-ASCII-table/00-TASK.txt
Normal file
7
Task/Show-ASCII-table/00-TASK.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
;Task:
|
||||
Show [https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/ASCII-Table.svg/1261px-ASCII-Table.svg.png the ASCII character set] from values '''32''' to '''127''' (decimal) in a table format.
|
||||
|
||||
|
||||
{{Template:Strings}}
|
||||
<br><br>
|
||||
|
||||
11
Task/Show-ASCII-table/11l/show-ascii-table.11l
Normal file
11
Task/Show-ASCII-table/11l/show-ascii-table.11l
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
L(i) 16
|
||||
L(j) (32 + i .. 127).step(16)
|
||||
String k
|
||||
I j == 32
|
||||
k = ‘Spc’
|
||||
E I j == 127
|
||||
k = ‘Del’
|
||||
E
|
||||
k = Char(code' j)
|
||||
print(‘#3 : #<3’.format(j, k), end' ‘’)
|
||||
print()
|
||||
119
Task/Show-ASCII-table/6502-Assembly/show-ascii-table.6502
Normal file
119
Task/Show-ASCII-table/6502-Assembly/show-ascii-table.6502
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
==========================================================================
|
||||
; task : show ascii table
|
||||
; language: 6502 Assembly
|
||||
; for: : rosettacode.org
|
||||
; run : on a Commodore 64 with command
|
||||
; sys 49152
|
||||
;
|
||||
; same logic of "Commodore BASIC"
|
||||
;
|
||||
; assembler win2c64 by Aart Bik
|
||||
; http://www.aartbik.com/
|
||||
;
|
||||
; 2020-05-01 alvalongo
|
||||
;==========================================================================
|
||||
; constants
|
||||
cr = 13 ; carriage-return
|
||||
white = 5 ; color white
|
||||
; ----------------------------------------------
|
||||
; memory on zero page
|
||||
linnum = $14
|
||||
; ----------------------------------------------
|
||||
; kernel routines
|
||||
linstr = $bdcd ; C64 ROM : convert a 16-bit value to string and print on current device (default screen)
|
||||
chrout = $ffd2 ; C64 ROM kernel: output a character to current device, default screen
|
||||
; use $fded for Apple 2
|
||||
;
|
||||
; ----------------------------------------------
|
||||
;
|
||||
.org $c000 ; start at free RAM, on Commodore 64
|
||||
; ----------------------------------------------
|
||||
l100 lda #147 ; clear screen
|
||||
jsr chrout
|
||||
;
|
||||
l110 lda #14 ;character set 2, upper/lower case mode
|
||||
jsr chrout
|
||||
;
|
||||
lda #white ; color for characters
|
||||
jsr chrout
|
||||
;
|
||||
l120 lda #<msg1
|
||||
ldx #>msg1
|
||||
jsr prtmsg
|
||||
;
|
||||
l130 lda #<msg2
|
||||
ldx #>msg2
|
||||
jsr prtmsg
|
||||
;
|
||||
l140 lda #cr
|
||||
jsr chrout
|
||||
;
|
||||
l150 lda #0
|
||||
sta row
|
||||
;
|
||||
l160 lda #0
|
||||
sta column
|
||||
;
|
||||
l170 clc
|
||||
lda row
|
||||
adc #32
|
||||
sta ascii
|
||||
lda column
|
||||
asl ; times 2, 2
|
||||
asl ; times 2, 4
|
||||
asl ; times 2, 8
|
||||
asl ; times 2, 16
|
||||
adc ascii
|
||||
sta ascii
|
||||
;
|
||||
l180 cmp #100
|
||||
bcs l185 ; equal or greater than
|
||||
lda #" " ; a space before values less than 100
|
||||
jsr chrout
|
||||
;
|
||||
l185 ldx ascii
|
||||
lda #0
|
||||
jsr linstr ; convert to string and print on screen
|
||||
lda #":"
|
||||
jsr chrout
|
||||
lda ascii
|
||||
jsr chrout
|
||||
lda #" "
|
||||
jsr chrout
|
||||
;
|
||||
l190 inc column ; next column
|
||||
lda column
|
||||
cmp #5
|
||||
bcc l170
|
||||
beq l170
|
||||
;
|
||||
l200 lda #cr
|
||||
jsr chrout
|
||||
;
|
||||
l210 inc row ; next row
|
||||
lda row
|
||||
cmp #15
|
||||
bcc l160
|
||||
beq l160
|
||||
;
|
||||
l220 rts ; return to operating system
|
||||
; ----------------------------------------------
|
||||
; print message
|
||||
;
|
||||
prtmsg sta linnum
|
||||
stx linnum+1
|
||||
ldy #0
|
||||
l310 lda (linnum),y
|
||||
beq l320
|
||||
jsr chrout
|
||||
iny
|
||||
bne l310
|
||||
l320 lda #cr
|
||||
jsr chrout
|
||||
rts
|
||||
; ----------------------------------------------
|
||||
msg1 .byte "COMMODORE 64 - BASIC V2",0
|
||||
msg2 .byte "CHARACTER SET 2 UPPER/LOWER CASE MODE",0
|
||||
row .byte 0
|
||||
column .byte 0
|
||||
ascii .byte 0
|
||||
68
Task/Show-ASCII-table/8080-Assembly/show-ascii-table.8080
Normal file
68
Task/Show-ASCII-table/8080-Assembly/show-ascii-table.8080
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
org 100h
|
||||
mvi a,32 ; Start with space
|
||||
mvi d,16 ; 16 lines
|
||||
dochar: mov c,a ; Print number
|
||||
call putnum
|
||||
mov a,c
|
||||
lxi h,spc ; Is it space?
|
||||
cpi 32
|
||||
jz print
|
||||
lxi h,del
|
||||
cpi 127 ; Is it del?
|
||||
jz print
|
||||
lxi h,chr ; Character
|
||||
mov m,a
|
||||
print: call puts
|
||||
adi 16 ; Next column
|
||||
jp dochar ; Done with this line?
|
||||
lxi h,nl
|
||||
call puts
|
||||
sui 95 ; Next line
|
||||
dcr d
|
||||
jnz dochar
|
||||
ret
|
||||
;;; Print number in A. C, D preserved.
|
||||
putnum: lxi h,num ; Set number string to spaces
|
||||
push h
|
||||
mvi b,' '
|
||||
mov m,b
|
||||
inx h
|
||||
mov m,b
|
||||
inx h
|
||||
mov m,b
|
||||
dgts: mvi b,-1
|
||||
divmod: sui 10 ; B = A/10, A = (A mod 10)-10
|
||||
inr b
|
||||
jnc divmod
|
||||
adi 58 ; Make digit
|
||||
mov m,a ; Store digit
|
||||
dcx h
|
||||
mov a,b ; Next digit
|
||||
ana a
|
||||
jnz dgts
|
||||
pop h ; Print number
|
||||
;;; Print zero-terminated (...ish) string
|
||||
puts: mov e,m
|
||||
call putch
|
||||
inx h
|
||||
dcr e
|
||||
jp puts
|
||||
ret
|
||||
;;; Output character in E using CP/M call,
|
||||
;;; preserving registers
|
||||
putch: push psw
|
||||
push b
|
||||
push d
|
||||
push h
|
||||
mvi c,2
|
||||
call 5
|
||||
pop h
|
||||
pop d
|
||||
pop b
|
||||
pop psw
|
||||
ret
|
||||
nl: db 13,10,0 ; Newline
|
||||
num: db ' : ',0 ; Placeholder for number string
|
||||
spc: db 'Spc ',0 ; Space
|
||||
del: db 'Del ',0 ; Del
|
||||
chr: db '* ',0 ; Placeholder for character
|
||||
58
Task/Show-ASCII-table/8086-Assembly/show-ascii-table.8086
Normal file
58
Task/Show-ASCII-table/8086-Assembly/show-ascii-table.8086
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
cpu 8086
|
||||
bits 16
|
||||
putch: equ 2h
|
||||
section .text
|
||||
org 100h
|
||||
mov cx,16 ; 16 lines
|
||||
mov bh,32 ; Start at 32
|
||||
dochar: mov al,bh ; Print number
|
||||
call putnum
|
||||
cmp bh,32 ; Space?
|
||||
je .spc
|
||||
cmp bh,127 ; Del?
|
||||
je .del
|
||||
mov [chr],bh ; Otherwise, print character
|
||||
mov di,chr
|
||||
jmp .out
|
||||
.spc: mov di,spc
|
||||
jmp .out
|
||||
.del: mov di,del
|
||||
.out: call putstr
|
||||
add bh,16 ; Next column
|
||||
cmp bh,128 ; Done with this line?
|
||||
jb dochar
|
||||
mov di,nl ; Print newline
|
||||
call putstr
|
||||
sub bh,95 ; Do next line
|
||||
loop dochar
|
||||
ret
|
||||
;;; Print number in AL as ASCII, right-aligned in 3 characters
|
||||
putnum: mov dx,2020h ; Put spaces in number
|
||||
mov di,num ; Two spaces
|
||||
mov [di],dx
|
||||
inc di
|
||||
inc di
|
||||
mov [di],dh ; Third space
|
||||
mov bl,10 ; Divisor
|
||||
.div: xor ah,ah ; Write digits
|
||||
div bl
|
||||
add ah,'0'
|
||||
mov [di],ah
|
||||
dec di
|
||||
test al,al
|
||||
jnz .div
|
||||
mov di,num ; Print number
|
||||
putstr: mov ah,putch ; Use zero-terminated strings
|
||||
.loop: mov dl,[di]
|
||||
test dl,dl
|
||||
jz .done
|
||||
int 21h
|
||||
inc di
|
||||
jmp .loop
|
||||
.done: ret
|
||||
section .data
|
||||
num: db ' : ',0 ; Placeholder for number string
|
||||
nl: db 13,10,0 ; Newline
|
||||
spc: db 'Spc ',0 ; Space
|
||||
del: db 'Del ',0 ; Del
|
||||
chr: db '* ',0 ; Placeholder for character
|
||||
14
Task/Show-ASCII-table/ALGOL-68/show-ascii-table.alg
Normal file
14
Task/Show-ASCII-table/ALGOL-68/show-ascii-table.alg
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# generate an ascii table for characters 32 - 127 #
|
||||
FOR c FROM 32 TO 32 + 15 DO
|
||||
FOR ach FROM c BY 16 TO c + ( 16 * 5 ) DO
|
||||
print( ( whole( ach, -4 )
|
||||
, ": "
|
||||
, IF ach = 32 THEN "SPC"
|
||||
ELIF ach = 127 THEN "DEL"
|
||||
ELSE " " + REPR ach + " "
|
||||
FI
|
||||
)
|
||||
)
|
||||
OD;
|
||||
print( ( newline ) )
|
||||
OD
|
||||
10
Task/Show-ASCII-table/ALGOL-W/show-ascii-table.alg
Normal file
10
Task/Show-ASCII-table/ALGOL-W/show-ascii-table.alg
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
% generate an ascii table for chars 32 - 127 %
|
||||
for i := 32 until 32 + 15 do begin
|
||||
write();
|
||||
for c := i step 16 until i + ( 16 * 5 ) do begin
|
||||
writeon( i_w := 3, s_w := 0, c, ": " );
|
||||
if c = 32 then writeon( "Spc ")
|
||||
else if c = 127 then writeon( "Del " )
|
||||
else writeon( code( c ), " " )
|
||||
end for_ach
|
||||
end for_i.
|
||||
1
Task/Show-ASCII-table/APL/show-ascii-table.apl
Normal file
1
Task/Show-ASCII-table/APL/show-ascii-table.apl
Normal file
|
|
@ -0,0 +1 @@
|
|||
{(¯3↑⍕⍵),': ',∊('Spc' 'Del'(⎕UCS ⍵))[32 127⍳⍵]}¨⍉6 16⍴31+⍳96
|
||||
289
Task/Show-ASCII-table/ARM-Assembly/show-ascii-table.arm
Normal file
289
Task/Show-ASCII-table/ARM-Assembly/show-ascii-table.arm
Normal file
|
|
@ -0,0 +1,289 @@
|
|||
.equ CursorX,0x02000000
|
||||
.equ CursorY,0x02000001
|
||||
ProgramStart:
|
||||
mov sp,#0x03000000 ;Init Stack Pointer
|
||||
|
||||
mov r4,#0x04000000 ;DISPCNT -LCD Control
|
||||
mov r2,#0x403 ;4= Layer 2 on / 3= ScreenMode 3
|
||||
str r2,[r4] ;now the screen is visible
|
||||
bl ResetTextCursors ;set text cursors to top left of screen
|
||||
|
||||
mov r2,#32
|
||||
mov r3,#32+20 ;screen height is 20 chars
|
||||
mov r5,#0 ;column spacer
|
||||
mov r6,#5
|
||||
|
||||
;R0 = Character to print (working copy)
|
||||
;R2 = real copy
|
||||
;R3 = compare factor
|
||||
loop_printAscii:
|
||||
mov r0,r2
|
||||
bl ShowHex
|
||||
|
||||
mov r0,#32
|
||||
bl PrintChar
|
||||
|
||||
mov r0,r2
|
||||
bl PrintChar
|
||||
|
||||
bl CustomNewLine
|
||||
add r2,r2,#1
|
||||
|
||||
cmp r2,#128
|
||||
beq forever ;exit early
|
||||
|
||||
cmp r2,r3
|
||||
bne loop_printAscii
|
||||
|
||||
|
||||
add r3,r3,#20 ;next section
|
||||
|
||||
;inc to next column
|
||||
add r5,r5,#5
|
||||
mov r0,r5
|
||||
mov r1,#0
|
||||
bl SetTextCursors
|
||||
subs r6,r6,#1
|
||||
bne loop_printAscii
|
||||
|
||||
|
||||
|
||||
|
||||
forever:
|
||||
b forever
|
||||
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;; INPUT/OUTPUT SUBROUTINES - CREATED BY KEITH OF CHIBIAKUMAS.COM
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
PrintString: ;Print 255 terminated string
|
||||
STMFD sp!,{r0-r12, lr}
|
||||
PrintStringAgain:
|
||||
ldrB r0,[r1],#1
|
||||
cmp r0,#255
|
||||
beq PrintStringDone ;Repeat until 255
|
||||
bl printchar ;Print Char
|
||||
b PrintStringAgain
|
||||
PrintStringDone:
|
||||
LDMFD sp!,{r0-r12, pc}
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
PrintChar:
|
||||
STMFD sp!,{r0-r12, lr}
|
||||
mov r4,#0
|
||||
mov r5,#0
|
||||
|
||||
mov r3,#CursorX
|
||||
ldrB r4,[r3] ;X pos
|
||||
mov r3,#CursorY
|
||||
ldrB r5,[r3] ;Y pos
|
||||
|
||||
mov r3,#0x06000000 ;VRAM base
|
||||
|
||||
mov r6,#8*2 ;Xpos, 2 bytes per pixel, 8 bytes per char
|
||||
mul r2,r4,r6
|
||||
add r3,r3,r2
|
||||
|
||||
mov r4,#240*8*2 ;Ypos, 240 pixels per line,
|
||||
mul r2,r5,r4 ;2 bytes per pixel, 8 lines per char
|
||||
add r3,r3,r2
|
||||
|
||||
adr r4,BitmapFont ;Font source
|
||||
|
||||
sub r0,r0,#32 ;First Char is 32 (space)
|
||||
add r4,r4,r0,asl #3 ;8 bytes per char
|
||||
|
||||
mov r1,#8 ;8 lines
|
||||
DrawLine:
|
||||
mov r7,#8 ;8 pixels per line
|
||||
ldrb r8,[r4],#1 ;Load Letter
|
||||
mov r9,#0b100000000 ;Mask
|
||||
|
||||
mov r2, #0b1111111101000000; Color: ABBBBBGGGGGRRRRR A=Alpha
|
||||
DrawPixel:
|
||||
tst r8,r9 ;Is bit 1?
|
||||
strneh r2,[r3] ;Yes? then fill pixel (HalfWord)
|
||||
add r3,r3,#2
|
||||
mov r9,r9,ror #1 ;Bitshift Mask
|
||||
subs r7,r7,#1
|
||||
bne DrawPixel ;Next Hpixel
|
||||
|
||||
add r3,r3,#480-16 ;Move Down a line (240 pixels *2 bytes)
|
||||
subs r1,r1,#1 ;-1 char (16 px)
|
||||
bne DrawLine ;Next Vline
|
||||
|
||||
LineDone:
|
||||
mov r3,#CursorX
|
||||
ldrB r0,[r3]
|
||||
add r0,r0,#1 ;Move across screen
|
||||
strB r0,[r3]
|
||||
mov r10,#30
|
||||
cmp r0,r10
|
||||
bleq NewLine
|
||||
LDMFD sp!,{r0-r12, pc}
|
||||
|
||||
NewLine:
|
||||
STMFD sp!,{r0-r12, lr}
|
||||
mov r3,#CursorX
|
||||
mov r0,#0
|
||||
strB r0,[r3]
|
||||
mov r4,#CursorY
|
||||
ldrB r0,[r4]
|
||||
add r0,r0,#1
|
||||
strB r0,[r4]
|
||||
LDMFD sp!,{r0-r12, pc}
|
||||
|
||||
CustomNewLine:
|
||||
STMFD sp!,{r0-r12, lr}
|
||||
mov r3,#CursorX
|
||||
mov r0,r5
|
||||
strB r0,[r3]
|
||||
mov r4,#CursorY
|
||||
ldrB r0,[r4]
|
||||
add r0,r0,#1
|
||||
strB r0,[r4]
|
||||
LDMFD sp!,{r0-r12, pc}
|
||||
|
||||
ResetTextCursors:
|
||||
STMFD sp!,{r4-r6,lr}
|
||||
mov r4,#0
|
||||
mov r5,#CursorX
|
||||
mov r6,#CursorY
|
||||
strB r4,[r5]
|
||||
strB r4,[r6]
|
||||
LDMFD sp!,{r4-r6,lr}
|
||||
bx lr
|
||||
|
||||
SetTextCursors:
|
||||
;input: R0 = new X
|
||||
; R1 = new Y
|
||||
STMFD sp!,{r5-r6}
|
||||
mov r5,#CursorX
|
||||
mov r6,#CursorY
|
||||
strB r0,[r5]
|
||||
strB r1,[r6]
|
||||
LDMFD sp!,{r5-r6}
|
||||
bx lr
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
ShowHex:
|
||||
STMFD sp!,{r0-r12, lr}
|
||||
mov r2,r0,ror #4
|
||||
bl ShowHexChar
|
||||
mov r2,r0
|
||||
bl ShowHexChar
|
||||
LDMFD sp!,{r0-r12, pc}
|
||||
|
||||
ShowHexChar:
|
||||
STMFD sp!,{r0-r12, lr}
|
||||
;mov r3,
|
||||
and r0,r2,#0x0F ; r3
|
||||
cmp r0,#10
|
||||
addge r0,r0,#7 ;if 10 or greater convert to alphabet letters a-f
|
||||
add r0,r0,#48
|
||||
bl PrintChar
|
||||
LDMFD sp!,{r0-r12, pc}
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
BitmapFont:
|
||||
;each byte represents a row of 8 pixels. This is a 1BPP font that is converted to the GBA's 16bpp screen format at runtime
|
||||
.byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ; 20
|
||||
.byte 0x10,0x18,0x18,0x18,0x18,0x00,0x18,0x00 ; 21
|
||||
.byte 0x28,0x6C,0x28,0x00,0x00,0x00,0x00,0x00 ; 22
|
||||
.byte 0x00,0x28,0x7C,0x28,0x7C,0x28,0x00,0x00 ; 23
|
||||
.byte 0x18,0x3E,0x48,0x3C,0x12,0x7C,0x18,0x00 ; 24
|
||||
.byte 0x02,0xC4,0xC8,0x10,0x20,0x46,0x86,0x00 ; 25
|
||||
.byte 0x10,0x28,0x28,0x72,0x94,0x8C,0x72,0x00 ; 26
|
||||
.byte 0x0C,0x1C,0x30,0x00,0x00,0x00,0x00,0x00 ; 27
|
||||
.byte 0x18,0x18,0x30,0x30,0x30,0x18,0x18,0x00 ; 28
|
||||
.byte 0x18,0x18,0x0C,0x0C,0x0C,0x18,0x18,0x00 ; 29
|
||||
.byte 0x08,0x49,0x2A,0x1C,0x14,0x22,0x41,0x00 ; 2A
|
||||
.byte 0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00 ; 2B
|
||||
.byte 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30 ; 2C
|
||||
.byte 0x00,0x00,0x00,0x7E,0x7E,0x00,0x00,0x00 ; 2D
|
||||
.byte 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00 ; 2E
|
||||
.byte 0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00 ; 2F
|
||||
.byte 0x7C,0xC6,0xD6,0xD6,0xD6,0xC6,0x7C,0x00 ; 30
|
||||
.byte 0x10,0x18,0x18,0x18,0x18,0x18,0x08,0x00 ; 31
|
||||
.byte 0x3C,0x7E,0x06,0x3C,0x60,0x7E,0x3C,0x00 ; 32
|
||||
.byte 0x3C,0x7E,0x06,0x1C,0x06,0x7E,0x3C,0x00 ; 33
|
||||
.byte 0x18,0x3C,0x64,0xCC,0x7C,0x0C,0x08,0x00 ; 34
|
||||
.byte 0x3C,0x7E,0x60,0x7C,0x06,0x7E,0x3E,0x00 ; 35
|
||||
.byte 0x3C,0x7E,0x60,0x7C,0x66,0x66,0x3C,0x00 ; 36
|
||||
.byte 0x3C,0x7E,0x06,0x0C,0x18,0x18,0x10,0x00 ; 37
|
||||
.byte 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00 ; 38
|
||||
.byte 0x3C,0x66,0x66,0x3E,0x06,0x7E,0x3C,0x00 ; 39
|
||||
.byte 0x00,0x00,0x18,0x18,0x00,0x18,0x18,0x00 ; 3A
|
||||
.byte 0x00,0x00,0x18,0x18,0x00,0x18,0x18,0x30 ; 3B
|
||||
.byte 0x0C,0x1C,0x38,0x60,0x38,0x1C,0x0C,0x00 ; 3C
|
||||
.byte 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00 ; 3D
|
||||
.byte 0x60,0x70,0x38,0x0C,0x38,0x70,0x60,0x00 ; 3E
|
||||
.byte 0x3C,0x76,0x06,0x1C,0x00,0x18,0x18,0x00 ; 3F
|
||||
.byte 0x7C,0xCE,0xA6,0xB6,0xC6,0xF0,0x7C,0x00 ; 40 @
|
||||
.byte 0x18,0x3C,0x66,0x66,0x7E,0x66,0x24,0x00 ; 41 A
|
||||
.byte 0x3C,0x66,0x66,0x7C,0x66,0x66,0x3C,0x00 ; 42 B
|
||||
.byte 0x38,0x7C,0xC0,0xC0,0xC0,0x7C,0x38,0x00 ; 43 C
|
||||
.byte 0x3C,0x64,0x66,0x66,0x66,0x64,0x38,0x00 ; 44 D
|
||||
.byte 0x3C,0x7E,0x60,0x78,0x60,0x7E,0x3C,0x00 ; 45 E
|
||||
.byte 0x38,0x7C,0x60,0x78,0x60,0x60,0x20,0x00 ; 46 F
|
||||
.byte 0x3C,0x66,0xC0,0xC0,0xCC,0x66,0x3C,0x00 ; 47 G
|
||||
.byte 0x24,0x66,0x66,0x7E,0x66,0x66,0x24,0x00 ; 48 H
|
||||
.byte 0x10,0x18,0x18,0x18,0x18,0x18,0x08,0x00 ; 49 I
|
||||
.byte 0x08,0x0C,0x0C,0x0C,0x4C,0xFC,0x78,0x00 ; 4A J
|
||||
.byte 0x24,0x66,0x6C,0x78,0x6C,0x66,0x24,0x00 ; 4B K
|
||||
.byte 0x20,0x60,0x60,0x60,0x60,0x7E,0x3E,0x00 ; 4C L
|
||||
.byte 0x44,0xEE,0xFE,0xD6,0xD6,0xD6,0x44,0x00 ; 4D M
|
||||
.byte 0x44,0xE6,0xF6,0xDE,0xCE,0xC6,0x44,0x00 ; 4E N
|
||||
.byte 0x38,0x6C,0xC6,0xC6,0xC6,0x6C,0x38,0x00 ; 4F O
|
||||
.byte 0x38,0x6C,0x64,0x7C,0x60,0x60,0x20,0x00 ; 50 P
|
||||
.byte 0x38,0x6C,0xC6,0xC6,0xCA,0x74,0x3A,0x00 ; 51 Q
|
||||
.byte 0x3C,0x66,0x66,0x7C,0x6C,0x66,0x26,0x00 ; 52 R
|
||||
.byte 0x3C,0x7E,0x60,0x3C,0x06,0x7E,0x3C,0x00 ; 53 S
|
||||
.byte 0x3C,0x7E,0x18,0x18,0x18,0x18,0x08,0x00 ; 54 T
|
||||
.byte 0x24,0x66,0x66,0x66,0x66,0x66,0x3C,0x00 ; 55 U
|
||||
.byte 0x24,0x66,0x66,0x66,0x66,0x3C,0x18,0x00 ; 56 V
|
||||
.byte 0x44,0xC6,0xD6,0xD6,0xFE,0xEE,0x44,0x00 ; 57 W
|
||||
.byte 0xC6,0x6C,0x38,0x38,0x6C,0xC6,0x44,0x00 ; 58 X
|
||||
.byte 0x24,0x66,0x66,0x3C,0x18,0x18,0x08,0x00 ; 59 Y
|
||||
.byte 0x7C,0xFC,0x0C,0x18,0x30,0x7E,0x7C,0x00 ; 5A Z
|
||||
.byte 0x1C,0x30,0x30,0x30,0x30,0x30,0x1C,0x00 ; 5B [
|
||||
.byte 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x00 ; 5C Backslash
|
||||
.byte 0x38,0x0C,0x0C,0x0C,0x0C,0x0C,0x38,0x00 ; 5D ]
|
||||
.byte 0x10,0x28,0x44,0x00,0x00,0x00,0x00,0x00 ; 5E ^
|
||||
.byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C ; 5F _
|
||||
.byte 0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00 ; 60 `
|
||||
.byte 0x00,0x00,0x38,0x0C,0x7C,0xCC,0x78,0x00 ; 61
|
||||
.byte 0x20,0x60,0x7C,0x66,0x66,0x66,0x3C,0x00 ; 62
|
||||
.byte 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00 ; 63
|
||||
.byte 0x08,0x0C,0x7C,0xCC,0xCC,0xCC,0x78,0x00 ; 64
|
||||
.byte 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00 ; 65
|
||||
.byte 0x1C,0x36,0x30,0x38,0x30,0x30,0x10,0x00 ; 66
|
||||
.byte 0x00,0x00,0x3C,0x66,0x66,0x3E,0x06,0x3C ; 67
|
||||
.byte 0x20,0x60,0x6C,0x76,0x66,0x66,0x24,0x00 ; 68
|
||||
.byte 0x18,0x00,0x18,0x18,0x18,0x18,0x08,0x00 ; 69
|
||||
.byte 0x06,0x00,0x04,0x06,0x06,0x26,0x66,0x3C ; 6A
|
||||
.byte 0x20,0x60,0x66,0x6C,0x78,0x6C,0x26,0x00 ; 6B
|
||||
.byte 0x10,0x18,0x18,0x18,0x18,0x18,0x08,0x00 ; 6C
|
||||
.byte 0x00,0x00,0x6C,0xFE,0xD6,0xD6,0xC6,0x00 ; 6D
|
||||
.byte 0x00,0x00,0x3C,0x66,0x66,0x66,0x24,0x00 ; 6E
|
||||
.byte 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00 ; 6F
|
||||
.byte 0x00,0x00,0x3C,0x66,0x66,0x7C,0x60,0x20 ; 70
|
||||
.byte 0x00,0x00,0x78,0xCC,0xCC,0x7C,0x0C,0x08 ; 71
|
||||
.byte 0x00,0x00,0x38,0x7C,0x60,0x60,0x20,0x00 ; 72
|
||||
.byte 0x00,0x00,0x3C,0x60,0x3C,0x06,0x7C,0x00 ; 73
|
||||
.byte 0x10,0x30,0x3C,0x30,0x30,0x3E,0x1C,0x00 ; 74
|
||||
.byte 0x00,0x00,0x24,0x66,0x66,0x66,0x3C,0x00 ; 75
|
||||
.byte 0x00,0x00,0x24,0x66,0x66,0x3C,0x18,0x00 ; 76
|
||||
.byte 0x00,0x00,0x44,0xD6,0xD6,0xFE,0x6C,0x00 ; 77
|
||||
.byte 0x00,0x00,0xC6,0x6C,0x38,0x6C,0xC6,0x00 ; 78
|
||||
.byte 0x00,0x00,0x24,0x66,0x66,0x3E,0x06,0x7C ; 79
|
||||
.byte 0x00,0x00,0x7E,0x0C,0x18,0x30,0x7E,0x00 ; 7A
|
||||
.byte 0x10,0x20,0x20,0x40,0x40,0x20,0x20,0x10 ; 7B {
|
||||
.byte 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10 ; 7C |
|
||||
.byte 0x08,0x04,0x04,0x02,0x02,0x04,0x04,0x08 ; 7D }
|
||||
.byte 0x00,0x00,0x00,0x20,0x52,0x0C,0x00,0x00 ; 7E ~
|
||||
.byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ; 7F
|
||||
.byte 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF ; 80
|
||||
13
Task/Show-ASCII-table/AWK/show-ascii-table.awk
Normal file
13
Task/Show-ASCII-table/AWK/show-ascii-table.awk
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# syntax: GAWK -f SHOW_ASCII_TABLE.AWK
|
||||
# syntax: MAWK -f SHOW_ASCII_TABLE.AWK
|
||||
BEGIN {
|
||||
for (i=0; i<16; i++) {
|
||||
for (j=32+i; j<128; j+=16) {
|
||||
if (j == 32) { x = "SPC" }
|
||||
else if (j == 127) { x = "DEL" }
|
||||
else { x = sprintf("%c",j) }
|
||||
printf("%3d: %-5s",j,x)
|
||||
}
|
||||
print ""
|
||||
}
|
||||
}
|
||||
35
Task/Show-ASCII-table/Action-/show-ascii-table.action
Normal file
35
Task/Show-ASCII-table/Action-/show-ascii-table.action
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
PROC Main()
|
||||
BYTE
|
||||
count=[96],rows=[16],
|
||||
first=[32],last=[127],
|
||||
i,j
|
||||
|
||||
Put(125) ;clear screen
|
||||
|
||||
FOR i=0 TO rows-1
|
||||
DO
|
||||
Position(2,3+i)
|
||||
|
||||
FOR j=first+i TO last STEP rows
|
||||
DO
|
||||
IF j>=96 AND j<=99 THEN
|
||||
Put(' )
|
||||
FI
|
||||
PrintB(j)
|
||||
Put(' )
|
||||
|
||||
IF j=32 THEN
|
||||
Print("SP ")
|
||||
ELSEIF j=125 THEN
|
||||
Print("CL")
|
||||
ELSEIF j=126 THEN
|
||||
Print("DL")
|
||||
ELSEIF j=127 THEN
|
||||
Print("TB")
|
||||
ELSE
|
||||
PrintF("%C ",j)
|
||||
FI
|
||||
OD
|
||||
PutE()
|
||||
OD
|
||||
RETURN
|
||||
23
Task/Show-ASCII-table/Ada/show-ascii-table.ada
Normal file
23
Task/Show-ASCII-table/Ada/show-ascii-table.ada
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
|
||||
|
||||
procedure Ascii_Table is
|
||||
N : Integer;
|
||||
begin
|
||||
for R in 0 .. 15 loop
|
||||
for C in 0 .. 5 loop
|
||||
N := 32 + 16 * C + R;
|
||||
Put (N, 3);
|
||||
Put (" : ");
|
||||
case N is
|
||||
when 32 =>
|
||||
Put ("Spc ");
|
||||
when 127 =>
|
||||
Put ("Del ");
|
||||
when others =>
|
||||
Put (Character'Val (N) & " ");
|
||||
end case;
|
||||
end loop;
|
||||
New_Line;
|
||||
end loop;
|
||||
end Ascii_Table;
|
||||
256
Task/Show-ASCII-table/AppleScript/show-ascii-table.applescript
Normal file
256
Task/Show-ASCII-table/AppleScript/show-ascii-table.applescript
Normal file
|
|
@ -0,0 +1,256 @@
|
|||
-- asciiTable :: () -> String
|
||||
on asciiTable()
|
||||
script row
|
||||
on |λ|(x)
|
||||
concat(map(justifyLeft(12, space), x))
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
unlines(map(row, ¬
|
||||
transpose(chunksOf(16, map(my asciiEntry, ¬
|
||||
enumFromTo(32, 127))))))
|
||||
end asciiTable
|
||||
|
||||
|
||||
-------------------------- TEST ---------------------------
|
||||
on run
|
||||
|
||||
asciiTable()
|
||||
|
||||
end run
|
||||
|
||||
|
||||
------------------------- DISPLAY -------------------------
|
||||
|
||||
-- asciiEntry :: Int -> String
|
||||
on asciiEntry(n)
|
||||
set k to asciiName(n)
|
||||
if "" ≠ k then
|
||||
justifyRight(4, space, n as string) & " : " & k
|
||||
else
|
||||
k
|
||||
end if
|
||||
end asciiEntry
|
||||
|
||||
-- asciiName :: Int -> String
|
||||
on asciiName(n)
|
||||
if 32 > n or 127 < n then
|
||||
""
|
||||
else if 32 = n then
|
||||
"Spc"
|
||||
else if 127 = n then
|
||||
"Del"
|
||||
else
|
||||
chr(n)
|
||||
end if
|
||||
end asciiName
|
||||
|
||||
|
||||
-------------------- GENERIC FUNCTIONS --------------------
|
||||
|
||||
-- chr :: Int -> Char
|
||||
on chr(n)
|
||||
character id n
|
||||
end chr
|
||||
|
||||
|
||||
-- chunksOf :: Int -> [a] -> [[a]]
|
||||
on chunksOf(k, xs)
|
||||
script
|
||||
on go(ys)
|
||||
set ab to splitAt(k, ys)
|
||||
set a to |1| of ab
|
||||
if {} ≠ a then
|
||||
{a} & go(|2| of ab)
|
||||
else
|
||||
a
|
||||
end if
|
||||
end go
|
||||
end script
|
||||
result's go(xs)
|
||||
end chunksOf
|
||||
|
||||
|
||||
-- concat :: [[a]] -> [a]
|
||||
-- concat :: [String] -> String
|
||||
on concat(xs)
|
||||
set lng to length of xs
|
||||
if 0 < lng and string is class of (item 1 of xs) then
|
||||
set acc to ""
|
||||
else
|
||||
set acc to {}
|
||||
end if
|
||||
repeat with i from 1 to lng
|
||||
set acc to acc & item i of xs
|
||||
end repeat
|
||||
acc
|
||||
end concat
|
||||
|
||||
|
||||
-- concatMap :: (a -> [b]) -> [a] -> [b]
|
||||
on concatMap(f, xs)
|
||||
set lng to length of xs
|
||||
if 0 < lng and class of xs is string then
|
||||
set acc to ""
|
||||
else
|
||||
set acc to {}
|
||||
end if
|
||||
tell mReturn(f)
|
||||
repeat with i from 1 to lng
|
||||
set acc to acc & |λ|(item i of xs, i, xs)
|
||||
end repeat
|
||||
end tell
|
||||
return acc
|
||||
end concatMap
|
||||
|
||||
|
||||
-- enumFromTo :: Int -> Int -> [Int]
|
||||
on enumFromTo(m, n)
|
||||
if m ≤ n then
|
||||
set lst to {}
|
||||
repeat with i from m to n
|
||||
set end of lst to i
|
||||
end repeat
|
||||
return lst
|
||||
else
|
||||
return {}
|
||||
end if
|
||||
end enumFromTo
|
||||
|
||||
|
||||
-- foldl :: (a -> b -> a) -> a -> [b] -> a
|
||||
on foldl(f, startValue, xs)
|
||||
tell mReturn(f)
|
||||
set v to startValue
|
||||
set lng to length of xs
|
||||
repeat with i from 1 to lng
|
||||
set v to |λ|(v, item i of xs, i, xs)
|
||||
end repeat
|
||||
return v
|
||||
end tell
|
||||
end foldl
|
||||
|
||||
|
||||
-- justifyLeft :: Int -> Char -> String -> String
|
||||
on justifyLeft(n, cFiller)
|
||||
script
|
||||
on |λ|(strText)
|
||||
if n > length of strText then
|
||||
text 1 thru n of (strText & replicate(n, cFiller))
|
||||
else
|
||||
strText
|
||||
end if
|
||||
end |λ|
|
||||
end script
|
||||
end justifyLeft
|
||||
|
||||
|
||||
-- justifyRight :: Int -> Char -> String -> String
|
||||
on justifyRight(n, cFiller, strText)
|
||||
if n > length of strText then
|
||||
text -n thru -1 of ((replicate(n, cFiller) as text) & strText)
|
||||
else
|
||||
strText
|
||||
end if
|
||||
end justifyRight
|
||||
|
||||
|
||||
-- length :: [a] -> Int
|
||||
on |length|(xs)
|
||||
length of xs
|
||||
end |length|
|
||||
|
||||
|
||||
-- map :: (a -> b) -> [a] -> [b]
|
||||
on map(f, xs)
|
||||
tell mReturn(f)
|
||||
set lng to length of xs
|
||||
set lst to {}
|
||||
repeat with i from 1 to lng
|
||||
set end of lst to |λ|(item i of xs, i, xs)
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end map
|
||||
|
||||
|
||||
-- Lift 2nd class handler function into 1st class script wrapper
|
||||
-- mReturn :: First-class m => (a -> b) -> m (a -> b)
|
||||
on mReturn(f)
|
||||
if class of f is script then
|
||||
f
|
||||
else
|
||||
script
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
||||
|
||||
-- Egyptian multiplication - progressively doubling a list, appending
|
||||
-- stages of doubling to an accumulator where needed for binary
|
||||
-- assembly of a target length
|
||||
-- replicate :: Int -> a -> [a]
|
||||
on replicate(n, a)
|
||||
set out to {}
|
||||
if n < 1 then return out
|
||||
set dbl to {a}
|
||||
|
||||
repeat while (n > 1)
|
||||
if (n mod 2) > 0 then set out to out & dbl
|
||||
set n to (n div 2)
|
||||
set dbl to (dbl & dbl)
|
||||
end repeat
|
||||
return out & dbl
|
||||
end replicate
|
||||
|
||||
|
||||
-- splitAt :: Int -> [a] -> ([a],[a])
|
||||
on splitAt(n, xs)
|
||||
if n > 0 and n < length of xs then
|
||||
if class of xs is text then
|
||||
Tuple(items 1 thru n of xs as text, items (n + 1) thru -1 of xs as text)
|
||||
else
|
||||
Tuple(items 1 thru n of xs, items (n + 1) thru -1 of xs)
|
||||
end if
|
||||
else
|
||||
if n < 1 then
|
||||
Tuple({}, xs)
|
||||
else
|
||||
Tuple(xs, {})
|
||||
end if
|
||||
end if
|
||||
end splitAt
|
||||
|
||||
|
||||
-- Tuple (,) :: a -> b -> (a, b)
|
||||
on Tuple(a, b)
|
||||
{type:"Tuple", |1|:a, |2|:b, length:2}
|
||||
end Tuple
|
||||
|
||||
|
||||
-- Simplified version - assuming rows of unvarying length.
|
||||
-- transpose :: [[a]] -> [[a]]
|
||||
on transpose(rows)
|
||||
script cols
|
||||
on |λ|(_, iCol)
|
||||
script cell
|
||||
on |λ|(row)
|
||||
item iCol of row
|
||||
end |λ|
|
||||
end script
|
||||
concatMap(cell, rows)
|
||||
end |λ|
|
||||
end script
|
||||
map(cols, item 1 of rows)
|
||||
end transpose
|
||||
|
||||
|
||||
-- unlines :: [String] -> String
|
||||
on unlines(xs)
|
||||
set {dlm, my text item delimiters} to ¬
|
||||
{my text item delimiters, linefeed}
|
||||
set str to xs as text
|
||||
set my text item delimiters to dlm
|
||||
str
|
||||
end unlines
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
0 GOTO 10: ONERR AI READ LY RND
|
||||
10 LET X = 256 * PEEK (104)
|
||||
11 LET X = X + PEEK (103) + 7
|
||||
20 CALL - 1184:B$ = CHR$ (8)
|
||||
21 NORMAL : PRINT :E = 61588
|
||||
22 PRINT TAB( 29)"APPLESOFT";
|
||||
23 PRINT " II"B$:M = - 1
|
||||
24 PRINT TAB( 22)"BASED ON ";
|
||||
25 FOR I = E + 9 TO E STEP M
|
||||
26 POKE 65, PEEK (I): CALL X
|
||||
27 NEXT : PRINT B$:S$ = " "
|
||||
28 PRINT TAB( 28)"6502 ";
|
||||
29 PRINT "BASIC V2" CHR$ (8)
|
||||
30 PRINT "CHARACTER SET"
|
||||
40 FOR R = 0 TO 15: PRINT
|
||||
50 FOR C = 2 TO 7:A = C * 16
|
||||
60 LET N$ = S$ + STR$ (A + R)
|
||||
70 LET N$ = RIGHT$ (N$,4)
|
||||
80 PRINT N$":" CHR$ (A + R);
|
||||
90 NEXT C,R: PRINT
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
LDA $41 ; ONERR A
|
||||
EOR #$87 ; I READ
|
||||
JMP $DB59 ; LY RND
|
||||
10
Task/Show-ASCII-table/Arturo/show-ascii-table.arturo
Normal file
10
Task/Show-ASCII-table/Arturo/show-ascii-table.arturo
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
loop 32..127 'num [
|
||||
k: ø
|
||||
case [num]
|
||||
when? [=32] -> k: "␠"
|
||||
when? [=127] -> k: "␡"
|
||||
else -> k: to :string to :char num
|
||||
|
||||
prints pad ~"|num|: |k|" 10
|
||||
if 1 = num%6 -> print ""
|
||||
]
|
||||
30
Task/Show-ASCII-table/AutoHotkey/show-ascii-table.ahk
Normal file
30
Task/Show-ASCII-table/AutoHotkey/show-ascii-table.ahk
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
AutoTrim,Off ;Allows for whitespace at end of variable to separate converted characters
|
||||
|
||||
MessageText := ;The text to display in the final message box.
|
||||
CurrentASCII := 32 ;Current ASCII number to convert and add to MessageText
|
||||
ConvertedCharacter := ;Stores the currently converted ASCII code
|
||||
RowLength := 0 ;Keeps track of the number of converted ASCII numbers in each row
|
||||
|
||||
Loop { ;Loops through each ASCII character and makes a list in MessageText
|
||||
if CurrentASCII > 127 ;When the current ASCII number goes over 127, terminate the loop
|
||||
Break
|
||||
if (RowLength = 6) { ;Checks if the row is 6 converted characters long, and if so, inserts a line break (`n)
|
||||
MessageText = %MessageText%`n
|
||||
RowLength := 0
|
||||
}
|
||||
if (CurrentASCII = 32) {
|
||||
ConvertedCharacter = SPC
|
||||
} else {
|
||||
if (CurrentASCII = 127) {
|
||||
ConvertedCharacter = DEL
|
||||
}
|
||||
else {
|
||||
ConvertedCharacter := Chr(CurrentASCII) ;Converts CurrentASCII number using Chr() and stores it in ConvertedCharacter
|
||||
}
|
||||
}
|
||||
MessageText = %MessageText%%CurrentASCII%: %ConvertedCharacter%`t ;Adds converted ASCII to end of MessageText
|
||||
CurrentASCII := CurrentASCII + 1
|
||||
RowLength := RowLength + 1
|
||||
}
|
||||
MsgBox, % MessageText ;Displays a message box with the ASCII conversion table, from the MessageText variable
|
||||
return
|
||||
14
Task/Show-ASCII-table/BASIC256/show-ascii-table.basic
Normal file
14
Task/Show-ASCII-table/BASIC256/show-ascii-table.basic
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
for i = 32 to 47
|
||||
for j = i to i + 80 step 16
|
||||
begin case
|
||||
case j = 32
|
||||
s$ = "Spc"
|
||||
case j = 127
|
||||
s$ = "Del"
|
||||
else
|
||||
s$ = chr(j)
|
||||
end case
|
||||
print rjust(" "+string(j),5); ": "; ljust(s$,3);
|
||||
next j
|
||||
print
|
||||
next i
|
||||
13
Task/Show-ASCII-table/BCPL/show-ascii-table.bcpl
Normal file
13
Task/Show-ASCII-table/BCPL/show-ascii-table.bcpl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
get "libhdr"
|
||||
|
||||
let str(n) =
|
||||
n=32 -> "%I3: Spc ",
|
||||
n=127 -> "%I3: Del ",
|
||||
"%I3: %C "
|
||||
|
||||
let start() be
|
||||
for i=32 to 47 do
|
||||
$( for j=i to 127 by 16 do
|
||||
writef(str(j), j, j)
|
||||
wrch('*N')
|
||||
$)
|
||||
4
Task/Show-ASCII-table/BQN/show-ascii-table-1.bqn
Normal file
4
Task/Show-ASCII-table/BQN/show-ascii-table-1.bqn
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
chs←⟨"SPC"⟩∾(@+33+↕94)∾⟨"DEL"⟩
|
||||
J←{𝕨∾' '∾𝕩}´
|
||||
_pad←{(𝕗×·⌈´≠¨)⊸(↑¨)}
|
||||
•Out˘J˘J¨⍉6‿16⥊<˘⍉(∾⟜':'¨¯1 _pad •Fmt¨32+↕96)≍1 _pad chs
|
||||
16
Task/Show-ASCII-table/BQN/show-ascii-table-2.bqn
Normal file
16
Task/Show-ASCII-table/BQN/show-ascii-table-2.bqn
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
32: SPC 48: 0 64: @ 80: P 96: ` 112: p
|
||||
33: ! 49: 1 65: A 81: Q 97: a 113: q
|
||||
34: " 50: 2 66: B 82: R 98: b 114: r
|
||||
35: # 51: 3 67: C 83: S 99: c 115: s
|
||||
36: $ 52: 4 68: D 84: T 100: d 116: t
|
||||
37: % 53: 5 69: E 85: U 101: e 117: u
|
||||
38: & 54: 6 70: F 86: V 102: f 118: v
|
||||
39: ' 55: 7 71: G 87: W 103: g 119: w
|
||||
40: ( 56: 8 72: H 88: X 104: h 120: x
|
||||
41: ) 57: 9 73: I 89: Y 105: i 121: y
|
||||
42: * 58: : 74: J 90: Z 106: j 122: z
|
||||
43: + 59: ; 75: K 91: [ 107: k 123: {
|
||||
44: , 60: < 76: L 92: \ 108: l 124: |
|
||||
45: - 61: = 77: M 93: ] 109: m 125: }
|
||||
46: . 62: > 78: N 94: ^ 110: n 126: ~
|
||||
47: / 63: ? 79: O 95: _ 111: o 127: DEL
|
||||
14
Task/Show-ASCII-table/BaCon/show-ascii-table.bacon
Normal file
14
Task/Show-ASCII-table/BaCon/show-ascii-table.bacon
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
FOR j = 0 TO 15
|
||||
FOR i = 32+j TO 127 STEP 16
|
||||
PRINT i FORMAT " %3d - ";
|
||||
SELECT i
|
||||
CASE 32
|
||||
PRINT "Spc";
|
||||
CASE 127
|
||||
PRINT "Del";
|
||||
DEFAULT
|
||||
PRINT i FORMAT "%c "
|
||||
ENDSELECT
|
||||
NEXT
|
||||
PRINT
|
||||
NEXT
|
||||
14
Task/Show-ASCII-table/Brainf---/show-ascii-table.bf
Normal file
14
Task/Show-ASCII-table/Brainf---/show-ascii-table.bf
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
> ++++++ ; 6 rows
|
||||
> ++++ ++++ ++++ ++++ ; 16 columns
|
||||
> ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ; 32: the starting character
|
||||
<< ; move to row counter
|
||||
[
|
||||
> ; move to the column counter
|
||||
[> ; move to character
|
||||
. ; print it
|
||||
+ ; increase it
|
||||
<- ; decrease the column counter
|
||||
]
|
||||
+++++ +++++.[-] ; print newline
|
||||
++++ ++++ ++++ ++++ ; set column counter again
|
||||
<-] ; decrease row counter and loop
|
||||
28
Task/Show-ASCII-table/C++/show-ascii-table.cpp
Normal file
28
Task/Show-ASCII-table/C++/show-ascii-table.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include <string>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
inline constexpr auto HEIGHT = 16;
|
||||
inline constexpr auto WIDTH = 6;
|
||||
inline constexpr auto ASCII_START = 32;
|
||||
// ASCII special characters
|
||||
inline constexpr auto SPACE = 32;
|
||||
inline constexpr auto DELETE = 127;
|
||||
|
||||
std::string displayAscii(char ascii) {
|
||||
switch (ascii) {
|
||||
case SPACE: return "Spc";
|
||||
case DELETE: return "Del";
|
||||
default: return std::string(1, ascii);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
for (std::size_t row = 0; row < HEIGHT; ++row) {
|
||||
for (std::size_t col = 0; col < WIDTH; ++col) {
|
||||
const auto ascii = ASCII_START + row + col * HEIGHT;
|
||||
std::cout << std::right << std::setw(3) << ascii << " : " << std::left << std::setw(6) << displayAscii(ascii);
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
14
Task/Show-ASCII-table/C-sharp/show-ascii-table.cs
Normal file
14
Task/Show-ASCII-table/C-sharp/show-ascii-table.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using static System.Console;
|
||||
using static System.Linq.Enumerable;
|
||||
|
||||
public class Program
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
for (int start = 32; start + 16 * 5 < 128; start++) {
|
||||
WriteLine(string.Concat(Range(0, 6).Select(i => $"{start+16*i, 3} : {Text(start+16*i), -6}")));
|
||||
}
|
||||
|
||||
string Text(int index) => index == 32 ? "Sp" : index == 127 ? "Del" : (char)index + "";
|
||||
}
|
||||
}
|
||||
18
Task/Show-ASCII-table/C/show-ascii-table.c
Normal file
18
Task/Show-ASCII-table/C/show-ascii-table.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int i, j;
|
||||
char k[4];
|
||||
for (i = 0; i < 16; ++i) {
|
||||
for (j = 32 + i; j < 128; j += 16) {
|
||||
switch (j) {
|
||||
default: sprintf(k, "%c", j); break;
|
||||
case 32: sprintf(k, "Spc"); break;
|
||||
case 127: sprintf(k, "Del"); break;
|
||||
}
|
||||
printf("%3d : %-3s ", j, k);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
18
Task/Show-ASCII-table/CLU/show-ascii-table.clu
Normal file
18
Task/Show-ASCII-table/CLU/show-ascii-table.clu
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
ascii = proc (n: int) returns (string)
|
||||
if n=32 then return("Spc")
|
||||
elseif n=127 then return("Del")
|
||||
else return(string$c2s(char$i2c(n)))
|
||||
end
|
||||
end ascii
|
||||
|
||||
start_up = proc ()
|
||||
po: stream := stream$primary_output()
|
||||
for i: int in int$from_to(32, 47) do
|
||||
for j: int in int$from_to_by(i, 127, 16) do
|
||||
stream$putright(po, int$unparse(j), 3)
|
||||
stream$puts(po, ": ")
|
||||
stream$putleft(po, ascii(j), 5)
|
||||
end
|
||||
stream$putl(po, "")
|
||||
end
|
||||
end start_up
|
||||
22
Task/Show-ASCII-table/COBOL/show-ascii-table.cobol
Normal file
22
Task/Show-ASCII-table/COBOL/show-ascii-table.cobol
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. CHARSET.
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 CHARCODE PIC 9(3) VALUE 32.
|
||||
PROCEDURE DIVISION.
|
||||
MAIN-PROCEDURE.
|
||||
PERFORM UNTIL CHARCODE=128
|
||||
DISPLAY FUNCTION CONCATENATE(
|
||||
FUNCTION CONCATENATE(
|
||||
CHARCODE,
|
||||
" : "
|
||||
),
|
||||
FUNCTION CONCATENATE(
|
||||
FUNCTION CHAR(CHARCODE),
|
||||
" "
|
||||
)
|
||||
)
|
||||
WITH NO ADVANCING
|
||||
ADD 1 TO CHARCODE
|
||||
END-PERFORM.
|
||||
END PROGRAM CHARSET.
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
10 cls
|
||||
20 for r = 0 to 15
|
||||
30 for c = 1 to 6
|
||||
40 a = 16+r+c*16
|
||||
50 print right$(" "+str$(a),4)": " chr$(a)tab (10*c);
|
||||
60 next c
|
||||
70 print
|
||||
80 next r
|
||||
18
Task/Show-ASCII-table/Clojure/show-ascii-table-1.clj
Normal file
18
Task/Show-ASCII-table/Clojure/show-ascii-table-1.clj
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
(defn cell [code]
|
||||
(let [text (get {32 "Spc", 127 "Del"} code (char code))]
|
||||
(format "%3d: %3s" code text)))
|
||||
|
||||
(defn ascii-table [n-cols st-code end-code]
|
||||
(let [n-cells (inc (- end-code st-code))
|
||||
n-rows (/ n-cells n-cols)
|
||||
code (fn [r c] (+ st-code r (* c n-rows)))
|
||||
row-str (fn [r]
|
||||
(clojure.string/join " "
|
||||
(map #(cell (code r %))
|
||||
(range n-cols))))]
|
||||
(->> (for [r (range n-rows)]
|
||||
(row-str r))
|
||||
(clojure.string/join "\n"))))
|
||||
|
||||
(defn pr-ascii-table [n-cols st-code end-code]
|
||||
(println (ascii-table n-cols st-code end-code)))
|
||||
22
Task/Show-ASCII-table/Clojure/show-ascii-table-2.clj
Normal file
22
Task/Show-ASCII-table/Clojure/show-ascii-table-2.clj
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(defn cell [code]
|
||||
(if (nil? code)
|
||||
""
|
||||
(let [text (get {32 "Spc", 127 "Del"} code (char code))]
|
||||
(format "%3d: %3s" code text))))
|
||||
|
||||
(defn ascii-table [n-cols st-code end-code]
|
||||
(let [n-cells (inc (- end-code st-code))
|
||||
n-rows (int (Math/ceil (/ n-cells n-cols 1.0)))
|
||||
code (fn [r c]
|
||||
(let [cd (+ st-code r (* c n-rows))]
|
||||
(if (> cd end-code) nil cd)))
|
||||
row-str (fn [r]
|
||||
(clojure.string/join " "
|
||||
(map #(cell (code r %))
|
||||
(range n-cols))))]
|
||||
(->> (for [r (range n-rows)]
|
||||
(row-str r))
|
||||
(clojure.string/join "\n"))))
|
||||
|
||||
(defn pr-ascii-table [n-cols st-code end-code]
|
||||
(println (ascii-table n-cols st-code end-code)))
|
||||
12
Task/Show-ASCII-table/Commodore-BASIC/show-ascii-table.basic
Normal file
12
Task/Show-ASCII-table/Commodore-BASIC/show-ascii-table.basic
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
100 PRINT CHR$(147);:REM CLEAR SCREEN
|
||||
110 PRINT CHR$(14);:REM CHARACTER SET 2
|
||||
120 PRINT "COMMODORE 64 - BASIC V2"
|
||||
130 PRINT "CHARACTER SET 2"
|
||||
140 PRINT
|
||||
150 FOR R=0 TO 15
|
||||
160 FOR C=0 TO 5
|
||||
170 A=32+R+C*16
|
||||
180 PRINT RIGHT$(" "+STR$(A),4);":";CHR$(A);
|
||||
190 NEXT C
|
||||
200 PRINT
|
||||
210 NEXT R
|
||||
18
Task/Show-ASCII-table/Common-Lisp/show-ascii-table.lisp
Normal file
18
Task/Show-ASCII-table/Common-Lisp/show-ascii-table.lisp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
(setq startVal 32)
|
||||
(setq endVal 127)
|
||||
(setq cols 6)
|
||||
|
||||
(defun print-val (val) "Prints the value for that ascii number"
|
||||
(cond
|
||||
((= val 32) (format t " 32: SPC "))
|
||||
((= val 127) (format t "127: DEL~%"))
|
||||
((and (zerop (mod (- val startVal) cols)) (< val 100)) (format t "~% ~d: ~a " val (int-char val)))
|
||||
((and (zerop (mod (- val startVal) cols)) (>= val 100)) (format t "~%~d: ~a " val (int-char val)))
|
||||
((< val 100) (format t " ~d: ~a " val (int-char val)))
|
||||
((>= val 100) (format t "~d: ~a " val (int-char val)))
|
||||
(t nil)))
|
||||
|
||||
(defun get-range (lower upper) "Returns a list of range lower to upper"
|
||||
(if (> lower upper) '() (cons lower (get-range (+ 1 lower) upper))))
|
||||
|
||||
(mapcar #'print-val (get-range startVal endVal))
|
||||
33
Task/Show-ASCII-table/Cowgol/show-ascii-table.cowgol
Normal file
33
Task/Show-ASCII-table/Cowgol/show-ascii-table.cowgol
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
include "cowgol.coh";
|
||||
|
||||
# Print number with preceding space if <100 and trailing colon
|
||||
sub print_num(n: uint8) is
|
||||
if n < 100 then print_char(' '); end if;
|
||||
print_i8(n);
|
||||
print(": ");
|
||||
end sub;
|
||||
|
||||
# Print character / Spc / Del padded to 5 spaces
|
||||
sub print_ch(c: uint8) is
|
||||
if c == ' ' then print("Spc ");
|
||||
elseif c == 127 then print("Del ");
|
||||
else
|
||||
print_char(c);
|
||||
print(" ");
|
||||
end if;
|
||||
end sub;
|
||||
|
||||
var c: uint8 := 32;
|
||||
loop
|
||||
print_num(c);
|
||||
print_ch(c);
|
||||
if c == 127 then
|
||||
break;
|
||||
end if;
|
||||
c := c + 16;
|
||||
if c > 127 then
|
||||
print_nl();
|
||||
c := c - 95;
|
||||
end if;
|
||||
end loop;
|
||||
print_nl();
|
||||
20
Task/Show-ASCII-table/D/show-ascii-table.d
Normal file
20
Task/Show-ASCII-table/D/show-ascii-table.d
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import std.stdio;
|
||||
|
||||
void main() {
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
for (int j = 32 + i; j < 128; j += 16) {
|
||||
switch (j) {
|
||||
case 32:
|
||||
writef("%3d : Spc ", j);
|
||||
break;
|
||||
case 127:
|
||||
writef("%3d : Del ", j);
|
||||
break;
|
||||
default:
|
||||
writef("%3d : %-3s ", j, cast(char)j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
writeln;
|
||||
}
|
||||
}
|
||||
32
Task/Show-ASCII-table/Dc/show-ascii-table.dc
Normal file
32
Task/Show-ASCII-table/Dc/show-ascii-table.dc
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
[ [1q]S.[>.0]xs.L. ] sl ## l: islt
|
||||
|
||||
## for initcode condcode incrcode body
|
||||
## [1] [2] [3] [4]
|
||||
[ [q]S. 4:. 3:. 2:. 1:. 1;.x [2;.x 0=. 4;.x 3;.x 0;.x]d0:.x Os.L.o ] sf
|
||||
## f: for
|
||||
|
||||
## for( i=0 ; i<16 ; ++i ) {
|
||||
## for( j=32+i ; j<128 ; j+=16 ) {
|
||||
## pr "%3d", j, " : "
|
||||
## ok = 0;
|
||||
## if( j == 32 ) { pr "Spc"; ok=1; }
|
||||
## if( j == 127 ) { pr "Del"; ok=1; }
|
||||
## if( !ok ) { pr "%c ", j; }
|
||||
## pr " "
|
||||
## }
|
||||
## pr NL
|
||||
## }
|
||||
|
||||
[0si] [li 16 llx] [li1+si] [
|
||||
[32 li+ sj] [lj 128 llx] [lj 16+ sj] [
|
||||
[[ ]P]sT 100 lj <T
|
||||
10 lj <T
|
||||
ljn [ : ]P
|
||||
0so
|
||||
[[Spc]P 1so]sT lj 32 =T
|
||||
[[Del]P 1so]sT lj 127 =T
|
||||
[ljP [ ]P ]sT lo 0 =T
|
||||
[ ]P
|
||||
] lfx
|
||||
[]pP
|
||||
] lfx
|
||||
29
Task/Show-ASCII-table/Delphi/show-ascii-table.delphi
Normal file
29
Task/Show-ASCII-table/Delphi/show-ascii-table.delphi
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
program Show_Ascii_table;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
var
|
||||
i, j: Integer;
|
||||
k: string;
|
||||
|
||||
begin
|
||||
for i := 0 to 15 do
|
||||
begin
|
||||
j := 32 + i;
|
||||
while j < 128 do
|
||||
begin
|
||||
case j of
|
||||
32:
|
||||
k := 'Spc';
|
||||
127:
|
||||
k := 'Del';
|
||||
else
|
||||
k := chr(j);
|
||||
end;
|
||||
Write(j: 3, ' : ', k: 3, ' ');
|
||||
inc(j, 16);
|
||||
end;
|
||||
Writeln;
|
||||
end;
|
||||
Readln;
|
||||
end.
|
||||
20
Task/Show-ASCII-table/Draco/show-ascii-table.draco
Normal file
20
Task/Show-ASCII-table/Draco/show-ascii-table.draco
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
proc write_item(byte n) void:
|
||||
*char chrstr = "* ";
|
||||
chrstr* := pretend(n, char);
|
||||
write(n:3, " : ",
|
||||
case n
|
||||
incase 32: "Spc "
|
||||
incase 127: "Del "
|
||||
default: chrstr
|
||||
esac)
|
||||
corp
|
||||
|
||||
proc main() void:
|
||||
byte row, col;
|
||||
for row from 32 upto 47 do
|
||||
for col from row by 16 upto 127 do
|
||||
write_item(col)
|
||||
od;
|
||||
writeln()
|
||||
od
|
||||
corp
|
||||
14
Task/Show-ASCII-table/EasyLang/show-ascii-table.easy
Normal file
14
Task/Show-ASCII-table/EasyLang/show-ascii-table.easy
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
numfmt 0 3
|
||||
for i range0 16
|
||||
for j = 32 + i step 16 to 127
|
||||
if j = 32
|
||||
x$ = "Spc"
|
||||
elif j = 127
|
||||
x$ = "Del"
|
||||
else
|
||||
x$ = strchar j & " "
|
||||
.
|
||||
write j & ": " & x$
|
||||
.
|
||||
print ""
|
||||
.
|
||||
14
Task/Show-ASCII-table/Ecstasy/show-ascii-table.ecstasy
Normal file
14
Task/Show-ASCII-table/Ecstasy/show-ascii-table.ecstasy
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
module ShowAsciiTable {
|
||||
@Inject Console console;
|
||||
void run() {
|
||||
for (Int offset : 0..<16) {
|
||||
for (Int ascii = 32+offset; ascii < 128; ascii += 16) {
|
||||
console.print($|{ascii.toString().rightJustify(3)}/\
|
||||
|{ascii.toByte().toByteArray()}: \
|
||||
|{new Char(ascii).quoted().leftJustify(5)}
|
||||
, suppressNewline=True);
|
||||
}
|
||||
console.print();
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Task/Show-ASCII-table/Excel/show-ascii-table-1.excel
Normal file
18
Task/Show-ASCII-table/Excel/show-ascii-table-1.excel
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
asciiTable
|
||||
=LAMBDA(i,
|
||||
justifyRight(3)(" ")(i) & ": " & (
|
||||
justifyRight(
|
||||
3
|
||||
)(" ")(
|
||||
IF(32 = i,
|
||||
"Spc",
|
||||
IF(127 = i,
|
||||
"Del",
|
||||
CHAR(i)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)(
|
||||
SEQUENCE(16, 6, 32, 1)
|
||||
)
|
||||
19
Task/Show-ASCII-table/Excel/show-ascii-table-2.excel
Normal file
19
Task/Show-ASCII-table/Excel/show-ascii-table-2.excel
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
justifyRight
|
||||
=LAMBDA(n,
|
||||
LAMBDA(c,
|
||||
LAMBDA(s,
|
||||
LET(
|
||||
lng, LEN(s),
|
||||
|
||||
IF(
|
||||
lng < n,
|
||||
MID(
|
||||
REPT(c, n),
|
||||
lng, n - lng
|
||||
) & s,
|
||||
s
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
19
Task/Show-ASCII-table/Excel/show-ascii-table-3.excel
Normal file
19
Task/Show-ASCII-table/Excel/show-ascii-table-3.excel
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
asciiTable2
|
||||
=LAMBDA(i,
|
||||
IF(0 <> MOD(i, 1),
|
||||
LET(
|
||||
code, FLOOR.MATH(i),
|
||||
|
||||
IF(32 = code,
|
||||
"Spc",
|
||||
IF(127 = code,
|
||||
"Del",
|
||||
CHAR(code)
|
||||
)
|
||||
)
|
||||
),
|
||||
i
|
||||
)
|
||||
)(
|
||||
SEQUENCE(16, 12, 32, 0.5)
|
||||
)
|
||||
15
Task/Show-ASCII-table/Factor/show-ascii-table-1.factor
Normal file
15
Task/Show-ASCII-table/Factor/show-ascii-table-1.factor
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
USING: combinators formatting io kernel math math.ranges
|
||||
pair-rocket sequences ;
|
||||
IN: rosetta-code.ascii-table
|
||||
|
||||
: row-values ( n -- seq ) [ 32 + ] [ 112 + ] bi 16 <range> ;
|
||||
|
||||
: ascii>output ( n -- str )
|
||||
{ 32 => [ "Spc" ] 127 => [ "Del" ] [ "" 1sequence ] } case ;
|
||||
|
||||
: print-row ( n -- )
|
||||
row-values [ dup ascii>output "%3d : %-3s " printf ] each nl ;
|
||||
|
||||
: print-ascii-table ( -- ) 16 <iota> [ print-row ] each ;
|
||||
|
||||
MAIN: print-ascii-table
|
||||
19
Task/Show-ASCII-table/Factor/show-ascii-table-2.factor
Normal file
19
Task/Show-ASCII-table/Factor/show-ascii-table-2.factor
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
USING: combinators formatting io kernel math math.ranges
|
||||
pair-rocket sequences ;
|
||||
IN: rosetta-code.ascii-table
|
||||
|
||||
: main ( -- )
|
||||
16 <iota> [
|
||||
32 + 127 16 <range> [
|
||||
dup {
|
||||
32 => [ "Spc" ]
|
||||
127 => [ "Del" ]
|
||||
[ "" 1sequence ]
|
||||
} case
|
||||
"%3d : %-3s " printf
|
||||
] each
|
||||
nl
|
||||
] each
|
||||
;
|
||||
|
||||
MAIN: main
|
||||
17
Task/Show-ASCII-table/Forth/show-ascii-table-1.fth
Normal file
17
Task/Show-ASCII-table/Forth/show-ascii-table-1.fth
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
DECIMAL
|
||||
: ###: ( c -- ) 3 .R ." : " ;
|
||||
|
||||
: .CHAR ( c -- )
|
||||
DUP
|
||||
CASE
|
||||
BL OF ###: ." spc" ENDOF
|
||||
127 OF ###: ." del" ENDOF
|
||||
DUP ###: EMIT 2 SPACES
|
||||
ENDCASE
|
||||
3 SPACES ;
|
||||
|
||||
: .ROW ( n2 n1 -- )
|
||||
CR DO I .CHAR 16 +LOOP ;
|
||||
|
||||
: ASCII.TABLE ( -- )
|
||||
16 0 DO 113 I + 32 I + .ROW LOOP ;
|
||||
17
Task/Show-ASCII-table/Forth/show-ascii-table-2.fth
Normal file
17
Task/Show-ASCII-table/Forth/show-ascii-table-2.fth
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
ASCII.TABLE
|
||||
32: spc 48: 0 64: @ 80: P 96: ` 112: p
|
||||
33: ! 49: 1 65: A 81: Q 97: a 113: q
|
||||
34: " 50: 2 66: B 82: R 98: b 114: r
|
||||
35: # 51: 3 67: C 83: S 99: c 115: s
|
||||
36: $ 52: 4 68: D 84: T 100: d 116: t
|
||||
37: % 53: 5 69: E 85: U 101: e 117: u
|
||||
38: & 54: 6 70: F 86: V 102: f 118: v
|
||||
39: ' 55: 7 71: G 87: W 103: g 119: w
|
||||
40: ( 56: 8 72: H 88: X 104: h 120: x
|
||||
41: ) 57: 9 73: I 89: Y 105: i 121: y
|
||||
42: * 58: : 74: J 90: Z 106: j 122: z
|
||||
43: + 59: ; 75: K 91: [ 107: k 123: {
|
||||
44: , 60: < 76: L 92: \ 108: l 124: |
|
||||
45: - 61: = 77: M 93: ] 109: m 125: }
|
||||
46: . 62: > 78: N 94: ^ 110: n 126: ~
|
||||
47: / 63: ? 79: O 95: _ 111: o 127: del ok
|
||||
24
Task/Show-ASCII-table/Fortran/show-ascii-table.f
Normal file
24
Task/Show-ASCII-table/Fortran/show-ascii-table.f
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
PROGRAM ASCTBL ! show the ASCII characters from 32-127
|
||||
IMPLICIT NONE
|
||||
INTEGER I, J
|
||||
CHARACTER*3 H
|
||||
|
||||
10 FORMAT (I3, ':', A3, ' ', $)
|
||||
20 FORMAT ()
|
||||
DO J = 0, 15, +1
|
||||
DO I = 32+J, 127, +16
|
||||
IF (I > 32 .AND. I < 127) THEN
|
||||
H = ' ' // ACHAR(I) // ' '
|
||||
ELSE IF (I .EQ. 32) THEN
|
||||
H = 'Spc'
|
||||
ELSE IF (I .EQ. 127) THEN
|
||||
H = 'Del'
|
||||
ELSE
|
||||
STOP 'bad value of i'
|
||||
END IF
|
||||
PRINT 10, I, H
|
||||
END DO
|
||||
PRINT 20
|
||||
END DO
|
||||
|
||||
END
|
||||
62
Task/Show-ASCII-table/Free-Pascal/show-ascii-table.pas
Normal file
62
Task/Show-ASCII-table/Free-Pascal/show-ascii-table.pas
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
// The FPC (FreePascal compiler) discards the program header
|
||||
// (except in ISO-compliant “compiler modes”).
|
||||
program showAsciiTable(output);
|
||||
|
||||
const
|
||||
columnsTotal = 6;
|
||||
|
||||
type
|
||||
// The hash indicates a char-data type.
|
||||
asciiCharacter = #32..#127;
|
||||
asciiCharacters = set of asciiCharacter;
|
||||
|
||||
var
|
||||
character: asciiCharacter;
|
||||
characters: asciiCharacters;
|
||||
column, line: integer;
|
||||
begin
|
||||
// characters needs to be initialized,
|
||||
// because the next `include` below
|
||||
// will _read_ the value `characters`.
|
||||
// Reading _unintialized_ values, however,
|
||||
// is considered bad practice in Pascal.
|
||||
characters := [];
|
||||
// `div` denotes integer division in Pascal,
|
||||
// that means the result will be an _integer_-value.
|
||||
line := (ord(high(asciiCharacter)) - ord(low(asciiCharacter)))
|
||||
div columnsTotal + 1;
|
||||
// Note: In Pascal for-loop limits are _inclusive_.
|
||||
for column := 0 to columnsTotal do
|
||||
begin
|
||||
// This is equivalent to
|
||||
// characters := characters + […];
|
||||
// i.e. the union of two sets.
|
||||
include(characters, chr(ord(low(asciiCharacter)) + column * line));
|
||||
end;
|
||||
|
||||
for line := line downto 1 do
|
||||
begin
|
||||
// the for..in..do statement is an Extended Pascal extension
|
||||
for character in characters do
|
||||
begin
|
||||
// `:6` specifies minimum width of argument
|
||||
// [only works for write/writeLn/writeStr]
|
||||
write(ord(character):6, ' : ', character);
|
||||
end;
|
||||
// emit proper newline character on `output`
|
||||
writeLn;
|
||||
|
||||
// `characters` is evaluated prior entering the loop,
|
||||
// not every time an iteration finished.
|
||||
for character in characters do
|
||||
begin
|
||||
// These statements are equivalent to
|
||||
// characters := characters + [character];
|
||||
// characters := characters - [succ(character)];
|
||||
// respectively, but shorter to write,
|
||||
// i.e. less susceptible to spelling mistakes.
|
||||
exclude(characters, character);
|
||||
include(characters, succ(character));
|
||||
end;
|
||||
end;
|
||||
end.
|
||||
21
Task/Show-ASCII-table/FreeBASIC/show-ascii-table.basic
Normal file
21
Task/Show-ASCII-table/FreeBASIC/show-ascii-table.basic
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
function getasc( n as unsigned byte ) as string
|
||||
if n=32 then return "Spc"
|
||||
if n=127 then return "Del"
|
||||
return chr(n)+" "
|
||||
end function
|
||||
|
||||
function padto( i as ubyte, j as integer ) as string
|
||||
return wspace(i-len(str(j)))+str(j)
|
||||
end function
|
||||
|
||||
dim as unsigned byte r, c, n
|
||||
dim as string disp
|
||||
|
||||
for r = 0 to 15
|
||||
disp = ""
|
||||
for c = 0 to 5
|
||||
n = 32 + 6*r + c
|
||||
disp = disp + padto(3, n) + ": " + getasc(n) + " "
|
||||
next c
|
||||
print disp
|
||||
next r
|
||||
6
Task/Show-ASCII-table/Frink/show-ascii-table.frink
Normal file
6
Task/Show-ASCII-table/Frink/show-ascii-table.frink
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
a = ["32 Space"]
|
||||
for i = 33 to 126
|
||||
a.push["$i " + char[i]]
|
||||
a.push["127 Delete"]
|
||||
|
||||
println[formatTableBoxed[columnize[a,8].transpose[], "left"]]
|
||||
31
Task/Show-ASCII-table/FutureBasic/show-ascii-table.basic
Normal file
31
Task/Show-ASCII-table/FutureBasic/show-ascii-table.basic
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
include "NSLog.incl"
|
||||
|
||||
local fn ASCIITable as CFStringRef
|
||||
'~'1
|
||||
NSinteger i
|
||||
CFStringRef temp
|
||||
|
||||
CFMutableStringRef mutStr = fn MutableStringWithCapacity( 0 )
|
||||
for i = 32 to 127
|
||||
temp = fn StringWithFormat( @"%c", i )
|
||||
if i == 32 then temp = @"Spc"
|
||||
if i == 127 then temp = @"Del"
|
||||
MutableStringAppendString( mutStr, fn StringWithFormat( @"%-1d : %@\n", i, temp ) )
|
||||
next
|
||||
|
||||
CFArrayRef colArr = fn StringComponentsSeparatedByString( mutStr, @"\n" )
|
||||
MutableStringSetString( mutStr, @"" )
|
||||
for i = 0 to 15
|
||||
ObjectRef col0 = fn StringUTF8String( fn ArrayObjectAtIndex( colArr, i ) )
|
||||
ObjectRef col1 = fn StringUTF8String( fn ArrayObjectAtIndex( colArr, i + 16 ) )
|
||||
ObjectRef col2 = fn StringUTF8String( fn ArrayObjectAtIndex( colArr, i + 32 ) )
|
||||
ObjectRef col3 = fn StringUTF8String( fn ArrayObjectAtIndex( colArr, i + 48 ) )
|
||||
ObjectRef col4 = fn StringUTF8String( fn ArrayObjectAtIndex( colArr, i + 64 ) )
|
||||
ObjectRef col5 = fn StringUTF8String( fn ArrayObjectAtIndex( colArr, i + 80 ) )
|
||||
MutableStringAppendString( mutStr, fn StringWithFormat( @"%-10s %-10s %-10s %-10s %-10s %-10s\n", col0, col1, col2, col3, col4, col5 ) )
|
||||
next
|
||||
end fn = fn StringWithString( mutStr )
|
||||
|
||||
NSLog( @"%@", fn ASCIITable )
|
||||
|
||||
HandleEvents
|
||||
11
Task/Show-ASCII-table/GW-BASIC/show-ascii-table.basic
Normal file
11
Task/Show-ASCII-table/GW-BASIC/show-ascii-table.basic
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
10 DEFINT I,J: DEFSTR S: DIM S(2)
|
||||
20 S(0)="* "
|
||||
30 S(1)="Spc"
|
||||
40 S(2)="Del"
|
||||
50 FOR I=32 TO 47
|
||||
60 FOR J=I TO 127 STEP 16
|
||||
70 MID$(S(0),1,1) = CHR$(J)
|
||||
80 PRINT USING "###: \ \ ";J;S(-(J=32)-2*(J=127));
|
||||
90 NEXT J
|
||||
100 PRINT
|
||||
110 NEXT I
|
||||
19
Task/Show-ASCII-table/Go/show-ascii-table.go
Normal file
19
Task/Show-ASCII-table/Go/show-ascii-table.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
for i := 0; i < 16; i++ {
|
||||
for j := 32 + i; j < 128; j += 16 {
|
||||
k := string(j)
|
||||
switch j {
|
||||
case 32:
|
||||
k = "Spc"
|
||||
case 127:
|
||||
k = "Del"
|
||||
}
|
||||
fmt.Printf("%3d : %-3s ", j, k)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
15
Task/Show-ASCII-table/Groovy/show-ascii-table.groovy
Normal file
15
Task/Show-ASCII-table/Groovy/show-ascii-table.groovy
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
class ShowAsciiTable {
|
||||
static void main(String[] args) {
|
||||
for (int i = 32; i <= 127; i++) {
|
||||
if (i == 32 || i == 127) {
|
||||
String s = i == 32 ? "Spc" : "Del"
|
||||
printf("%3d: %s ", i, s)
|
||||
} else {
|
||||
printf("%3d: %c ", i, i)
|
||||
}
|
||||
if ((i - 1) % 6 == 0) {
|
||||
println()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Task/Show-ASCII-table/Haskell/show-ascii-table.hs
Normal file
33
Task/Show-ASCII-table/Haskell/show-ascii-table.hs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import Data.Char (chr)
|
||||
import Data.List (transpose)
|
||||
import Data.List.Split (chunksOf)
|
||||
import Text.Printf (printf)
|
||||
|
||||
----------------------- ASCII TABLE ----------------------
|
||||
|
||||
asciiTable :: String
|
||||
asciiTable =
|
||||
unlines $
|
||||
(printf "%-12s" =<<)
|
||||
<$> transpose
|
||||
(chunksOf 16 $ asciiEntry <$> [32 .. 127])
|
||||
|
||||
asciiEntry :: Int -> String
|
||||
asciiEntry n
|
||||
| null k = k
|
||||
| otherwise = concat [printf "%3d" n, " : ", k]
|
||||
where
|
||||
k = asciiName n
|
||||
|
||||
asciiName :: Int -> String
|
||||
asciiName n
|
||||
| 32 > n = []
|
||||
| 127 < n = []
|
||||
| 32 == n = "Spc"
|
||||
| 127 == n = "Del"
|
||||
| otherwise = [chr n]
|
||||
|
||||
|
||||
--------------------------- TEST -------------------------
|
||||
main :: IO ()
|
||||
main = putStrLn asciiTable
|
||||
7
Task/Show-ASCII-table/IS-BASIC/show-ascii-table.basic
Normal file
7
Task/Show-ASCII-table/IS-BASIC/show-ascii-table.basic
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
100 TEXT 80
|
||||
110 FOR R=0 TO 15
|
||||
120 FOR C=32+R TO 112+R STEP 16
|
||||
130 PRINT USING "###":C;:PRINT ": ";CHR$(C),
|
||||
140 NEXT
|
||||
150 PRINT
|
||||
160 NEXT
|
||||
18
Task/Show-ASCII-table/Java/show-ascii-table-1.java
Normal file
18
Task/Show-ASCII-table/Java/show-ascii-table-1.java
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
public class ShowAsciiTable {
|
||||
|
||||
public static void main(String[] args) {
|
||||
for ( int i = 32 ; i <= 127 ; i++ ) {
|
||||
if ( i == 32 || i == 127 ) {
|
||||
String s = i == 32 ? "Spc" : "Del";
|
||||
System.out.printf("%3d: %s ", i, s);
|
||||
}
|
||||
else {
|
||||
System.out.printf("%3d: %c ", i, i);
|
||||
}
|
||||
if ( (i-1) % 6 == 0 ) {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
19
Task/Show-ASCII-table/Java/show-ascii-table-2.java
Normal file
19
Task/Show-ASCII-table/Java/show-ascii-table-2.java
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
String printASCIITable() {
|
||||
StringBuilder string = new StringBuilder();
|
||||
String newline = System.lineSeparator();
|
||||
string.append("dec hex binary oct char").append(newline);
|
||||
for (int decimal = 32; decimal <= 127; decimal++) {
|
||||
string.append(format(decimal));
|
||||
switch (decimal) {
|
||||
case 32 -> string.append("[SPACE]");
|
||||
case 127 -> string.append("[DELETE]");
|
||||
default -> string.append((char) decimal);
|
||||
}
|
||||
string.append(newline);
|
||||
}
|
||||
return string.toString();
|
||||
}
|
||||
|
||||
String format(int value) {
|
||||
return "%-3d %01$-2x %7s %01$-3o ".formatted(value, Integer.toBinaryString(value));
|
||||
}
|
||||
106
Task/Show-ASCII-table/JavaScript/show-ascii-table.js
Normal file
106
Task/Show-ASCII-table/JavaScript/show-ascii-table.js
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
(() => {
|
||||
|
||||
"use strict";
|
||||
|
||||
// ------------------- ASCII TABLE -------------------
|
||||
|
||||
// asciiTable :: String
|
||||
const asciiTable = () =>
|
||||
transpose(
|
||||
chunksOf(16)(
|
||||
enumFromTo(32)(127)
|
||||
.map(asciiEntry)
|
||||
)
|
||||
)
|
||||
.map(
|
||||
xs => xs.map(justifyLeft(12)(" "))
|
||||
.join("")
|
||||
)
|
||||
.join("\n");
|
||||
|
||||
// asciiEntry :: Int -> String
|
||||
const asciiEntry = n => {
|
||||
const k = asciiName(n);
|
||||
|
||||
return "" === k ? (
|
||||
""
|
||||
) : `${justifyRight(4)(" ")(n.toString())} : ${k}`;
|
||||
};
|
||||
|
||||
// asciiName :: Int -> String
|
||||
const asciiName = n =>
|
||||
32 > n || 127 < n ? (
|
||||
""
|
||||
) : 32 === n ? (
|
||||
"Spc"
|
||||
) : 127 === n ? (
|
||||
"Del"
|
||||
) : chr(n);
|
||||
|
||||
// ---------------- GENERIC FUNCTIONS ----------------
|
||||
|
||||
// chr :: Int -> Char
|
||||
const chr = x =>
|
||||
// The character at unix code-point x.
|
||||
String.fromCodePoint(x);
|
||||
|
||||
|
||||
// chunksOf :: Int -> [a] -> [[a]]
|
||||
const chunksOf = n => {
|
||||
// xs split into sublists of length n.
|
||||
// The last sublist will be short if n
|
||||
// does not evenly divide the length of xs .
|
||||
const go = xs => {
|
||||
const chunk = xs.slice(0, n);
|
||||
|
||||
return 0 < chunk.length ? (
|
||||
[chunk].concat(
|
||||
go(xs.slice(n))
|
||||
)
|
||||
) : [];
|
||||
};
|
||||
|
||||
return go;
|
||||
};
|
||||
|
||||
|
||||
// enumFromTo :: Int -> Int -> [Int]
|
||||
const enumFromTo = m =>
|
||||
n => Array.from({
|
||||
length: 1 + n - m
|
||||
}, (_, i) => m + i);
|
||||
|
||||
|
||||
// justifyLeft :: Int -> Char -> String -> String
|
||||
const justifyLeft = n =>
|
||||
// The string s, followed by enough padding (with
|
||||
// the character c) to reach the string length n.
|
||||
c => s => n > s.length ? (
|
||||
s.padEnd(n, c)
|
||||
) : s;
|
||||
|
||||
|
||||
// justifyRight :: Int -> Char -> String -> String
|
||||
const justifyRight = n =>
|
||||
// The string s, preceded by enough padding (with
|
||||
// the character c) to reach the string length n.
|
||||
c => s => Boolean(s) ? (
|
||||
s.padStart(n, c)
|
||||
) : "";
|
||||
|
||||
|
||||
// transpose :: [[a]] -> [[a]]
|
||||
const transpose = rows =>
|
||||
// The columns of the input transposed
|
||||
// into new rows.
|
||||
// This version assumes input rows of even length.
|
||||
0 < rows.length ? rows[0].map(
|
||||
(x, i) => rows.flatMap(
|
||||
v => v[i]
|
||||
)
|
||||
) : [];
|
||||
|
||||
|
||||
// MAIN ---
|
||||
return asciiTable();
|
||||
})();
|
||||
27
Task/Show-ASCII-table/Jq/show-ascii-table-1.jq
Normal file
27
Task/Show-ASCII-table/Jq/show-ascii-table-1.jq
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# Pretty printing
|
||||
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
|
||||
|
||||
def nwise($n):
|
||||
def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end;
|
||||
n;
|
||||
|
||||
def table($ncols; $colwidth):
|
||||
nwise($ncols) | map(lpad($colwidth)) | join(" ");
|
||||
|
||||
# transposed table
|
||||
def ttable($rows):
|
||||
[nwise($rows)] | transpose[] | join(" ");
|
||||
|
||||
# Representation of control characters, etc
|
||||
def humanize:
|
||||
def special:
|
||||
{ "0": "NUL", "7": "BEL", "8": "BKS",
|
||||
"9": "TAB", "10": "LF ", "13": "CR ",
|
||||
"27": "ESC", "127": "DEL", "155": "CSI" };
|
||||
|
||||
if . < 32 or . == 127 or . == 155
|
||||
then (special[tostring] // "^" + ([64+.]|implode))
|
||||
elif . > 127 and . < 160 then "\\\(.+72|tostring)"
|
||||
else [.] | implode
|
||||
end
|
||||
| lpad(4) ;
|
||||
9
Task/Show-ASCII-table/Jq/show-ascii-table-2.jq
Normal file
9
Task/Show-ASCII-table/Jq/show-ascii-table-2.jq
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# produce a flat array
|
||||
def prepare($m;$n):
|
||||
[range($m; $n) | "\(lpad(7)): \(humanize)" ];
|
||||
|
||||
# Row-wise presentation of 32 through 127 in 6 columns
|
||||
prepare(32;128) | table(6; 10)
|
||||
|
||||
# Column-wise with 16 rows would be produced by:
|
||||
# prepare(32;128) | ttable(16)
|
||||
2
Task/Show-ASCII-table/Jq/show-ascii-table-3.jq
Normal file
2
Task/Show-ASCII-table/Jq/show-ascii-table-3.jq
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# Column-wise representation with 16 rows
|
||||
(prepare(128;256) | ttable(16))
|
||||
67
Task/Show-ASCII-table/Jsish/show-ascii-table.jsish
Normal file
67
Task/Show-ASCII-table/Jsish/show-ascii-table.jsish
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env jsish
|
||||
|
||||
/* Show ASCII table, -showAll true to include control codes */
|
||||
function showASCIITable(args:array|string=void, conf:object=void) {
|
||||
var options = { // Rosetta Code, Show ASCII table
|
||||
rootdir :'', // Root directory.
|
||||
showAll : false // include control code labels if true
|
||||
};
|
||||
var self = {};
|
||||
parseOpts(self, options, conf);
|
||||
|
||||
function main() {
|
||||
var e;
|
||||
var first = (self.showAll) ? 0 : 2;
|
||||
var filler = '='.repeat(19 + ((first) ? 0 : 9));
|
||||
puts(filler, "ASCII table", filler + '=');
|
||||
var labels = [
|
||||
'NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL',
|
||||
'BS ', 'HT ', 'LF ', 'VT ', 'FF ', 'CR ', 'SO ', 'SI ',
|
||||
'DLE', 'DC1', 'DC2', 'DC3', 'DC4', 'NAK', 'SYN', 'ETB',
|
||||
'CAN', 'EM ', 'SUB', 'ESC', 'FS ', 'GS ', 'RS ', 'US '];
|
||||
var table = new Array(128);
|
||||
for (e = 0; e < 32; e++) table[e] = labels[e];
|
||||
for (e = 32; e < 127; e++) table[e] = ' ' + Util.fromCharCode(e) + ' ';
|
||||
table[32] = 'SPC';
|
||||
table[127] = 'DEL';
|
||||
|
||||
for (var row = 0; row < 16; row++) {
|
||||
for (var col = first; col < 8; col++) {
|
||||
e = row + col * 16;
|
||||
printf('%03d %s ', e, table[e]);
|
||||
}
|
||||
printf('\n');
|
||||
}
|
||||
}
|
||||
return main();
|
||||
}
|
||||
|
||||
provide(showASCIITable, 1);
|
||||
|
||||
if (isMain()) {
|
||||
if (Interp.conf('unitTest')) showASCIITable('', {showAll:true});
|
||||
else runModule(showASCIITable);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=!EXPECTSTART!=
|
||||
============================ ASCII table =============================
|
||||
000 NUL 016 DLE 032 SPC 048 0 064 @ 080 P 096 ` 112 p
|
||||
001 SOH 017 DC1 033 ! 049 1 065 A 081 Q 097 a 113 q
|
||||
002 STX 018 DC2 034 " 050 2 066 B 082 R 098 b 114 r
|
||||
003 ETX 019 DC3 035 # 051 3 067 C 083 S 099 c 115 s
|
||||
004 EOT 020 DC4 036 $ 052 4 068 D 084 T 100 d 116 t
|
||||
005 ENQ 021 NAK 037 % 053 5 069 E 085 U 101 e 117 u
|
||||
006 ACK 022 SYN 038 & 054 6 070 F 086 V 102 f 118 v
|
||||
007 BEL 023 ETB 039 ' 055 7 071 G 087 W 103 g 119 w
|
||||
008 BS 024 CAN 040 ( 056 8 072 H 088 X 104 h 120 x
|
||||
009 HT 025 EM 041 ) 057 9 073 I 089 Y 105 i 121 y
|
||||
010 LF 026 SUB 042 * 058 : 074 J 090 Z 106 j 122 z
|
||||
011 VT 027 ESC 043 + 059 ; 075 K 091 [ 107 k 123 {
|
||||
012 FF 028 FS 044 , 060 < 076 L 092 \ 108 l 124 |
|
||||
013 CR 029 GS 045 - 061 = 077 M 093 ] 109 m 125 }
|
||||
014 SO 030 RS 046 . 062 > 078 N 094 ^ 110 n 126 ~
|
||||
015 SI 031 US 047 / 063 ? 079 O 095 _ 111 o 127 DEL
|
||||
=!EXPECTEND!=
|
||||
*/
|
||||
6
Task/Show-ASCII-table/Julia/show-ascii-table-1.julia
Normal file
6
Task/Show-ASCII-table/Julia/show-ascii-table-1.julia
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
for i in 32:127
|
||||
c= i== 0 ? "NUL" : i== 7 ? "BEL" : i== 8 ? "BKS" : i== 9 ? "TAB" :
|
||||
i==10 ? "LF " : i==13 ? "CR " : i==27 ? "ESC" : i==155 ? "CSI" : "|$(Char(i))|"
|
||||
print("$(lpad(i,3)) $(string(i,base=16,pad=2)) $c")
|
||||
(i&7)==7 ? println() : print(" ")
|
||||
end
|
||||
6
Task/Show-ASCII-table/Julia/show-ascii-table-2.julia
Normal file
6
Task/Show-ASCII-table/Julia/show-ascii-table-2.julia
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
for i in 0:255
|
||||
c= i== 0 ? "NUL" : i== 7 ? "BEL" : i== 8 ? "BKS" : i== 9 ? "TAB" :
|
||||
i==10 ? "LF " : i==13 ? "CR " : i==27 ? "ESC" : i==155 ? "CSI" : "|$(Char(i))|"
|
||||
print("$(lpad(i,3)) $(string(i,base=16,pad=2)) $c")
|
||||
(i&7)==7 ? println() : print(" ")
|
||||
end
|
||||
25
Task/Show-ASCII-table/Julia/show-ascii-table-3.julia
Normal file
25
Task/Show-ASCII-table/Julia/show-ascii-table-3.julia
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
print("\e[2J") # clear screen
|
||||
print("""
|
||||
0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
╔═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╗
|
||||
║nul│soh│stx│etx│eot│enq│ack│bel│ bs│tab│ lf│ vt│ ff│ cr│ so│ si║
|
||||
""") # indent is set by this (least indented) line
|
||||
for i = 0:14
|
||||
a = string(i,base=16)
|
||||
println( "$a ║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║ $a")
|
||||
println( " ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢")
|
||||
println(i==0 ? " ║dle│dc1│dc2│dc3│dc4│nak│syn│etb│can│ em│eof│esc│ fs│ gs│ rs│ us║"
|
||||
: " ║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║")
|
||||
end
|
||||
println("""
|
||||
f ║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║ f
|
||||
╚═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╝
|
||||
0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
""") # """ string is indented here
|
||||
for i = 1:255
|
||||
r,c = divrem(i,16)
|
||||
r,c = 3r+4,4c+5
|
||||
i > 31 && print("\e[$(r-1);$(c-1)H$(lpad(i,3))")
|
||||
6<i<11 || i==155 || i==173 || print("\e[$r;$(c)H$(Char(i))")
|
||||
end
|
||||
print("\e[54;1H")
|
||||
48
Task/Show-ASCII-table/Julia/show-ascii-table-4.julia
Normal file
48
Task/Show-ASCII-table/Julia/show-ascii-table-4.julia
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#= CONSOLE TABLES =============================================================
|
||||
rn: nrows, rh: height of rows
|
||||
cn: ncols, cw: width of columns
|
||||
T[rn,cn,rh] table data strings
|
||||
cr: rows in colum headers
|
||||
CH[cn,cr] column header strings of max cw length
|
||||
hl: lengths of row header strings
|
||||
RH[rn,rh] row header strings of max length hl
|
||||
==============================================================================#
|
||||
|
||||
struct Table
|
||||
rn::Int; rh::Int; cn::Int; cw::Int; T::Array{String,3}
|
||||
cr::Int; CH::Array{String,2}
|
||||
hl::Int; RH::Array{String,2}
|
||||
function Table(rn,rh,cn,cw,cr,hl) # constructor
|
||||
new(rn,rh,cn,cw,fill("",(rn,cn,rh)), # arrays initialized with empty strings
|
||||
cr,fill("",(cr,cn)), hl,fill("",(rn,rh)))
|
||||
end
|
||||
end
|
||||
Base.iterate(T::Table,i=1) = i<=nfields(T) ? (getfield(T,i),i+1) : nothing
|
||||
|
||||
cpad(s::String,n::Integer) = (m=length(s))<n ? lpad(rpad(s,(n+m)>>1),n) : first(s,n)
|
||||
|
||||
function prt((rn,rh,cn,cw,T, cr,CH, hl,RH)::Table)
|
||||
TL,TX,TR,BH = '╔','╤','╗','═'
|
||||
IL,IX,IR,IV,IH='╟','┼','╢','│','─'
|
||||
BL,BX,BR,BV = '╚','╧','╝','║'
|
||||
|
||||
u,v,w,d,t = BH^cw, IH^cw, " "^hl, cn-2, " "^hl
|
||||
b = w*(cn==1 ? IL*v*IR : IL*v*(IX*v)^d*IX*v*IR)*'\n' # internal separator
|
||||
for r = 1:cr
|
||||
for c = 1:cn t*=cpad(CH[r,c],cw+1) end
|
||||
t *= "\n$w"
|
||||
end
|
||||
|
||||
t *= (cn==1 ? TL*u*TR : TL*u*(TX*u)^d*TX*u*TR)*'\n' # top border
|
||||
for r = 1:rn
|
||||
for p = 1:rh
|
||||
s = cpad(RH[r,p],hl)*BV
|
||||
for c = 1:cn-1
|
||||
s *= cpad(T[r,c,p],cw) * IV
|
||||
end
|
||||
t*= s * cpad(T[r,cn,p],cw) * BV *'\n'
|
||||
end
|
||||
t*=r<rn ? b : cn<2 ? w*BL*u*BR : w*BL*u*(BX*u)^d*BX*u*BR # bottom border
|
||||
end
|
||||
println("\n$t\n")
|
||||
end
|
||||
7
Task/Show-ASCII-table/Julia/show-ascii-table-5.julia
Normal file
7
Task/Show-ASCII-table/Julia/show-ascii-table-5.julia
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Tbl = Table(16,2,16,3, 2,3) # construct table
|
||||
Tbl.CH[1,:] = string.(0:15,base=16) # Column headers
|
||||
Tbl.RH[:,2] = string.(0:15,base=16) # Row headers
|
||||
for i = 0:255 # populate table, exclude special characters
|
||||
Tbl.T[i>>4+1,i&15+1,1:2]=["$i",i∈(0,7,8,9,10,13,27,155) ? "" : "$(Char(i))"]
|
||||
end
|
||||
prt(Tbl) # format and print table on console
|
||||
17
Task/Show-ASCII-table/K/show-ascii-table.k
Normal file
17
Task/Show-ASCII-table/K/show-ascii-table.k
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
`0:"\n"/" "/'+6 16#{-6$($x),-2$`c$x}'32+!96
|
||||
32 48 0 64 @ 80 P 96 ` 112 p
|
||||
33 ! 49 1 65 A 81 Q 97 a 113 q
|
||||
34 " 50 2 66 B 82 R 98 b 114 r
|
||||
35 # 51 3 67 C 83 S 99 c 115 s
|
||||
36 $ 52 4 68 D 84 T 100 d 116 t
|
||||
37 % 53 5 69 E 85 U 101 e 117 u
|
||||
38 & 54 6 70 F 86 V 102 f 118 v
|
||||
39 ' 55 7 71 G 87 W 103 g 119 w
|
||||
40 ( 56 8 72 H 88 X 104 h 120 x
|
||||
41 ) 57 9 73 I 89 Y 105 i 121 y
|
||||
42 * 58 : 74 J 90 Z 106 j 122 z
|
||||
43 + 59 ; 75 K 91 [ 107 k 123 {
|
||||
44 , 60 < 76 L 92 \ 108 l 124 |
|
||||
45 - 61 = 77 M 93 ] 109 m 125 }
|
||||
46 . 62 > 78 N 94 ^ 110 n 126 ~
|
||||
47 / 63 ? 79 O 95 _ 111 o 127
|
||||
15
Task/Show-ASCII-table/Kotlin/show-ascii-table.kotlin
Normal file
15
Task/Show-ASCII-table/Kotlin/show-ascii-table.kotlin
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Version 1.2.60
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
for (i in 0..15) {
|
||||
for (j in 32 + i..127 step 16) {
|
||||
val k = when (j) {
|
||||
32 -> "Spc"
|
||||
127 -> "Del"
|
||||
else -> j.toChar().toString()
|
||||
}
|
||||
System.out.printf("%3d : %-3s ", j, k)
|
||||
}
|
||||
println()
|
||||
}
|
||||
}
|
||||
35
Task/Show-ASCII-table/Lambdatalk/show-ascii-table.lambdatalk
Normal file
35
Task/Show-ASCII-table/Lambdatalk/show-ascii-table.lambdatalk
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{def format
|
||||
{lambda {:i :c}
|
||||
{if {< :i 100}
|
||||
then {span {@ style="color:white;"}.}:i : :c
|
||||
else :i : :c}}}
|
||||
-> format
|
||||
|
||||
{S.map
|
||||
{lambda {:i}
|
||||
{div}
|
||||
{S.map {lambda {:i}
|
||||
{if {= :i 32} then {format :i {span {@ style="color:#fff;"}.}}
|
||||
else {if {= :i 123} then {format :i left brace}
|
||||
else {if {= :i 125} then {format :i right brace}
|
||||
else {if {= :i 127} then {format :i del}
|
||||
else {format :i {code2char :i}}}}}}}
|
||||
{S.serie {+ 32 :i} 127 16}}}
|
||||
{S.serie 0 15}}
|
||||
|
||||
32 : 48 : 0 64 : @ 80 : P 96 : ` 112 : p
|
||||
33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q
|
||||
34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r
|
||||
35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s
|
||||
36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t
|
||||
37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u
|
||||
38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v
|
||||
39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w
|
||||
40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x
|
||||
41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y
|
||||
42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z
|
||||
43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : left brace
|
||||
44 : , 60 : < 76 : L 92 : \ 108 : l 124 : |
|
||||
45 : - 61 : = 77 : M 93 : ] 109 : m 125 : right brace
|
||||
46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~
|
||||
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : del
|
||||
19
Task/Show-ASCII-table/Lang/show-ascii-table.lang
Normal file
19
Task/Show-ASCII-table/Lang/show-ascii-table.lang
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
$i
|
||||
repeat($[i], 16) {
|
||||
$j $= $i + 32
|
||||
|
||||
while($j < 128) {
|
||||
if($j == 32) {
|
||||
$val = SPC
|
||||
}elif($j == 127) {
|
||||
$val = DEL
|
||||
}else {
|
||||
$val = fn.char($j)
|
||||
}
|
||||
fn.printf(%4d : %-3s, $j, $val)
|
||||
|
||||
$j += 16
|
||||
}
|
||||
|
||||
fn.println()
|
||||
}
|
||||
7
Task/Show-ASCII-table/Langur/show-ascii-table.langur
Normal file
7
Task/Show-ASCII-table/Langur/show-ascii-table.langur
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
for .i of 16 {
|
||||
for .j = 31 + .i ; .j < 128 ; .j += 16 {
|
||||
val .L = given(.j; 32: "spc"; 127: "del"; cp2s .j)
|
||||
write $"\.j:3; : \.L:-4;"
|
||||
}
|
||||
writeln()
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
10 mode 1:defint a-z
|
||||
20 for x=1 to 6
|
||||
30 for y=1 to 16
|
||||
40 n=16*(x-1)+y+31
|
||||
50 locate 6*(x-1)+1,y
|
||||
60 print using "###";n;
|
||||
70 print " ";chr$(n);
|
||||
80 next
|
||||
90 next
|
||||
16
Task/Show-ASCII-table/Lua/show-ascii-table.lua
Normal file
16
Task/Show-ASCII-table/Lua/show-ascii-table.lua
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
-- map of character values to desired representation
|
||||
local chars = setmetatable({[32] = "Spc", [127] = "Del"}, {__index = function(_, k) return string.char(k) end})
|
||||
|
||||
-- row iterator
|
||||
local function iter(s,a)
|
||||
a = (a or s) + 16
|
||||
if a <= 127 then return a, chars[a] end
|
||||
end
|
||||
|
||||
-- print loop
|
||||
for i = 0, 15 do
|
||||
for j, repr in iter, i+16 do
|
||||
io.write(("%3d : %3s "):format(j, repr))
|
||||
end
|
||||
io.write"\n"
|
||||
end
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
Function ProduceAscii$ {
|
||||
Document Ascii$="\"
|
||||
DelUnicode$=ChrCode$(0x2421)
|
||||
j=0
|
||||
Print Ascii$;
|
||||
For i=0 to 15
|
||||
Print Hex$(i, .5);
|
||||
Ascii$=Hex$(i, .5)
|
||||
Next
|
||||
For i=0 to 32
|
||||
If pos>16 then
|
||||
Ascii$={
|
||||
}+Hex$(j, .5)
|
||||
Print : Print Hex$(j, .5);: j++
|
||||
End if
|
||||
Print Chrcode$(i+0x2400);
|
||||
Ascii$=Chrcode$(i+0x2400)
|
||||
Next
|
||||
For i=33 to 126
|
||||
If pos>16 then
|
||||
Ascii$={
|
||||
}+Hex$(j, .5)
|
||||
Print : Print Hex$(j, .5);: j++
|
||||
End if
|
||||
Print Chr$(i);
|
||||
Ascii$=Chr$(i)
|
||||
Next
|
||||
Print DelUnicode$
|
||||
=Ascii$+DelUnicode$+{
|
||||
}
|
||||
}
|
||||
Clipboard ProduceAscii$()
|
||||
43
Task/Show-ASCII-table/MACRO-11/show-ascii-table.macro11
Normal file
43
Task/Show-ASCII-table/MACRO-11/show-ascii-table.macro11
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
.TITLE ASCTAB
|
||||
.MCALL .PRINT,.EXIT
|
||||
ASCTAB::MOV #40,R5
|
||||
MOV #20,R4
|
||||
1$: MOV #NBUF,R1
|
||||
MOV R5,R2
|
||||
2$: MOV #-1,R3
|
||||
3$: INC R3
|
||||
SUB #12,R2
|
||||
BCC 3$
|
||||
ADD #72,R2
|
||||
MOVB R2,-(R1)
|
||||
MOV R3,R2
|
||||
BNE 2$
|
||||
CMP R1,#NUM
|
||||
BEQ 4$
|
||||
MOVB #40,-(R1)
|
||||
4$: .PRINT #NUM
|
||||
CMP #40,R5
|
||||
BEQ 5$
|
||||
CMP #177,R5
|
||||
BEQ 6$
|
||||
MOVB R5,CHR
|
||||
.PRINT #CHR
|
||||
BR 7$
|
||||
5$: .PRINT #SPC
|
||||
BR 7$
|
||||
6$: .PRINT #DEL
|
||||
7$: ADD #20,R5
|
||||
CMP R5,#200
|
||||
BLT 1$
|
||||
SUB #137,R5
|
||||
.PRINT #NL
|
||||
DEC R4
|
||||
BNE 1$
|
||||
.EXIT
|
||||
NUM: .ASCII / /
|
||||
NBUF: .ASCII /: /<200>
|
||||
CHR: .ASCII /. /<200>
|
||||
SPC: .ASCII /SPC /<200>
|
||||
DEL: .ASCII /DEL /<200>
|
||||
NL: .ASCIZ //
|
||||
.END ASCTAB
|
||||
1
Task/Show-ASCII-table/Mathematica/show-ascii-table.math
Normal file
1
Task/Show-ASCII-table/Mathematica/show-ascii-table.math
Normal file
|
|
@ -0,0 +1 @@
|
|||
StringRiffle[StringJoin@@@Transpose[Partition[ToString[#]<>": "<>Switch[#,32,"Spc ",127,"Del ",_,FromCharacterCode[#]<>" "]&/@Range[32,127],16]],"\n"]
|
||||
34
Task/Show-ASCII-table/MiniScript/show-ascii-table.mini
Normal file
34
Task/Show-ASCII-table/MiniScript/show-ascii-table.mini
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// Prints ASCII table
|
||||
// Note changing the values of startChar and endChar will print
|
||||
// a flexible table in that range
|
||||
|
||||
startChar = 32
|
||||
endChar = 127
|
||||
characters = []
|
||||
|
||||
for i in range(startChar, endChar)
|
||||
addString = char(i) + " "
|
||||
if i == 32 then addString = "SPC"
|
||||
if i == 127 then addString = "DEL"
|
||||
characters.push addString
|
||||
end for
|
||||
|
||||
for i in characters.indexes
|
||||
iNum = i + startChar
|
||||
iChar = " " + str(iNum)
|
||||
characters[i] = iChar[-5:] + " : " + characters[i]
|
||||
end for
|
||||
|
||||
columns = 6
|
||||
line = ""
|
||||
col = 0
|
||||
for out in characters
|
||||
col = col + 1
|
||||
line = line + out
|
||||
if col == columns then
|
||||
print line
|
||||
line = ""
|
||||
col = 0
|
||||
end if
|
||||
end for
|
||||
if line then print line // final check for odd incomplete line output
|
||||
12
Task/Show-ASCII-table/Miranda/show-ascii-table.miranda
Normal file
12
Task/Show-ASCII-table/Miranda/show-ascii-table.miranda
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
main :: [sys_message]
|
||||
main = [Stdout table]
|
||||
|
||||
table :: [char]
|
||||
table = lay [concat [item n | n<-[row, (row+16)..127]] | row<-[32..47]]
|
||||
|
||||
item :: num->[char]
|
||||
item n = num ++ " : " ++ desc
|
||||
where num = reverse (take 3 (reverse (shownum n) ++ repeat ' '))
|
||||
desc = "Spc ", if n = 32
|
||||
= "Del ", if n = 127
|
||||
= decode n : " ", otherwise
|
||||
26
Task/Show-ASCII-table/Modula-2/show-ascii-table.mod2
Normal file
26
Task/Show-ASCII-table/Modula-2/show-ascii-table.mod2
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
MODULE AsciiTable;
|
||||
FROM InOut IMPORT Write, WriteCard, WriteString, WriteLn;
|
||||
|
||||
VAR row, col: CARDINAL;
|
||||
|
||||
PROCEDURE WriteItem(n: CARDINAL);
|
||||
BEGIN
|
||||
WriteCard(n, 3);
|
||||
WriteString(": ");
|
||||
CASE n OF
|
||||
32: WriteString("Spc ")
|
||||
| 127: WriteString("Del ")
|
||||
ELSE
|
||||
Write(CHR(n));
|
||||
WriteString(" ")
|
||||
END
|
||||
END WriteItem;
|
||||
|
||||
BEGIN
|
||||
FOR row := 32 TO 47 DO
|
||||
FOR col := row TO 127 BY 16 DO
|
||||
WriteItem(col)
|
||||
END;
|
||||
WriteLn
|
||||
END
|
||||
END AsciiTable.
|
||||
14
Task/Show-ASCII-table/Nanoquery/show-ascii-table.nanoquery
Normal file
14
Task/Show-ASCII-table/Nanoquery/show-ascii-table.nanoquery
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
k = ""
|
||||
for i in range(0, 15)
|
||||
for j in range(32 + i, 127, 16)
|
||||
if j = 32
|
||||
k = "Spc"
|
||||
else if j = 127
|
||||
k = "Del"
|
||||
else
|
||||
k = chr(j)
|
||||
end
|
||||
print format("%3d : %-3s ", j, k)
|
||||
end
|
||||
println
|
||||
end
|
||||
10
Task/Show-ASCII-table/Nim/show-ascii-table.nim
Normal file
10
Task/Show-ASCII-table/Nim/show-ascii-table.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import strformat
|
||||
|
||||
for i in 0..15:
|
||||
for j in countup(32 + i, 127, step = 16):
|
||||
let k = case j
|
||||
of 32: "Spc"
|
||||
of 127: "Del"
|
||||
else: $chr(j)
|
||||
write(stdout, fmt"{j:3d} : {k:<6s}")
|
||||
write(stdout, "\n")
|
||||
8
Task/Show-ASCII-table/OCaml/show-ascii-table.ocaml
Normal file
8
Task/Show-ASCII-table/OCaml/show-ascii-table.ocaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
let show_char i =
|
||||
Printf.printf "%5u: %s" i (match i with 32 -> "SPC" | 127 -> "DEL"
|
||||
| _ -> Printf.sprintf " %c " (char_of_int i))
|
||||
|
||||
let () =
|
||||
for i = 32 to 47 do
|
||||
for j = 0 to 5 do show_char (j lsl 4 + i) done |> print_newline
|
||||
done
|
||||
17
Task/Show-ASCII-table/Objeck/show-ascii-table.objeck
Normal file
17
Task/Show-ASCII-table/Objeck/show-ascii-table.objeck
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
class AsciiTable {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
for(i := 32; i <= 127 ; i += 1;) {
|
||||
if(i = 32 | i = 127) {
|
||||
s := i = 32 ? "Spc" : "Del";
|
||||
"{$i}:\t{$s}\t"->Print();
|
||||
}
|
||||
else {
|
||||
c := i->ToChar();
|
||||
"{$i}:\t{$c}\t"->Print();
|
||||
};
|
||||
if((i-1) % 6 = 0 ) {
|
||||
"\n"->Print();
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
17
Task/Show-ASCII-table/OxygenBasic/show-ascii-table.basic
Normal file
17
Task/Show-ASCII-table/OxygenBasic/show-ascii-table.basic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
uses console
|
||||
int i,j
|
||||
string c
|
||||
for i=32 to 127
|
||||
select case i
|
||||
case 32 : c="spc"
|
||||
case 127: c="del"
|
||||
case else c=chr i
|
||||
end select
|
||||
print i ": " c tab
|
||||
j++
|
||||
if j = 8 'columns
|
||||
print cr
|
||||
j=0
|
||||
endif
|
||||
next
|
||||
pause
|
||||
16
Task/Show-ASCII-table/PHP/show-ascii-table.php
Normal file
16
Task/Show-ASCII-table/PHP/show-ascii-table.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
echo '+' . str_repeat('----------+', 6), PHP_EOL;
|
||||
for ($j = 0 ; $j < 16 ; $j++) {
|
||||
for ($i = 0 ; $i < 6 ; $i++) {
|
||||
$val = 32 + $i * 16 + $j;
|
||||
switch ($val) {
|
||||
case 32: $chr = 'Spc'; break;
|
||||
case 127: $chr = 'Del'; break;
|
||||
default: $chr = chr($val) ; break;
|
||||
}
|
||||
echo sprintf('| %3d: %3s ', $val, $chr);
|
||||
}
|
||||
echo '|', PHP_EOL;
|
||||
}
|
||||
echo '+' . str_repeat('----------+', 6), PHP_EOL;
|
||||
32
Task/Show-ASCII-table/PL-M/show-ascii-table.plm
Normal file
32
Task/Show-ASCII-table/PL-M/show-ascii-table.plm
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
100H: /* SHOW AN ASCII TABLE FROM 32 TO 127 */
|
||||
/* CP/M BDOS SYSTEM CALL */
|
||||
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
|
||||
/* I/O ROUTINES */
|
||||
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END;
|
||||
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
|
||||
PR$BYTE: PROCEDURE( N );
|
||||
DECLARE N BYTE;
|
||||
DECLARE V BYTE;
|
||||
V = N MOD 100;
|
||||
CALL PR$CHAR( ' ' );
|
||||
CALL PR$CHAR( '0' + ( N / 100 ) );
|
||||
CALL PR$CHAR( '0' + ( V / 10 ) );
|
||||
CALL PR$CHAR( '0' + ( V MOD 10 ) );
|
||||
END PR$BYTE;
|
||||
/* ASCII TABLE */
|
||||
DECLARE ( A, C ) BYTE;
|
||||
DO C = 32 TO 32 + 15;
|
||||
DO A = C TO C + ( 16 * 5 ) BY 16;
|
||||
CALL PR$BYTE( A );
|
||||
CALL PR$STRING( .': $' );
|
||||
IF A = 32 THEN CALL PR$STRING( .'SPC$' );
|
||||
ELSE IF A = 127 THEN CALL PR$STRING( .'DEL$' );
|
||||
ELSE DO;
|
||||
CALL PR$CHAR( ' ' );
|
||||
CALL PR$CHAR( A );
|
||||
CALL PR$CHAR( ' ' );
|
||||
END;
|
||||
END;
|
||||
CALL PR$STRING( .( 0DH, 0AH, '$' ) );
|
||||
END;
|
||||
EOF
|
||||
20
Task/Show-ASCII-table/Perl/show-ascii-table.pl
Normal file
20
Task/Show-ASCII-table/Perl/show-ascii-table.pl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use charnames ':full';
|
||||
binmode STDOUT, ':utf8';
|
||||
|
||||
sub glyph {
|
||||
my($n) = @_;
|
||||
if ($n < 33) { chr 0x2400 + $n } # display symbol names for invisible glyphs
|
||||
elsif ($n==124) { '<nowiki>|</nowiki>' }
|
||||
elsif ($n==127) { 'DEL' }
|
||||
else { chr $n }
|
||||
}
|
||||
|
||||
print qq[{|class="wikitable" style="text-align:center;background-color:hsl(39, 90%, 95%)"\n];
|
||||
|
||||
for (0..127) {
|
||||
print qq[|-\n] unless $_ % 16;;
|
||||
printf qq[|%d<br>0x%02X<br><big><big title="%s">%s</big></big>\n],
|
||||
$_, $_, charnames::viacode($_), glyph($_);
|
||||
}
|
||||
}
|
||||
print qq[|}\n];
|
||||
9
Task/Show-ASCII-table/Phix/show-ascii-table.phix
Normal file
9
Task/Show-ASCII-table/Phix/show-ascii-table.phix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
|
||||
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">ascii</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #000000;">32</span> <span style="color: #008080;">to</span> <span style="color: #000000;">127</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #000000;">ascii</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ascii</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%4d (#%02x): %c "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ch</span><span style="color: #0000FF;">))</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ascii</span><span style="color: #0000FF;">,</span><span style="color: #000000;">16</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"\x7F"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"del"</span><span style="color: #0000FF;">))</span>
|
||||
<!--
|
||||
16
Task/Show-ASCII-table/Prolog/show-ascii-table.pro
Normal file
16
Task/Show-ASCII-table/Prolog/show-ascii-table.pro
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
ascii :-
|
||||
forall(between(32, 47, N), row(N)).
|
||||
|
||||
row(N) :- N > 127, nl, !.
|
||||
row(N) :-
|
||||
code(N),
|
||||
ascii(N),
|
||||
Nn is N + 16,
|
||||
row(Nn).
|
||||
|
||||
code(N) :- N < 100, format(' ~d : ', N).
|
||||
code(N) :- N >= 100, format(' ~d : ', N).
|
||||
|
||||
ascii(32) :- write(' Spc '), !.
|
||||
ascii(127) :- write(' Del '), !.
|
||||
ascii(A) :- char_code(D,A), format(' ~w ', D).
|
||||
19
Task/Show-ASCII-table/PureBasic/show-ascii-table.basic
Normal file
19
Task/Show-ASCII-table/PureBasic/show-ascii-table.basic
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
If OpenConsole("Show_Ascii_table: rosettacode.org")
|
||||
Define r.i, c.i
|
||||
For r=0 To 15
|
||||
For c=32+r To 112+r Step 16
|
||||
Print(RSet(Str(c),3)+" : ")
|
||||
Select c
|
||||
Case 32
|
||||
Print("Spc")
|
||||
Case 127
|
||||
Print("Del")
|
||||
Default
|
||||
Print(LSet(Chr(c),3))
|
||||
EndSelect
|
||||
Print(Space(3))
|
||||
Next
|
||||
PrintN("")
|
||||
Next
|
||||
Input()
|
||||
EndIf
|
||||
10
Task/Show-ASCII-table/Python/show-ascii-table-1.py
Normal file
10
Task/Show-ASCII-table/Python/show-ascii-table-1.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
for i in range(16):
|
||||
for j in range(32+i, 127+1, 16):
|
||||
if j == 32:
|
||||
k = 'Spc'
|
||||
elif j == 127:
|
||||
k = 'Del'
|
||||
else:
|
||||
k = chr(j)
|
||||
print("%3d : %-3s" % (j,k), end="")
|
||||
print()
|
||||
16
Task/Show-ASCII-table/Python/show-ascii-table-2.py
Normal file
16
Task/Show-ASCII-table/Python/show-ascii-table-2.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
from unicodedata import name
|
||||
from html import escape
|
||||
|
||||
def pp(n):
|
||||
if n <= 32:
|
||||
return chr(0x2400 + n)
|
||||
if n == 127:
|
||||
return '␡'
|
||||
return chr(n)
|
||||
|
||||
print('<table border="3px" style="background-color:LightCyan;text-align:center">\n <tr>')
|
||||
for n in range(128):
|
||||
if n %16 == 0 and 1 < n:
|
||||
print(" </tr><tr>")
|
||||
print(f' <td style="center">{n}<br>0x{n:02x}<br><big><b title="{escape(name(pp(n)))}">{escape(pp(n))}</b></big></td>')
|
||||
print(""" </tr>\n</table>""")
|
||||
108
Task/Show-ASCII-table/Python/show-ascii-table-3.py
Normal file
108
Task/Show-ASCII-table/Python/show-ascii-table-3.py
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
'''Plain text ASCII code table'''
|
||||
|
||||
from functools import reduce
|
||||
from itertools import chain
|
||||
|
||||
|
||||
# asciiTable :: String
|
||||
def asciiTable():
|
||||
'''Table of ASCII codes arranged in 16 rows * 6 columns.'''
|
||||
return unlines(
|
||||
concat(c.ljust(12, ' ') for c in xs) for xs in (
|
||||
transpose(chunksOf(16)(
|
||||
[asciiEntry(n) for n in enumFromTo(32)(127)]
|
||||
))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# asciiEntry :: Int -> String
|
||||
def asciiEntry(n):
|
||||
'''Number, and name or character, for given point in ASCII code.'''
|
||||
k = asciiName(n)
|
||||
return k if '' == k else (
|
||||
concat([str(n).rjust(3, ' '), ' : ', k])
|
||||
)
|
||||
|
||||
|
||||
# asciiName :: Int -> String
|
||||
def asciiName(n):
|
||||
'''Name or character for given ASCII code.'''
|
||||
return '' if 32 > n or 127 < n else (
|
||||
'Spc' if 32 == n else (
|
||||
'Del' if 127 == n else chr(n)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# TEST ----------------------------------------------------
|
||||
# main :: IO ()
|
||||
def main():
|
||||
'''Test'''
|
||||
print(
|
||||
asciiTable()
|
||||
)
|
||||
|
||||
|
||||
# GENERIC ABSTRACTIONS ------------------------------------
|
||||
|
||||
# chunksOf :: Int -> [a] -> [[a]]
|
||||
def chunksOf(n):
|
||||
'''A series of lists of length n,
|
||||
subdividing the contents of xs.
|
||||
Where the length of xs is not evenly divible
|
||||
the final list will be shorter than n.'''
|
||||
return lambda xs: reduce(
|
||||
lambda a, i: a + [xs[i:n + i]],
|
||||
range(0, len(xs), n), []
|
||||
) if 0 < n else []
|
||||
|
||||
|
||||
# concat :: [[a]] -> [a]
|
||||
# concat :: [String] -> String
|
||||
def concat(xxs):
|
||||
'''The concatenation of all the elements in a list.'''
|
||||
xs = list(chain.from_iterable(xxs))
|
||||
unit = '' if isinstance(xs, str) else []
|
||||
return unit if not xs else (
|
||||
''.join(xs) if isinstance(xs[0], str) else xs
|
||||
)
|
||||
|
||||
|
||||
# enumFromTo :: (Int, Int) -> [Int]
|
||||
def enumFromTo(m):
|
||||
'''Integer enumeration from m to n.'''
|
||||
return lambda n: list(range(m, 1 + n))
|
||||
|
||||
|
||||
# splitAt :: Int -> [a] -> ([a], [a])
|
||||
def splitAt(n):
|
||||
'''A tuple pairing the prefix of length n
|
||||
with the rest of xs.'''
|
||||
return lambda xs: (xs[0:n], xs[n:])
|
||||
|
||||
|
||||
# transpose :: Matrix a -> Matrix a
|
||||
def transpose(m):
|
||||
'''The rows and columns of the argument transposed.
|
||||
(The matrix containers and rows can be lists or tuples).'''
|
||||
if m:
|
||||
inner = type(m[0])
|
||||
z = zip(*m)
|
||||
return (type(m))(
|
||||
map(inner, z) if tuple != inner else z
|
||||
)
|
||||
else:
|
||||
return m
|
||||
|
||||
|
||||
# unlines :: [String] -> String
|
||||
def unlines(xs):
|
||||
'''A single newline-delimited string derived
|
||||
from a list of strings.'''
|
||||
return '\n'.join(xs)
|
||||
|
||||
|
||||
# MAIN ---
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
16
Task/Show-ASCII-table/Python/show-ascii-table-4.py
Normal file
16
Task/Show-ASCII-table/Python/show-ascii-table-4.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# One-liner
|
||||
# print('\n'.join([''.join(["%3d : %-3s" % (a, 'Spc' if a == 32 else 'Del' if a == 127 else chr(a)) for a in lst]) for lst in [[i+c*16 for c in range(6)] for i in range(32, 47+1)]])
|
||||
|
||||
## Detailed version
|
||||
|
||||
# List of 16 lists of integers corresponding to
|
||||
# each row of the table
|
||||
rows_as_ints = [[i+c*16 for c in range(6)] for i in range(32, 47+1)]
|
||||
|
||||
# Function for converting numeric value to string
|
||||
codepoint2str = lambda codepoint: 'Spc' if codepoint == 32 else 'Del' if codepoint == 127 else chr(codepoint)
|
||||
|
||||
rows_as_strings = [["%3d : %-3s" % (a, codepoint2str(a)) for a in row] for row in rows_as_ints]
|
||||
|
||||
# Joining columns into rows and printing rows one in a separate line
|
||||
print('\n'.join([''.join(row) for row in rows_as_strings]))
|
||||
16
Task/Show-ASCII-table/QB64/show-ascii-table.qb64
Normal file
16
Task/Show-ASCII-table/QB64/show-ascii-table.qb64
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
DIM s AS STRING
|
||||
|
||||
FOR i% = 32 TO 47
|
||||
FOR j% = i% TO i% + 80 STEP 16
|
||||
SELECT CASE j%
|
||||
CASE 32
|
||||
s$ = "Spc"
|
||||
CASE 127
|
||||
s$ = "Del"
|
||||
CASE ELSE
|
||||
s$ = CHR$(j%)
|
||||
END SELECT
|
||||
PRINT USING "###: \ \"; j%; s$;
|
||||
NEXT j%
|
||||
PRINT
|
||||
NEXT i%
|
||||
17
Task/Show-ASCII-table/Quackery/show-ascii-table.quackery
Normal file
17
Task/Show-ASCII-table/Quackery/show-ascii-table.quackery
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
[ dup 32 = iff
|
||||
[ drop say 'spc' ] done
|
||||
dup 127 = iff
|
||||
[ drop say 'del' ] done
|
||||
emit sp sp ] is echoascii ( n --> )
|
||||
|
||||
[ dup echo say ': '
|
||||
dup echoascii
|
||||
84 < 3 + times sp ] is echoelt ( n --> )
|
||||
|
||||
[ sp 81 times
|
||||
[ dup i^ + echoelt 16 step ]
|
||||
drop cr ] is echorow ( n --> )
|
||||
|
||||
[ 16 times [ i^ 32 + echorow ] ] is echotable ( --> )
|
||||
|
||||
echotable
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue