| Bytes | Lang | Time | Link |
|---|---|---|---|
| 107 | QBasic | 180629T181814Z | Taylor R |
| nan | JavaScript ES6 + HTML | 170802T225246Z | Justin M |
| 096 | Python 2 | 170803T093318Z | lynn |
| 5247 | 65c02 machine code + Apple //e ROM | 170803T082708Z | insert_n |
| 132 | Python 2 | 170802T182226Z | musicman |
| 253 | C++ Visual C++ | 170803T000420Z | Rob Gate |
| 212 | Node.js 233 | 170802T224131Z | Jared Sm |
| 062 | x8616 Machine Code | 170802T181929Z | user7234 |
| 116 | Python 3 | 170802T195754Z | C McAvoy |
| nan | C# .NET Core | 170802T184854Z | jkelm |
| 023 | SOGL V0.12 | 170802T175621Z | dzaima |
QBasic, 107 bytes
An anonymous function that takes as keystrokes, and erases an ASCII table
FOR x=32TO 126
L x
?CHR$(x)
NEXT
DO
L ASC(Input$(1))
?" "'<- `"` included for highlighting only
LOOP
SUB L(x)
LOCATE x\16-1,2*(x MOD 16)+1
END SUB
-8 bytes thanks to @DLosc
JavaScript (ES6) + HTML, 139 136 116 + 10 16 = 132 bytes
-3 bytes thanks to @Shaggy.
-14 bytes inspired by @Arnauld.
for(i=32;i<127;)O[h="innerText"]+=String.fromCharCode(i++)+(i%16?" ":`
`);onkeypress=e=>O[h]=O[h].replace(e.key," ")
<pre id=O></pre>
Closing pre tag is required in this case, since we need the innerText value to start totally empty.
Python 2, 96 bytes
from textwrap import*
a=fill(str(bytearray(range(32,127))),16)
while 1:a=a.replace(input(a),' ')
Try it online! Output looks iffy on TIO (because input is passed from a file), but it’s fine interactively. I hope 'A'\n, 'B'\n etc is an okay input format.
65c02 machine code + Apple //e ROM, 52 (47?) bytes
Hex dump:
8000- 20 58 FC A9 A0 20 20 80
8008- 20 ED FD 1A C9 FF D0 F5
8010- AD 00 C0 10 FB 8D 10 C0
8018- 20 20 80 20 57 DB 80 F0
8020- 48 38 E9 A0 48 29 0F 0A
8028- 85 24 68 4A 4A 4A 4A 20
8030- 5B FB 68 60
Commented assembly:
1 HTAB = $24 ; HORIZONTAL POSITION OF CURSOR
2 SETVTAB = $FB5B ; SETS VERTICAL POSITION OF CURSOR FROM ACC
3 COUT = $FDED ; OUTPUTS CHARACTER IN ACC
4 HOME = $FC58 ; CLEARS SCREEN
5 OUTSP = $DB57 ; APPLESOFT ROUTINE THAT OUTPUTS A SPACE
6 KBD = $C000 ; KEY LAST PRESSED
7 KBSTROBE = $C010 ; ACCESS TO RESET "NEW KEY PRESSED" INDICATOR
8 ORG $8000
9 JSR HOME
10 * PRINT INITIAL CHARACTER MAP
11 LDA #" "
12 LOOP JSR CHARPOS
13 JSR COUT
14 INC ; INCREMENT ACCUMULATOR
15 CMP #"~"+1
16 BNE LOOP
17 * WAIT FOR KEYPRESS
18 GETCH LDA KBD ; GET LAST KEY PRESSED
19 BPL GETCH ; READ AGAIN IF KEYPRESS IS NOT NEW
20 STA KBSTROBE ; RESET "NEW KEYPRESS" INDICATOR
21 JSR CHARPOS
22 JSR OUTSP
23 BRA GETCH
24 * SUBROUTINE TO POSITION CURSOR TO PRINT OVER CHARACTER IN ACCUMULATOR
25 CHARPOS PHA ; PRESERVE ACC
26 SEC ; MAKE SURE CARRY IS SET TO SUBTRACT
27 SBC #" " ; SUBTRACT CHAR CODE OF SPACE
28 PHA ; SAVE ACC
29 AND #$0F ; GET LOWER 4 BITS TO GET CURSOR X POSITION
30 ASL ; SHIFT LEFT TO MAKE SPACES BETWEEN CHARS
31 STA HTAB
32 PLA ; GET OLD ACC
33 LSR ; SHIFT HIGH NIBBLE
34 LSR ; INTO LOW NIBBLE
35 LSR ; TO GET CURSOR Y POSITION
36 LSR
37 JSR SETVTAB
38 PLA ; RESTORE ACC
39 RTS
This has no cursor whatsoever. I also have a 47 byte version which might be valid, depending on what is meant by "put the cursor out of the way, so the text won't get in the way of the map":
8000- 20 58 FC A9 A0 20 1B 80
8008- 20 ED FD 1A C9 FF D0 F5
8010- 20 0C FD 20 1B 80 20 57
8018- DB 80 F5 48 38 E9 A0 48
8020- 29 0F 0A 85 24 68 4A 4A
8028- 4A 4A 20 5B FB 68 60
This puts a cursor at the character after the character you type (which is the space between characters), so it won't overwrite any of the actual characters in the map. Whether this is valid or not is up to the creator of the challenge.
Python 2, 132 bytes
Saved 4 bytes thanks to @alleks!
s=''
for i in range(32,128,16):s+=' '.join(map(chr,range(i,i+16)))+'\n'
while 1:print s[:-2];i=2*ord(input())-64;s=s[:i]+' '+s[i+1:]
C++ (Visual C++), 253 (@Step Hen) 261 bytes
#include<cstdlib>
#include<iostream>
#include<conio.h>
int main(){char a[0x5E];for(int i=0;i<0x5E;i++)a[i]=(char)(i+0x20);while(true){system("cls");for(int i=0;i<0x5E;i++)if(i&&!(i%16))printf("\n%c ",a[i]);else printf("%c ",a[i]);a[_getch()-0x20]=' ';}}
Node.js 233 212 bytes
Saved 21 bytes thanks to @thePirateBay
This works, I'm still trying to find an online option as all the repls I've found hijack stdin.
a=[];l=_=>console.log(a.join``);for(i=32;i<127;i++)(x=String.fromCharCode(i)),a.push(i%16?x:x+'\n');l();b=require('readline');b.createInterface(process.stdin).on('line',c=>(a=a.join``.replace(c,' ').split``),l())
x86-16 Machine Code, 62 bytes
Hex dump:
BC0100B101B07EBAFE0581EAE00080EA02B402CD1085E4750830E439C5750A30C0B40ACD1084C074094884D275E085D275D831C031E4CD1630E489C5EBC7
Assembly:
mov sp, 0x0001 ; Stack pointer is used as a flag; 0 - Print all characters, 1 - Delete specific character
mov cl, 0x01 ; Number of characters to print per interrupt call
printString:
mov al, 0x7E ; Last character to print
mov dx, 0x05FE ; Row: 0x05, Collumn: 0xFE
printRow:
sub dx, 0x00E0 ; Decrement row number + 2 extra characters
printChar:
sub dl, 0x02 ; Decrement collumn index + 1 space
mov ah, 0x02 ; Prepare for interrupt call, 0x02 - Set cursor position
int 0x10 ; BIOS interrupt
test sp, sp ; Are we printing all characters or removing specific character
jnz print ; In first case just print it and go on
xor ah, ah ; Otherwise reset the upper byte of ax (shorter than "and ax, 0x00FF")
cmp bp, ax ; Is the current character same as the input character
jne after ; If no, continue searching
xor al, al ; If yes, remove it
print:
mov ah, 0x0A ; Prepare for print
int 0x10 ; Print
test al, al ; If we found target character
jz loop ; then stop searching
after:
dec ax ; Shorter than "dec, al"
test dl, dl ; Is it the last character in the row
jnz printChar ; If no, continue searching
test dx, dx ; Is it last char
jnz printRow ; If no, go to next row
loop:
xor ax, ax ; Remove "ah" cache
xor sp, sp ; Reset sp (it will never become 1 again)
int 0x16 ; BIOS interrupt for reading keyboard input
xor ah, ah ; Again reset "ah", because BIOS may change it
mov bp, ax ; Save it in stack base pointer
jmp printString ; Remove the character from the list
Python 3, 116 bytes
o='\n'.join(''.join(map(chr,range(i,16+i)))for i in range(32,124,16))[:-1]
while 1:print(o);o=o.replace(input()," ")
C# (.NET Core), (138 + using System;) 151 bytes
()=>{var j="";for(int i=32;i<127;i++){if(i%16<1)j+='\n';j+=(char)i+" ";}while(1>0){Console.Write(j);j=j.Replace(Console.ReadLine()," ");}}
SOGL V0.12, 23 bytes
] ~Δ8«n"5αx2⁰³⁄¹‘→č@ŗ░T
Takes input in the input box. I hope that it isn't too big of an issue that characters can be deleted :p
Explanation:
] do.. while (popping (which makes the stack not blow up luckily :D))
~Δ push the ascii characters (range("~"))
8«n split into lines of length 16
"...‘ push "inputs.value" (could be 2 bytes less if my dictionary contained the word "inputs". I even added "input", but only now realise that the input box is id=inputs :/)
→ evaluate as JavaScript, then push the result
č chop into characters
@ŗ replace each of the characters in the array with space
░ clear the output
T output without popping (so do..while continues looping)
