This commit is contained in:
commit
568474d52f
1591 files changed
+528213
No files matched your search
@@ -0,0 +1,23 @@
|
||||
# probe: shifting letters through an alphabet string with find()
|
||||
# status: the expected output is Programming+'s interpreter's prediction; corpus.py verify confirms or refutes it on godbolt
|
||||
# expect-stdout: khoor zruog
|
||||
# expect-stdout: hello world
|
||||
# expect-stdout: bcd
|
||||
def shift(s: String, k: Int) -> String:
|
||||
var alphabet = String("abcdefghijklmnopqrstuvwxyz")
|
||||
var out = String("")
|
||||
for i in range(s.count_codepoints()):
|
||||
var c = String(s[codepoint=i])
|
||||
var at = alphabet.find(c)
|
||||
if at < 0:
|
||||
out += c
|
||||
else:
|
||||
out += String(alphabet[codepoint=(at + k) % 26])
|
||||
return out
|
||||
|
||||
|
||||
def main():
|
||||
var secret = shift("hello world", 3)
|
||||
print(secret)
|
||||
print(shift(secret, 23))
|
||||
print(shift("xyz", 4))
|
||||
Reference in new issue
Block a user