[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 359
Thread images: 39

File: whoops.png (7KB, 234x119px) Image search: [Google]
whoops.png
7KB, 234x119px
Functional Edition

Previous Thread: >>55652267

What are you working on, /g/?
Is it functional?
>>
First for OOP is a horrible meme.
>>
File: OOP.png (69KB, 1210x467px) Image search: [Google]
OOP.png
69KB, 1210x467px
OOP is terribly bad, on that we can all agree.
But should it be considered a war crime?
>>
Third for I like OOP
>>
>>55660368
Honestly, 2000 lines or anything in that magnitude or several above it is not enough to make an impact on performance for storage. You could pretty much use any willy nilly storage container if you wished to store it and it would still be negligible.

If down-to-the-wire performance is an issue, I'm pretty sure there's a way to nextline without needing to pass to container. and then you nextline until you need to getline. And then you may as well learn ASM.

I'll repeat my question from previous thread:

I'm making a graphics builder for stuff as a side project for my job.

Anyone have any experience with standard control mechanisms for select/drag/hittest/etc? I'm technically an EE so I've never had to build something like this before. I've got the draw and hittesting working, but for some reason I'm stuck on how to implement the select/multiple select and how to handle mouse move/mouse down/mouse up

Not asking how to implement it function wise, but how I should implement the overall control loop.

Programming es hard
>>
>>55660444
>3 posters in this thread
>3 replies + OP
>I'm the first reply in this thread
>This post must be either OP or the second reply
Please don't samefag alternating opinions. It's clear that you're just shitposting.
>>
>>55660468
Stop samefagging.
>>
File: code2.png (25KB, 616x697px) Image search: [Google]
code2.png
25KB, 616x697px
>>55660141
I changed it up but now its just completely crashing after I enter a value for the Numerator.
>>
Working on my computational optimization research. It's written with a functional style in javascript. Haters come at me. :^)
>>
>>55660482
Line 33 and 35. You're giving it an int where it expects an int pointer.
Use &f->numer and &f->denom.
>>
>>55660484
>computational optimization
enjoy doing something 100% niche and 95% useless
>>
>>55660468
Well I'm not samefagging and I do like OOP
But I'm definitely shitposting, that much is true
:^)))
>>
>>55660372
what does the image mean op?

also, does c++ have functional aspects?
like idontknow, maybe mapping, folding, filtering, or even good typing
>>
>>55660495
Thank you so much! It's always something that's so simple that needs to be changed.
>>
File: 1455048537359.jpg (194KB, 1600x1600px) Image search: [Google]
1455048537359.jpg
194KB, 1600x1600px
how pajeet am I if my first job involves converting C# to Node.js and coding in Node.js?
>>
File: 1468885379093.jpg (117KB, 1280x720px) Image search: [Google]
1468885379093.jpg
117KB, 1280x720px
>to learn a language you need to practice it by doing projects

Great, but how? I mean, how to start?

I have this idea: a program that counts how many (You)'s you get in a thread. Sounds simple enough but I have no idea how to start the program. Do I need to do a research first? What about other projects?
>>
>>55660521
Learn gdb. It'll save you so much headache in the long run. Like, learn how to use it now.
>>
Anon's word or name req.
replace words with lines if they're seperated by lines
import System.Environment
import System.Random
main ∷ IO ()
main = do
s ← words <$> readFile "path"
r ← randomRIO (0, length s)
putStrLn $ s !! r


>>55660468
OP here
I posted >>55660412
>>
>>55660507
lol, my algorithm beats the current state of the art and it's also generalizable to any problem...
>>
>>55660515
C++11 and newer have been getting more functional aspects in the standard library.
>>
Okay guys quick I just started learning programming a couple of days ago, starting with C#. If OOP really is the Devil's paradigm, what should I learn instead?
>>
>>55660515
>does c++ have functional aspects?
It has lambdas and "parametric polymorphism"
>mapping, folding, filtering, or even good typing
Difficult to implement without garbage collection. The standard library doesn't provide full FP versions of these things in order to attempt container-agnosticism but you could easily implement your own.
e.g.
template <typename T,typename U,typename F>
std::vector<U> map (F f, const std::vector<T>& vec) {
std::vector<U> out;
out.reserve(vec.size());
for (auto& x : vec)
out.push_back(f(x));
return out;
}
>>
>>55660527

projects are good if you can come up with the ideas for them and are motivated enough to do them.

You can use Hackerrank.com if you lack motivation and just want to do interview tier coding questions.
>>
>>55660537
>generalizable to any problem
this is what CORtards actually believe
>>
>>55660549
Too bad that can't fix all of the other glaring flaws in the language.
>>
>>55660372
anyone can help me configure spacemacs autocompletion with c++ ?
>>
>>55660552
You should learn Haskell

>>55660549
C++ and friends are nowhere near real functional programming
There's more to it than just map, filter & fold
>>
>>55660552
Don't listen to the autists. You'll only waste time jumping from language to language. C# is good enough and you're better off just continuing down the path you're on and switching to a better language later.
>>
>>55660558
yeah, flaws like not accounting for your stupidity

>>55660552
you're going to end up using OOP for anything useful, might as well learn an OOP language now.

instead of learning c# id recommend python or c/c++. im a microdrone but using a programming language developed by microsoft just feels wrong to me.
>>
>>55660588
I second this. You should be able to eventually learn for yourself why OOP isn't so good, but at this point in time it doesn't matter.
>>
>>55660588
>you're better off just continuing down the path you're on and switching ... later.
horrible advice

>>55660600
>might as well learn an OOP language
>C/C++
Neither of those are OOP languages
>>
>>55660552
Just keep learning C#.
>>
>>55660609
>Neither of those are OOP languages
well, close enough
>>
Doing a prompt that requires me to reset a randomly-generated name while also checking for collisions.

void robot::reset()
{
fstream nameHistoryFile("nameHistory.txt", fstream::in | fstream::out | fstream::app);

string tempNewName = generateName(), nameFromHistory = "";

reGenName:
while (getline(nameHistoryFile, nameFromHistory, ',')) {
if (tempNewName == nameFromHistory) {
tempNewName = generateName();
goto reGenName;
}
}

nameHistoryFile << tempNewName << ',';

robotsName = tempNewName;

nameHistoryFile.close();
}


Surely there's a better way to do this.
>>
>>55660600
>c/c++
Why are you grouping two completely different languages together?
That's like saying Java/Javascript.

>You're going to end up using OOP for anything useful
No. OOP is awful and shouldn't be used to write anything.
>>
>>55660628
Ditch the goto and replace that line with "continue"...
>>
>>55660554
I see.
anyways, is it true that c++ is sought after in the job market
>>
>>55660484
> optimization
> javascript

lol
>>
>>55660630
The functional differences between the two might be huge, but the syntax is pretty much exactly the same

Stop being so autistic and edgy
>>
>>55660628
Won't the destructor automatically close the file?
Also do this: >>55660641

Might be a bit bad for readability but you could also do
nameHistoryFile << (robotsName = tempNewName) << ',';
>>
File: 1454447848380.jpg (24KB, 300x300px) Image search: [Google]
1454447848380.jpg
24KB, 300x300px
>>55660557
Except this shit is a global black box algorithm for optimizing arbitrary sequences of binary data. It can do MINLP problems, or really whatever I want to throw at it. Fuck, my code can even write code.

