/dpt/ - Daily Programming Thread

anime edition?

Other urls found in this thread:

youtube.com/watch?v=njos57IJf-0
youtube.com/watch?v=p9YXY45CFpI
twitter.com/SFWRedditImages

#include
#include

void squeeze(char* str1, char* str2)
{
int i, iNew, j, member;
iNew = 0;
for(i = 0; str1[i] != '\0'; ++i)
{
//printf("%c\n", str1[i]);
member = 0;
for(j = 0; str2[j] != '\0'; ++j)
{
//printf("\t%c\n", str2[j]);
if(str2[j] == str1[i]) member = 1;
}
if(!member) str1[iNew++] = str1[i]; // this segfaults
//printf("\t\t%c\n", str1[iNew]);
//printf("%d %d %d\n", i, j, iNew);
}
str1[iNew] = '\0';
}

int main()
{
char* str = "barack hussein obama";
char* str2 = "abracadabra";
squeeze(str, str2);
printf("%s\n", str);
return 0;
}


why does this segfault?

I wrote a fizzbuzz that asks counts how many times fizz, buzz, and fizzbuzz are displayed. God damn. I never would have been able to do it if I hadn't drawn a flow diagram!

are you still in cs50?

It's not even a CS class, its an Engineering class and we're learning Matlab

What? Everytime you print Fizz, you increment a counter by 1. And then you increment the respective counters each by 1 everytime a word gets printed. Why the fuck do you need a flow diagram for that?

Fuck off C-sharp, you were asking inane and piss easy questions yesterday. You have no right to diss others.

Because I am by no means an experienced programmer and it helps to visualize what I need to program.

I thought making Flow diagrams was good programming practice?

Are you being sarcastic on the Internet where nobody can hear sarcastic tones, or are you just actually retarded.

String literals are read-only. Trying to modify them will fug you up.

Fuck you

>ENGINEERING?
good! now build a physical machine that does this with real world materials
>or have a redstone contraption in minecraft (no commandblocks)
i asked 1 question u 'tard and it was just a punctuation error, u fuck off!

Don't overcomplicate simple programs. Soon you will be using OOP in places you don't need to.

You are disowned from using C# as of right now, go pollute another gene pool

they're a meme
i went to pajeet overflow and they said the same thing and it works now. i guess [] isn't just pure syntactic sugar for * like i thought it was. i haven't gotten to that section i K&R yet

O-OK

and i wasn't talking shit... i was asking for a fact.
is the kid still in cs50?
he answered engineering, so while i was typing a response, you flamers trying to start some shit. FFS get a life

Frick off Barb

>Barb
???

someone draw a 4d array right now

just allocate a flat array and multiply your variables by factors of the array bounds.
A 4D array would take forever to allocate if done the idiomatic C way.

r8 the meme i made

>implement sieve
>use array of unsigned chars for truth testing, so memory efficient
>only check odd values, so cut array size in half, and forgo initial even sieving, so fast
>happy that I can program well enough to implement this
>try to implement segmented sieve with wheel factorization for memory and sieve optimization
>tenfold harder to implement than standard sieve
>realize I can't program at all and am trash

>A 4D array would take forever to allocate if done the idiomatic C way.
why?

You're retarded

>use strings on a program
>a shit ton of the strings found are pathnames to source code of the application

Is this most likely assert data left over that was never removed?

unsigned i, j, k, l;
int *****a = (int *****) malloc(sizeof(int ****) * n);
for (i = 0; i < n; i++)
a[i] = (int ****) malloc(sizeof(int ***) * n);
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
a[i][j] = (int ***) malloc(sizeof(int **) * n);
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
for (k = 0; k < n; j++)
a[i][j][k] = (int **) malloc(sizeof(int *) * n);
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
for (k = 0; k < n; j++)
for (l = 0; l < n; l++)
a[i][j][k][l] = (int *) malloc(sizeof(int) * n);

C-sharp, can you help me?
can you tell me in everyday speech:
what's the difference between a class and a struct in C#?
i read the definitions of several sites and in my textbook, but damn it. it's just not sinking in.
how do i know when to use which?
is there any difference in how to write them or how to call upon them?

Well memed

>5 star pointer
ohhhhhhhhhhhhh

Holy fuck this is retarded. Just allocate the array as a contiguous block.

2d array:
arr[width*height]
2d access:
arr[I*rows + J]

3d array:
arr[width*height*depth]

3d access:
arr[K*rows*cols + I*rows + J]

(access functions may vary depending on your desired ordering)

follow this pattern for
4d
5d
nd

If you formalize it with the official image and a readable flowchart, I'll even save it.

umm yes?
that's the point I was making earlier.
Though in practice, I can't think of any valid reason to have a 4 dimensional array of anything, I've never used more than 3 levels of indirection and it was just a 2D array full of pointers.

I don't see why this would take forever to allocate.

the only failure I see here is that you gave up

