Today's challenge is to write a function that when given a string returns the string with the characters in the reverse order.
E.g.
reverseStri...
For further actions, you may consider blocking this person and/or reporting abuse
Why not use Python's [::-1], but entirely in the browser? We can load the Pyodide runtime so we can run Python in the browser through WebAssembly. We'll have to eval as no ES module is shipped, but surely that's not a problem. Also the runtime is 20MB, but it's worth it!
Copy it into your browser console and be amazed..
Just shuffle the characters and see if it reversed the string! We'll get the reverse eventually.... (prepare to wait a long time for strings longer than 8 characters)
Perfect!
I'm loving this. Here my attempt:
This is my favorite so far. The reversed signatures are a nice touch
Thanks! Felt very meta some how.
My humble submission:
❤️ this challenge
This solution is inspired by my_first_calculator.py. It works for all lowercase alphabetic strings of length 3. The generated (non-
eval
ed) version is 17,582 lines of code.When I open the "my_first_calculator.py" file it took so long, I thought something was wront with the git site ou my internet was down. Then I saw the file and I understood
so easy
this works for any amount of chars xd
We need a computer network.
WEDIDIT 🎉
I am too lazy to implement the reverse function so I made cursed version instead.
Ok, so this monstrosity uses the built-in
substr
method. But instead of using that to determine the string, it builds a whole bund of PHP code to execute within the shell, calls that via exec, and returns the string.Awfully bad practice, inefficient, and dangerous. It's the type of code which gives PHP a bad name!
Go - convert the string to a slice of runes, swap the runes in the slice via some bit manipulation, then convert the slice back to string and return it.
Remember, to swap the values of two integers a and b...
a = a XOR b
b = a XOR b
a = a XOR b
Update: it occurred to me that the solution above may be odd, but it's not that inefficient. We can do better. So... take 2:
We split the string into a slice of ordered rune-index pairs, reverse the slice by sorting based on the indices, then get the resulting string from the reordered slice. It's pretty inefficient to begin with, and choosing bubblesort as our sorting algorithm gets us some O(N^2) fun.
Recursive reverse.
function reverse(s) {
if(!s) return “”;
return reverse(s.substring(1)) + s[0];
}
include
using namespace std;
int main(){
cout << "Syntax error";
return 0;
}
OOoooooooooooo, I love it! Bit late to this party (we'll see if I can get a terrible answer in later), but I hope you make a habit of posting these! My kind of challenge. :D