>>55660647
It's just the command and control server that has to handle loads of data being spewed out by clients, so it's written in Node for high concurrency (and also ease of implementation)
>>
>>55660656
>but the syntax is pretty much exactly the same
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time).count() << ":";

Sure thing, fuckwit.
>>
>>55660641
But it wouldn't check to see if the tempNewName that was generated inside the while loop collides.
>>
>>55660645

SQL (Why is this considered a language..?), Java, Java script, C#, Python, and c++ are the most common / in demand languages for jobs.
>>
>>55660693
You want to do the whole loop over?
You're definitely doing something in an awfully weird way

And don't remember you're getting lines from the file, so you can't just "go back"
>>
>>55660672

using cout = std::cout;
using chrono = std::chrono;

cout << chrono::duration_cast<chronno::microseconds>(end_time - start_time).count() << ":";


C++ 11 type aliasing helps a lot.
>>
>>55660672
Oh wow, that really won you the internet argument. Good for you.

>>55660666
If you've honestly written something in JS that beats state of the art CO stuff used by companies then I don't see why you're not marketing it instead of bragging on 2+2 chan about it.

And don't throw that writing code shit at me. Any idiot can write code.
>>
>>55660748
{
using namespace std;
using namespace chrono;
cout << duration_cast<microseconds>(end_time - start_time).count << ":";
};
>>
>>55660748
That still looks nothing like C.
>>
>>55660767
printf("%d:", microsecondsElapsed(start_time,end_time));
>>
Employed Haskell programmer reporting in
>>
>>55660783
Which mcdonalds do you work at?
>>
>>55660782
So you created a seemingly equivalent program which looks nothing alike.
Good one.
>>
>>55660792
>mcdonalds
>m c d o n a l d s
>m ..... o n a . d s
>>
>>55660749
I'm going to publish a paper on it in about a month, but I'm still tuning the implementation at the moment.

Also automatic code generation (i.e. here's a problem, write something from scratch) is pretty cutting edge stuff.
>>
>>55660694
>Structured Query Language
>Why is this considered a language..?
>>
>>55660709
>you're getting lines from the file, so you can't just "go back"
I'll have to re-do that part then. Thanks for the feedback.
>>
>>55660801
So, which cherry picked conditions does your code do better than state of the art?
>>
>>55660923
>muh special snowflake genetic algorithm
>>
>>55660923
If by binary data then you mean its a MILP limited to [0,1], none of that is impressive
>>
>>55660965
at least his algorithm is right up to 40% of the time
>>
>>55660947
It shits all over GA's

>>55660965
It's a 0-1 MILNP. Note the N. It assumes unpredictable nonlinearites in the interactions between the bits, which lets it handle way more different problem types.
>>
>>55661028
*MINLP

Fuck
>>
>>55661028
>Well quite a few of them.
>-It's a global search algorithm, so it's not hindered by highly noisy, nonconvex search spaces
>-it's a black box algorithm, so it can be easily applied to different problems without needing to extract certain prerequisite data from your fitness function
>-it operates on binary data, so you can have it optimize machine instructions, decision trees, mechanical parts, floating point values, etc.
>-it converges to optimal solutions really (REALLY!) fucking fast (orders of magnitude better)

Have you got something to hide? Why delete this?
>>
>>55661035
4chan dickwaving is less important than somehow being beaten to publishing. Better safe than sorry. :^)
>>
File: 1370806841471.jpg (4KB, 171x211px) Image search: [Google]
1370806841471.jpg
4KB, 171x211px
>>55661062
>makes state-of-the-art bleeding edge algorithms that need to be kept secret before publication
>doesn't know that everything posted on the website gets archived and indexed for searching
>>
>>55661075
Nah, I haven't posted my secret sauce. But I don't want people getting any ideas.
>>
>>55661062
>implying anyone would want to expose their autism by publishing a paper on CO
although this is 4chan, i guess you do have a reason to be worried
>>
File: 1279499666729.jpg (106KB, 554x439px) Image search: [Google]
1279499666729.jpg
106KB, 554x439px
>>55661081
Yet, you bothered to delete your post that had already been indexed and can be found on Google, and any autist who would care about your shitty algorithm would only take more notice at a deleted post.
>>
File: Drunken Nagisa.png (404KB, 633x478px) Image search: [Google]
Drunken Nagisa.png
404KB, 633x478px
I'm doing baby's first linked list on C. I'm a little puzzled with something.
struct linked_list{
struct node *root;
int size;
};

struct node{
char value;
struct node *next;
};

void add_member(struct linked_list *list, char value){
struct node *ptr = list->root;
struct node *element = (struct node *) malloc(sizeof(struct node));
element->value = value;
element->next = NULL;

if(ptr == NULL)
list->root = element; //right here is where I'm puzzled
else{
while(ptr->next != NULL)
ptr = ptr->next;
ptr->next = element;
}

list->size += 1;
return;
}

It used to be
ptr = element
when it's the first element, but that gave me a segmentation fault.
With this line, however, everything is fine. What gives? The while is going through the list using the node pointer and adding an element seem to work. Why wouldn't it work on the very first one?
>>
>>55661187
Disregard this, I suck cocks.
>>
>>55660103
The rest of the reasonable comment aside, Haskell DOES have a surprisingly shitty community. It's stupid, because it doesn't have to be, but the culture is self-reinforcing at this point.
>>
>>55660527
Read the github page for 4chan's API. Find your language's JSON libraries. Count all posts in the thread that are responses to a particular post you give the program (i.e., your (you) post).
>>
>>55661578
Oops, sorry, typo.

for _ in range(int(42 == 420/10)):
while int(not _):
_+=int(not 1336 == 666)
with open(hex(_), "a+") as ride_my_eggplant:
ride_my_eggplant.write(str(_) * 6661337420)


Okay, here is my finished FizzBuzz. I think it's nice and readable.
>>
Why does C++ use double colons to access namespaces instead of just a dot like most other languages?
>>
>>55661691
Bjarne and the C++ committee did as much as they could to make the language's syntax as disgusting as possible.
>>
>>55661705
I can clearly see that.
>>
File: Filthy_street_homeless_India[2].jpg (346KB, 590x393px) Image search: [Google]
Filthy_street_homeless_India[2].jpg
346KB, 590x393px
>>55660522
pajeet enough to poo in loo
>>
File: 465867652.jpg (110KB, 850x758px) Image search: [Google]
465867652.jpg
110KB, 850x758px
SICP neophyte here again. I'm trying to build a tail-recursive program that sums the squares of numbers

#lang racket

