Definiremo il cifrario pari / dispari ASCII tramite lo pseudocodice seguente:
Define 'neighbor' as the characters adjacent to the current letter in the string
If the one of the neighbors is out of bounds of the string, treat it as \0 or null
Take an input string
For each letter in the string, do
If the 0-based index of the current letter is even, then
Use the binary-or of the ASCII codes of both its neighbors
Else
If the ASCII code of the current letter is odd, then
Use the binary-or of itself plus the left neighbor
Else
Use the binary-or of itself plus the right neighbor
In all cases,
Convert the result back to ASCII and return it
If this would result in a code point 127 or greater to be converted, then
Instead return a space
Join the results of the For loop back into one string and output it
Ad esempio, per l'input Hello, l'output è emmol, poiché
- I
Hgiri a\0 | 'e'cui èe - Il
eturno diventa'e' | 'l', o101 | 108, che è109om - Il primo
lsi trasforma anche in101 | 108om - Il secondo
lsi trasforma in108 | 111, che è111oo - Il
oturno a108 | \0, ol
Ingresso
- Una frase composta esclusivamente da caratteri ASCII stampabili, in qualsiasi formato adatto .
- La frase può contenere punti, spazi e altri segni di punteggiatura, ma sarà sempre e solo una riga.
- La frase avrà una lunghezza di almeno tre caratteri.
Produzione
- La cifra risultante, basata sulle regole sopra descritte, restituita come stringa o output.
Le regole
- È accettabile un programma completo o una funzione.
- Sono vietate le scappatoie standard .
- Si tratta di code-golf, quindi si applicano tutte le normali regole del golf e vince il codice più breve (in byte).
Esempi
Input su una riga, output su quanto segue. Le righe vuote separano esempi.
Hello
emmol
Hello, World!
emmol, ww~ved
PPCG
PSWG
Programming Puzzles and Code Golf
r wogsmmoonpuu ~ meannncoooeggonl
abcdefghijklmnopqrstuvwxyz
bcfefgnijknmno~qrsvuvw~yzz
!abcdefghijklmnopqrstuvwxyz
aaccgeggoikkomoo qsswuww yy
Test 123 with odd characters. R@*SKA0z8d862
euutu133www|todddchizsscguwssr`jS{SK{z~|v66
omodifiche a lnel primo esempio, sono abbastanza sicuro che le tue specifiche assicurino che il primo onon cambi lnel secondo esempio. Dovrebbe cambiare 'l' | ',', qualunque cosa sia, giusto?
'l' | ',', che è 108 | 44 --> 1101111 | 0101100, che diventa 108, che è l. Il ,accade per allinearsi con la l, quindi non c'è alcun cambiamento quando il binario o avviene.