Thank you for not using anime photo

This is the idiomatic way is allocating an array

if n is 10, malloc will be called 11110 times

C-sharp seems to have left.
can anyone else help me please?

>I can't think of any valid reason to have a 4 dimensional array of anything
4D totally antisymmetric tensor. I've programmed it into a numerical code that calculates Feynman diagrams.

I'm going to keep posting this until the meme dies.
int size = 2000000;

long sum = 0;

boolean[] isPrime = new boolean[size];

Arrays.fill(isPrime, true);

isPrime[0] = false;

isPrime[1] = false;

for(int i = 2; i

clarify for me, i don't see how (1,0) and (0,1) don't get put in the same index

I'm in FecesOS right now, can you O3 both methods and show me the assembly?

>Arrays.fill(isPrime, true);
stopped reading

...

for num in range(1,2000000):
if all(num%i!=0 for i in range(2,num)):
print (num)

so this.. is the power.. of python.. woah

Hi lads i have an interesting idea.

seed a random int from 0 to 10^6

then right a while loop that increments +1 until the number is found

How long would this take?

devops was a mistake.

You can start j off at i*i instead of i*2.

It would be found pretty much instantaneously.

I thought it was sieve of aristophanes. Is this the Mandela effect?

you're just dumb, sorry

tic
x = 10^9;
i = 0;
while (i Elapsed time is 2.927581 seconds.

/dpt/ op images should always be anime themed animated algorithms

Run this program if you dare

x = 10^9;
i = 0;
while (i

This and with traps too

How do FP programmers deal with the fact that IO is actually all their program is supposed to care about. Getting from the input to the output is stuff the compiler should make as efficient as possible. So you're just writing code where the computer should and your paradigm is oriented around writing code there. Dumb.

the 6 magically became a 9, weird

go to bed pajeet, you're tired

All well written programs separate logic (manipulating values) from input and output. Pure FP just forces you to do it in a somewhat esoteric manner, or else risk making your code horrible to work with.

main :: IO ()
main = do
input U
displayWithIO :: U -> IO ()

To be fair the 10^6 evaluated in 3/10th of a second. Not exactly instantaneous

you could say the same if it was .0000001 seconds and the statement would be just as valid

Only 10 times faster? 10^6 is 1000 times less than 10^9.

transformPurelyFunctionally getInputFromIO >>= displayWithIO

doesn't your CPU's Ghz determine how long this takes?

Yes, and other factors. For example if it is an Intel or AMD CPU

I bought a Sams Learn C++ book at a thrift store.
Its from 2009 and a couple "editions" old.

Will I still be able to learn properly from it, or has stuff changed enough that ill be learning something antiquated?

what if i have a ryzen cpu?

AMDfags don't count

In HS competitions we assumed 10^8 operations/second for rough estimates

10 HOME
20 SWEET
30 GOTO 10

youtube.com/watch?v=njos57IJf-0

Yes. But more importantly your OS and more specifically the file stream buffer size. Larger is better in this case.
Benchmarking basic IO is fairly pointless usually.
The compiler can also play a role but I'm not sure how constrained they are on fpritnf

What programming language is this?

hehe epic meme amirite :^)

...

could be a snippet from java, C# or a number of other OOP languages.

but its just basic simple logic (while tatement)

yes.
meme to the normies.
nice easter eggs to those in the know.
the more we know about the characters, the better these ERB videos are.

go back there

None of those languages have "end" though. And fprintf (which isn't even being used properly) is generally considered specific to C.

What anime is this?

>go back there
u wot m8?
where is there?

anime?
MANGA!
still frames vs animation

Closest I can think of is lua.

My bad (I wasn't trying to be funny at all). What manga is this?

Manga is just animation consisting of very few frames

Not that user, but it's pseudocode.

OP, you are a moron.
Leave a link to the old thread.
Old thread:

Describe to me the coolest program you've ever made

I'm working with a 2d CSV where a lot of the entries have commas in them. Is there a way in Python to keep these commas without messing up how the csv is read in? Or to delete them without messing up csv formatting?

made a program that can transfer arbitrary files between 2 devices for my computer networks class

he wrote like 90% of the code already though b/c the class has BAs in it and they can't code

>CSV where a lot of the entries have commas in them
wtf kind of data set is this? i hope they at least have some type of marker around them like "". look into regex if they do otherwise you're fucked

The entries with commas in them are surrounded by double quotes right?

it's for the Quora kaggle competition; the dataset is comments pulled from the site, many of which have commas in them with no marker

I'm not really sure how to proceed but this seems like a really dumb thing to get stuck on

youtube.com/watch?v=p9YXY45CFpI

wait a second I'm retarded I was filtering out the double quotes too early never mind
polite sage

catches running refridgerators

>many of which have commas in them with no marker

If there's no marker to delineate quotes and separators then it's malformed. There's nothing you can do.

self driving cars: let's just put horse brain in them.