/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

web.archive.org/web/20160619103848/http://www.nomachetejuggling.com/2014/06/24/the-worst-programming-interview-question/
youtube.com/watch?v=AWnza5JX7jQ
en.wikipedia.org/wiki/Run-length_encoding
en.wikipedia.org/wiki/Huffman_coding
twitter.com/NSFWRedditGif

I need help with this class assignment

#include
#include
int main()

{
int n, odd=0, even=0, num, cont=0;
printf("What is the sequence size: ");
scanf("%d", &n);

while (cont < n){

printf("Type the %dth number: ",cont+1);
scanf("%d", &num);
if (num%2 == 0) even = even + 1;
else odd = odd + 1;

cont = cont + 1;
}
printf("The sequence contains %d even numbers and %d odd numbers .\n\n",even,odd);
return 0;
}

I need to print the odd and even numbers of the sequence WITHOUT USING ARRAYS OR STRINGS

I think it's impossible and my professor is just fucking with us

>print WITHOUT USING STRINGS
what the fuck?

Learn fucking for loops and fucking format your damn code.

A homebrew webserver

>I need to print the odd and even numbers of the sequence WITHOUT USING ARRAYS OR STRINGS
Just print them?
I don't see what's hard here at all. But you're counting the number of odd and even numbers for some reason. I don't get why.

Can you give the exact problem description?

>blocking request handling

It's shit and your wasting your time.

sepples question
I need to allocate some things in a fixed location in memory (eg, a std::vector allocated directly in video memory)
what's the best way to design this?

Well yeah. It's also iterative. I spend all of maybe an evening working on it so far, it's not supposed to be """"""production-ready"""""" yet.

That problem description sounds very odd, is the original text available?

I know, the OS was just an '''example'''. What I mean is, how can I jump that gap, how can I make myself better at it, not if building an OS is a big thing or not.
Do I use my basic knowledge and try to join a team of experts as an aspiring scrub? Do I keep making shit and hopefully getting better at making shit until I make some good shit? Do I keep reading books and believing I need a solid theory understanding and never doing anything?

>Do I keep making shit and hopefully getting better at making shit until I make some good shit?
for me personally, that's the only way to learn.

Is there some kind of RAD for Java?

Any tips on shit to make? Or just do something I'm interested in and eventually become better?
I'm interested in Machine Learning and games. Any tips on how to follow these paths?

i got to touch some old code for a company. This shit is wrote in flex3
Anyone experienced with this technology ?

I got a UI created dynamically and then I would like to access each element knowing their ID, name or whatever

define "lightweight" and tell us what you're trying to do

>ut it's works only on MS platforms
Both of those are cross-platform.

Why can't CS graduates program?
web.archive.org/web/20160619103848/http://www.nomachetejuggling.com/2014/06/24/the-worst-programming-interview-question/

>Write a function that can detect a cycle in a linked list.
This guy threw up a shitfit because he can't think up the solution in 10 seconds, it's really stupidly easy.

> define "lightweight" and tell us what you're trying to do
Lightweight means abscense of necessity to download heavy Visual Studio

write them on a file and then read the file

