[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

We've already seen too many threads about fizzbuzz. Let's

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 10
Thread images: 1

File: time_sparrow.jpg (131KB, 640x640px) Image search: [Google]
time_sparrow.jpg
131KB, 640x640px
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"))
Thread posts: 10
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.