/dpt/ - Daily Programming Thread

prev: What are you working on, Sup Forums?

Other urls found in this thread:

en.wikipedia.org/wiki/ELIZA
en.wikipedia.org/wiki/Serial_experiments_lain#Apple_computers
cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/fun/life.cl
twitter.com/SFWRedditVideos

Trying to program myself a girlfriend

Is it possible to average two numbers in C?

You may be pleasantly surprised with what I cook up.

If there is, it's probably not with stdio

en.wikipedia.org/wiki/ELIZA

I hate eliza, never has her own opinions just kind of repeats what I say and asks weird vague questions.

>(e ~: t) means e has type t

Why the difference from the regular e : t

Nope. That's a new concept only invented in the last year or so.

Which lisp did Lain use?

python is faster than perl... I cant believe it

and yet it's still shit.

CRowViewCL

Does HRT make you a better programmer?

I'm new to programming and kinda want to get into the it / server admin world. Anyone recommend languages to learn for that? I've heard c# but I have no idea

>admin
You'll want bash/powershell.

ofc

too late bro, these days server admins are the people who were installing gnu/linux as toddlers

Define "number" here.

a quantity or amount.

Be more specific. The name of a set of numbers is fine.

>It's another average autist episode

within the natural numbers it is not necessarily true that there is a natural number solution to averaging

would rational results be allowed?

>it / server admin
reconsider this. they don't do programming.

No computer or programming language can truly average two arbitrary rational numbers.
It would require a computer with potentially infinite memory.

Bash is faster than Python.

>rational numbers
Natural numbers*
I read rational in the other post, and ended up writing that instead.

Lucky for you that ℕ isn't Q.

You could be dealing with numbers so large, they couldn't fit into memory. If you add more memory, I'll just throw a bigger number at it.
The algorithm obviously exists, but you can't execute something over an infinite set in the reality.

I'm only really bringing this up because I'm trying to pre-empt any equally autistic replies about "but your solution only works with N-bit numbers, what if I want to use N+1-bit numbers?".

Just post your fucking code already.

But it's the job of a compiler, not the language. Post your code.

What is Reflection?