Alternatively, create two processes, pipe between them
One read the user input, print the even numbers, and send the odd numbers to the other process on the pipe
Once it is done reading user input (and thus printing all even numbers, the other one start reading on the pipe and print the odd numbers.

I don't know if this kind of solution would work, it's been a while I didn't played with processes and pipes in C.
Is there any C wizard ? I'm actually interested on my solution and the actual solution to its problem

for(auto* n : list)
{
if(n->next != nullptr && n->next->next == n)
// found it
}

would this work?

Would they accept my answer if I just stored all the *next pointers in a flat array and sorted it?

If you have a duplicate of any memory address, that's a cycle, right?

That would work if the duplicate was right after the last iteration.

copy to vector, erase duplicates, if list is different in size you have a cycle.

>Both of those are cross-platform.
I wouldn't use incomplete (and third-party) solutions to be honest.

oh youre right.
btw, what if i didnt want to create a copy, would a for inside a for do it?

>read the article

Just cuck my shit up already
fwrite(&(((uint8_t*)&code[offset][i])[j]), sizeof(uint8_t), 1, fout);

>yes we know what the article says, we're talking about

vector + unique is pretty fast, counting duplicates needs a copy, two loops iterating doesn't sound as fast

>tfw your repository type is up to 8 different I*Repository interfaces implemented and 1400 lines of code and you're only about a third of the way through what was supposed to be a 'quick easy project'

Making an email automation desktop program in C#, what's the best way to store email templates while preserving string interpolation? The end goal is that I want a user to either not have to worry about selecting one (pick one at random) or allow them to select a template.

Using Rust to make a TUI game.
hbu?

Writing C code like a real man because I'm not a little faggot special snowflake that can't handle anything that as a pointer in it. Your kind should fucking die, you're the reason softwares are so shit nowadays. Pajeet use java but faggot numale code artisan, starbuck sipper like you use Rust. Enjoy your piece of shit language will you can. In 2 days max you'll abandon your shit project and consider suicide. Then after getting fucked in the ass by your girlfriend's feminine penis you'll come back here shitting on C programmers telling us how our language is so shit. Yeah guess what faggot, no one cares about you so how about you take a shovel and go bury yourself in the forest so you actually serve a purpose in your life by helping tree grow. Then MAYBE you'll pay back the debt you owe at humanity for even existing.

doing things with memories

>user responds to OP's question
>Someone gets triggered because its Rust
Everytime

Hm... Is there a way to get youtube to stream audio directly?
I remember that a while ago an user made a youtube audio player, but I don't know he did something like that, or if it was just download+convert...

bad post
good post

#triggered by zero-cost abstractions, move semantics, guaranteed memory safety, threads without data races, trait-based generics, pattern matching, type inference, minimal runtime, and efficient C bindings. Truly Rust is the next step forward in programming.

B-but I didn't write it

"Read a sequence of "n" numbers, count how many of them are odd and how many are even, then display the odd and even numbers that were inputed along with the count"

The issue is doing that without arrays and pointers

All I should use are loops

What, you can't handle the borrow checker, can you?

Bumping question

>That style
Kill yourself.

But it's not a list if it has a cycle.

I'm not 100% clear on the problem from the way you phrased your question but I'm guessing you're supposed to either output the number of even and odd integers in a sequence given an arbitrary sequence length, OR output all even integers and all odd integers, separately, given an arbitrary sequence length.
All you gotta do is a little bit of math on the sequence size to know the number of even and odd integers.
Simply counting up towards the sequence size and checking if the current number is even or odd will give you the ability to filter out odd from even when printing them separately.
int seq;
int i;
printf("Enter a sequence size:\n");
scanf_s("%d", &seq);
printf("Quantity of Even Integers in Sequence: %d\n", (seq % 2 == 0) ? (seq / 2) : ((seq - 1) / 2));
printf("Quantity of Odd Integers in Sequence: %d\n", (seq % 2 == 0) ? (seq / 2) : (((seq - 1) / 2) + 1));
printf("Sequence of All Even Integers: ");
for (i = 1; i

What editor is this?

visual studio.

Write the entire problem description because I don't see where it says "don't use arrays or strings".

Christ. That is a nasty assignment. He's probably messing with you if this is an introductory course and it's not an introduction to recursive functions.
#include

void countAndPrint(int odd, int even, int count){
int num;
if(count==0){
printf("There were %d even numbers and %d odd numbers.\nPrinted in reverse order:\n",even,odd);
return;
}
scanf("%d", &num);
if(num%2==0) {
countAndPrint(odd, even+1, count-1);
}
else{
countAndPrint(odd+1, even, count-1);
}
printf("%d ",num);
return;
}

int main()
{
int count;
printf("What is the sequence size: ");
scanf("%d", &count);
countAndPrint(0, 0, count);
return 0;
}

I haven't tested this.

And I'm not sure it even fits the description perfectly.
It's displaying the odd and even numbers but not grouped as odd and or even.

Working on encoding algorithm

ENCODE MY ANUS!

data is a text file but it can work with anything

use an index in the header or another file and remove the null bytes

(´・ω・`)

Thanks you, but he thing is that you can input any number
Let's say you chose a 5 number sequence

Then you input
66
7
8
129
6666

The program must tell there are 3 even numbers, 2 odds
and show that the even numbers are 66,8,6666 and the odds are 7 and 129

The problem is how to store those numbers without arrays/strings
I think the word sequence isn't the right one

Daily reminder that Cobol got user-defined functions in 2002.

How would this work tho? Do I save the position of the null bytes in the index?

Read:

>linking Rust to C
The absolute mad-man.

Assuming you're using them as separators between rows or chunks (or a similar concept to separate something) yep.

Does anybody know an PSO r software package by any chance? I don't know the language that well

oops
youtube.com/watch?v=AWnza5JX7jQ

No they are actually used, they're not separator. I'm using the huffman coding so all I have in the file is a table at the beginning with the number of symbols (a symbol is a byte) and the code given to it then all the encoded symbols.

disgusting. Look at this faggot, typical Rust """programmer"""

void fun(const Foo* const bar const);


How the eff do i remember what the different levels of const does? Every time i need it i've forgotten and have to read up on it again. Every single time!

see if it saves you any size by removing them and implementing that idea anyway, it seems like the table could be replaced with their position

Assuming you're talking about >you can input any number
Check. You can input numbers up until you get a stack buffer overflow.
>then you input ...
Yep that's how it does things.
>The program must tell there are 3 even numbers, 2 odds
Yep
>and show that the even numbers are 66,8,6666 and the odds are 7 and 129
This is where it fails yes.

I can't work around this unless I get to use a bit array. And even then it'd be limited to 64 numbers total. And frankly I'd have an easier time just reading directly out of the stack.

This is also a question I have: Maybe you misunderstood the constraint?

And since you're probably new. This is all pure wank. Nobody will ever realistically ask you to work under these constraints or will give you any problems similar to this.

Looks like a typical nerdy white male programmer to me. He just doesn't look like YOUR idea of a typical programmer which is a stinky Indian.

Yeah but each null byte is one byte, storing the position of a byte would take one or more byte so it would compress. Or am I missing something?

Couldn't you do something where you have four ints, two are counters for odd and even numbers, respectively, then the other two hold the actual numbers and you can just mod them out at the end?

User inputs: 1 3 5 7 2 4
Then you store:
countodd = 4
odds = 1357
counteven = 2
evens = 24

You could probably monkey around with the method to store numbers that are greater than single digits as well maybe by padding with zeros or something to signal the start and stop of a single number

See en.wikipedia.org/wiki/Run-length_encoding

That's close
But I need to print the odds and even separately

>Maybe you misunderstood the constraint?

No, I even confirmed that
We can use array/stings since we " haven't learned it" yet

You could always be a cheeky little fuck and malloc a chunk of memory to hold ints instead of directly using array syntax
size_t seq_size;
int *seq;
int *seq_idx;
size_t i;
int value;
printf("Enter a sequence size:\n");
scanf_s("%d", &seq_size);
seq = (int*)malloc(seq_size * sizeof(int));
seq_idx = seq;
for (i = 0; i < seq_size; ++i)
{
scanf_s("%d", &value);
*seq_idx = value;
seq_idx++;
}
seq_idx = seq;
printf("Values entered: ");
for (i = 0; i < seq_size; ++i)
{
printf("%d ", *seq_idx);
seq_idx++;
}

Don't cast malloc, btw. Only reason I'm doing it is because I'm using a C++ compiler.

const is read from right to left. This is a reason I continually tell people to always put const on the right.
void fun(Foo const * const, Bar const);
fun takes a constant pointer to a constant Foo type and a constant Bar type as parameters.

I see. Thing is, consecutive null bytes, or consecutive bytes of any kind are pretty rare in the encoded file. I not sure it would be worth the trouble.

>We can use array/stings since we " haven't learned it" yet
Ok. So we're even more constrained then. Can't do recursive calls.
What have you learned?

Interesting idea, it wouldn't be a string after all

Let's say I separate the numbers with zeros, how do I clean it up later for print?

i.e. 1077017709 to 1 77 177 9

We just finished while,for and do loops

I suggested the RLE article, but I'm not the one that suggested encoding the null bytes.

Looking back at the earlier posts, I'm not really clear now on what it is you're trying to accomplish.

That'll work, but then again I can't use all those "fancy" things

I'm implementing this en.wikipedia.org/wiki/Huffman_coding

this teacher sounds like a moron desu

you rarely need to nest your const levels that deep. in general:

const thing* // = mutable pointer to const thing.
thing* const* // = const pointer to mutable thing
const thing* const // = const pointer to const thing.

Without actually working through it my intuition is to use a loop and mod through the number accumulating the digits until a 0 comes out then print the number and reset the accumulator

edit: second should be thing* const.

So you're gonna do this using the basic types like int, char & whatever. No conditionals aside from while for and do loops? I'm fairly certain you've misunderstood something or it's just a crappy teacher.

You really have more productive things to spend your time on. Playing videogames, masturbating or shitposting.

The most important thing is to not use the edge case special syntax where you put const before anything else. If you don't, you just read from right to left and you get your answer.
int const * // pointer to constant int
int *const // constant pointer to int
int const *const // constant pointer to constant int

>The most important thing is to not use the edge case special syntax where you put const before anything else.
What does that case mean?

this guy gets it

no, that's the confusing way. think of it as:
[const thing]* // = mutable pointer to const thing.
thing[* const] // = const pointer to mutable thing.
[const thing][* const] // = const pointer to const thing.

I'll try that
>or it's just a crappy teacher.

Probably
I'm curious to see her fucking resolution

What you want to do is compute the autocorrelation function of your byte sequence and see if the data exhibits any periodicity. If it has some dominant high frequency patterns, you can XOR it with a simple periodic sequence to remove the periodic part. If your data is not random, this will often leave you with a pattern with a lot of repetition where run-length encoding is more applicable.

>I'm curious to see her fucking resolution
I say you shouldn't complain about it (even to classmates). Accept it and move on. That's the wise decision.

just stop your shitposting isnt funny

If you put const before the type it's like putting const just after the type, but it breaks the easy right-to-left rule.

How is it confusing? It's more consistent.

>const
>const *
>*const
>c++
>good language

Almost got it, just need to know what does the % does here:

printf("%d\n", score % 10);
score /= 10;

modulus

% means modulus.
You divide the two numbers and the result is the remainder.
5%4

is 1.
4%5

is 4.
4%4

is 0.

divides by 10 and gives you the remainder

How did I forgot that
Thanks again

Wow. So much effort just to use Rust for what's at most a marginal benefit.
Doesn't seem very realistic to expect people to do this.

Wait a minute.
int const x, y; // both x and y are const
int *x, y; // only x is a pointer

What the fuck were they thinking?

>Rust for what's at most a marginal benefit.
Well, converting a 500k C base to rust does have its benefits. But their situation is going to be very slow for a complete one.

Although I think Rust is overrated, this is one of its prime use cases.