[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 21
File: Black_Lagoon_012b.jpg (44 KB, 848x480) Image search: [Google]
Black_Lagoon_012b.jpg
44 KB, 848x480
old thread >>53982596

what are you working on, koders?? xDDDD
>>
>>53991003
first for koding
>>
>>53991003
pls don't stare at Revy's thighs thanks
>>
>>53991003
Max of two numbers

How can I do it in sepples?
>>
>>53991039
She'll break your neck before you get a chance
>>
>>53991046
int maxInt(int a, int b){
if(a > b) return a;
else return b;
}
>>
>>53991104
now THIS is koding
>>
>>53991104
Where do I handle the case that a < b?
>>
>>53991137
the function's 2 lines long. figure it out.
>>
>>53991137
The second return statement handles it retard. If it doesn't return in the first if then b HAS to be bigger than a.
>>
anyone know how to find the limits for each board? I'm pretty sure some of these are outdated:
#  /abc/ - Description|threads/page,pages,bump limit,image
/3/ - 3DCG|15,10,300,150
/a/ - Anime & Manga|15,10,500,250
/aco/ - Adult Cartoons|15,10,300,150
/adv/ - Advice|15,10,300,150
/an/ - Animals & Nature|15,10,300,150
/asp/ - Alternative Sports|15,10,300,150
/b/ - Random|15,10,500,250
/biz/ - Business & Finance|15,10,300,150
/c/ - Anime/Cute|15,10,300,150
/cgl/ - Cosplay & EGL|15,10,300,150
/ck/ - Food & Cooking|15,10,300,150
/cm/ - Cute/Male|15,10,300,150
/co/ - Comics & Cartoons|15,10,500,250
/d/ - Hentai/Alternative|15,10,300,150
/diy/ - Do-It-Yourself|15,10,300,150
/e/ - Ecchi|15,10,300,150
/fa/ - Fashion|15,10,300,150
/fit/ - Fitness|15,10,300,150
/g/ - Technology|15,10,300,150
/gd/ - Graphic Design|15,10,300,150
/gif/ - Adult GIF|15,10,300,150
/h/ - Hentai|15,10,300,150
/hc/ - Hardcore|15,10,300,150
/his/ - History & Humanities|15,10,300,150
/hm/ - Handsome Men|15,10,300,150
/hr/ - High Resolution|15,10,300,150
/i/ - Oekaki|15,10,300,150
/ic/ - Artwork/Critique|15,10,300,150
/int/ - International|15,10,300,150
/jp/ - Otaku Culture|15,10,300,150
/k/ - Weapons|15,10,300,150
/lgbt/ - Lesbian, Gay, Bisexual, & Transgender|15,10,300,150
/lit/ - Literature|15,10,300,150
/m/ - Mecha|15,10,300,150
/mlp/ - Pony|15,10,500,250
/mu/ - Music|15,10,300,150
/n/ - Transportation|15,10,300,150
/news/ - Current News|15,10,300,150
/o/ - Auto|15,10,300,150
/out/ - Outdoors|15,10,300,150
/p/ - Photo|15,10,300,150
/po/ - Papercraft & Origami|15,10,300,150
/pol/ - Politically Incorrect|15,10,300,150
/qa/ - Question & Answer|10,11,1500,250
/r/ - Request|15,10,250,150
/r9k/ - ROBOT9001|15,10,500,150
/s/ - Sexy Beautiful Women|15,10,300,150
/s4s/ - Shit 4chan Says|15,10,300,150
/sci/ - Science & Math|15,10,250,150
/soc/ - Cams & Meetups|15,10,500,250
/sp/ - Sports|15,10,500,250
/t/ - Torrents|15,10,250,150
/tg/ - Traditional Games|15,10,300,150
/toy/ - Toys|15,10,300,150
>>
>>53991219
/trv/ - Travel|15,10,250,150
/tv/ - Television & Film|15,10,300,150
/u/ - Yuri|15,10,300,150
/v/ - Video Games|15,10,500,250
/vg/ - Video Game Generals|15,10,750,375
/vp/ - Pokémon|15,10,300,150
/vr/ - Retro Games|15,10,500,250
/w/ - Anime/Wallpapers|15,10,300,150
/wg/ - Wallpapers/General|15,10,300,150
/wsg/ - Worksafe GIF|15,10,300,150
/wsr/ - Worksafe Requests|15,10,300,150
/x/ - Paranormal|15,10,300,150
/y/ - Yaoi|15,10,300,150


I guess /g/'s bump limit is 310, right? so others boards probably are too?
>>
>>53991233
/g/'s is 310, I think /b/ is still 300, so it's a crapshoot. You can just use the bumplimit flag on 4chan's API if you're building a program.
>>
>>53991003

I say, steady on, OP actually chose a decent character.

Is the end nigh?
>>
>>53991251
hmm.. I don't know anything about the api. can it be accessed with standard a POST/GET request?
>>
>>53991286
... did you look into this at all before posting?
>>
>>53991219
$ wget -O- https://a.4cdn.org/boards.json | python -m json.tool > boards.json


Then just go read boards.json, here's /g/:

        {
"board": "g",
"title": "Technology",
"ws_board": 1,
"per_page": 15,
"pages": 10,
"max_filesize": 4194304,
"max_webm_filesize": 3145728,
"max_comment_chars": 2000,
"max_webm_duration": 120,
"bump_limit": 310,
"image_limit": 150,
"cooldowns": {
"threads": 600,
"replies": 30,
"images": 60,
"replies_intra": 60,
"images_intra": 60
},
"meta_description": "&quot;/g/ - Technology&quot; is 4chan's imageboard for discussing computer hardware and software, programming, and general technology.",
"is_archived": 1,
>>
I always loved those interactive flash sites. I thought I would try one with js. So here's what I was working on this week.

http://www.particleplayground.com
>>
>>53991104
int maxInt(int a, int b)
{
return (a > b)? a : b;
}
>>
File: doubleandaphro.jpg (265 KB, 1200x1672) Image search: [Google]
doubleandaphro.jpg
265 KB, 1200x1672
Haskell is a meme language.
>>
>>53991296
what, you mean figure something out by myself? that's too hard, and I'm too lazy.
>>
>>53991299
>boards.json
exactly what I needed. thanks. :)
>>
>>53991375
Well yeah if you want to absolutely destroy readability
>>
>>53991414
Okay please do me a favor. Please tell me if you're trolling. Please. Just this once be honest. Let me know.
>>
template <class T>
T min (const T x, const T y) {
if (x < y) {
return x;
} else {
return y;
}
}
>>
>>53991382
oh no she is going to get the dutch snake isn't she.
>>
>>53991414
This, it took me 30 minutes to figure out what that piece of code meant
>>
When I'm overloading a standard arithmetic operator in c++ I do something like
Class Class::operator + (Class other)..

But when I need to overload the stream operators << and >> I mustn't or can't put Class::operator << (...)...
Is that because it is always implied that the right operand for those is an instance of istream, ostream... etc?
>>
>>53991440
And again
template <class T>
T min (const T x, const T y)
{
return (x > y)? x : y;
}
>>
>>53991467
It's the same thing.
>>
>>53991450
Yeah. I actually forgot what it was I even wrote. Fuck. Now I have to start over.
>>
Ok guys lets try this again.
We create a hello world program but can only type one line. Make sure you don't close the brackets to early, ill start:
#include <iostream>
>>
>>53991475
It compiles to the same thing, true.

One is better written than the other and easier to read if you're not a monkey.
>>
>>53991450
>30 minutes to figure out max
git gud, fgt
>>
>>53991445
https://www.youtube.com/watch?v=6F87Zc_92js&t=4m44s
>>
>>53991467
max :: Ord a => a -> a -> a
max a b = if a > b then a else b
>>
>>53991485
using namespace std;
>>
>>53991485
print hello world;
>>
>>53991003
Good character choice. Keep on the good work.
>>
>>53991500
He lectures her outside after that scene. I can't find it on Youtube though. Would've been perfect for my joke.
>>
>>53991515
#define false 1
#define true 0
>>
File: Untitled.png (41 KB, 703x880) Image search: [Google]
Untitled.png
41 KB, 703x880
I'm running on 24 hours without sleep, trying to whittle away an addressbook program, and I feel like I don't know a goddamn thing about anything.

I get a compile error because I didn't declare pic related in the function it's sitting in. The problem is, I'm lost on how to create a vector and then have my functions point to and use that properly

Am I going about this entirely the wrong way? Is there an easier/better method of creating menus/submenus?

code here: http://codepad.org/hGj3LoMb
>>
>>53991525
wp

void main()
>>
>>53991548
>>53991525
>>53991515
We haven't failed yet, maybe we can do this. If we do I will post source code to my viruses
>>
>>53991566
please please please please
>>
>>53991548
{
>>
{
>>
>>53991495
Only a monkey find one easier to read.
>>
Extra scopes. I like it.
>>
>>53991538
>I'm running on 24 hours without sleep,
>Am I going about this entirely the wrong way?
Yes.
>>
>>53991538
vector <string> vecNames;
do{
switch ( showMainMenu() ){
case 'E': selectEditMenu (&vecNames); break;


void selectEditMenu (vector <string> &vecNames){
do{
switch ( showEditMenu() ){
case 'E': editFunc (); break;
case 'A': addFunc (vecNames); break;
>>
>>53991569
?
>>
>>53991629
it's okay broski I've hooked an IV of caffeine to my arteries
>>
>>53991586
You go ahead, I'm going to stop now to avoid messing this up.
>>
>>53991587
No. Just because they're both easy to read does not mean one isn't easier to read. Having to scan one clean line of code to determine what it's doing is better than scanning two.

cout << "hello world"; }}
>>
>>53991673
Monkey.
>>
File: 1418704633819.png (598 KB, 722x525) Image search: [Google]
1418704633819.png
598 KB, 722x525
>>53991500
>Dub
>>
>>53991698
Unscrupulous duct tape spaghetti code writing monkey.
>>
>>53991673
>>53991467
>>53991495
this

>>53991698
kill yourself
>>
>>53991706
Monkey.
>>
>>53991698
ook ook
>>
at what point can you call yourself a programmer?
>>
>>53991758
When you write code
>>
>>53991758
When you know how to code.
>>
Is it possible to send a keydown(button) or keyup(button) command via the sendkeys method in C#? Or do I have to use postmessage or something?
>>
>>53991758
I prefer the term software alchemist
>>
>>53991767
I wrote fizzbuzz, am I a programmer?
>>
>>53991807
Did you use the ternary operator?
>>
>>53991850
refresh me
>>
>>53991900
If you don't get your fizzbuzz program down to one line with nested ternary operations you disgust me.
>>
>>53991985
Do it in C++
>>
File: r8 pls.png.png (17 KB, 740x376) Image search: [Google]
r8 pls.png.png
17 KB, 740x376
r8 my code pls
pic related
>>
>>53991767
>>53991774
Way off. You're describing a coder. A. Programmer knows how to structure a program.
>>
>>53992073
>A. Programmer knows how to structure a program.
LOL. no.
>>
>>53992073
You mean like

struct Program {

I am the very model of a modern Major-General,
I've information vegetable, animal, and mineral,
I know the kings of England, and I quote the fights historical
From Marathon to Waterloo, in order categorical;
I'm very well acquainted, too, with matters mathematical,
I understand equations, both the simple and quadratical,
About binomial theorem I'm teeming with a lot o' news,
With many cheerful facts about the square of the hypotenuse.

}
>>
>>53991179
or equal to it
>>
>>53991758
depends on how smug you are
>>
>>53992092
Do you actually have a counterpoint?
>>
>>53992209
No, you've put me into a fugue state.
>>
>>53992053
#include <iostream>;
#include <string>;

void main() {for (size_t i=1;i<=100;i++) {std::cout << (!(i % 3)? (!(i%5)? "Fizzbuzz" : "Fizz") : (!(i%5)? "Buzz" : std::to_string(i))) << "\n";}}
>>
>>53992281
>#include <string>;
>;
>>
>>53992209
Most programmers are shit at structuring.
>>
>>53992321

Looking at anything GNU will reinforce that point.
>>
>>53991281
The end of trapposting? Hopefully
>>
>>53992069
Styke: good
Usefulness: good
Reinventing the wheel: yes
>>
>>53992304
I tried to put the preprocessors on one line too and it didn't work, I forgot to delete the semicolons. You caught me.
>>
>>53992365
thanks, I was really produ of it
>>
>>53992365
How did I reinvent the wheel?
>>
>>53992321
Okay, maybe I should say programmers know a bit more than coders about program structure
>>
>>53992448
if you write programs you are a programmer.
if you write code, you are a coder.
If you have different personal definitions for these words and spaz out when other people don't share them, you are autistic.

simple
>>
What are the best books on Python for an intermediate programmer?
I'm coming from a background of C/LiSP.
preferably reference style, but well written is more important.
>>
>>53991003
nothing but thanks for asking appreciate it
>>
>>53991698
D.
>>
File: i know all the memes.jpg (97 KB, 245x337) Image search: [Google]
i know all the memes.jpg
97 KB, 245x337
I just opened up a book on data structures and tried implementing hashtables without reading the whole chapter.
rate my hashing function!
int hash(const char *key, int table_size)
{
const unsigned len = strlen(key);
unsigned hash = 0;
unsigned i;
for (i = 0; i < len; i++)
hash += (hash * 37) + key[i];
hash %= table_size;
if (hash < 0) /* if overflow */
hash += table_size;

return hash;
}
>>
>>53991233
ok, using the boards.json file, I've found that most boards have a 310 bump limit, but 20 have a 300 limit, and 9 have a 500 limit, with /vg/ having the highest at 750.

most boards have a 150 image limit, but 27 have a 250 image limit, and /jp/ has the highest at 300.
>>
>>53992770
wtf, why does jp have a 300 image limit?
>>
>>53992788
guess who owns 4chan now?
>>
>>53992788
every time I go there, the most popular threads are 2hu image dumps and "pictures from japan"
>>
>>53992770
I still don't get the 310 vs 300 bump limit.
>>
>>53992849
Why they have a bump limit at all confuses me. It just gets archived anyways.
>>
>>53992892
well it's a good thing for threads to eventually die and need to be recreated. threads with 1000s of replies really suck for loading (cpu/ram) and navigating.
>>
>>53992892
It removes old content. That's part of what makes 4chan, 4chan.
>>
>>53992926
this
>>
What's harder

writing a cycle-accurate sega saturn (or ps2) emulator
or
writing a standards-compliant c++ compiler?
>>
File: php_origins.png (335 KB, 1280x720) Image search: [Google]
php_origins.png
335 KB, 1280x720
>>53992762
php tier
>>
>>53993020
c++ compiler
>>
What are some good gentle introduction-level books to reinforcement learning and q-learning?
Also, what short books which overview the modern state of AI are considered the best in the field?

I'm looking for something under ~400 pages.
>>
>>53993020
These look like equals buy I lean toward 100% standard compliant C++ compiler. ps2 is a very challenging platform for emulation though

>mfw prime autists waste their time writing emulator instead of writing general AI
>>
>>53993020
proooobably a fully fledged compiler, but both are one of those projects that are never finished
>>
>>53993114
>>53993111
>>53993020
That's what I was thinking myself.

Tons and tons of hours have been put into c++ compilers and is there still a fully standards compliant one?

Whereas ps2 and saturn emulation is incredibly complex but not nearly as many hours have been put into it.
>>
>>53993136
is there even a fully standards compliant one?*
>>
>>53993020

Probably writing a C++ compiler, given that the syntax is literally undecidable, among other things.
>>
>>53992499
I have Learning Python and like it a lot, very detailed.
>>
Integer a = Optional.of(2)
.map(x -> null)
.orElse(2);

wont compile -
error: incompatible types: Object cannot be converted to Integer
.orElse(2);

wtf java?
>>
>>53993156
>given that the syntax is literally undecidable

thanks stroustrup
>>
>>53993156
true
I wonder if it's possible to formally specify an emulator, considering that the programs it runs are also undecidable.
>>
File: qlearning.gif (5 KB, 610x250) Image search: [Google]
qlearning.gif
5 KB, 610x250
>>53993105
>What are some good gentle introduction-level books to reinforcement learning and q-learning?
literally this https://webdocs.cs.ualberta.ca/~sutton/book/the-book.html (or this pdf http://people.inf.elte.hu/lorincz/Files/RL_2006/SuttonBook.pdf)

Q learning is very easy though, fits in <10 lines.

Current state of art in reinforcement learning is DQN http://www.nervanasys.com/demystifying-deep-reinforcement-learning/ and (recently) A3C http://arxiv.org/abs/1602.01783

Also there is completely different line of work based on dumbing down the theoretically optimal reinforcement learner https://en.wikipedia.org/wiki/AIXI : https://github.com/moridinamael/mc-aixi


It's cool that you are interested in RL, senpai. it's very rare to meet someone like you on /g/ I only remember a couple of people including myself mentioning RL here. What do you want to do with RL?
>>
>>53993153

Not really. Most C++ compilers will tell you to fuck off of your templates form infinite loops -- or more specifically, if the recursion depth gets too high, since they can't tell if there's an infinite loop.
>>
>>53993020
Writing a fully compliant c++ compiler is is impossible, because some of the standards aren't defined so that they are implementation defined. But if you actually studied programming languages, you would know that.
>>
File: sweat pepe.jpg (55 KB, 500x473) Image search: [Google]
sweat pepe.jpg
55 KB, 500x473
>about 7 hours ago the girl who convinced me to send her my C program asked me to send her my java program for the final project, after i already finished telling her about the general way to do it
> i didn't respond
>fastfoward to now and she sends me "Just kidding i got it!"
is she being sarcastic? is she mad? what do i say now
>>
>>53993156
Agreed. Look at this shit
>>
>>53993136
>Tons and tons of hours have been put into c++ compilers and is there still a fully standards compliant one?
desu there was a paid course about it http://www.cppgm.org/ but looks like it is abandoned.
>>
>>53993208

Well, more or less, think of it like this: With a C++ compiler, you are writing an interpreter for constant expressions and template metaprograms in addition to also writing a compiler.
>>
>>53993230
>being this fucking dense
she was trying to copy your final project, most likely by submitting it with no changes
she probably managed to find some other beta orbiter to copy from
>>
>>53993219
>if the recursion depth gets too high, since they can't tell if there's an infinite loop.

What does this mean for template's turing completeness?
>>
>>53993236
>c++ grandmaster
what the literal fuck
>>
>>53993264
then why'd she even bother following up with me 7 hours later? i basically told her "fuck off" by not replying for 7 hours
>>
>>53993230
She probably is too stupid to change the code, you are going to be caught for cheating on the C code. Might as well ask for a BJ for the Java since you are going to fail anyway.
>>
>>53993286
>then why'd she even bother following up with me 7 hours later?

She's a woman and they are insane.
>>
>>53993274

What the spec allows for and what the compilers that exist will actually allow you to do are not the same thing.

Although I think some may allow you to specify that there is no maximum recursion depth in the command line arguments.
>>
>>53993290
i didn't really help her with the java, i just told her not to use the book since it's shit. how do i go about getting the blowjob?
>>
entry 99986: key 'qoMz)lX%$bquM8o<GG@^wUZj= ]f7x'
entry 99987: key '>`Zq1^o&fU$RkcSI-?ji}kbV>Ugh,s'
entry 99988: key '(null)'
entry 99989: key 'Ul<f*mHoSySzp]LmS~r9"QLp[2-C\I'
entry 99990: key '#sOvR-+@fxX?;:'N-r)q*oM[bmiY8z'
entry 99991: key '01a3Uxzzni7sU*p.S>xbaJHzrrUHF;'
entry 99992: key '(null)'
entry 99993: key 'EbY`~jnw~}{0`[vx"t.u39f~o@`nUC'
entry 99994: key '(null)'
entry 99995: key 'ek5g/{zrfpqu#?,}"Py+DGtp&v][^c'
entry 99996: key '(null)'
entry 99997: key '(null)'
entry 99998: key 'kPV%nu+q]Q^|N%}/.X3C>((vEnmYq|'
entry 99999: key 'Yb-MpBk'V7s)),+dGc]pQDIBS{-W<3'


I wrote a hashtable implementation, but I don't know how to handle hashtable collisions.
I tried incrementing the hash number and letting it try again until it's successful, but this just segfaults immediately.

help
>>
>>53993322
>what the compilers that exist will actually allow you to do
There is nothing they forbid me from doing because I can use preprocessors and inline asm.
>>
>>53993274
Nothing. There is a limit to recursion in a computer (stack overflows), for instance, but they are Turing machines. Turing machines are ideal, real machines only need to approximate Turing machines to receive that specification. Given enough resources templates are Turing complete, so they are complete.
>>
>>53993369
google: open addressing hash tables
>>
Currently implementing a Java EE web application which delegates most of its work to R which delegates most of its work to FORTRAN.
>>
>>53993369
https://en.wikipedia.org/wiki/Linear_probing
>>
>>53993369
Make each bucket a list. All keys with the same bucket get shoved into the list. Or if you really want to make it super efficient at high load make the lists red-black trees instead.
>>
>>53993380

Mate, I'm saying there are valid C++ programs that modern C++ compilers will fail to compile and give errors for. A correct interpretation of such programs might result in the compiler never terminating, where instead, they will complain that the recursion depth is too high.
>>
>>53993369
there are two basic ideas
- store a linked list in each bucket, when retrieving, do a linear search of the list for the given key

- design a scheme to map a key to multiple positions in the hash table (e.g. repeated hashing), when retrieving search through the possible positions for the given key
>>
>>53993453
struct _hash_table {
char **table;
int table_size;
};


right now my hashtable is implemented as an array of char arrays.
Should I make it an array of linked lists then?
>>
>>53993436

Sounds enterprisey. I like it.
>>
>>53993369
If you want to see a real dictionary implementation

https://github.com/apple/swift/blob/master/stdlib/public/core/HashedCollections.swift.gyb#L44
>>
>>53993469
i guess you could generalize the first case as putting any kind of search capable data structure in each hash bucket
>>
>>53993331
You have to be careful about it. Don't want it in writing or any witnesses in case she claims harassment. Then just say that's your price for it. Simple enough. If she says no, then let her fail. And then tell her to git gud at Java.
>>
>>53993491
>implying they need evidence
don't you know?
a woman's testimony is worth 10x more than that of a man
>>
>>53993474
Yeb. Linked lists are pretty easy to implement if you haven't done so already in your study of data structures.
>>
in languages where there is implicit deferencing of pointers, is it still possible to do pointer arithmetic?
>>
>>53993491
This. If she has doubts about it, remind her that prostitutes exchange sex for favours all the time.
>>
>>53993477
It's actually an academic thing but the PI decided it ought to be a web application.

One grad student left it unfinished and we decided I might as well make it work properly to squeeze out a publication.
>>
>>53993520
Yeah, do it explicitly.
*(&var + 2)
>>
>>53993526
don't call her a whore
don't even try alluding that she is a whore, it's gonna blow up in your face
>>
>>53993543
wow that looks painful
>>
>>53993538

At least it'll demonstrate how things really work. Everything is glued together and there's code in codebase that predates the revolutionary war.
>>
>>53993491
but she texted me that she already finished the java project
>>
>>53993559
Wait until you see how a Berkley socket is initialized :^)
>>
>>53993575

Text her a pic of your cock and ask if she wants to finish that, too.
>>
>>53993586
my phone doesn't take pictures, it's a track phone. do i send it to her school email instead?
>>
>>53993575

Then you have failed to get the blowjob.
>>
>>53992762
>if (hash < 0) /* if overflow */
hash is unsigned though, so it can't possible be below zero. Also unsigned overflow is defined, so you probably don't even need to worry about it in this situation.
>>
>>53993575
Probably lying to save face. She doesn't want you to think she is retarded.
>>
>>53993436
agile as fuck
>>
>>53993609
2 years ago i had a girlfriend and she told me she wanted me to talk dirty to her as we were having sex, so i called her a fucking retarded cunt and she broke up with me that same week
>>
File: 1448489938337.png (375 KB, 1920x1200) Image search: [Google]
1448489938337.png
375 KB, 1920x1200
When do you choose Recursion over a Loop?
>>
>>53993230
what kind of class mixes C and java?
>>
>>53993647
when they aren't equivalent without whole-program changes
>>
>>53993598
yes
>>
>>53993621
You didn't do anything wrong
>>
File: 1447465495851.png (2 MB, 1920x1080) Image search: [Google]
1447465495851.png
2 MB, 1920x1080
>>53993659
Can you elaborate a tad bit more. I'm not sure I entirely understand.
>>
>>53992762
The hash function shouldn't do the modulo.

I'd give it a 5/10, 8/10 because you're a beginner. You know to factor the position of each of the elements into the computation, so you aren't retarded, but short strings will have small hashes, it's biased. Most hash functions make heavy use of xoring and bit rotating for the mixing step.
>>
>>53993647

When trees/graphs are involved.
>>
>>53993230
did you actually ask her for sex and what did she say
>>
>>53993647
the better question is when do you choose a loop over recursion, and the answer to that is when it would otherwise be tail recursion. tail recursion is when the recursive call is the last thing done.
void multiply(int a, int b){
if(b == 1) return a;
return a + multiply(a, b-1);
}


is tail recursion and can be very easily changed to a loop. in fact, your compiler may optimize it to a loop automatically.
>>
>>53993647
When doing anything with trees.
>>
>>53993647
When the problem really favors recursion over iteration. Calculating the fibonacci sequence for example, or building and traversing tree data structures. Research your problem and see how it looks both ways then implement whichever is cleaner.
>>
>>53993647
ALWAYS A LOOP

ALWAYS
>>
File: fuck.jpg (44 KB, 600x600) Image search: [Google]
fuck.jpg
44 KB, 600x600
What's /dpt/'s opinion on Rust and Go?
>>
>>53993656
she's in 2 classes with me, one uses c and the other java
>>53993698
no but i did call her not today and she didn't pick up, then texted later that she had left her phone downstairs
>>
>>53993679
Think about how you would convert a function that calls other functions recursively into a loop.
>>
>>53993700
>a +
That's not tail recursion.
>>
>>53993704
Doesn't the Fibonacci sequence actually work better with a loop since you actually have the previous iteration at hand.
>>
>>53993704
>fibonacci
>recursion

haha
>>
>>53993621
Girls don't know what they want. Switches before bitches.
>>
>>53993647
Whichever would be simpler. Will avoid recursion if I can't be sure there won't be a stack overflow.
>>
>>53993704
>Calculating the fibonacci sequence for example
are you trolling? recursive fibonacci is the worst way to do fibonacci in both time and space.
>>
>>53993726
It was most likely subtle bait
>>
>>53993726
recursive fibonacci is what a sperg would do after reading the mathematical definition, the intuitive naive solution is obviously to do it iteratively like 1 1 2 3 5 8 etc
>>
>>53993713
dead end langugaes.
>>
>>53993726
Yeah, guys retarded. Only justified use of a recursive fibonacci is if you do memoization.
>>
>>53993700
how about

void state_a() {
if something {
state_b();
} else {
state_c();
}
}
>>
How do I learn FORTRAN?
>>
>>53993725
yeah it is. the a+ doesn't mean it still doesn't have a tail call
>>
>>53993713
Rust *could* replace C, but won't. Go's core-language concurrency is nice, but the rest of the language blows. Both will be forgotten in 5 years.
>>
>>53993773
not sure what that has to do with recursion vs loops, you're just calling one of 2 different functions based on the value of something
>>
>>53993754
>>53993745
It's actually simpler to derive the optimized logarithmic algorithm if you start with the recursive definition.
>>
anyone know something fun to do in x86 assembly, for a total beginner?
>>
>>53993726
>>53993730
>>53993739
I meant factorial. Had a retard moment.
>>
>>53993788
Imagine a complex state machine, where each state is a function that calls other states recursively. That's what I was trying to convey.
>>
>>53993775
Yes it does.
Your code is equivalent to
int multiply(int a, int b){
if(b == 1)
return a;
int tmp = multiply(a, b-1);
return a + tmp;
}

Your recursive call must return to the function to do 'a +' with the result, making the recursive call not the last thing done.
>>
>>53993803
for factorial the iterative solution is also the intuitive one for fuck's sake
>>
>>53993803
recursive factorial has similar time and space issues as recursive fibonacci, they just grow slower.
>>
>>53993821
I'd say the iterative and recursive versions of both of them are pretty intuitive.
>>
>>53993847
doesn't justify using recursive function calls. if you ever find yourself wanting to use recursion - there's probably a better way to design your function.
>>
>>53993867
looks decent enough
>>
>>53993867
Please take consumershit out of here
>>
>>53993860
Some things are just much more natural and concise to do recursively.
You seriously can't argue that iteratively traversing a tree is better, especially since the stack only grows log(n) frames for a binary tree, meaning you would need a fuckhuge tree for stack overflow to be a problem.
>>
>>53993860
That's way too broad of a statement. I wouldn't want to write a set of ast traversal functions into a single loop unless I absolutely had to. And how would I rewrite a program written in CPS iteratively?
>>
>>53993860
Okay, tell me a better way to traverse a binary search tree without recursion.
>>
>>53993897
>You seriously can't argue that iteratively traversing a tree is better

As much as I shitpost about recursion being obsolete, iterative tree traversal is cancer.
>>
>>53993897
an explicit stack to iteratively traverse a tree makes perfect sense. and only memers use trees anyway
>>
>>53993917
Here is your (You)
>>
>>53993700
>your compiler may optimize it to a loop automatically.

No. The compiler sees through your functional garbage fapping and just uses the correct intrinsic:

multiply(int, int):
cmp esi, 1
je .L3
sub esi, 1
imul esi, edi
.L2:
lea eax, [rsi+rdi]
ret
.L3:
xor esi, esi
jmp .L2


>imul
>>
>>53993810
shut up nerd
>>
>>53993957
rekt
>>
File: costanza angry shig.jpg (42 KB, 658x370) Image search: [Google]
costanza angry shig.jpg
42 KB, 658x370
>>53993986
>>53993957
I SAID SHUT UP NERD
>>
>>53993917

>Only memers use trees
The world is built on abstract syntax trees.
>>
>>53993959
>>53994001
Dumbass
>>
>>53994010
Nerd. i'm objectively right btw
>>
>>53993647
Isn't there always an easy way to write it as a loop rather than recursively? Like not CS 101 easy but easy.
>>
>>53994032
Professor is going over recursion, and I was messing around with permutations on my own free time for a challenge at Codeeval and everything I read up on creating permutations stressed that recursion is easier in that scenario.

Before that I thought what you thought, now I'm not so sure.
>>
recursion is gay
>>
>>53994112
do you even program at all?
>>
how hard is C++ really if it's my 3rd or 4th language? not to git gud, just to learn the basics, like get through an introductory textbook
>>
File: learnC++.png (152 KB, 744x638) Image search: [Google]
learnC++.png
152 KB, 744x638
>>53994133
Apply this one easy trick for each sub set of the language.
>>
>>53994133
Do you know C?
Because C is so simple and intuitive and that you won't want to use C++ after learning C.
>>
>>53994133
depends on what your first few languages are.
>>
>>53994154
this
>>
>>53994156

C, Javascript, Ruby, currently studying Java
>>
>trying to write some bithacky square root function in assembly
>it's not working
>start debugging
>start taking shit away
>none of my instructions were doing anything except sar rdx, 1 and movq xmm0, rdx
>this function
f_sqrt:
push rbp
mov rbp, rsp
sar rdx, 1
movq xmm0, rdx
leave
ret

>is somehow returning roughly the square root of xmm0, but *10^-154
>fsqrt(9) = 3.16979e-154
>fsqrt(2) = 1.49167e-154
>fsqrt(25) = 5.31407e-154
>I haven't used rdx anywhere else in my program
>changing rdx to any other register else breaks it
>trying to print the contents of rdx breaks it
maybe I'm not cut out for assembly
>>
>>53994028
No you're clueless
>>
>>53994198
You should be able to pick it up very quickly. Syntax is similar to C and it allows you to pick and choose what you want to be OOP. Very convenient.
>>
>>53994070
Well my idea is that recursion relies on the stack to keep track of data for it. So if your language has malloc/new capability and not just predefined variables you can store anything really. you just keep a list of pointers to a struct of whatever information needs to be preserved. It's recreating the call stack situation except instead of having massive overhead you just have a few pointers and an index to tell you what function iteration you're on.

No Stack overflows.
>>
>>53994155
>Because C is so simple and intuitive and that you won't want to use C++ after learning C.
Fucking this. I can't even look at non-trivial C++ code without retching.
>>
>>53991003
would fug
>>
>>53994244
no YOU are. nice doubles btw, did your mommy buy them for you?
>>
>>53994155
>Because C is so simple and intuitive and that you won't want to use C++ after learning C.
This. There's stuff like function overloading and maybe operator overloading that's pretty sweet.
But other than that C is just nicer most of the time.
>>
>>53994200
f_sqrt:
push rbp
mov rbp, rsp

movq rdx, xmm0
sub rdx, 8388608
sar rdx, 1
add rdx, 536870912
movq xmm0, rdx

leave
ret

this was the old function, based on some C code from a wikipedia article
apparently nothing that I cut out actually did anything
>>
>>53992281
I think mine is better
#include<iostream>
int main(){for(int i=0;i++<100;){if(i%5&&i%3)std::cout<<i;std::cout<<(i%3?"":"Fizz")<<(i%5?"":"Buzz")<<'\n';}}
>>
>>53994275
>function overloading
>operator overloading
They're shit. All they do is obfuscate your code and led the the absolute retardation that is C++ stringstreams.
>>
>>53994255
What's not to love about
const::std::const::vector<const & const Typename const T>(const & const 10) const vec = new const vec;

?
>>
>>53993774
with a book that teaches it
>>
>>53994291
I hate vector math like:
vec3 a;
vec3 b;
vec3c=vec3Add(a,b);

instead of
vec3 a;
vec3 b;
vec3c=a+b;

It has its uses.
>function overloading
It's fine when it's not silly. Like taking an integer instead of a double and stuff like that.

Also makes using libraries way easier..
>>
>>53994291
Only thing I like about C++ is having the *option* of using language supported OOP. When I do write in C++, I pretty much use it as C with come classes and at the most some polymorphism. C is much more straightforward on its own, though, and I'd always rather use it.
>>
>>53994155
>>53994275
>>53994291
>>53994347
How's D?
>>
>>53994383
unemployable
>>
>>53994383
breddy gud desu
>>
>>53994277
>>53994200
if anyone has any idea what the cunting fuck is going on with this, I'd really appreciate it
>>
>>53994326
>vec3 c=a+b;
That's so limiting though. What if I want to add b to a, storing the result in a? Doing it this way just leads to a bunch of unnecessary copying.

>It's fine when it's not silly. Like taking an integer instead of a double and stuff like that.
C11's _Generic makes it so you can do that, although it's more work.
>>
>>53994244
>>53994268
I'm not sure which one of you claimed that
return a + multiply(a, b-1);

was tail recursive, but to whoever it was, you're a gigantic retard
>>
>>53994032
Try converting a program written in CPS to a loop. Not easy.
>>
>>53994426
I'd rather not have
a+b

change anything.

The problem with functions is that if you have stuff like
c=a/(2+(b*3)) //as vectors

That'd be something like
c=div(a,(add(2,(mul(b,3)));

And add in your nomenclature for vec2->x and it's gonna look like shit. You can get rid of that using templates but that's just another can of worms. I just think this alone looks bad enough.

But it's mostly because it's math and I read math too. Stuff like sets could also be neat. But I see the confusion argument there. Would have to make comments to remind myself probably.
>>
> recursive fibonacci sucks

(defun fib (n &optional (a 1) (b 0) (p 0) (q 1))
(cond ((zerop n) b)
((evenp n)
(fib (/ n 2) a b
(+ (* p p) (* q q))
(+ (* q q) (* 2 p q))))
(t
(fib (1- n)
(+ (* b q) (* a q) (* a p))
(+ (* b p) (* a q))
p q))))
>>
File: wheeeeee.jpg (95 KB, 244x260) Image search: [Google]
wheeeeee.jpg
95 KB, 244x260
i managed to reach 7 levels of indirection with my linked list hash table implementation

CEL 99991 / 100000 | ENTRY 1 / 1: key 'H\0,m'fPsD'
CEL 99992 / 100000 | N U L L
CEL 99993 / 100000 | ENTRY 1 / 1: key ']}K4K!$qq>'
CEL 99994 / 100000 | ENTRY 1 / 1: key 'Dpj-f%q,K_'
CEL 99995 / 100000 | N U L L
CEL 99996 / 100000 | ENTRY 1 / 1: key 'Mz!M@C%I%1'
CEL 99997 / 100000 | ENTRY 1 / 2: key '<S.rPT&B/J'
CEL 99997 / 100000 | ENTRY 2 / 2: key 'B[^auJRf;R'
CEL 99998 / 100000 | ENTRY 1 / 3: key 'ef"|@X{x@u'
CEL 99998 / 100000 | ENTRY 2 / 3: key '?[TM+ZOV2Q'
CEL 99998 / 100000 | ENTRY 3 / 3: key 'L`?.jP=/@)'
CEL 99999 / 100000 | ENTRY 1 / 1: key 'fg;{sPz$*b'
CEL 100000 / 100000 | ENTRY 1 / 2: key 'zV]1ICcXcu'
CEL 100000 / 100000 | ENTRY 2 / 2: key 'z@j%RiO8?m'
>>
>>53994577
disgusting

function fibonacci(len) {
function recur(len, origLen, oldVal, newVal) {
if(len == origLen)
return oldVal + newVal;

return recur(len + 1, origLen, newVal, oldVal + newVal);
}

return recur(1, len, 0, 1);
}
>>
>>53994577
dumbest fuzzbiz in this thread so far desu senpai
>>
File: pacha.jpg (43 KB, 500x500) Image search: [Google]
pacha.jpg
43 KB, 500x500
>>53994577
> tail recursion
Thread replies: 255
Thread images: 21

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.