We've already seen too many threads about fizzbuzz. Let's see if /g/ is able to come up with the code to implement the Atbash cipher:
>Atbash is a mono-alphabetic substitution cipher originally used to encode the Hebrew alphabet.
>It works by substituting the first letter of an alphabet for the last letter, the second letter for the second to last and so on, effectively reversing the alphabet.
You can use any programming language you want. You have 10 minutes.
alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p", "q","r","s","t","u","v","w","x","y","z"]
word = input("Enter a word: ")
new_word = []
for letter in word:
if letter.lower() in alphabet:
old_letter = letter.lower()
position = alphabet.index(old_letter)
new_letter = alphabet[(25 - position)]
new_word.append(new_letter)
else:
new_word.append(letter)
new = "".join(new_word)
print(new)
>>59643518
Is this bait?
In Ruby it's:"atbash this cool string".reverse
And if you want to make it more elaborated, you can do this:def atbash me
puts me.chars.map {|i| (i >= 'a' && i <= 'z') ? (219 - i.ord).chr : i}.join
end
atbash "abc xyz"
Am I hired?
>>59644215
The second solution is correct.
The first one is not because it reverses the string itself, it doesn't reverse the alphabet
>>59643518
>whoiteboard questions
>2017
yeah we don't need your racist, misogynistic trumpet stuff here thank you very much
>>59644286
Oh I see, so "ab" becomes "zy", not "ba"..
>>59643725
>Having to type out the alphabet
Ew, no thanks. Surely it'd be easier to use the < and > comparison operators.
Also, I'm pretty sure Python lets you append strings, what's this jiggery-fuckery with appending an array just to turn it into a string?
>>59644515
I'm a 4th year CS student and i think i did pretty good
def atbash(word):
a, z = ord('a'), ord('z')
return ''.join([chr(z-ord(l)+a) for l in word.lower()])
Lowercase only, but you get the idea.
Here's my idea. It's only lowercase and can't cope with blanks, though..def atbash(it):
abc = list(map(chr, range(97, 123)))[::-1]
return "".join([abc[ord(i)-97] for i in it])
print(atbash("aabbcc"))