( define sum_of_squares ( lambda ( L )
( cond
( ( equal? L ' ( ) ) 0 )
( #t ( + ( * ( car L ) ( car L ) ) ( sum_of_squares ( cdr L ) ) ) )
)
))

( define sumOfSquares
( lambda (L)
(sumOfSquaresHelper L '(0))
)
)


( define sumOfSquaresHelper (lambda (L acc)
(cond
(( equal? L '()) acc)
( (set! acc (+ ((toNumb(acc)) (+ ( * (car L) (car L))))))
(sumOfSquaresHelper (cdr L) acc))
)
)
)

( define (toList n)
(cond
((number? n) (list n))
((#t n))
)
)

(define (toNumb L)
(cond
(equal? '())(0)
((list?) (car L))
(#t L)
)
)


(sum_of_squares '(2 2))
(sumOfSquares '(2 2))


Right now it's throwing the error "application: not a procedure;
expected a procedure that can be applied to arguments
given: '(0)
arguments...: [none]"

What the fuck, the toNumb is definitely a procedure. It's taking an argument. AUGH

Yes, I'm aware that I'm garbage. Being garbage is step 1 to being less garbage.
>>
>>55660694
SQL is not pleb tier
>>
>>55661691
I hate it, and the fact that Rust uses it as well.
>>
>>55662181
Use a real programming language to write real programs.
>>
void println="Hello World"
>>
>>55662181
I haven't bothered looking at the whole thing but your equal? cond clause is bad, you need more parens
>>
>>55662181
The problem is
(acc)

That means "run the procedure 'acc' with no arguments", and acc isn't a procedure (in this case it is '(0))
>>
File: fsasfdac.png (76KB, 1234x536px) Image search: [Google]
fsasfdac.png
76KB, 1234x536px
>>55660372
>>
>>55662494
>need more parens

Jesus christ how shitty is this language
>>
>>55662515

At least in >>55662510 it was too many parens
>>
>>55662512
the fuck you expected
>>
>>55662512
>javascript
typical js devs
>>
>>55662181
First of all, that's some heinous Lisp formatting, closing brackets on new lines and spaces before operators make it annoying to read. If your editor isn't helping you with this I'd advise you to change. Emacs will always be the best lisp editor, but most will support it.

The cond clause in tonumb isn't valid, in the first condition you're only passing equal? one argument and you don't need the brackets for the answer. These should both be wrapped in a set of brackets.
An expression in lisp is always in the form (operator operand-1 ... operand-n) or it's an self-evaluating atom. In the answer to the first conditional you don't want to call the operator named 0 with no arguments, you simply want to return the self-evaluating value 0.
>>
>>55662583
>(((Lisp)))
>>
File: 1468977097596.gif (1MB, 245x280px) Image search: [Google]
1468977097596.gif
1MB, 245x280px
>>55662546
>this convoluted swap
>>
>>55660537
Post it to AI if it's really that good.
https://github.com/kennyledet/Algorithm-Implementations
>>
>>55660800

Underrated post.
>>
>>55662592
It's elegant. Brackets and basic evaluation rules are the only syntax you need to know in Lisp. Most other languages feels like visual white noise and doesn't compile before you tidy up a dozen typos.
>>
Is learning python the hard way a good book? Should I use it to learn python? Or should I use another book?
>>
>>55662592
Scots are NOT Jewish.
>>
>>55662891
No. Avoid anything and everything by Zed Shaw.
>>
>>55662891
Nothing by Zed Shaw is good, take the intro MIT course if you want to learn to program or just look up a quick tutorial and reference if you already know how and want to pick up python.
>>
>>55662916
I already know a bit of javascript, learning C at the moment. Just wanted to get some good material on python.
>>
>>55662962
>Just wanted to get some good material on python.

Think Python is much, much better.
>>
>>55663022
>Think Python
Aight, thats the book I will use then. Thx anons. Btw, random questions, but are all "O'reily" books good? I am currently reading "Javascripts: The Good Parts", pretty good so far. Just wanted to know if they are all worth reading?
>>
>>55663179
They're fine.
>>
>>55663195
Aight, I am currently learning C, then I will move on to Jquery, and Python. Wish me luck!
>>
>>55663207
Godspeed, senpai. c:
>>
Reminder that C, Python, GoLang, and the LISP family of languages (with Clojure being the most practical) are all anybody ever needs.
>>
>>55663270
>GoLang
No.
>>
>>55662542
agreed m80
>>
Is Perl worth learning? I have thinking about learning it after learning Java and ruby.
>>
>>55663281
Come on m8, there literally isn't a better language for web dev. Being the best language for web dev is a bit like winning the gold medal at the special olympics, but it has to count for something.
>>
>>55663355
html templates with sexp in lisp macros in where it's at.
Go got nothing going for it.
>>
>>55663394
Fair enough, I don't really fuck with web dev because the entire industry is cancer. I was just basing my recommendation of Go based on my experience with web dev; which consists entirely of
>needing to make myself a website for a job hunt
>taking one look at php, js, jsquery, and Go
>immediately deciding to use Go.
>>
So do I put all my functions in my header files? Some of them? What's the point?

I don't get how C++ should be organized.
>>
>>55663642
Declarations in hpp files, implementation in cpp.
Unless you're working with templates/inline functions then everything goes into the headers.
>>
Why does /dpt/ hate Zed Shaw?
Just curious, I don't know anything about him other than he wrote a few books.
>>
>>55663355
Go isn't good at web-dev, by a long shot.
>>
>>55663668
http://hentenaar.com/dont-learn-c-the-wrong-way
>>
>>55663668
His books are terrible.
When he received criticism, he acted like a little bitch.
>>
>>55661592
This is a cute idea but creating the "1" * 6661337420 string is slow as fuck and will likely make the OS kill the process before even writing to the HDD (nigga you're allocating like 6 GiB for that string).
>>
>>55663723
I'm a retard can you explain how this works?
>>
>>55663780
It isn't fizzbuzz. This just attempts to write 6 GiB of 1s into a file called 0x1.
>>
>>55663820
Looks like it's writing multiple files.
>>
>>55663916
Nah.
The for loop is just _ = 0, the while loop is just _ == 0.
>>
>>55663942
I see now, should've actually looked at the operation in the range() call lol
>>
File: 4pdZT5h.png (39KB, 1074x1011px) Image search: [Google]
4pdZT5h.png
39KB, 1074x1011px
>>55660527
>a program that counts how many (You)'s you get in a thread
That's a good project.

Note that the APIs don't change based on who's accessing them. You'll have to record your own post numbers somewhere to compare.

https://github.com/4chan/4chan-API
>>
>>55660527
code like a 4chinner:

>string up the whole thread fuck em LAMESON lib's
>count the "(You)" 's
>???
>PROFIT!!!
>>
>>55664028
kek
>>
>>55664028
>the program counts this post as 2 (You)s
>>
>>55664049
>the program counts this post as 2 (You)s

No problem, we just edit the code 4chin style:

>only allow " EMPTYSPACE(You) " as valid (You)
>Count the occurrences
>???
PROFIT!!!
>>
>>55664120
What if somebody is memeing about getting (you) 's in the thread? See, that right there would count as a (you) that wasn't really a you.
>>
>>55664135
Good question for a 4chin program.

We will make a nice disclaimer on top of our GUI or Console app:
>**THE (you) OCCURENCES MIGHT BE OFF | DO NUT USE IN /b/, /g/ **
>???
>PROFIT!!!
>>
>>55664167
Kek

Sadly however this coding approach is handed by 99% of /dpt/. The other 1% is even too retarded for that style. You can find the 1% in /wdg/
>>
Fuck you, OP

IO should only have a Cobind instance, not a Comonad instance

It's this sort of shit that is ruining Haskell

I hope your code space leaks
>>
>>55664338
Can't ruin what's already ruined.
>>
>>55664338
abstract everything to the MAX
>>
File: fragezeichen yui.png (94KB, 396x395px) Image search: [Google]
fragezeichen yui.png
94KB, 396x395px
How can I
(apply)
a macro to a S-expression?

Or more importantly: why isn't this allowed by default? There must be a good reason.
>>
Has anyone here tried programming in Malbolge?
Post your work.
>>
>>55660372
I'm a bit confused about creative commons license, specifically the share alike license. If I license software or art under cc 4 attribute share alike license, does the specific art or code only have to be under the same license or does the entire thing have to be under the same or compatible license? Can i mix code or art under share alike with code under licenses like BSD or MIT?
>>
Hey /dpt/, I want to learn a functional programming language to feel special.

Which should I learn?
>>
>>55664978
Scheme

Don't bother with ML types, especially not Haskell
>>
>>55664978
Scala, of course.
>>
>>55664978
Haskell
>>
File: monk.png (110KB, 480x250px) Image search: [Google]
monk.png
110KB, 480x250px
>>55663353
If you're dealing with *nix machines all day, then yes it's pretty good.

Also if you want a powerful language to do text analysis or just prototyping something, it's a nice companion to have.
>>
File: swift.webm (933KB, 640x1186px) Image search: [Google]
swift.webm
933KB, 640x1186px
r8 my space shooter /g/
>>
>>55665139
2/10, looks like another garbageware app, would not even install.
>>
File: 1468983265884.png (2KB, 256x29px) Image search: [Google]
1468983265884.png
2KB, 256x29px
>>55660372
How can you edit a file_field button's height? I can make it wider or narrower, but not taller or shorter. At best, I've been able to create an invisible space around it that turns your cursor into a hand, indicating that when you click it something will happen, but it's just a ruse. For what it's worth I've also managed to turn the button/file_field fully invisible, partially visible, and fully invisible under normal circumstances but partially visible when you hover your cursor over it.
>>
How is F# as a functional language? Or is it just functional programming so Pajeet can feel special too?
>>
>>55665146
made this in 2 days, there's a lot to be improved.

Thanks for the honest opinion though.
>>
>>55665056
>>55665094
>>55665101

WHICH IS IT
>>
>>55665168
OCaml, if you know what's good for you.
>>
>>55665139
The enemies need to shoot back. Even better if you implement bullet hell style patterns.
>>
>>55665161
It's one of the most loved languages by people who write it.

I would use it, but it doesn't have as much support and popularity as C#.
>>
>>55665139
No explosions. 0/10
>>
>>55665181
They will shoot soon, I will keep you guys updated!

> bullet hell
holy shit dude, I'm not there yet
>>
>>55660527
>ctrl + f
>type "(You)"
>>
File: F.png (144KB, 600x500px) Image search: [Google]
F.png
144KB, 600x500px
What is wrong with my recursive algorithm? It is to detect for palindromes:


import java.util.Scanner;


public class recursivePal {

public static boolean palindrome(String word) {
boolean status = false;
String val = "";

if(word.length()==0){
status = true;
return status;
} else if(word.length()==1){
status = true;
return status;

} else if(word.length()>1){
val+=word.substring(1, word.length()-1);
palindrome(val);
}
return status;
}


public static void main(String[] args) {
Scanner reader = new Scanner(System.in);

System.out.print("Type a text: ");
String text = reader.nextLine();
if (palindrome(text)) {
System.out.print("The text is a palindrome!");
} else {
System.out.print("The text is not a palindrome!");

}
}
}



It fails on words that are palindromes like "lool"
>>
File: beer.png (34KB, 1457x265px) Image search: [Google]
beer.png
34KB, 1457x265px
Just finished the 99 Bottles of Beer problem, first problem I've solved past Hello World, feeling real proud of myself
How'd I do, /dpt/?
>>
File: 14196764332930.png (442KB, 937x960px) Image search: [Google]
14196764332930.png
442KB, 937x960px
>>55660482
>arrow notation
Consider suicide.
>>
>>55665227
where is the code that's actually detecting whether a char is the same as its counterpart on the other end?
>>
>>55665255
That code looks really roboust, and futureproof. Great job, Anon.
>>
>>55665256
not equal to?
implication arrows?
>>
File: cover-full.jpg (132KB, 540x666px) Image search: [Google]
cover-full.jpg
132KB, 540x666px
>>55665168
Perl 5, not a real FPL, but interesting at least.

Be sure to read pic related
>>
>>55665168
All three are quite different.

Lisp-like languages are free-flowing designated hacker jerkoff realms where you can create anything you can dream of but nobody else will ever be able to read your code

Haskell is a strictly-typed ultra-autistic playground where you can forget about inserting print statements into your code to debug it. It's the perfect language to drag into a conspicuous space in your office, wait however long it takes for somebody to look over your shoulder and say
"whats that lol", and turn around with a shit-eating grin saying, "I'm glad you asked. It's called Haskell. Let me tell you about monads..."

Scala is just an abortion no matter how you look at it. The worst of every world cobbled together in the most godawful syntax imaginable.
>>
>go through cs50
>paren
>open paren
>close paren
Jesus Christ is there anything Americans won't butcher
>>
You're right. I forgot about that. I'll code it in and repaste the code to show whether I got it working or not.
>>
>>55665312
>forget about inserting print statements
>what is trace
>what is unsafeperformIO
>>
File: RZPW5qw.png..png (14KB, 1401x101px) Image search: [Google]
RZPW5qw.png..png
14KB, 1401x101px
>>55665255
:)
>>
>>55665281
They are called indirect membership operators and they are harmful, use pointer dereferencing with the direct membership operator to access struct/class attributes
>>
>>55665383
ohhhh I was just responding to the derpy image you posted
>>
>>55665405
Factorial.
>>
>>55665383
why are they harmful?
>>
I need some help. i keep getting array index out of bounds on fName[x] line. what am i doing wrong!? also dont make fun of me for being a new...
String[] letters = {
"A", "B", "C", "D",
"E", "F", "G", "I",
"J", "K", "L", "M",
"N", "O", "P", "Q",
"R", "S", "T", "U",
"V", "W", "X", "Y",
"Z"
};
int length = (int) Math.floor(letters.length);
int random = (int) (Math.random() * 15 + 0);
String[] fName = new String[random];
for(int x = 0; x < random; x++) {
fName[x] = letters[length];
}
System.out.println("fName = " + fName.length);
>>
File: 1234567890-.png (346KB, 819x472px) Image search: [Google]
1234567890-.png
346KB, 819x472px
>Spend years learning OpenGL
>/v/ games dev general says it's shit and that I should have learned DX
How can I possibly go on?
>>
File: 1461787278980.jpg (169KB, 471x600px) Image search: [Google]
1461787278980.jpg
169KB, 471x600px
>>55665344 meant for >>55665260

I am trying to code this requirement in but having some issues,

I am trying to either do something like


if(word.length()>1 && word.charAt(0).equals(word.charAt(word.length()-1)){
crap here
}



but that doesn't seem to be working. Can I not do an AND in an else if statement?



} else if(word.length()>1 && word.charAt(0).equals(word.charAt(word.length()-1))){
val+=word.substring(1, word.length()-1);
palindrome(val);
}



even if I break the else-if into an else-if and an if I still get errors

    } else if(word.length()>1){
if(word.charAt(0).equals(word.charAt(word.length()-1))){
}
val+=word.substring(1, word.length()-1);
palindrome(val);
}


How do I fix this?
>>
>>55665435
opengl is better
praise be
>>
>>55665427
are you excluding H on purpose?
>>
>>55665439
>word.charAt(0).equals(word.charAt(word.length()-1))
Java is disgusting.
>>
>>55665435
>/v/ games dev general says it's shit and that I should have learned DX
>/v/
They have multiple times more shills there than here.
>>
>>55665426
furthermore, why are primitives provided to do the same thing different ways in so many languages? If the pointer should be dereferenced and then accessed as a struct, then the language should only allow you to do that
It's not even a complaint with C. It's even worse in other languages
that is what's truly harmful
>>
>>55665448
i realized i missed it after i made the post
>>
>>55665435
>/v/
>Microcuck platform
>>
>>55665435
>/v/
nuff said

why do you care what a board full of winnigger manchildren thinks
>>
>>55665435
dont listen to them, anon. we need more games for opengl
>>
File: 1460724355249.png (8KB, 225x225px) Image search: [Google]
1460724355249.png
8KB, 225x225px
>>55665439
>>55665260

I tried updating it to

    } else if(word.charAt(0).equals(word.charAt(word.length()-1))){
val+=word.substring(1, word.length()-1);
palindrome(val);
}


>>55665450
I know. I dislike it. Python is much cleaner.
>>
>>55665426
Because it's syntactic sugar which doesn't belong in the language and sometimes can even obscure your intentions in the code. If you're working with pointers use pointer notation.
>>
>>55665139
10/10 best game ever
>>
>>55665139
I like it. Reminds me of the good old days.
https://www.youtube.com/watch?v=0ie4U89t7Cs
>>
>>55665483
ok. I ask because I don't normally write C, but I had to recently and the compiler told me to use arrow notation with a pointer to a struct
>>
File: Cuckuri2.png (16KB, 148x204px) Image search: [Google]
Cuckuri2.png
16KB, 148x204px
Next up, Magical 8-Ball
>>55665279
t-thanks anon, this made me happy
>>55665378
The last one has to be a singular "bottle"
but nice
>>
>>55665457
>>55665383
>>55665256
It's called syntactic sugar.
Sure, the arrow operator isn't strictly necessary in C, but if it wasn't there, it would be a shitload worse.
a->b->c->d->e
(*(*(*(*a).b).c).d).e

If a language was truly minimal, and didn't have any syntactic sugar, it would be fucking awful to use.
>Why have all of these comparison operators when all you need is <= and >=
>a == b is a <= b && a >= b
>a < b is a <= b && !(a >= b)
>etc.

>Why have all of these boolean and bitwise operators when all you need is NAND?
>>
>>55665435
>/v/
mah nigga
>>
>>55665483
>If you're working with pointers use pointer notation
Arrow notation ONLY works with pointers to structs/unions. There is no information hiding there.
>>
>>55665536
>(*(*(*(*a).b).c).d).e
I see nothing wrong with this. You can clearly see what's what.
>>
reminder that Haskell is just syntactic sugar for C + bytecode
>>
File: 1462059217678.jpg (74KB, 604x402px) Image search: [Google]
1462059217678.jpg
74KB, 604x402px
Need help with detecting palindromes. How do I fix it? Also, do I need to test for a string being greater than 1 outside of my 2 base cases?

The error is with the else if statement


Can't invoke equals(char) on primitive type char




import java.util.Scanner;


public class recursivePal {

public static boolean palindrome(String word) {
boolean status = false;
String val = "";

if(word.length()==0){
status = true;
return status;
} else if(word.length()==1){
status = true;
return status;

} else if(word.charAt(0).equals(word.charAt(word.length()-1))){
val+=word.substring(1, word.length()-1);
palindrome(val);
}
return status;
}


public static void main(String[] args) {
Scanner reader = new Scanner(System.in);

System.out.print("Type a text: ");
String text = reader.nextLine();
if (palindrome(text)) {
System.out.print("The text is a palindrome!");
} else {
System.out.print("The text is not a palindrome!");

}
}
}

>>
>>55665584
Maybe you should read the error.
>>
>>55665554
I bet you love all of the brackets in Lisp-like languages too.
C's operator precedence doesn't lend itself well to accessing many levels of pointer members. Language designers typically don't want a bunch of unnecessary and/or annoying brackets, as it just adds a bunch of visual noise, so they add syntactic sugar to reduce the need for them.
>>
File: 55EWrE2.png (15KB, 2628x91px) Image search: [Google]
55EWrE2.png
15KB, 2628x91px
>>55665526
Fine.

At this point, I can hardly call it a 'one-liner'.
>>
Are there any must read books about functional programming?
>>
>>55665604
SICP ya fookn fagit
>>
>>55665584
See this is the kind of people who make fun of Java people who can't program at all

Your error says the problem
>>
>>55665584
>facebook meme
Please no

>>55665614
SICP is no longer relevant
t. writers of sicp
>>
File: ghostbusters.jpg (441KB, 2048x3240px) Image search: [Google]
ghostbusters.jpg
441KB, 2048x3240px
>>55665618
>SICP is no longer relevant
>>
File: required reading for (You).png (381KB, 528x528px) Image search: [Google]
required reading for (You).png
381KB, 528x528px
>>55665632
>i don't actually listen to the authors of SICP on their own book
>i just want a chance to post this dumb, completely unrelated and shitty meme
>>
>>55665592
>>55665617
I fixed it with ==.



} else if(word.charAt(0) == (word.charAt(word.length()-1))){
val+=word.substring(1, word.length()-1);
palindrome(val);
}



The logic of the problem looks correct, but it still isn't correctly detecting palindromes and I'm not sure why. Any idea where the error is occuring? It isn't a compile error at this point

import java.util.Scanner;


public class recursivePal {

public static boolean palindrome(String word) {
boolean status = false;
String val = "";

if(word.length()==0){
status = true;
return status;
} else if(word.length()==1){
status = true;
return status;

} else if(word.charAt(0) == (word.charAt(word.length()-1))){
val+=word.substring(1, word.length()-1);
palindrome(val);
}
return status;
}


public static void main(String[] args) {
Scanner reader = new Scanner(System.in);

System.out.print("Type a text: ");
String text = reader.nextLine();
if (palindrome(text)) {
System.out.print("The text is a palindrome!");
} else {
System.out.print("The text is not a palindrome!");

}
}
}
>>
>>55665632
For some reason I imagine them going into the room of a white boy who is terminally ill and going to die soon and screaming at him to check his privilege.
>>
>>55665643
sugin?
>>
>>55665643
>he non-ironically thinks SICP is irrelevant
I bet you think learning Dijkstra's algorithm is irrelevant too, since we have better path-finding algorithms.
>>
>>55665644
>>55665584
Jesus christ, that is some awful code.
>>
File: abyss.jpg (576KB, 1150x1000px) Image search: [Google]
abyss.jpg
576KB, 1150x1000px
>>55665647
I imagine pic related
>>
>>55665677
learning Dijkstra's algorithm is irrelevant too, since we have libraries
>>
>>55665679
i never programmed before so teaching myself with this problem
>>
>>55665548
>There is no information hiding there.
There is, because he initially allocates the struct instance on the stack and not on the heap, so someone somewhere in the code might get confused why he's using direct membership operator without pointer dereferencing in one block of code and indirect membership operator (direct member operator with pointer dereferencing in another block of code). Code should be readable, you should explicitly state you're using pointers to structs in your subroutines and dereference them accordingly. Of course it doesn't matter in such a small program, but coding habits tend to stick.
>>
"...Sussman said that in the 80s and 90s, engineers built complex systems by combining simple and well-understood parts. The goal of SICP was to provide the abstraction language for reasoning about such systems.
Today, this is no longer the case. Sussman pointed out that engineers now routinely write code for complicated hardware that they don’t fully understand (and often can’t understand because of trade secrecy.) The same is true at the software level, since programming environments consist of gigantic libraries with enormous functionality. According to Sussman, his students spend most of their time reading manuals for these libraries to figure out how to stitch them together to get a job done. He said that programming today is 'More like science. You grab this piece of library and you poke at it. You write programs that poke it and see what it does. And you say, ‘Can I tweak it to do the thing I want?''. ... "
>>
>>55665702
Also MIT teach introductory courses in Python

Sussman is now just another Python library fag
>>
>>55665697
jesus christ anon
your ignorance is baffling
>>
>>55665679
I am>>55665697
How would you rewrite it and where can I learn to write better code? Also, any idea where my logic error is occuring?
>>
>>55665644
bool is_palindrome_aux(const char* first, const char* last) {
if (*first == '\0') return true;
if (*first != *last) return false;

return is_palindrome_aux(first + 1, last - 1);
}

bool is_palindrome(const char* str) {
return is_palindrome_aux(str, str + strlen(str) - 1);
}


:^)
>>
>>55665701
Functions don't need to care where its arguments are allocated. They have a pointer, and they will treat it like a pointer. It's not "information hiding", it's "doesn't know".
>>
>>55665697
just ignore him, keep going

>>55665739
>Java
>>
>>55665716
take a algebraic geometry course and let me bitch you out at how much of a retard you'll be
>>
Makin' some reports to HTML files in Python.

Any good modules for HTML stylizing/marking up?
>>
>>55665644
What a pajeet. You should visit to hackerrank.com or any other educational resource, because your code is awful.
>>
>>55665756
ninja2
>>
>>55665753
ok pajeet
>>
>>55665759
Do you not have reading comprehension? This is literally the first java program I ever wrote.

Show me how to correct the logic error in my code or squarely fuck off
>>
>>55660372
Friendly reminder that the IO monad is a stateful container and has side-effects.
>>
>>55665679 >>55665716 >>55665759 >>55665772
Why not get a tripcode so we can filter you?
>>
>>55665644
You're discarding the result of the recursive call and just returning false. Also, the end index needs to be length() - 2, because otherwise the string in the recursive call still has the final character in place.
public static boolean palindrome(String word) {
if (word.length() < 2){
return true;
} else if(word.charAt(0) == word.charAt(word.length() - 1))){
return palindrome(word.substring(1, word.length() - 2);
}
return false;
}
>>
>>55665776
>is writing his first java program
>is a complete pajeet
>is judging the java language and with that the competency of the people working on it
pajeet have you ever considered killing yourself
>>
>>55665783
>we
Speak for yourself, rajeesh.
>>
>>55665791
>those parentheses
oops
>>
>>55665791
>Teaching recursive functions to someone who is a new beginner
>>
Guys, why the fuck everyone use recursive calls instead of fucking "for" cycle ?
>>
File: average java programmer.png (371KB, 800x600px) Image search: [Google]
average java programmer.png
371KB, 800x600px
>>55665820
if you understand functions you should understand recursion, but i do think this would be better done iteratively in an imperative language


>>55665798
>>55665812
>is a complete cunt
>thinks java is a good language but calls others pajeet/rajeesh
get a load of yourself, who abused you as a child?
>>
>>55665737
Your indentation bothers me.
>status = true;
>return status;
'status' is completely unnecessary.
Just
return true;

>if(word.length()==0){
>} else if(word.length()==1){
if (word.length() <= 1) {

>palindrome(val);
You're not using the return code.
It should be
return palindrome(val);


Anyway, here is how I would write the complete function:
public static boolean palindrome(String word) {
int len = word.length();
if (len <= 1)
return true;
if (word.charAt(0) == word.charAt(len - 1))
return palindrome(word.substring(1, len - 1));
return false;
}
>>
>>55665827
It's neater and more concise
If you've got TCO then it's not really any different to using a for loop, except you can return values
>>
>>55665828
>java is a good language
oh boy here we go anon is coming up with things i supposedly said
>>
>>55665830
>>55665791
Thanks for the advice. I'll modify my code.
>>
>>55665828
>>55665841
No Recursion is bad because of all the same method calls to itself and in production calls at any professional company you never ever use recursion you guys are all programming hipsters
>>
>>55665841
>It's neater and more concise
Enjoy your bloated stacks.
>>
>>55665862
TCO has been a thing for quite awhile, you know.
>>
>>55665855
>recursion is bad because of all the method calls
>>55665862
>bloated stacks
TCO
TCO
TCO
https://en.wikipedia.org/wiki/Tail_call
>>
>>55665841
>tail recursion
>neater and more concise than a for loop

that's wrong though
>>
>>55665869
>>55665841
JAVA DOES NOT HAVE TCO YOU FUCKING NEET PAJEET
>>
>>55665855
You can use recursion without worrying in languages that have segmented stacks.
>>
>>55665884
Really?
What a fucking joke of a language.
>>
>>55665506
Thanks anon! it will get better!
>>
>>55665874
it depends on the situation, which is exactly the point
"never use recursion" is unreasonable
>>55665884
we're not talking about Java you dumbass
>>
>>55665886
Java is the only language that matters Recursion is shit
>>
>>55665791
One question:
>the end index needs to be length() - 2, because otherwise the string in the recursive call still has the final character in place.

Why is this the case? I thought word.substring(n, m) would actually be substring(n,m-1)

So for instance I thought

word.substring(1,5) for "String" would return

"Stri"

where is my misunderstanding here?
>>
>>55665827
>why the fuck everyone use recursive calls
Most people (sadly) use for

>>55665855
You make no sense

>>55665820
Nothing difficult with recursion.

>>55665884
>calls others pajeets
>uses java
You use that meme wrong.
Also, Java is a language, not an implementation.
>>
>>55665884
Adding this to the reasons not to use
>>
>>55665905
Go home, Rahul.
>>
>>55665901
>we're not talking about Java you dumbass
We are, you can't just make new assumptions in the middle of a discussion.
>>
>>55660372
You can fucking bet on it.
I'm currently working on a clojure port of reversi and an AI for it. It's pretty simple, but it gives me the opportunity of using a real lot of best practices to show off to an eventual employer. Next may be a distributed crawler, always in clojure, pluggable in hadoop/spark/whatever the fuck is currently used in industry for the distributed computing.
I sometimes dream about building a browser someday, using only functional languages (High performance lisp, Haskell). Among the essential features it shall have:
- an internal command line, preferably in lisp
- a sane plugin system (not that XPI/webaddons bullshit that we currently have in ffox/chrome/ium), like the emacs one
- a retard-proof GUI made using the FRP principles, probably in Qt, since it's multiplatform
- design capable of reloading configurations and shit without the need of rebooting.
- a new rendering engine with html/css/js code hot reloading
That's one huge project. But hey, we're a little bit short on Free as in Freedom browsers here. So why not?
>>
In C++, I have a class that receives filepaths and sorts them into vectors of structs that hold certain attributes, it gets the file extension, tests if it exists, keeps track of a count of various file types, etc.

Right now if any given step fails, the function call's return is non-zero. It feels sloppy to have a temporary value, then test it. I'm certain there must be a better way to manage flags for a class's state, without making another function to call. If it's relevant, I don't know anything about exceptions and am reading about them as I write this.

If the call "fails", the program immediately terminates either way.
>>
>>55665917
I meant (0,5) not (1,5)
>>
>>55665901
when is tail recursion ever more concise?

you got a point with normal recursion where you can use the stack but tail recursion is little more than an awkward way to write a loop
>>
>>55665935
use a Maybe monad or an Either monad or even just a tuple of a value and a bool
>>
>>55665926
No we are fucking not.
>>
>>55665479
>val +=
>palindrome(val) without return

Wtf, this isn't even correct recursion style..
>>
>>55665644
I modified your code a bit (from java to C++, and changed the return type)

You don't need to return boolean , I found, if you're purpose is only to see whether something is a palindrome or not

std::string checkIfPalindrome(std::string testString)
{
bool isAPalindrome = false;
int j = testString.length()-1;
int i = 0;

if(testString.length() == 0 || testString.length() == 1)
{
isAPalindrome = true;
std::cout << "\nCongrats!\n It's a Palindrome!" << std::endl;
}
else if(testString[i] == testString[j])
{
std::cout << testString;
checkIfPalindrome(testString.substr(i+1, j-1));
}
else{ isAPalindrome = false;}

if(!isAPalindrome)
{
std::cout << testString << "\nThis isn't a palindrome, ya dingus\n";
}
return testString;
}
>>
>>55665917
My mistake. It should be length() - 1
>>
File: sort.gif (983KB, 300x300px) Image search: [Google]
sort.gif
983KB, 300x300px
guess sort
>>
>>55665967
>passing by value
>>
>>55665978
Well, I passed by value because (that I know of) you can't pass by reference in Java
>>
>>55665976
Quicksort, or something similar.
>>
>>55665985
Everything is a reference in Java as far I know.
>>
>>55665986
yea was too easy an example, the way the two sides get partitioned reveals it very quickly
>>
>>55665985
you can pass pointer values though
>>
>>55665985
>you can't pass by reference in Java
You can't NOT pass by reference in Java, except for primitives.
It's a really stupid inconsistency.
>>
>>55665985
Objects and arrays are always passed by reference in Java
>>
It makes more logical sense to use a four loop instead of recursion because recursion is just a confusing way to do things
>>
>>55665948
when you're dealing with recursive data structures.
>>
>>55665974
Here is my updated code


import java.util.Scanner;


public class recursivePal {

public static boolean palindrome(String word) {
String val = "";
int len = word.length();

if(word.length()<=1){
return true;

} else(word.charAt(0) == (word.charAt(len-1)){
return palindrome(word.substring(1, len-1));
}
return false;
}


public static void main(String[] args) {
Scanner reader = new Scanner(System.in);

System.out.print("Type a text: ");
String text = reader.nextLine();
if (palindrome(text)) {
System.out.print("The text is a palindrome!");
} else {
System.out.print("The text is not a palindrome!");

}
}
}



The error is with:


} else(word.charAt(0) == (word.charAt(len-1)){
return palindrome(word.substring(1, len-1));
}
return false;
}



I believe it has something to do with the brackets but not sure.
>>
>>55666015
>confusing

f(x) = 2 * f(x - 1)
f(0) = 1
>>
I feel like shit because I can't write a simple solution to a simple problem. But on the other hand I never programmed for more than a week. I'm slowly thinking that programming may not be for me.
>>
>>55666015
They say it depends on which way (iterative/recursive) you were introduced to first.
>>
before this gets out of hand
JAVA IS PASS BY VALUE
PRIMITIVES ARE PASSED DIRECTLY BY VALUE
OBJECTS ARE PASSED BY POINTER VALUE
IT IS NOT PASS BY REFERENCE BECAUSE THAT WOULD IMPLY THAT A FUNCTION void swap(Object a, Object b) IS POSSIBLE
PLEASE COMPROMISE ON ONE DEFINITION FOR "PASSING BY REFERENCE" BEFORE CONTINUING THIS ARGUMENT
>>
>>55666044
It takes about a year and a half to get decent at programming
>>
>>55666044
Happens sometimes to all of us, and I've been programming for years.
>>
>>55666015
>Recursion
>Confusing
You must be retarded.
>>
>>55666044
Be like me, post on here your first program and get called a retard/pajeet because your code is shitty.
>>
>>55666050
autism: the post
>>
>>55666015
just because you don't understand it, it doesn't mean that it's confusing. Git gud.
People naturally think in recursion. You know how much is 562 294 because it's 5*10^6 + 6*10^5+...+4*10^0 which is a recursively defined data structure.
>>
>>55666049
>>55666067
everyone is introduced to iterative first because it is much more easier to understand and comprehend. Using a whale loop makes things much more simple
>>
>>55666074
Never reply to me again unless you're contributing to the thread.
>>
File: 1463178629539.png (231KB, 436x512px) Image search: [Google]
1463178629539.png
231KB, 436x512px
I want to create a finite array of ArrayLists

ArrayList<Integer>[] ourBucketList = new ArrayList<Integer>[];


is giving me an error saying I can't create a generic array of arrayList. So is my only option to use two nested ArrayList? I'm trying to implement the buckets for a radix sort
>>
>>55666086
>whale loop
>>
I am not >>55666015, but the reason I'm using recursion for my first program is because I am comfortable/used to it from mathematics.

Ok back to this:
>>55666032 need help with the else statement.
>>
>>55666086
>whale loop
do you use ur mom 4 programming? XD
>>
>>55666050

What do you expect a function with this signature to do?
void swap(int* a, int* b);


or

void swap(int& a, int& b);



void swap(Integer a, Integer b)


will do exactly the same as the above functions
>>
>>55666108
XDDDD
>>
>>55666086
>because it is much more easier to understand and comprehend
No. It's just because you're using an imperative language and that is what imperative languages do.
If you were using a purely functional language, or pure mathematics, there is no concept of iteration, and you would get the recursive version.
>>
>>55666059
>to get decent
define decent
>>
>>55666029
loops still beat it

for (i=list; i = i.next; i != null)
do shit

foo(list) {
if list == null
return
do shit
foo(list.next)
}
foo(list)
>>
>>55666134
No I am using a Java Object Oriented language which Object Oriented is clearly superior than functional languages
>>
File: imagecryingpepe.jpg (3KB, 98x95px) Image search: [Google]
imagecryingpepe.jpg
3KB, 98x95px
I fixed it.

Thanks for the help.


import java.util.Scanner;


public class recursivePal {

public static boolean palindrome(String word) {
String val = "";
int len = word.length();

if(word.length()<=1){
return true;

} else if(word.charAt(0) == (word.charAt(len-1))){
return palindrome(word.substring(1, len-1));
}
return false;
}


public static void main(String[] args) {
Scanner reader = new Scanner(System.in);

System.out.print("Type a text: ");
String text = reader.nextLine();
if (palindrome(text)) {
System.out.print("The text is a palindrome!");
} else {
System.out.print("The text is not a palindrome!");

}
}
}

>>
>>55666134
>there is no concept of iteration
that's wrong
in scheme a tail recursive function is called an iterative recursion, while the ones that use the stack are called recursive
that's why you often get internal definitions of for example factorial-iter, or fib-iter
>>
>>55665584

This is a really convoluted solution bro. You definitely didn't even need the status variable. I came up with this in no time. Read Algorithms, 4th ed., study on my site: http://algorithm.zone
>>
>>55666201
>0 || 1
You could do
length < 2
>>
>>55666201
>Algorithms, 4th ed
Found the pdf for the text. Bookmarked your site. Any way can keep in contact with you bro?

Anyway, thanks
>>
is_palindrome = lambda x: x==x[::-1]
>>
>>55666201
>using the recursive ((()))
>>
>>55666114
As I said, it's a pretty thin line.
Java is not called "pass by reference" because "pass by reference" would allow you to mutate a in the caller like a = foo, which, when used like that in Java, doesn't mutate a in the caller.
The first variant would require you to write *a = foo, which is a syntax that doesn't exist in the first place, so a decade ago people came to the conclusion that it makes more sense to call this "pass by value".
>>
>>55666142
Now to it for a tree.
>>
>>55666159
dumb frogposter
>>
>>55666201
hey kendrick dope site my man !
>>
>>55666201
>kendrick

fuck off kendrick
>>
>>55666270
Did you miss the whole TAIL recursion thing?
It means you can't do shit like this:
foo(tree) {
foo(tree.left)
foo(tree.right)
}


A tail recursive solution would require a stack and accumulator, i.e. it would be fucking awkward.
>>
>>55666249
Add me on Github brethren: https://github.com/kennyledet

>>55666243
Derp, true true. Been up all night

New code
public class Palindrome {

public static boolean detect(String word) {
// word gets whittled down to 1 char,
// unless first and last characters don't match.
// if it makes it, it's considered a palindrome
if (word.length() <= 1)
return true;

if (word.charAt(0) != word.charAt(word.length()-1))
return false;
else
return detect(word.substring(1, word.length()-1));
}

public static void main(String[] args) {
// Test client
System.out.println(detect("test"));
System.out.println(detect("lel"));
System.out.println(detect("hahhah"));
}
}
>>
I understand now what /dpt/ is for. It's to be used as a toilet, because 90% of the people here are shit human beings with shit opinions. So here it goes:

*shits and pisses over all of you and your functional memes*
ahhh, that felt good :)
>>
>>55666311
And this is why your language should have segmented stacks!!
Golang to the rescue!
≡/( .-.)\ ︵╰(«○»益«○»)╯︵ /(.□. /)̨
>>
File: 6ldSHNF.png (12KB, 480x243px) Image search: [Google]
6ldSHNF.png
12KB, 480x243px
>>55666201
>this faggot

return input.SequenceEqual(input.Reverse());
>>
>>55666336
>https://github.com/kennyledet
Thanks bro. You've really helped me. Mad respect.
>>
>>55666338
figures pajeet would post something like that
>>
>>55666201
Based Kenny is back?
>>
>>55660372
Apache reports an error close to the last "break", I cannot find it.
Help?
switch ($_FILES['filename']['type']) {
case 'image/jpeg': $ext = 'jpg';
break;
case 'image/png': $ext = 'png';
break;
case 'image/gif': $ext = 'gif';
break;
default: $ext = '';
}
>>
>>55666346
Lel, I assumed he was trying to do it without using the obvious reverse method, because that's not recursive.
>>
>>55666311
Yes you can, tail call optimization handles that case just fine. You're don't have to accumulate anything if you simply want to traverse the tree.
>>
>>55666387
It is clearly not a tail call, TCO won't do shit.
>>
>>55666387
>tail call optimization handles that case just fine
is foo(tree.left) a tail call?
>>
>>55666387
>he does not know what TCO is
>>
>>55666311
this doesn't require a stack

all you need are registers for this
>>
>>55666350
Np man, we all gotta look out for each other.
>>
>>55666142
It's bad because your code is shit.
>>
Is there a go-to solution for a tag database akin to leveldb? I'm thinking of writing simple non-grabby hydrus clone of personal use, probably learning a new language in process.
>>
why is coding anything good and cool so difficult?
>>
>>55666416
I'm beginning to think that everyone who complains about a (proper iterative) language not having TCO here, is some first-year CS student who thinks it's pixie magic that works on any recursive function.
>>
>>55666426
Then post better one as a counter-example.
>>
>>55666418
Exactly brother.
>>
>>55666263
>"pass by reference" would allow you to mutate a in the caller
You can mutate a by doing a.setValue(newValue)
>>
>>55666460
um, excuse you, but I'm very smart for someone in my year. I have read the first pages of The C Programming Language and SICP, and I read a rant that Linux Torvalds once made about C++ so now I hate it. All my community college teaches say I'm going to go very far, so I think I know what a TCO is, okay?
>>
>>55666367
Halp me. cunts
tell me whats wrong
>>
>>55666405
>>55666411
Depends on the definition your shitty professors teached you. A tail call for me is a recursive call that doesn't need to process the result of further calls.

>>55666416
Explain it then, genius.
>>
>>55666508
Sure you can, but that isn't what I was talking about.
As I said, it's a very minor difference and "pass by value" as definition in Java is preferred over "pass by reference" to not make people assume that a = foo mutates a in the caller.
>>
foo(){
foo()
foo()
actually this needs a stack to remember where to jump next right, unlike
foo(){
foo()


or am i wrong
>>
>>55666555
dunno, but maybe you have to have break in the default
default: 
$ext = '';
break;
>>
>>55666580
first one calls itself twice
>>
>>55666565
>Depends on the definition your shitty professors teached you
There is a well known as well as well accepted definition. So it does not depend on what your professor teaches you.

>A tail call for me
A man for me is a person who has a vagina.

>Explain it then, genius.
Duck duck go it.
>>
New thread
>>55666624
>>
>>55666581
rly dude?
>>
>>55666565
you're wrong and humiliating yourself at this point. please don't reply to this post (it'll just fuel more pointless posts) and go read on tail call optimisation

that piece of code does have a taill call in foo(tree.right), but foo(tree.left) is not a tail call because it still has to return control to the caller for foo(tree.right) to happen. while a smart compiler might be able to make this into a tail call anyway, if it determines that foo(tree.left) will not affect foo(tree.right), this is not what anyone would think of when talking about tail calls. tail calls on trees are notoriously less clear than tail calls on lists - you may be interested in reading about continuation-passing as a way of handling this.

have a nice day
>>
>>55666646
it's php after all, you have to expect everything
>>
>>55666658
>falling for the php meme
>>
>>55661691
>>55662236
I like it actually. It lets you see the difference between static functions (associated functions in Rust) and methods.
>>
>>55665600
Lol that looks disgusting
>>
File: 1466371935880.png (2MB, 1080x1920px) Image search: [Google]
1466371935880.png
2MB, 1080x1920px
It's not possible to implement a counter in a recursive function? You would be creating new counters all the time. So in those instances it would make sense to try to implement using loops.
>>
>>55667619
wat

if you want to count it's just 1 + func(), or func(acc+1)
>>
>>55667657
I want to count all the lines of code I have ever written and implemented a recursive function to iterate through all my files until it finds a .java file, in which case I iterate through that with a loop and count the lines.
>>
>>55667682
Of course you can do that recursively
e.g. something like:
int func(file f)
if (f.readline() != EOF)
return 1 + func(f);
else
return 0;
}


makes no sense to do it that way in Java of course
>>
>>55664411
So a compiler can do macro expansion only at compile-time. There are no "macro values" so there is no argument you can give to apply. You could make a macro that applies a macro to a sexp though
>>
>>55665139
Needs an esoteric scoring system so only the best elite can get the high scores
>>
>>55666311
There are some tail-recursive tree algorithms, like binary search
>>
Reminder: Passing a pointer is not pass by reference. It is passing a pointer by value. This is the same in Java, even if you can't do pointer arithmetic with your references
>>
>>55666565
>a tail call for me is [not a call that happens at the tail]
>>
>>55667749
this will never terminate
Thread posts: 359
Thread images: 39


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.