I'll just post my arbitrary number of integer averaging function.
int iavg(int n, const int arr[static const n])
{
int avg = 0;

/* A buffer of values that are lost to integer truncation.
* It should always be in the closed interval (-n, n).
*/
int error = 0;

for (int i = 0; i < n; ++i) {
avg += arr[i] / n;

int loss = arr[i] % n;

// error + loss >= n
if (error > 0 && loss > 0 && error >= n - loss) {
// error = (error + loss) - n
error -= n - loss;
++avg;

// error + loss 0 && error < 0)
--avg;

return avg;
}

This was for natural numbers, not integers retard.

Natural numbers are a subset of integers, idiot.

It doesn't average two numbers, because the second argument is not a number.

Doesn't matter, nobody asked for your faggy negative numbers. Your average is gay.

working on this stupid cuck website but im getting paid a shit ton for it so i dont really give a fuck. just knocked out like 10 features with the other dude so our prototype shit is mostly done i guess.

Is this the power of C?

Yeah but with repeated /dpt/ shitposting added to it.

Yet you still failed to produce a function that actually averages two numbers, even within our arbitrary confinement.

Because that's impossible to achieve in C.

Can't be done, lad.

I have to admit, the cat is pretty fucking cute. Thanks for showing me.

It's the power of working in modular arithmetic.

I wrote that function ages ago to shut up all of the stupid averaging maymays on here.
It can average any number of integers, so shut the hell up.

Post that function

you shouldn't use it normal circumstances. it's a way to find methods, fields etc at runtime. for example on android you might use it to detect if a hidden API is present on the device your app is running on.

I already did:

...

rate the program laddies
double avg(T)(in T[] a)
{
import std.numeric: FPTemporary;

if (a.length == 0) return 0;
FPTemporary!double res = 0;
foreach (e; a) res += e;
return res / a.length;
}

void main()
{
import std.stdio: writeln;
[562, 6662, 11, -34187.564, -5].avg.writeln;
}

Are you stupid?

Is it too hard for you to follow instructions?

>foreach (e; a)
niceu, what language is this?
>res += e
you are already dead

>average of nothing is 0

no bully
D

>you are already dead
Please explain. Is this some kind of FP problem?

>foreach (e; a)
ABSOLUTELY
DISGUSTING

novice programmer here, what kind of program would be good to build to work on concurrency

i can only think of trivial cases

Is this confusing?
function remove_nonmatching_words(words, guess, correct)
return filter(function(word) return Multiset(map(table.unpack..operator.sub, zip(word:byte(), guess:byte())))[0] == correct end, words)
end

Note, I've implemented all the functions as you would assume. The '..' syntax between the function references is my syntax for composition. I've gone through the trouble of implementing that for every function in the environment on load. I think I'm going a little too far down the rabbit hole with this...

but why

the funny thing is that the most elegant solution (of averaging two ints without casting to a more precise type) seems to have been forgotten

You're a failure as a human being.

Why's that?

Necrophilia is disgusting.

solve the halting problem

Pony already did.

God C syntax is such doodycaca

It's not unreadable but it's not really elegant either.

Maybe I should do it all in reading order? And fuck the whole character arithmetic bit.

function remove_nonmatching_words(words, guess, correct)
return words:filter(function(word) zip(word:byte(), guess:byte()):filter(table.unpack..operator.eq):len() == correct end)
end

>function nonMatchingWords(words, guess, correct)
return words:filter(function(word) zip(word:byte()
, guess:byte()):filter(table.unpack..operator.eq)
:len() == correct end)
end

>Java Enterprise Ready®

I don't know the language, i just like conforming things to my personal tastes.
function nonMatchingWords(words, guess, correct)
return words:filter(function(word)
zip(word:byte()
, guess:byte()) : filter(table.unpack..operator.eq)
: len() == correct end)
end


v2

She's seen using Common Lisp.
>The HandiNAVI programming language, as seen on the seventh episode, is a dialect of Lisp. Notice that the Newton also used a Lisp dialect (NewtonScript). The program being typed by Lain can be found in the CMU AI repository;[27] it is a simple implementation of Conway's Game of Life in Common Lisp.
en.wikipedia.org/wiki/Serial_experiments_lain#Apple_computers

Here's the program.
cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/code/fun/life.cl

Subete ga F ni Naru also has some Lisp code in the OP.

It's the fact that you're squeezing everything together into 1 line. Everything just looks clobbered together.

Even adding whitespace, I don't even see how to make it look not shit. Syntax just sucks.

Well if that's the case, separate it logically.
function nonMatchingWords(words, guess, correct)
return words:filter(function(word) -- filter out certain words
zip(word:byte(), guess:byte()) -- do character-wise comparison of guess and each word
: filter(table.unpack..operator.eq) -- remove any characters (in the same pos) that aren't equal
: len() == correct -- count how many characters remain, if this is equal to the correct number of characters
end) -- then the word is a possibility of a match and return it
end

fucken shitty-ass quick reply editor

yeah that does look better having all the lines almost equal length.

I do prefer the "data:operation(params)" syntax, it's more readable IMO. BUt now I have to go back and redo much of my environment. I'll have to make an iterator interface and define map, filter, etc. on them. And yes, before you ask, all that is possible in Lua.

What do programmers mean by "sanity check"?

just a broad term for casual unit testing

Affirm what you've been assuming and log an error/crash if you've been adsuming wrong

I need help understanding how to write a pyramid like mario (mario.c)

I know how to make the white spaces push the pyramid to the right but don't understand why my code doesnt work (pic related)

It's a very catch-all term that can be applied to many things, basically just saying "does ____ make sense on a very surface level."

A sanity check on an algorithm might be a simple "input X and see if it gets the expected result on Y."

Or a sanity check can be done on data, for example if you're running a database and it stores the time something happen, a sanity check might check if that any of those times are in the future or before the database was made.

Or you can do sanity checks on parameters. For example, if you have an algorithm which uses an index of the array as a parameter, you could do a sanity check to make sure it's in between 0 and the size of the array - 1, throwing an error/returning a trivial response if it's not.

A very broad term.

>Wrote internal framework to support multi platform development for certain types of devices
>other people in the company use it
>great results


Best feeling

No more CS50 for you

Okay ?

learn for loops

It's easier to do if you just remove the repeating char loop from your outer loop. Then all that's left is figuring out how many spaces and how many *.

void put(char ch, size_t n)
{
while (n --> 0)
putchar(ch);
}

int main()
{
size_t max = 5;

for (size_t n = 1; n

nice spoonfeeding
she still won't have sex with you

this works for me desu
#include

#define HEIGHT 5

int main(int argc, char *argv[]) {
int i, j;
for(i=0; i0;j--) putchar(' ');
for(j=i;j>0;j--) putchar('#');
putchar('#');
putchar('\n');
}
return 0;
}

Don't care that I'm doing his homework, struggling with that mess of loops is not a learning experience anyway.

In fact, it might be better for somebody to show him. Otherwise he'll probably end up writing code that looks like

it's such a stupid question though, probably just copied someone else's code with no concept of how a for loop works, even a day 1 student should be able to figure it out

Absolutely nothing wrong with that code you first-year cs nu-male cia nigger.

Working on remote data acquisition software for pic related. Also shitty texting app that you can spam people with.

Is that a raygun?

Close, its a part of the particle accelerator at fermilab. Using it to test particle detectors, pic related

This might be a retarded question but I honestly am stuck and am a beginner. Python 3.

Trying to code a function that basically takes as input a 2d list.

I want to make a while loop that keeps on asking the user to input an integer.

If they do not input an integer, I want the program to tell them they didnt enter an integer and to retry (i.e. enter an integer once more).

If they do enter an integer, I want to traverse my 2d list and see whether that integer exists (the 2d list is a list of tuples where the first value is an integer and the 2nd is a list of strings like so [ (1,[ 'xd']), (2,['lol']) ] and if it does exist, I want to return that integer.

How would I go about doing this? I've tried several things that seemed to have worked for other stuff in the past but they just didnt work this time.

This is one thing I tried but it just didn't work:

choice=input("enter an integer: ")
while type(choice) != int:
print("incorrect try again")
choice=input("enter an integer: ")