Post string palindrome check in your favourite language

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)

Other urls found in this thread:

stackoverflow.com/questions/51318512/it-is-command-line-based-c-program-to-check-for-palindrome-string-and-my-answer
twitter.com/SFWRedditVideos

char string[200];
gets(string);
(argv[1]) == string;
return palindrome(argv[1]);

Attached: 1520728088331.jpg (534x820, 141K)

Huh?

Attached: 8fe[1].jpg (613x531, 41K)

f(s) ={s.localCompare(s.split('').reverse().join())}


I don't understand the difficulty? what the fuck is your program doing?

>+>,[>,]

[
[>]+]>[-]>[-[[-]]
]
(6++++++)[->(8++++++++)+.

oh look it's another fizzbuzz thread

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

the ABSOLUTE STATE of Jow Forums

In Julia:

palin(s) = length(s) < 2 || (s[1] == s[end] && palin(s[2:end-1]))

palin("hello")
palin("hellolleh")
palin("helllleh")

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

What a hideous language. I was all hyped about Haskell 3 years ago, now I despise all the naming it uses.

Nice quadratic complexity faggot.

def is_palindrome(s):
return s == s[::-1]

f=a=>a.toLowerCase()==a.toLowerCase().split``.reverse().join``

Lmfao okay which one of you did this?

Attached: Untitled.png (909x714, 2.48M)

funnily, that strlen(string) in loop and condition might actually be optimized out because there is no mutation of underlying string

How is that quadratic complexity?

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.

(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)

Those are linked lists, so last takes linear time.

function isPalindrome?(argument)
return argument == tnemugra
end

Something like this or?

Attached: Untitled.png (802x510, 1.17M)

I don't feel so Jow Forumsood

Attached: portugal-v-france-france-shutterstock-editorial-5754282gc[1].jpg (341x450, 40K)

You can't make code like this up. This guy was specifically taught shit code by some random fucker.

>palindrome :: [Char] -> IO Int

START LEARNING KOTLIN LADS

fun main(args: Array) {

fun String.isPalidrome() = this == this.reversed()

assert(!"test".isPalidrome())
assert("lol".isPalidrome())

}

What's happening here? Are you defining a generic function or what?

def is_palindrome( s ) :
hl = len( s ) // 2
return s[ :hl ] == s[ -hl: ][ ::-1 ]

geeez surly this must be deleted by now

stackoverflow.com/questions/51318512/it-is-command-line-based-c-program-to-check-for-palindrome-string-and-my-answer

>2 super serious answers for muh internet likes

gott ist tot.

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()

return s == s[::-1]

Much prettier.

>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.

palindrome = (\x -> map toLower x == reverse (map toLower x))

local function is_palindrome(s)
return s == s:reverse()
end

why the unnecessary lambda
palindrome x = map toLower x == reverse (map toLower x)

why the unnecessary argument
palindrome = ((==) `on` map toLower) id reverse

why the pointless reply?

why the no fun allowed attitude?

bool is_palindrome(std::string_view const s)
{ return std::equal(std::begin(s), std::begin(s) + (s.length() >> 1), std::rbegin(s)); }

def isPalindrome(str: String): Boolean = str == str.reverse


Meh. Something more complicated would have helped showing features of different languages

I'm and I approve, fun absolutely allowed

what language is this?

Scala.
I forgot to deal with lowercases, so:

def isPalindrome(str: String): Boolean = str equalsIgnoreCase str.reverse

...

reverse getLine >>= putStrLn

Attached: 1531476634066.png (742x774, 552K)

>palindrome
ah

main = do
wrd print True
| otherwise -> print False

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;
}

"a\";w=]1-::[w trinp;)(tupni_war=w;";w=raw_input();print w[::-1]==w;"\a"