KeyF

From Esolang
Jump to navigation Jump to search

KeyF is an esolang invented by User:None1.

Execution

KeyF uses a simplified version of computer keyboard:

1 2 3 4 5 6 7 8 9 0
Q W E R T Y U I O P
 A S D F G H J K L
  Z X C V B N M
    _________

(_________ is the space bar)

There is a pointer that starts at F.

Commands

< Move pointer to leftmost key above and adjacent to current key. for example, F -> R, if there's no such key, do nothing
> Move pointer to rightmost key above and adjacent to current key. for example, F -> T, if there's no such key, do nothing
v Move pointer to the rightmost key under the current key. for example, F -> V, if there's no such key, do nothing
^ Move pointer to the leftmost key under the current key. for example, F -> C, if there's no such key, do nothing
. Press the key
, Press the key and shift simutaneously
! Press caps lock
? Press enter

BORING, so let's add some restrictions, the pointer must stop at K in the end, and should reach U first then C before the end.

To say it more simply, fuck must be a subsquence of all the keys the pointer reached.

Examples

Print FUCK

!.>v>v>.^^<^<^.>>v>v>v>v.

Print HI

!>v>v.>v>.^<^^<^<^>>v>v>v>v

Print line feed

?>v>v>^^<^<^>>v>v>v>v

Hello World!

>v>v,<^<^<^<.v>v>v>v>v>v>v..<.^^<^^.<<<,v>v>v>v>v>v>v>.^<^<^<^<^<.v>v>v>v>v>v.<^<^<^<^<^<^.<^<^<<,vvv>v>v>v>v>v>v>

Yes, I spent 16 minutes writing it.

Interpreters

Python

The esolang is simple, yet making an interpreter is hard.

import re
keys={'0': '  pp',
 '1': '  qq',
 '2': '  ww',
 '3': '  ee',
 '4': '  rr',
 '5': '  tt',
 '6': '  yy',
 '7': '  uu',
 '8': '  ii',
 '9': '  oo',
 '_': 'xn  ',
 'a': 'qwzz',
 'b': 'gh__',
 'c': 'df__',
 'd': 'erxc',
 'e': '33sd',
 'f': 'rtcv',
 'g': 'tyvb',
 'h': 'yubn',
 'i': '88jk',
 'j': 'uinm',
 'k': 'iomm',
 'l': 'op  ',
 'm': 'jk  ',
 'n': 'hj__',
 'o': '99kl',
 'p': '00ll',
 'q': '11aa',
 'r': '44df',
 's': 'wezx',
 't': '55fg',
 'u': '77hj',
 'v': 'fg__',
 'w': '22as',
 'x': 'sd__',
 'y': '66gh',
 'z': 'as  '} # Keys in a keyboard
code=input()
shiftkeys=')!@#$%^&*('
k='f'
reached_keys='f'
output=''
caps=False
def printkey(x,shift):
    if x.isalpha():
        return (x.upper() if (shift!=caps) else x.lower())
    if x=='_':
        return ' '
    return (shiftkeys[int(x)] if shift else x)
for i in code:
    if i in '<>^v':
        temp_k=keys[k]['<>^v'.index(i)]
        if temp_k!=' ':
            k=temp_k
            reached_keys+=k
    else:
        if i=='.':
            output+=printkey(k,False)
        if i==',':
            output+=printkey(k,True)
        if i=='!':
            caps=(not caps)
        if i=='?':
            output+='\n'
if not re.search('u(.*)c',reached_keys) or k!='k':
    raise Exception('Invalid program')
print(output)