fork(2) download
  1. # http://c...content-available-to-author-only...e.com/a/94351/34718
  2.  
  3. def f(s):
  4. s="\0%s\0"%s
  5. r=''
  6. for i in range(1,len(s)-1):
  7. if i%2: # even (parity is changed by adding \x00 to the front)
  8. a=ord(s[i-1]) | ord(s[i+1])
  9. else: # odd
  10. a=ord(s[i])
  11. if a%2: # odd
  12. a|=ord(s[i-1])
  13. else: # even
  14. a|=ord(s[i+1])
  15. r+=chr(a if a<127 else 32)
  16. print r
  17.  
  18. f("hello")
  19. f("Hello, World!")
  20. f("PPCG")
  21. f("Programming Puzzles and Code Golf")
  22. f("abcdefghijklmnopqrstuvwxyz")
  23. f("!abcdefghijklmnopqrstuvwxyz")
  24. f("Test 123 with odd characters. R@*SKA0z8d862")
Success #stdin #stdout 0.01s 9024KB
stdin
Standard input is empty
stdout
emmol
emmol, ww~ved
PSWG
r wogsmmoonpuu ~ meannncoooeggonl
bcfefgnijknmno~qrsvuvw~yzz
aaccgeggoikkomoo qsswuww yy
euutu133www|todddchizsscguwssr`jS{SK{z~|v66