bool is_palindrome(const char *s) { size_t i, j; size_t len = strlen(s);
if (len == 0) { return false; } if (len == 1) { return true; }
for (i = 0, j = len-1; i < len/2; ++i, --j) { if (s[i] != s[j]) { return false; } }
return true; }
Nicholas Mitchell
>i < a.length What's the fucking point if you only need to do half of the word
Nathan Wood
>if condition: >return True >else: >return False
hmmmmmmmmm
Adrian Jones
>returning a boolean value
David Bell
>python """programmers"""
Bentley Martin
You can also return a condition fuckwit
Jeremiah Wood
Func _IsPalindrome($s_Str) $s_Str = StringLower($s_Str) If $s_Str = StringReverse($s_Str) Then Return True Return False EndFunc
Levi Torres
>muh minimalistic code Better code readability and no difference in speed, turd smoker.
But since you're probably a Pajeet javafag or unemployed, you wouldn't understand it.
Owen Thompson
Only because you don't define the return type beforehand
James Baker
isPalindrome s = s == reverse s
Haskell
Joseph Martin
>tfw to intelligent to use strings 2 int main(void){ 3 puts("Performing five_digit_palindrome_tester."); 4 puts("This program will test if the number obtained from the user input is symmetrical"); 5 6 int num; 7 puts("Enter your 5 digit integer: "); 8 scanf("%d", &num); 9 10 int is_palindrome=0; 11 12 if (num9999){ 13 //in a palindrome the total of each side is divisable by 11 14 //21421=(12+21)%11=0 15 int first_two_digits=num/1000; 16 int last_two_digits=num-num/100*100; 17 is_palindrome*=(first_two_digits+last_two_digits)%11==0?1:0; 18 //printf("%d\t%d", first_two_digits, last_two_digits); 19 }else{ 20 puts("Input was not of 5 digits."); 21 } 22 23 if (is_palindrome) 24 puts("The number is a palindrome."); 25 else 26 puts("The number is not a palindrome."); 27 28 return 0; 29 }
Henry Smith
>21421 >21412*
Michael Peterson
>reverse What a bloat
John Perez
λ length "reverse = foldl (flip (:)) []" 29
Oh god, not the 29 characters! How will my hard disk cope?
Camden Allen
>hard disk what a retard
Josiah Parker
>le (((SSD))) maymay you're not fooling anyone, shill
Thomas Long
that data doesn't go on your harddrive or your SSD if you have one
Brody Nguyen
Oh right, it goes into the cloud. I forgot we were all using haskell-as-a-service compilers
Blake Brooks
>mfw python shows up and absolutely destroys the competition
Actually I included the str() when I didn't have to. I'm afraid Python is still superior user
n == n[::-1]
Jordan Richardson
if palindrome == palindrome.reverse
Roooby
Tyler Jones
bool res = true; for (int i = 0; i < str.length/2; i++) { if (str[i] != str [str.length - 1 - i]) { red = false; break; } }
Integer division ensures a word with odd number of letters leaves middle letter unchecked and even number of letters means both middles are checked.
Anthony Martin
>python is one of the slowest languages out there >if you're not careful enough with what language features you use haskell, even though compiled, manages to still be slower than python
uh haslelbabs?
Aaron Campbell
>mfw Python has blown everyone out of the water with the shortest solution in the thread
Nicholas Nguyen
too bad it's only useful for toy programs
Andrew Hall
That's a variable not a function dude
Josiah Miller
how dare you
Leo Mitchell
Is it unicode compatible?
Luke Smith
???
Brandon Wood
I am far from an expert at Python, but I have done a couple of semi-serious projects in the language and will try to recall specifically what I didn't like.
- Everything you write will be open source. No FASLs, DLLs or EXEs. Developer may want to have control over the level of access to prevent exposure of internal implementation, as it may contain proprietary code or because strict interface/implementation decomposition is required. Python third-party library licensing is overly complex. Licenses like MIT allow you to create derived works as long as you maintain attrubution; GNU GPL, or other 'viral' licenses don't allow derived works without inheriting the same license. To inherit the benefits of an open source culture you also inherit the complexities of the licensing hell. - Installation mentality, Python has inherited the idea that libraries should be installed, so it infact is designed to work inside unix package management, which basically contains a fair amount of baggage (library version issues) and reduced portability. Of course it must be possible to package libraries with your application, but its not conventional and can be hard to deploy as a desktop app due to cross platform issues, language version, etc. Open Source projects generally don't care about Windows, most open source developers use Linux because "Windows sucks". - Probably the biggest practical problem with Python is that there's no well-defined API that doesn't change. This make life easier for Guido and tough on everybody else. That's the real cause of Python's "version hell".
Joseph Phillips
I've never used a lambda function before. Neat, I leaned something new today
Mason Parker
- Global Interpreter Lock (GIL) is a significant barrier to concurrency. Due to signaling with a CPU-bound thread, it can cause a slowdown even on single processor. Reason for employing GIL in Python is to easy the integration of C/C++ libraries. Additionally, CPython interpreter code is not thread-safe, so the only way other threads can do useful work is if they are in some C/C++ routine, which must be thread-safe. - Python (like most other scripting languages) does not require variables to be declared, as (let (x 123) ...) in Lisp or int x = 123 in C/C++. This means that Python can't even detect a trivial typo - it will produce a program, which will continue working for hours until it reaches the typo - THEN go boom and you lost all unsaved data. Local and global scopes are unintuitive. Having variables leak after a for-loop can definitely be confusing. Worse, binding of loop indices can be very confusing; e.g. "for a in list: result.append(lambda: fcn(a))" probably won't do what you think it would. Why nonlocal/global/auto-local scope nonsense? - Python indulges messy horizontal code (> 80 chars per line), where in Lisp one would use "let" to break computaion into manageable pieces. Get used to things like self.convertId([(name, uidutil.getId(obj)) for name, obj in container.items() if IContainer.isInstance(obj)]) - Crippled support for functional programming. Python's lambda is limited to a single expression and doesn't allow conditionals. Python makes a distinction between expressions and statements, and does not automatically return the last expressions, thus crippling lambdas even more. Assignments are not expressions. Most useful high-order functions were deprecated in Python 3.0 and have to be imported from functools. No continuations or even tail call optimization: "I don't like reading code that was written by someone trying to use tail recursion." --Guido
Nolan Howard
- Python has a faulty package system. Type time.sleep=4 instead of time.sleep(4) and you just destroyed the system-wide sleep function with a trivial typo. Now consider accidentally assigning some method to time.sleep, and you won't even get a runtime error - just very hard to trace behavior. And sleep is only one example, it's just as easy to override ANYTHING. - Python's syntax, based on SETL language and mathematical Set Theory, is non-uniform, hard to understand and parse, compared to simpler languages, like Lisp, Smalltalk, Nial and Factor. Instead of usual "fold" and "map" functions, Python uses "set comprehension" syntax, which has overhelmingly large collection of underlying linguistic and notational conventions, each with it's own variable binding semantics. Using CLI and automatically generating Python code is hard due to the so called "off-side" indentation rule (aka Forced Indentation of Code), also taken from a math-intensive Haskell language. This, in effect, makes Python look like an overengineered toy for math geeks. Good luck discerning [f(z) for y in x for z in gen(y) if pred(z)] from [f(z) if pred(z) for z in gen(y) for y in x] - Python hides logical connectives in a pile of other symbols: try seeing "and" in "if y > 0 or new_width > width and new_height > height or x < 0". - Quite quirky: triple-quoted strings seem like a syntax-decision from a David Lynch movie, and double-underscores, like __init__, seem appropriate in C, but not in a language that provides list comprehensions. There are better ways to mark certain features as internal or special than just calling it __feature__. self everywhere can make you feel like OO was bolted on, even though it wasn't.
Easton Bailey
>two sentences in and he's wrong stopped reading there
John Nguyen
- Python has too many confusing non-orthogonal features: references can't be used as hash keys; expressions in default arguments are calculated when the function is defined, not when it’s called. Why have both dictionaries and objects? Why have both types and duck-typing? Why is there ":" in the syntax if it almost always has a newline after it? The Python language reference devotes a whole sub-chapter to "Emulating container types", "Emulating callable Objects", "Emulating numeric types", "Emulating sequences" etc. -- only because arrays, sequences etc. are "special" in Python. - Python's GC uses naive reference counting, which is slow and doesn't handle circular references, meaning you have to expect subtle memory leaks and can't easily use arbitrary graphs as your data. In effect Python complicates even simple tasks, like keeping directory tree with symlinks. - Patterns and anti-patterns are signs of deficiencies inherent in the language. In Python, concatenating strings in a loop is considered an anti-pattern merely because the popular implementation is incapable of producing good code in such a case. The intractability or impossibility of static analysis in Python makes such optimizations difficult or impossible. - Problems with arithmetic: no Numerical Tower (nor even rational/complex numbers), meaning 1/2 would produce 0, instead of 0.5, leading to subtle and dangerous errors. - Poor UTF support and unicode string handling is somewhat awkward. - No outstanding feature, that makes the language, like the brevity of APL or macros of Lisp. Python doesn’t really give us anything that wasn’t there long ago in Lisp and Smalltalk.
Jaxson Taylor
>sees that python has won the thread's competition >proceeds to copy / paste a bunch of excuses written by someone else
how mad are you right now? python rules, everyone else drools
Samuel Roberts
what did he mean by this?
Brayden Williams
haskell is shorter if you write a function like the op wanted
Lucas Long
It means he copy pasted someone complaining about Python 2 (which was replaced 8-9 years ago). Python 3 fixed a lot.
Brody Campbell
I might believe you if you showed some code, instead of just talking about it
Levi Parker
>replaced
Leo Miller
f = lambda s: s == s[::-1]
vs
f s = s == reverse s
Jace Reyes
mixed up the posts but you get the point
Anthony Rogers
cool, thanks for showing proof
Isaiah Scott
[citation needed]
Juan Gomez
#include #include #include #include
#define MAX_INPUT 200
int main(int argc, char *argv[]) { char input[MAX_INPUT]; switch (argc) { case 1: fgets(input, MAX_INPUT, stdin); char *nl = strchr(input, '\n'); if (nl) *nl = 0; else input[MAX_INPUT] = 0; break; case 2: strcpy(input, argv[1]); break; default: printf("Usage: %s [str]\n", argv[0]); exit(EXIT_FAILURE); } size_t i = 0; size_t j = strlen(input) - 1; while (!isalpha(input[i])) ++i; while (!isalpha(input[j])) --j; char palyndromic = 1; while (i < j) { if (tolower(input[i]) != tolower(input[j])) { palyndromic = 0; break; } else { do ++i; while (!isalpha(input[i])); do --j; while (!isalpha(input[j])); } } if (palyndromic) puts("breddy gud :^)"); else puts("smhtbhfam :^("); return EXIT_SUCCESS; } If your code does not ignore punctuation and digits, it's wrong.
Liam Phillips
import Data.Text (reverse)
now it is :^)
Jose Bennett
f = ap (==) reverse
Jayden Perry
holy shit that's convoluted compared to
Brandon Jones
At least it works, faggot. Also, >calculating a new string just to check if the original one is a palindrome Functional programmers should be hung.
Christopher Gomez
>pretends to understand functional programming okay
>store numbers of occurrences in hash table >trivially get your sorted array Go on, Pajeet.
William Perez
Pajeet doesn't know a thing about functional programming, at least get your insults right.
Jeremiah Torres
So how do you sort an array of strings?
Adrian Myers
>side effect >functional programmers have to not be purists to get reasonable complexities in their own paradigm really makes u think
>he doesn't know what an increasing function is
Jackson Morris
>>side effect >>functional programmers have to not be purists to get reasonable complexities in their own paradigm That code doesn't have side effects
Brandon Ramirez
>>he doesn't know what an increasing function is But your curryshit's Object.GetHash() won't be homomorphic on comparison, so good luck building your abstraction
>good luck building your abstraction >MUH ABSTRAKSHUN Why aren't you memeing constraint programming; Pajeet?
Alexander Price
HLists are a degenerate abomination that should never have existed.
Ryan Bailey
APL f←{∧/=⌿↑⍵(⌽⍵)}
Christopher Flores
Nice cherry picking out the single one of those sorting algorithms that uses an extra array as auxiliary space. I'm sure your idea of using a separate hash table is magically O(1) space though
Joshua Thomas
Who mentioned HLists?
Dominic Garcia
This shows how retarded python fags are: >return True if word == word[::-1] else False >return True if True else False Why do you need an if/else? def check(word): return word == word[::-1]
Tyler Johnson
J code is pretty short too.
Alexander Wright
How else are you going to achieve this?
Robert Clark
>nobody has solved it recursively yet This board is shit
Jonathan Miller
>implying the recursive solution is any better than any of the one-liners
David Richardson
I like this one
Jonathan Gutierrez
Yeah but using libraries is for niggers
Logan Carter
>literally no-one using a library
Julian Reyes
...
Nicholas Rivera
Are you retarded? That wasn't even related to the problem in OP at all.
Charles Cook
isPal :: String -> Bool isPal s = s == reverse s
Haskell master race
Jace Powell
Idris master race.
Cameron Bailey
>Nice cherry picking out the single one of those sorting algorithms that uses an extra array as auxiliary space. No, I "cherrypicked" the only algorithm whose space complexity was actually given.
>I'm sure your idea of using a separate hash table is magically O(1) space though It's not but that wasn't asked.