Post string palindrome check in your favourite language.
#include < stdio.h > #include < string.h > int palindrome(char string[200]) { int i; int flag = 0; for (i = 0; i < strlen(string); i++) { if (string[i] == string[strlen(string) - i - 1]) flag = 1; break; } if (flag == 1) printf("palindrome string"); else printf("not palindrome string");
return 0;
} int main(int argc, char * argv[]) { char string[200]; gets(string); (argv[1]) == string; return palindrome(argv[1]);
}
Attached: signal-2018-06-30-012943.jpg (640x1136, 149K)
July 13, 2018 - 08:07
char string[200]; gets(string); (argv[1]) == string; return palindrome(argv[1]);
Attached: 1520728088331.jpg (534x820, 141K)
July 13, 2018 - 08:11
Attached: 8fe[1].jpg (613x531, 41K)
July 13, 2018 - 08:18
f(s) ={s.localCompare(s.split('').reverse().join())}
I don't understand the difficulty? what the fuck is your program doing?
July 13, 2018 - 08:24
>+>,[>,]
[ [>]+]>[-]>[-[[-]] ] (6++++++)[->(8++++++++)+.
July 13, 2018 - 08:30
oh look it's another fizzbuzz thread
July 13, 2018 - 08:30
ran it through my compiler seems to work program = (arg) => { let output = '';let memory = [];let ptr = 0;let get = (ptr) => memory[ptr]||0;++ptr;memory[ptr] = get(ptr)+1;++ptr;memory[ptr] = arg.charCodeAt(0); arg = arg.substring(1);while (get(ptr)) {++ptr;memory[ptr] = arg.charCodeAt(0); arg = arg.substring(1);}--ptr;while (get(ptr)) {--ptr;}++ptr;++ptr;while (get(ptr)) {while (get(ptr)) {++ptr;}--ptr;memory[ptr] = get(ptr)+1;while (get(ptr)) {memory[ptr] = get(ptr)-1;++ptr;memory[ptr] = get(ptr)+1;--ptr;}--ptr;while (get(ptr)) {--ptr;}++ptr;memory[ptr] = get(ptr)-1;++ptr;while (get(ptr)) {while (get(ptr)) {++ptr;}++ptr;while (get(ptr)) {memory[ptr] = get(ptr)-1;--ptr;}--ptr;while (get(ptr)) {++ptr;}--ptr;while (get(ptr)) {--ptr;}++ptr;memory[ptr] = get(ptr)-1;}memory[ptr] = get(ptr)+1;++ptr;while (get(ptr)) {++ptr;}++ptr;while (get(ptr)) {--ptr;memory[ptr] = get(ptr)+1;++ptr;memory[ptr] = get(ptr)-1;while (get(ptr)) {while (get(ptr)) {memory[ptr] = get(ptr)-1;}--ptr;memory[ptr] = get(ptr)-1;++ptr;}--ptr;while (get(ptr)) {memory[ptr] = get(ptr)-1;--ptr;while (get(ptr)) {--ptr;}}}++ptr;++ptr;++ptr;}memory[ptr] = get(ptr)+1;memory[ptr] = get(ptr)+1;memory[ptr] = get(ptr)+1;memory[ptr] = get(ptr)+1;memory[ptr] = get(ptr)+1;memory[ptr] = get(ptr)+1;while (get(ptr)) {memory[ptr] = get(ptr)-1;++ptr;memory[ptr] = get(ptr)+1;memory[ptr] = get(ptr)+1;memory[ptr] = get(ptr)+1;memory[ptr] = get(ptr)+1;memory[ptr] = get(ptr)+1;memory[ptr] = get(ptr)+1;memory[ptr] = get(ptr)+1;memory[ptr] = get(ptr)+1;--ptr;}--ptr;--ptr;while (get(ptr)) {++ptr;++ptr;++ptr;memory[ptr] = get(ptr)+1;--ptr;--ptr;--ptr;memory[ptr] = get(ptr)-1;}++ptr;++ptr;++ptr;output += String.fromCharCode(get(ptr));return output;}
not sure what the 8 and the 6 is supposed to do, it works without that
July 13, 2018 - 08:37
the ABSOLUTE STATE of Jow Forums
July 13, 2018 - 08:43
In Julia:
palin(s) = length(s) < 2 || (s[1] == s[end] && palin(s[2:end-1]))
palin("hello") palin("hellolleh") palin("helllleh")
July 13, 2018 - 09:15
checkPal :: (Ord a) => [a] -> Bool checkpal [] = True checkPal [x] = True checkPal x = do if ((head x)==(last x)) then checkPal(tail$init x) else False
July 13, 2018 - 09:26
What a hideous language. I was all hyped about Haskell 3 years ago, now I despise all the naming it uses.
July 13, 2018 - 09:32
Nice quadratic complexity faggot.
July 13, 2018 - 09:39
def is_palindrome(s): return s == s[::-1]
July 13, 2018 - 09:43
f=a=>a.toLowerCase()==a.toLowerCase().split``.reverse().join``
July 13, 2018 - 09:44
Lmfao okay which one of you did this?
Attached: Untitled.png (909x714, 2.48M)
July 13, 2018 - 09:51
funnily, that strlen(string) in loop and condition might actually be optimized out because there is no mutation of underlying string
July 13, 2018 - 09:58
How is that quadratic complexity?
July 13, 2018 - 10:19
I'm lazy with strings so I did it for lists: isPalindrome(X):- s(X,[]).
s --> []. s --> [X]. s --> [X],s,[X].
gives ?- isPalindrome([a,b,c,b,a]). true
?- isPalindrome([p,r,o,l,o,g]). false.
July 13, 2018 - 10:28
(def testlist ["abba" "abcdef" "abcdcba" "azba" "dcbc"])
(defn paltest [string] (let [test (for [idx (range 0 (/ (count string) 2)) :let [y (= (nth string (+ idx 0)) (nth string (- (- (count string) 1) idx))) ]] y)] (every? true? test)) )
(map paltest testlist)
July 13, 2018 - 10:30
Those are linked lists, so last takes linear time.
July 13, 2018 - 11:12
function isPalindrome?(argument) return argument == tnemugra end
July 13, 2018 - 11:20
Something like this or?
Attached: Untitled.png (802x510, 1.17M)
July 13, 2018 - 11:53
You can't make code like this up. This guy was specifically taught shit code by some random fucker.
July 13, 2018 - 11:58
>palindrome :: [Char] -> IO Int
July 13, 2018 - 12:03
START LEARNING KOTLIN LADS
fun main(args: Array) {
fun String.isPalidrome() = this == this.reversed()
assert(!"test".isPalidrome()) assert("lol".isPalidrome())
}
July 13, 2018 - 12:04
What's happening here? Are you defining a generic function or what?
July 13, 2018 - 12:06
def is_palindrome( s ) : hl = len( s ) // 2 return s[ :hl ] == s[ -hl: ][ ::-1 ]
July 13, 2018 - 12:07
just a few features, no generics tho.
1. extension function on the built in `String` type. 2. type interference so I don't have to specify the return type as Boolean.
here is how the function could evolve, using more basic language features.
C like fun isPalidrome(input: String): Boolean { if (input == input.reversed()) { return true } else { return false } }
expression based fun isPalidrome(input: String): Boolean { return if (input == input.reversed()) { true } else { false } }
futher simplifaction fun isPalidrome(input: String): Boolean { return input == input.reversed() }
One liner can be use the '=' function syntax
fun isPalidrome(input: String) = input == input.reversed()
finally, lets use turn it into an extension function
fun String.isPalidrome() = this == this.reversed()
July 13, 2018 - 12:13
>s[ -hl: ][ ::-1 ] this is bad, but wow there is really weird behavior a = 'abcdefghi' hl = len(a) // 2
now try to combine the two square brackets into one a[hl::-1] => 'edcba' a[:hl:-1] => 'ihgf'
This is the opposite of what I've expected. Intuitively [hl::-1] would start from half to end and went in reverse, but it first reverses and then takes the right half.
July 13, 2018 - 12:20
palindrome = (\x -> map toLower x == reverse (map toLower x))
July 13, 2018 - 12:54
local function is_palindrome(s) return s == s:reverse() end
July 13, 2018 - 12:54
why the unnecessary lambda palindrome x = map toLower x == reverse (map toLower x)
July 13, 2018 - 12:58
why the unnecessary argument palindrome = ((==) `on` map toLower) id reverse
July 13, 2018 - 13:12
why the no fun allowed attitude?
July 13, 2018 - 13:14
bool is_palindrome(std::string_view const s) { return std::equal(std::begin(s), std::begin(s) + (s.length() >> 1), std::rbegin(s)); }
July 13, 2018 - 13:18
def isPalindrome(str: String): Boolean = str == str.reverse
Meh. Something more complicated would have helped showing features of different languages
July 13, 2018 - 13:19
I'm and I approve, fun absolutely allowed
July 13, 2018 - 13:20
Scala. I forgot to deal with lowercases, so:
def isPalindrome(str: String): Boolean = str equalsIgnoreCase str.reverse
July 13, 2018 - 13:25
reverse getLine >>= putStrLn
Attached: 1531476634066.png (742x774, 552K)
July 13, 2018 - 13:34
>palindrome ah
main = do wrd print True | otherwise -> print False
July 13, 2018 - 13:37
fn palindrome(s: &str) -> bool { return s.chars() .zip(s.chars().rev()) .take(s.chars().count() / 2 + 1) .all(|(a, b)| a == b); }
Works with UTF-8.
And bonus in C. bool palindrome(char* s) { char * e = s + strlen(s) - 1; while(e >= s) if(*s++ != *e--) return false; return true; }
July 13, 2018 - 13:49
"a\";w=]1-::[w trinp;)(tupni_war=w;";w=raw_input();print w[::-1]==w;"\a"
July 13, 2018 - 15:24