[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: 350
Thread images: 37

File: 1490551593437.jpg (72KB, 400x579px) Image search: [Google]
1490551593437.jpg
72KB, 400x579px
What are you working on, /g/?

Old thread: >>59591959
>>
anime <3
>>
C#
>>
>>59594649
>What are you working on, /g/?
I got too tired reading books and want to apply myself as I am learning. So basically looking for short programming problems
>>
>>59594687
sum of all primes below 2 mil computed in less than a second
>>
Cry more discretefags, dynamic typing is unironically the future
>>
>>59594666
>anime <3
too much anime on 4chan.
>>
>>59594687
x86_64 kernel with userland and GUI.
>>
School project for component-based software design, hoping I can get some advice here.

We have to make a mastermind game following the SOLID/GRASP principles perfectly. https://en.wikipedia.org/wiki/Mastermind_(board_game)

My teacher hinted to us to separate the solution area, the guess area and the hint area into their own classes. I understand putting the solution in one class and the gameboard itself in the other class but I dont get the point of having the hints in their own class?

The solution needs to be totally encapsulated and the method to check for a winning guess would be in there for that reason. But the same method that can check for the win can easily supply the hints as well. Would that be violating cohesivness?

I hope this makes sense
>>
File: 1445101406258s.jpg (4KB, 119x125px) Image search: [Google]
1445101406258s.jpg
4KB, 119x125px
>>59594760
a-and what
>>
>>59594760
Yes
>>
File: anal beads.png (8KB, 819x98px) Image search: [Google]
anal beads.png
8KB, 819x98px
>>59594710
>>
I'm in a basic java class. I'm trying to do a word scramble game where you have to take a string from a file, scramble it and then have the user play a game where they swap indicies that they choose. I could probably get the indicies from the user easily and then do a loop that continues while the user doesn't have the right word, but my problem is that trying to scramble it is a pain in the ass. If anyone could help that would be much appreciated.
>>
File: 1489771460960.jpg (145KB, 800x642px) Image search: [Google]
1489771460960.jpg
145KB, 800x642px
Do C# compilers for JVM exist?
>>
>>59594839
>trying to scramble it is a pain in the ass
wtf just use the
.Randomize()
extension method
>>
>>59594752
> too much anime on an anime website
>>
>>59594853
Short answer: No.
>>
>>59594867
>anime website
>>
>>59594853
Not yet, but I'm writing one.
>>
>>59594856
Do I have to import anything to use it, or can I just use it via the random object
>>
>>59594884
Do you have a logo?
>>
>>59594886
http://docs.oracle.com/javase/7/docs/api/java/util/Random.html
>>
>>59594895
Nope. I will at some point and it will be some sort of anime image.
>>
>>59594886
You have to switch languages to use that.
>>
void whatever(MyClass& abc);
void whatever(MyClass &abc);
void whatever(MyClass abc&);

are these all the same thing?
>>
>>59594797
wrong
>>
>>59594839
Bad solution, but you could do something like (Index*RandomInt())%Length for the initial jumble and if that index is already set, just inc/decrement
>>
>>59594938
1 and 2 should be added, I'm assuming?
>>
>>59594952
wrong
>>
>>59594952
no the correct answer's 142913828922
>>
>>59594839
Actually you could also just reverse the problem. To jumble just choose two random unique indicies and swap. Do this Length*n times
>>
>>59594710
is that possible without a look up table?
>>
File: 84bdzyuhksny.gif (2MB, 320x240px) Image search: [Google]
84bdzyuhksny.gif
2MB, 320x240px
>>59594985
>>
>>59594994
ye
>>
converting JSON to SQL DDL
>>
>>59594994
Euclidean Algorithm
>>
>>59595014
Are you using DFELQ?
>>
Well OP, recently I gave up Clojure to try Elixir. Coming from a Python background with a love of the power of lisp macros and a desire to avoid anything-java, seems like it might work out.

I'm going to distribute keks far and wide with the erlang vm.
>>
>>59595003
jesus christ how horrifying
>>
>>59594710
echo 142913828922
>>
>>59595003
Is there a problem with that? You could maybe improve it by not allowing it on set slots before the whole string is set
>>
>>59595028
>Coming from a Python background
Oh... I'm sorry to hear that, anon...
>>
File: 18-726s09.jpg (14KB, 320x320px) Image search: [Google]
18-726s09.jpg
14KB, 320x320px
>>59594649
Javascript, Jquery , General topology and Kolmogorov complexity
>>
>>59595021

no enlighten me I suspect this is going to be great
>>
>>59595089
i was kidding

some acronym i just made up
>>
File: 1475566478902.png (17KB, 400x300px) Image search: [Google]
1475566478902.png
17KB, 400x300px
Are there other language virtual machines than .NET and JVM for compiled languages?
>>
>>59595118
who cares?
>>
>take proofs exam
>randomized questions
>end up writing 8 pages of simple proofs
>look over and the girl next to me is drawing lines between sets
>>
>>59595118
erlang vm
>>
>>59594839
Look up and implement knuth random shuffle
>>
File: dpt.jpg (164KB, 800x1000px) Image search: [Google]
dpt.jpg
164KB, 800x1000px
>>59594649
>>
Elixir is bootiful anons
>>
>>59595118
>usually compiled languages
fixed that for you.
>>
>>59595187
It's dynamic garbage.
>>
>>59595205
>tfw not in presence of an argument
>>
>>59594649
Please do not use an anime image next time. Thank you.
>>
>>59595205
Static typing is garbage.
>>
>>59595239
Impossibru.
>>
>>59595239
Please do not make posts of this type in the future. Thank you.
>>
>>59595205
i guess that's just your opinion man
>>
Litterally can't find documentation on python's type rules
>>
>>59595126
>proofs

WHERE IS PROOFS?
>>
>>59595287
i think he meant an exam on proofs
>>
>>59595286
https://en.wikipedia.org/wiki/Python_syntax_and_semantics
>>
>>59594763
advice? :(
>>
if ( some long condition
&& some long condition
&& some long condition) {
...
}


looks good to me, is this an ok convention?
>>
>>59595322
if (
some long condition
&&
some long condition &&
some long condition
){
}
>>
>>59595343
Not him, but what's the difference?
>>
I am getting through a quick intro to Rust. I don't get one thing: why do some expressions require the semicolon, while others don't? Also, why is println called as a macro, and not as a simple function?
>>
>>59595390
mine has a secret optimization
>>
>>59595394
The semicolon in Rust turns an expression into a statement by replacing the value with (). If the return type of your function is () and the last expression is of type (), then you can either give it a semicolon or not.

println is a macro to handle a variable number of arguments.
>>
>>59595394
you need to die your hair blue and get a septum piercing in order to become a true rust programmer
>>
What's the best way to migrate a VS solution to a newer toolset just for myself when it's on a tracking branch in my local git repo? Ideally, I want to do it in a way that doesn't result in merge conflicts on the vcxproj files when I pull (so something besides the skip-worktree flag). Is a smudge/clean filter really the best way?
>>
>>59595294
I've looked through this, but nothing actually says how a dynamic type is inferred. Maybe it isnt since it's interpreted
>>
>>59595467
import types
dir(types)
>>
>>59594936
>>59594936
>>59594936
>>59594936
>>59594936
>>
>>59595523
the 1st and 2nd are
the 3rd no
>>
>>59595547
then what is the third one called?
>>
If i put object instances in queue in c#, how do i retrieve it and print it in console?
>>
>>59595559
fuck me if i know
>>
File: 12ewsd.jpg (104KB, 640x480px) Image search: [Google]
12ewsd.jpg
104KB, 640x480px
>>59595567
dequeue it
>>
>>59595559
Syntax error
>>
char** lines = (char**) malloc(5*sizeof(char*));


is this equivalent to char
 lines[5][5] 
?
>>
File: index.jpg (7KB, 224x224px) Image search: [Google]
index.jpg
7KB, 224x224px
>>59595624
>>
>>59595429
Oh STFU. It has some interesting ideas, that's all. I probably know more languages than you do.
>>
>>59595632
>casting malloc
>>
>>59595654
Kill yourself
>>
>>59595632
No.
>>
>>59595648
Most retards here know 1 or 2 languages so that isn't saying much.
>>
>>59595648
So angry!
>>
>>59595661
why would i kill myself, brainlet?
>>
>>59595632
char** lines = (char**) malloc(5*5*sizeof(char));

is the equivalent.
>>
if I have a method in a class.
I make another class and inherit from said class.
Can I overload it in the new class?

How does @Override work with overloaded methods
>>
>>59595668
Try me. About 10. Mastered 5, average at 3, meh at 2.
>>
>>59595603
Doesn't work
>>
>>59595696
Look into dynamic method casting.
>>
>>59595702
Why would you lie on an anonymous image board anon?
>>
>>59595691
then my exmaple is equivalent to
char lines[][5] 
?
>>
>>59595691
Kinda. But then the indexing is more difficult. You have to dynamically allocate each element with 5 chars for ex, than you can index it like a matrix. In your case, you have to index by i * 5 + j
>>
>>59595632
Apparently because everyone else in /dpt/ is unable to answer it, no, they are not equivalent. An array is NOT a pointer, it just decays to one when passed to a function. Declaring an array as
lines[5][5];
means it's stored on the stack (or in bss if declared globally). If it's on the stack, then it's automatically freed when the scope is exited. Malloc on the other hand is heap allocation, which can fail (giving you a null pointer) and will lead to memory leaks if you don't explicitly call free() on it before leaving the scope in which the pointers are declared. Additionally, in your example, you end up with "lines" being a pointer to the stack to an array of heap-allocated pointers to characters, but you have no space to ACTUALLY store those characters. To do it properly, you'd need to do something like this:
char** lines = (char**) malloc(5*sizeof(char*));
lines[0] = malloc(5);
lines[1] = malloc(5);
lines[2] = malloc(5);
lines[3] = malloc(5);
lines[4] = malloc(5);
>>
>>59595735
It would be "mastered 10" if I lied. Feeling insecure about yourself? I do this spend my entire day playing games and watching anime, but actually working my ass off. These are the 30 minutes at the end of the day that I dedicate to shitposting.
>>
>>59595750
>An array is NOT a pointer, it just decays to one when passed to a function.
It's more clear to say that an array name is a pointer, not that the array itself decays to a pointer.
>>
>>59595750
>will lead to memory leaks if you don't explicitly call free() on it before leaving the scope in which the pointers are declared
Wrong. You could perfectly forward the pointer to another object.
>>
I got pretty much everything to work except the shuffle. I followed this: https://www.experts-exchange.com/questions/25665828/shuffling-a-character-array-in-Java.html

But the problem is it doesn't know when a letter has already used and thus results in insolvable puzzles.
>>
>>59595769
>All this was inspired by the principle—which is quite true within itself—that in the big lie there is always a certain force of credibility
>>
File: 1477532334439.gif (2MB, 500x281px) Image search: [Google]
1477532334439.gif
2MB, 500x281px
>mfw tried to get into OOP through Java
OOP principles quickly became convoluted and yet I haven't finished reading about classes in Java fully.
>>
>>59595781
Sure, certainly. I was just simplifying assuming it was being used just for local data, like a stack array. That is another difference, you CAN safely return a pointer to a heap array to the caller, you can't do that with a pointer pointing to local stack in the current frame.
>>
>>59595702
>About 10
Brainlet.
>>
>>59595852
don't use Java to learn OOP, you use Java to learn Java
use C++ to learn OOP (and everything else)
>>
File: chrono.png (33KB, 807x521px) Image search: [Google]
chrono.png
33KB, 807x521px
>>59594649
still doing chrono.
it's way off for some reason and I'm too tired to see why
>>
>>59595950
Why are you using DPMI in C++?
>>
>>59595981
why not? it's a fun platform.
>>
>>59595935
>use C++ to learn OOP (and everything else)
You don't sound like a person whom I must believe.
>>
File: 1460370891149.gif (49KB, 200x210px) Image search: [Google]
1460370891149.gif
49KB, 200x210px
Something fun to program in asm?
>>
How about this: don't learn OOP at all.
>>
File: 8319238123912.jpg (104KB, 408x408px) Image search: [Google]
8319238123912.jpg
104KB, 408x408px
>engineering course but not CS/CEng
>C assignment
>sensible and readable code, a couple of comments where necessary
>guy marking it docks me a fair amount of points for not commenting
>"anon, comments are the most important thing in a program, what if someone that doesn't know C wants to look at your code and modify something"
>I was already on the brink of failing the class because I skipped all the technical drawing and CAD bullshit
>mfw I may fail the class because of fucking comments and "academia" logic
>>
>>59596087
Program an anime girl.
>>
Anyone familiar with Python and pandas?

I have a table like this

A B
1 0
1 0
2 1
2 1
2 1
3 1
3 1
3 0
4 1
4 0
5 0


And I want to transform it into one like this (the values are the counts)

A 1 2 3 4 5
B
0 2 0 1 1 1
1 0 3 2 1 0


Can't figure it out
>>
File: disdain for nigger babies.png (684KB, 606x886px) Image search: [Google]
disdain for nigger babies.png
684KB, 606x886px
>>59596130
>what if someone that doesn't know C wants to look at your code and modify something
>someone that doesn't know C
>reading C code
I bet it's for the diversity hires.
>>
Noob here:
Is ASP.NET bad?
Should threading scare me?
>>
>>59596148
Do you want to know what the bottom table represents?
>>
>>59596263
anything .net is bad.
>>
>>59596148
>>59596281
Don't care.
>>
>>59596281
What do you mean?
>>
>>59596300
I'm asking him if he understands what the bottom table displays before asking for help
>>
>>59596282
C# and VB are fine.
>>
>>59596312
If you're asking if I know a term for the type of table the bottom one is then I don't. It's been hard to google because of that.
>>
>>59596306
Do you get how you get the bottom table from the top table?
>>
What do you think about JMonkeyEngine /g/??
>>
I'm studying c++
>>
>>59596357
>I'm studying c++
>>
>>59596352
>>59596357
Trash
>>
>>59596282
But Paint.NET is good.
>>
File: 1481721308217.jpg (340KB, 1180x842px) Image search: [Google]
1481721308217.jpg
340KB, 1180x842px
I'll create my own language called MonkeyCode and i'll become the greatest wageslave know to mankind.
>>
>>59596326
Sum of Bs per A.
>>
>>59594895
How do you make logos? I tried once and I sucked at it
>>
>>59596371
>I'll
Oh, so I shouldn't care now.
>>
>>59595170
Nobody likes the picture you made.
>>
>>59595467
Types aren't inferred you dipshit.
>>
>>59595691
>sizeof char
>>
Name reasons why we shouldn't go with 1-based array indexing (regular indexing, like in matrices) if your language doesn't have direct memory access, where 0-based array indexing (offset in memory) is justified.
>>
>>59596438
Then how can there be type errors?
>>
>>59594649
>work on something you enjoy, anon :)
alright, lets get sdldoom source and migrate it to sdl2, lets check the wiki... good, lets fire up this thing
>Thread 3 "SDLAudioDev1" received signal SIGSEGV, Segmentation fault.
>[Switching to Thread 0xa58feb40 (LWP 19509)]
>0x00000000 in ?? ()
Ok, audio is called by function I_InitSound, the game might be calling some wangblows midi function, lets comment it out and compile, this will do it!
>Thread 1 "xdoom" received signal SIGSEGV, Segmentation fault.
>0x0806513c in V_DrawPatch (x=<optimized out>, y=<optimized out>, scrn=0, patch=0xb6f21e34) at v_video.c:256
>256 *dest = *source++;
JUST
>>
>>59596474
They happen at runtime dumbass. When your stupid code tries to treat a value of one type as if it was of another type.
>>
>>59596470
>her language doesn't have direct memory access
>>
Rename thread to shitposting general.
>>
File: 2015_bjarne_straustroup.jpg (39KB, 200x250px) Image search: [Google]
2015_bjarne_straustroup.jpg
39KB, 200x250px
>>59596024
Stop using Java
>>
>>59596491
Right, and it knows the type it wants and the type the value actually is, and that's called type inference.
>>
>>59596148
>>59596326
Got it thanks.

data = data.pivot_table(index='b', columns='a', aggfunc = len)
>>
Can someone explain why this code doesn't show up in my python interpreter?
def func(Choice):
input("Do you " + colored("run ", 'blue')+"or " + colored("attack? ", 'blue') + "")
>>
>>59596470
You're wasting an element of the integer type.
>>
File: Daddy.jpg (42KB, 512x512px) Image search: [Google]
Daddy.jpg
42KB, 512x512px
>>59596554
Stop using C++
>>
>>59596024
cute anime desu
i have this image too
>>
File: computer generated vagoos.png (577KB, 512x512px) Image search: [Google]
computer generated vagoos.png
577KB, 512x512px
>want to train a neural net that decensors hentai
>spend fifty hours cropping vaginas from uncensored hentai
>spend another fifty reading research papers and installing and learning Python and machine learning library APIs
>result of my effort is pic related
>realize I need 100x more data

At least I have a good idea for what I need to do. Small steps.
>>
>>59596693
What element?
>>
>>59596854
0
>>
>>59596862
0 isn't an integer
>>
>>59596845
lewd
>>
>>59596845
You're doing gods work anon. Keep it up.
>>
File: 1486690644495.png (113KB, 255x256px) Image search: [Google]
1486690644495.png
113KB, 255x256px
>>59596874
>>
>>59596862
So?
In 0-based indexing, if I declared an array with INT_MAX elements, I can only access 0 to INT_MAX-1 element.
What's the difference between accessing from 0 to INT_MAX-1 versus accessing from 1 to INT_MAX?
>>
>>59596904
Good point.
>>
>>59596845
A great journey starts with a single step.
>>
How did you learn to program anon?
>>
>>59596845
What are you trying to do? Pass in censored -> get uncensored?
>>
File: 1464252858641.png (141KB, 429x521px) Image search: [Google]
1464252858641.png
141KB, 429x521px
>>59596965
I'm on it but i can't think of anything fun to program on ASM.
I was thinking of another programming language that i want to be easy, simple and practical but i don't know where to start.
I also want to make a notepad for it.
>>
>>59596965
No one here knows to program
>>
>>59597022
Speak for yourself.
>>
>>59597046
Stop trying
>>
>have to submit C programming assignments in a online check tool
>this tools runs your program against dozens of inputs
>test the shit out of my program
>everything works
>submit
>Wrong Answer (30 points in 130)

fml
>>
>>59597123
>C
I bet you had a memory fuckup.
If you don't use Valgrind you're not a professional.
>>
>>59597170
it was not a memory fuckup because it didn't show Runtime Error
and i use valgrind + gdb, anon
>>
>>59597123
Nice implementation defined behavior
>>
>>59597202
hmm what?
>>
how the hell do you get stdout to work with racket's FFI

i've been trying to define printf but all i get is the int return value, which is useful but i don't get the actual output
>>
File: vertical red lines.png (595KB, 512x512px) Image search: [Google]
vertical red lines.png
595KB, 512x512px
>>59596882
Have another

>>59596995
Yeah. If a neural network can generate vaginas images, you can make it fill in empty parts of images.
>>
>>59597235
Are you serious?
>>
>>59596845
>neural net
I hope it's not just a single layer NN.
>>
File: sam.jpg (117KB, 1024x576px) Image search: [Google]
sam.jpg
117KB, 1024x576px
>>59597368
as a matter of fact, i am
>>
File: test (2).png (716KB, 811x599px) Image search: [Google]
test (2).png
716KB, 811x599px
>>59595062
How much quantum do you know?
>>
>>59597389
It's gonna be many times more complicated than a single layer NN.
>>
File: chrono.png (32KB, 615x775px) Image search: [Google]
chrono.png
32KB, 615x775px
chrono thing works now!
I'm using a circular buffer to calculate a moving average of the time interval between irqs, so I have something to sync rdtsc to.
>>
>>59594994
Sieve of Eratosthenes
>>
File: 1467008649838.jpg (155KB, 753x706px) Image search: [Google]
1467008649838.jpg
155KB, 753x706px
My Miller-Rabin implementation is taking forever to compute 2**44497-1. I thought I could program until now. Where did all go so wrong for me?
>>
>>59594649
trying to survive until the will and desire to work on something again grows in me.
>>
>>59595118
>.NET
You mean the CLR, right?
>>
>>59597592
It's all the same Microcuck shit.
>>
>>59597565
You were born
>>
>>59596904
+1
>>
>>59597600
>meme
>>
>>59597620
Who are you quoting?
>>
What's etiquette for creating user agent strings? I've got some crawlers and scrapers and their strings are generally
ApplicationName:v0.0
is that enough
>>
>>59595118
any brainfuck interpreter
>>
>>59597426
(print "~a", my_integer_return_value)
>>
>>59597679
oh no, i know that function exists already

i'm just learning how to get foreign functions to work
>>
>>59597679
>,
>using underscores in lisp variables
Trash
>>
>>59597694
It's racket, not Common Lisp
>>
>>59597635
just use 'Mozilla/6.0'
>>
>>59597707
So?
>>
>>59597707
you're still using underscores in your variable names as if you've never heard of camelCase.
>>
Is it possible for a poor brainlet third world obese memer to become a programmer?
>>
>>59597748
It's bound to not follow lisp conventions

>>59597785
Welcome to Exampleville, population you & me
>>
File: 1486431480793.jpg (31KB, 695x363px) Image search: [Google]
1486431480793.jpg
31KB, 695x363px
>>59597608
no bullying
>>
>>59597796
It does follow these conventions though. Don't use comma except in a backquote. Use dashes in your names.
>>
>>59597565
2^44497-1 is 44497 ones
>>
>>59597815
You weren't bullied hard enough.
>>
Pascals triangle.
Write a program that returns an array that which is the last row of the triangle of n.

so pa(2) should be [1,2,1]
pa(3) should be [1 3 3 1]
>>
>>59597919
>so pa(2) should be [1,2,1]
Should it be [1, 1]?
>>
>>59597953
(x+y)^2 = x^2 + 2x + 1
>>
>>59597859
See >>59597679
>>
>>59597960
(x+y)^2 = x^2 + 2xy + y^2, friendo.
>>
>>59597961
I don't see "using underscores in lisp variables" in that post.
>>
File: PTriangle.gif (2KB, 293x298px) Image search: [Google]
PTriangle.gif
2KB, 293x298px
>>59597953
That is pa(1).
Pascal triangle starts from row 0
Pic related
>>
>>59597975
You get the idea
>>
>>59597991
That's because you have to obtain the skill Reading Comprehension to comprehend that post.
>>
>>59597919
def pa(n):
line = [1]
for x in range(n):
line.append(line[x] * (n-x) / (x+1))
return line
>>
>>59597995
What you stated was false, though.
(x+y)^2 =/= x^2 + 2x + 1
>>
>>59598012
I've asked a third party and the truth of that sentence simply not being there hasn't changed.
>>
File: Yun 1--article_image.jpg (28KB, 620x400px) Image search: [Google]
Yun 1--article_image.jpg
28KB, 620x400px
What's a simple and efficient programming language?
>>
>>59598027
C
>>
>>59598020
see >>59597995
>>
>>59598040
He said simple, not easy
>>
>>59598044
C is simple and easy
Only a fucking moron won't be able to program in C
>>
>>59597919
I wrote one a while back that goes up to pa(65535).
You can use it as example.
>>
>>59598022
You're right, it's always been there!
>>
>>59597919
>>59598055
forgot link
http://pastebin.com/8L6BLFkc
>>
>>59598052
>Only a fucking moron won't be able to program in C
Yeah because C is easy
>>
>>59598052
C is not simple.
>>
>>59597785
>camelCase
And this clown doesn't use emojis for his variables. It's 2017, almost 2018. Get with the times grampus.
>>
>>59598063
>C is not simple
Lmao
>>
>>59598058
Seems like you can't parse basic English sentences yet.
>>
>>59598081
>Seems like you can't parse basic English sentences yet.
Seems like you can't parse basic English sentences yet.
>>
>>59597919
import std.stdio;

void main()
{
writeln(pascal_row(4));
}

int[] pascal_row(int n)
{
int[] row;
for(int i=0; i<n; i++)
{
row ~= combination(n,i);
}
return row~[1];
}

int combination(int n, int r)
{
return factorial(n)/(factorial(r)*factorial(n-r));
}

int factorial(int x)
{
int factorial_result = 1;
for (int i=x; i>1; i--)
{
factorial_result *= i;
}
return factorial_result;
}
>>
>>59598088
Good. This is actually a valid usage of the symbol '>'. You're learning!
>>
>>59598117
Not an argument.
>>
>>59598102
Was there a need to split everything into a multiple functions when 1 would have sufficed?
>>
File: 1463064892991.png (139KB, 270x360px) Image search: [Google]
1463064892991.png
139KB, 270x360px
>>59598117
>there are valid uses of greentext
>>
>>59598102
Memoize, faggot.
>>
>>59598128
I'm quaking in my boots, truly.
>>59598135
Can you stop typing in this retarded fashion if you aren't quoting anyone?
>>
>>59598102
What does tilde mean in D?
>>
>>59598129
Code reusability
>>
>>59598149
>scared of text on the internet
>>
>>59598156
Quote properly next time, please.
>>
>>59598155
>Code usability
>When none of the functions are remotely reuseable or general equations
Lmao. These are the people who code in C++
>>
>>59598168
>scared
>getting this mad at text
Seek professional help.
>>
File: 1464988239571.png (509KB, 454x642px) Image search: [Google]
1464988239571.png
509KB, 454x642px
>>59598149
>hello anon, how do you do? nice to meet you. yours gayly, a faggot
>>
>>59598179
Are you purposefully being dense? Honest question.
>>
>>59598179
>factorial generation is not reusable
>>
>>59598188
Or you could just have schizophrenia.
>>59598203
You have a very low IQ anon.
Yours faithfully
Anonymous
>>
>>59598188
How the fuck would a hooker help in this case?
>>
>>59598212
>>59598218
>Arguing with a C toddler
>>
>>59598027
Go.
>>
What's your Erdős number, /dpt/?
>>
I really appreciate the AKS primality test.
R8
import std.stdio;

void main()
{
writeln(isPrime(12));
}

bool isPrime(int p)
{
ulong[] pascal_row = generate_pascal_row(p);

for(int i=1; i+1<pascal_row.length; i++)
{
if (pascal_row[i]%p != 0)
{
return false;
}
}
return true;
}

ulong[] generate_pascal_row(int n)
{
ulong[] row;
for(int i=0; i<n; i++)
{
row ~= combination(n,i);
}
//Here I can't do row ~= [1]
//int[] is not compatible with ulong[]
//So I had to come up with this shitty workaround
//ulong last_el = 0;
//last_el++;
//return row~[last_el];
row ~= 1;
return row;
}

ulong combination(int n, int r)
{
return factorial(n)/(factorial(r)*factorial(n-r));
}

ulong factorial(int x)
{
int factorial_result = 1;
for (int i=x; i>1; i--)
{
factorial_result *= i;
}
return factorial_result;
}

> ldc2 test.d ;and ./test
false
>>
>>59598480
1
>>
>>59598495
>Deadland
0/10
>>
>>59598515
lang*
>>
>>59598480
0
>>
>>59598515
>>59598523
Translate this into your language, the algorithm is pretty generic. Let's see how your language looks like
>>
>>59598539
Here >>59598015
>>
>>59598551
That's not a primality test, and python's not what you use, do you?
import std.stdio;

void main()
{
writeln(isPrime(17));
}

bool isPrime(int p)
{
ulong[] pascal_row = generate_pascal_row(p);

for(int i=1; i+1<pascal_row.length; i++)
{
if (pascal_row[i]%p != 0)
{
return false;
}
}
return true;
}

ulong[] generate_pascal_row(int n)
{
ulong[] row;
for(int i=0; i<n; i++)
{
row ~= combination(n,i);
}
return row~1;
}

ulong combination(int n, int r)
{
return factorial(n)/(factorial(r)*factorial(n-r));
}

ulong factorial(int x)
{
int factorial_result = 1;
for (int i=x; i>1; i--)
{
factorial_result *= i;
}
return factorial_result;
}
>>
I don't get php

If I write php inside of my html will the end users even be able to see it if they click "inspect element"?
>>
>>59598585
>>>/g/wdg/
>>
>>59598153
concatenation operator
>>
>>59598585
No, they will not. Php files will be interpreted by the server first, which results in the final html file.
>>
>>59598515
More alive than your programming and spelling skills.
>>
>>59598613
I forgot: Stop using php.
>>
Some russian faggot is following my git repo for 0 reason. Then I deleted the repo since It's meant to serve as my personal algorithms testbed and I expect no contributors.

I re created the repo again and the fag is following me again. I feel like being raped.
>>
>>59598015
This returns floats, aka it's wrong for large n.
Mine works for all n:
def pascal_row(n):
row_n = [1]*(n+1)
for i in range(1, n):
row_n[i] = int(row_n[i-1]*((n+1-i)/i))
return row_n
>>
>>59598749
Why would you have anything "personal" on a public repo? Keep it to yourself, local. I detest people like you who litter their repos with random crap like their dotfiles. There's literally no reason why you can't keep it on a private server, or on a USB stick.
>>
>>59598854
That's because I have multiple desktops.
>>
>>59598863
And git is comfy
>>
>>59598863
Like I said, turn one of those desktops into a server and host your own git. Or easy mode is simply a USB with the repo.
>>
>>59598819
>Mine works for all n
Never mind, I'm an idiot.
>>
File: o.jpg (142KB, 1024x576px) Image search: [Google]
o.jpg
142KB, 1024x576px
>>59598904
Hmm
delet this
>>
>>59598871
Use bitbucket. You can create free private repos.
>>
>>59598929
>tries to be so diverse that it spreads itself so wide it ceases to exist
>>
>>59596845

you magnificent bastard. clean up the place, lads, put on your nice underwear, we've got a future legend in our presence
>>
I need to write a script that refreshes a webpage every few seconds, waits for it load completely and then checks the value of a div with a certain id. It's super simple, but if I refresh the page, the script stops running. How do I get around this?
>>
How the fuck do you look for remote programming jobs
Every career site somehow sucks for programming jobs despite being made by programmers
>>
>>59598947
Did someone just say shitbucket?
I feel sorry for the cucks that actually had their repo deleted recently
>>
File: 1485135807808.jpg (80KB, 762x768px) Image search: [Google]
1485135807808.jpg
80KB, 762x768px
Are humans just sets of functions?
>>
Need help with a simple Java program i'm a noob so i don't quite understand, any help is appreciated btw reading Tony Gaddis Java

Write an if statement that sets the variable hours to 10 when the boolean flag variable
minimum is equal to true.
>>
>>59599084
if(minimum == true) hours = 10;
>>
>>59599084
Only a literal retard could find this hard. Fuck off.
>>
>>59599093
>>59599098
>Taking the bait
>>
>>59599093
>>59599084
Skill level: C toddler
>>
hours = minimum == true ? 10 : hours;
>>
hours = true != !minimum ? 10 : hours;
>>
>>59599114
How would you do it?
>>
>>59599084
hours = static_cast<std::uint32_t>(minimum) * 10;
>>
What is a great C++ book for starters?
>>
>>59599142
>>59599152
>>59599155
Readability is important, you goofballs.
>muh fp meme said if statements are bad!
>>
>>59599152
second place, double negation, might as well just kill yourself now cuck.
>>
>>59599172
those aren't FP, you understand that those statements are ifs right? Do you understand that the first two produce identical asm?
>>
File: ameameame.jpg (58KB, 480x360px) Image search: [Google]
ameameame.jpg
58KB, 480x360px
I'm working on an inverted index using mapreduce.
>>
>>59599174
hello
>>
thanks for the help guys but i'm getting errors when running it like incompatible types int and boolean here is my code, any help is appreciated and please be nice

public class AlgorithmWorkbenchPage185Q4{

public static void main(String[] args){

int hours, minimum = false;

if (minimum == true){

hours = 10;
System.out.println(hours);
}

else{

hours = 5;
System.out.println(hours);
}

}

}
>>
>>59599164
cppreference.com
>>
>>59599185
You do know x86 is imperative, right? Like there's no way to produce purely functional x86 asm. Yet you have FP compilers targeting x86. So no, it's not the machine instructions that make the difference, it's the semantics in the source code. Also, those examples are FP-ish as they use expressions rather than statements. FP is all about constructs "returning a value" rather than "doing stuff." Even FP I/O is just "a function returning the action of printing to the screen".
>>
>330
>>
>>59599219
You're supposed to declare minimum as bool. Also since System.out.println(hours) is called either way, put it below the second loop block to simplify.
>>
>>59599237
Who said that?
>>
ok got it thanks a bunch
>>
>>59599266
>333
>>
>>59599232
nigga are you retarded? Ternary operators in C are literally if/else statements. That is literally what they are, just written differently. I was saying that none of those examples are FP.
>>
>>59599219
>int hours = false
>>
>>59599280
Wrong. Ternaries are different, they return a value rather than performing an action. You CAN use them to perform an action via a function call, as in
cond ? func1() : func2();
. But you can also use them to return a value, using the entire ternary expression to initialize a variable, i.e.
int x = cond ? 2 : 1;
. You can't do that with ifs in c, at least not with a single assignment statement.
>>
>338
>>
>>59599316
int x;
if( cond )
x = 2;
else
x = 1;

this produces the same asm nerd.
>>
>tfw I can only answer the easy exercise problems in programming books and anything with math where you have to think I have no idea to answer it like the probability math questions
>>
>>59599391
What language are you on?
>>
>>59599391
I mean have you studied probability ever?
>>
>Fall for the microshills in /g/
>Install Visual Studio Code
>Install two plugins
>Open project directory
>System halts for 3 minutes
Sublime kek remains the best
>>
>>59599415
Java

>>59599426
Only basic probability like flipping a coin but not ones they are asking like what are all the different string combinations of rearranging "abdcfgeg" with a string length of 8
>>
>>59599461
Permutations and combinations is a math concept used frequently in probability but they aren't used only in probablility.

Also doesn't high school fucking teach permutations and combinations?
>>
>>59599457
>Visual Studio Code
>not using actual Visual Studio
>>
>>59599475
>system now halts for 30 minutes
gg
>>
>>59599474
nah they focused more on algebra trig functions graphs etc

I see so my problem is having to read up on math
>>
>>59599490
>I see so my problem is having to read up on math

Why are you doing programming of maths equation in the first place?
>>
>>59599461
I'm not sure I have any resources I can link you, but to you can look up Discrete math to get some things that will help with this sort of math like combinations and permutations. That string combinations problem also isn't too hard.
>>
>>59599524
it is in the programming exercise book

>>59599531
thanks
>>
>>59599524
>>59599490
The problem is that public school types think "word problems" are solely within the domain of math and not critical thinking. This is further evidence of a lack of critical thinking.
>>
>>59599547
>it is in the programming exercise book
Drop it then. Or skip to the chapters that don't require maths.
>>
>>59599547
I'll also warn you discrete math is a very broad topic, what might help you the most is counting, logic, and graph theory. I'm not saying everything else is useless, but these are the things I felt I've used the most.
>>
>>59599573
what is graph theory?
>>
>>59599571
It probably isn't a good idea to skip anything that's hard in an exercise book, because that kind of defeats the purpose doesn't it? A lot of the math for these things can be googled and you get kind of work from there anyway.
>>
>>59599583
Properties and application of graphs
>>
R8 my N-queens
import Control.Monad(guard, join, mapM_)
import System.IO
data Queens = Queens [Int]

instance Show Queens where
show (Queens ns) =
jj [replicate n ". "
++ ["Q "]
++ replicate (length ns - n - 1) ". "
++ ["\n"] | n <- ns]
where
jj = join . join

nQ :: Int -> [Queens]
nQ n = Queens <$> aux n []
where
aux 0 brd = [brd]

aux k brd = do
i <- [0..(n-1)]
guard (ok i brd)
aux (k - 1) (i:brd)

ok q brd =
not (elem q brd
|| or [i == abs (q - q')
| (i,q') <- zip [1..] brd])

main :: IO ()
main = do
putStr "Enter N: "
hFlush stdout
n <- readLn
mapM_ print (nQ n)
>>
>>59599592
I have done these programming exercise books before. Most of the questions with maths involve understanding the equation and then coming up with a clever shortcut via programming (like the entire Euler's challenge). If you don't understand the math or just have a cursory knowledge, you are going to be brute forcing the questions 99% of the time and that is simply a waste of time.
>>
File: graph7.png (10KB, 383x183px) Image search: [Google]
graph7.png
10KB, 383x183px
>>59599583
Graph theory is stuff like finding paths through a graph, and trees. I don't mean things like bar graphs, but nodes connected with edges between them, like this picture.
>>
>>59599612
Oh I see, yeah if you just end up brute forcing everything then I agree that doesn't sound helpful.
>>
So is object oriented programming just programming with mathematical objects?
>>
>>59599605
why hflush?
>>
>>59599620
alright I think I understand so finding the different ways you can go based on all those numbers
>>
>>59599658
object oriented programming has almost nothing to do with mathematical objects.

It's a way of dividing large programs into understandable bytes (in theory). The method binds together attributes and behavior, provides interfaces, and allows programmers to build around interfaces without regards to implementation.
>>
>>59599680
so that it will flush the prompt string in my terminal

also updated:
import Control.Monad(guard, join, mapM_)
import System.IO
data Queens = Queens [Int]

instance Show Queens where
show (Queens xs) =
join [ (do
i <- [0..(length xs - 1)]
if i == x
then "Q "
else ". ") ++ "\n"
| x <- xs]

nQ :: Int -> [Queens]
nQ n = Queens <$> aux n []
where
aux 0 brd = [brd]

aux k brd = do
i <- [0..(n-1)]
guard (ok i brd)
aux (k-1) (i:brd)

ok q brd =
and [q /= q' && i /= abs (q - q')
| (i,q') <- zip [1..] brd]

main :: IO ()
main = do
putStr "Enter N: "
hFlush stdout
readLn >>= (mapM_ print . nQ)
>>
>>59599701
Why did they call it that then? It sounds retarded by the way.
>>
>>59599714
This is a virus! Don't run it
>>
>>59599738
too late copy and pasted into my IDE
>>
>>59599733
because conceptually you are dividing your program into computation units called objects.

You have data, you have methods that do work on the data, you bind them together and provide an interface for other programmers to have a standardised way to do useful things.

It works pretty well in practice, or roughly about as well as structured programming did before it. Most of OO-design is just making structured programs slightly easier to understand really.

Sometimes you get nightmares that are made by people who would've fucked up a structured imperative program too and people act like OO is a failure because of that.

It works when it works, and it seems to have much stronger adoption than FP will ever get, because FP is a meme.
>>
@59599745
why the hell do you space your posts like that, plebbitor?
>>
>there is not a better language from engineering point of view than C#
Prove me wrong
>>
>>59599958
Who said this?
>>
>>59599958
Everyone that actually works isntead of shitposting about C
>>
>>59599958
What engineering? Cause microprocessor sure as fuck don't use C#
>>
>>59600012
Not sure you understand what I meant.

Also C and assembly are standart, however I have programmed microprocessors in C# and C++.

Language not being used somewhere does not mean it's not good from engineering point of view.
>>
>>59600054
>however I have programmed microprocessors in C# and C++
Disgusting
>>
NEW THREAD!!!

>>59600065
>>59600065
>>
>>59600069
>disgusting
I believe advanced companies use only C++ nowdays
Thread posts: 350
Thread images: 37


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