/dpt/ - Daily Programming Thread

/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Other urls found in this thread:

github.com/nothings/stb/blob/master/docs/stb_howto.txt
youtu.be/FKFH_-QogN0?t=16m35s
yarchive.net/comp/linux/x86.html
github.com/nothings/stb/
reddit.com/r/dailyprogrammer/comments/5e4mde/
reddit.com/r/dailyprogrammer/comments/5emuuy/
upload.wikimedia.org/wikipedia/commons/1/15/Table_of_x86_Registers_svg.svg
docs.oracle.com/javase/7/docs/api/java/io/BufferedWriter.html
twitter.com/AnonBabble

>it's a hasklel spergs out about a feature his language omits episode

kawaii

konijinkontje

4th for Clojure.

Assistance with C++ templates requested.

Well if you're gonna keep the template remove the =int part. Don't start with a specialization.

Also you may be interested in this later:
github.com/nothings/stb/blob/master/docs/stb_howto.txt

so im running a C# program that references a DLL file from a separate project.
when i export the project into an exe it works just fine, but when i try it on a different computer i get this error

System.IO.FileNotFoundException: Could not load file or assembly 'SudokuWrapper.dll' or one of its dependencies. The specified module could not be found.
File name: 'SudokuWrapper.dll'


the the DLL file is clearly in the same folder. i try dragging the DLL file into the exe and running it that way but i get the same error.
I put copy local to true in the DLL project but i still get this error.

/dpt/-chan, daisuki~

Ask your much beloved programming literate anything (IAMA)

What have you written in clojure?

Thank you for using an anime image.

Programming is one of the most difficult branches of applied mathematics; the poorer mathematicians had better remain pure mathematicians.

Also, youtu.be/FKFH_-QogN0?t=16m35s (go at 16m35s if you watch embedded)

> let x = 1 + 2
> :sprint x
x = _
> seq x ()
> :sprint x
x = _


???

>remove the =int part
Then the compiler complains that it can't deduce the type from the call signature. Naturallly, since there's nothing in the call signature to deduce the type from.

I'd like to add that in the C# project the way i get it to work with the dll is I right click on the project node in solution explorer -> add -> Reference...
Then i use the file manager to locate and select the DLL which is in a separate project.
I know that this is the cause of the issue because other computers obviously don't have the file path that i have, which is why i thought setting copy local to true would fix the issue but alas, it didn't.

Yeah so use a template for a function where it matters.
This has nothing to do with a header only library.
I just don't see why you decide to introduce stuff for no real reason.

If you saw the posts yesterday about average functions, please post some solutions that properly round two ints' average. (away from zero).

Like the other user says, you're using a template where it doesn't make sense.

If you absolutely must, you can indicate the type to use when calling it like so:
PrintFoo();

> What have you written in clojure?
Nothing major. I'm not an actual programmer. I'm a 'wet' scientist.

say I had a massive switch block with 100 cases

would it be a good optimization to run the program for a long tme and see which case gets "chosen" the most and put those in desc order?

this doesn't round, but for that you can do
round . avg

*In pedantic c.

(%) is the ratio constructor (i.e. a king of (/)), NOT modulo

Next time, try not to give it an absolute filepath or add an openfiledialog, moron.

int avg(int a, int b){
double c=(double)a+(double)b/(double)2.0;
return (int)c;
}

why is x86 such a pile of shit?
can anyone explain the reasoning behind having only 4 registers etc?
there are other languages with more freedom and better features, why did the tech industry chose x86?

Two things this weekend:

1) Working through a Data Science specialization on Coursera. It's all R programming and working with data sets.

2) OS homework due tomorrow by midnight. A small project (

Extension for Windows Firewall allowing to handle outbound connections and create rules automatically

>This has nothing to do with a header only library.
It is of course possible that i'm taking an entirely wrong approach.
How do i implement a header library the right way then, according to you?

>PrintFoo();
That's even worse, for this use case.

from num in nums.avg
select num
:[] :^) :&

That's because your use case is shit.

post a screen shot of your programming environment

yarchive.net/comp/linux/x86.html

if you remove the segmentation memory model, which is now the case, x86 is the best ISA after VAX. VAX now being dead, x86 is the best.

>How do i implement a header library the right way then, according to you?
github.com/nothings/stb/
This. He's an experienced programmer who prefers header only libraries.
I like his libraries too.
He does it perfectly.
And it's just 'write the fucking code'.

Well, we use x86-64 now which has more registers

are you FUCKING kidding me

Better than "average int" assholes deserve.

...

>only 4 registers

Umm...

t. I can't solve the problem

t. someone who doesn't know how to use t.

Of course you can't because you can't average (C) integers.
What you most likely aim to do is average integers. Which is an entirely different problem. And that's not possible on computers due to limited memory.

It's a completely arbitrary standard put up by idiots. Like you.

Rate my (untested) solution guys
int avg(int a, int b) {
double result = a/2 + b/2;
result += ((a % 2) + (b % 2)) / 2;
return result;
}

Most compilers turn switch statements above a certain length into binary search trees, so I doubt that would do anything.

whoops i meant "double avg(", not "int avg("

can you compute something like (999^999^999) mod (a number)?

#include

typedef struct {
int numerator, denominator;
} ratio_t;

ratio_t divide(int x, int y) {
ratio_t result;
result.numerator = x;
result.denominator = y;
return result;
}

int gcd(int x, int y) {
if (y == 0) return x;
return gcd(y, x % y);
};

ratio_t simplify(ratio_t r) {
int k = gcd(r.numerator, r.denominator);
return divide(r.numerator / k, r.denominator / k);
}

ratio_t inc(ratio_t r) {
ratio_t result = simplify(r);
result.numerator += result.denominator;
return simplify(result);
}

ratio_t dec(ratio_t r) {
ratio_t result = simplify(r);
result.numerator -= result.denominator;
return simplify(result);
}

ratio_t addInt(ratio_t r, int i); // TODO

ratio_t average(int x, int y) {
if (x == 0) return divide(y, 2);
if (y == 0) return divide(x, 2);
if (x == y) return divide(x, 1);
if (x == -y) return divide(0, 1);
if (x < 0 || y < 0) return dec(average(x + 1, y + 1));
return inc(average(x - 1, y - 1));
}
#define n 5
int main(void) {
int tests[n][2] = { { 7, 0 }, { 3, 4 }, { -3, 7 }, { 192, 33 }, { 396, 728 } };
for (int i = 0; i < n; ++i) {
ratio_t result = average(tests[i][0], tests[i][1]);
printf("%d/%d\n", result.numerator, result.denominator);
}
return 0;
}

Use static, not template, derp.
Thanks guys. I'm glad i bothered to ask /dpt/ for help.

Still exploring the deepest, darkest corners or Racket.

this is btw
i would love to test it on int_min and int_max but it would take at least int_min or int_max operations

>Use static
Why? It has nothing to do with your stated issue.

int AverageAndRound(int a, int b)
{
return Math.Round((a+b)/2d);
}

Good points. Stay mad.

Yes.
Key points:
x*y mod n = (x mod n)*(y mod n) mod n
x^(2n) = (x*x)^n
x^(2n+1) = x * (x*x)^2

Nigga why use such a beautiful language and such an ugly af font?

Recursive in C.

I'd like to see you average two integers

What? It has everything to do with my stated issue. And it's how Sean T. Barrett solves it, it looks like to me at least.

What do you think my stated issue was?

neat image
saved

you should use haskell with sublime text in starbuks you know?

I'm op. I posted the solution a couple days ago, and I think one person saw it. It was only 3 lines, 2 assignments.

The average of 2 and 4 is 3.

...

Then post it again.

please, just this once, can i get spoonfed.
I did enough "just figure it out" tasks already this is LITERALLY the last thing i need to do.
pls

what is that challenge about? I see from some time but havent found the source

Non-standard extension

optimized image to save space in your computer

return a/2 + b/2;
>me on the right

reddit.com/r/dailyprogrammer/comments/5e4mde/
and
reddit.com/r/dailyprogrammer/comments/5emuuy/

You're trying to make a header library, I guess, but it seems that you don't actually understand much of the syntax you're attempting to use.

'template' makes a C++ template, in which a function will be generated new (at compile time) for each different template arguments you give it.
template
void foo () { std::cout

That's one of the worst solutions, I love it. It not only gives incorrect rounding, but also gives completely wrong answers.

you know what
I just save em both

I'm going to try this in Haskell

who cares

The original is an svg. I only converted it to sate Sup Forums's uploader. Have the original:

upload.wikimedia.org/wikipedia/commons/1/15/Table_of_x86_Registers_svg.svg

>Average of 5 and 7 is 5.
You should

Why the fuck are there so many classes for Java I/O? I'm trying to learn how it works so I can save the state of my text game but it's a fucking mess.

> python3
> 5/7
> 0.7142857142857143

why bother averaging numbers in C, when you can do it in python?

Thanks, I really couldn't afford to take up that extra 200 kilobytes.

you know who is a mess?

any programming languages?
do you have a test case?

you're welcome!

In C, I have a program that tests them.

return (int) ((double) a / 2 + (double) b / 2)
ez

(disclaimer: I'm not a java programmer and never use it) It's not uncommon to have a lot of writing methods for many languages because there are a lot of ways to write (even linux itself has several different system calls for writing to a fd). For GENERAL purposes, though, you want a writer that is buffered (so that you're don't get shit performance). From a 2 second google, this is probably what you want:

docs.oracle.com/javase/7/docs/api/java/io/BufferedWriter.html

>I have a program that tests them.
post code

Takes the floor, not rounding.

>'template' makes a C++ template, in which a function will be generated new (at compile time)
Which solves the problem. Although rather uglily, as demonstrated by my original solution.
I was looking at how gml does it, and they used templates for everything, although i suppose, with better cause than i had.

>'static' makes a symbol local to that file, so that you can redifine it with a different name in another file without it clashing.
Which also solves the problem. So why do you say it has nothing to do with my problem?

Are you saying i should inline everything instead, and that will work as well? I'm going to try that.

I have been writing C and Java for years and I want to switch to C++. I can obviously just Google a tutorial to learn from it, but there is obviously a ton of overlap.

How would you go about learning it given how I already know a good chunk of it. What projects would you recommend?

// true value = average + remainder/2
typedef struct result {
int average; // truncated
int remainder; // remainder * 2
} result_t;

result_t average(int x, int y) {
int z = x%2 + y%2;
result_t result;
result.average = x/2 + y/2 + z/2;
result.remainder = z%2;
return result;
}

show me an incorrect result

Some book, titled "C++ for [Java/C] Programmers" or similar.

What does buffered mean in this context?

I_IO.Default_Width := 12;
Open(Input_File, Mode=>In_File, Name=>"INPUT");

for I in Function_Names'Range loop
Reset(Input_File);
Put_Line(Function_Names(I).All);
Failure_Count := 0;

while not End_Of_File(Input_File) loop
I_IO.Get(Input_File, A);
I_IO.Get(Input_File, B);
C_Ada := Ada_Average(A, B);
C_C := Function_Array(I)(A, B);
if C_Ada /= C_C then
Put("Failed");
I_IO.Put(A);
I_IO.Put(B);
Put(" with output =");
I_IO.Put(C_C);
Put(" :: Expected");
I_IO.Put(C_Ada);
New_Line(1);
Failure_Count := Failure_Count + 1;
end if;
end loop;

Put_Line("Total Failures : " & Integer'Image(Failure_Count) & "/21");
New_Line(1);
end loop;

5 and 6 takes the floor, outputting 5.

It means that when you write to it, you're writing to a buffer that wont flush it's contents unless the buffer fills, or it otherwise has to in order to work. So instead of writing bits to the file arbitrarily, it does it in some multiple of the block size.

So wasteful. Why save all the color?
This image still contains the relevant information.

Though 32-bit and 64-bit may seem similar to the not so observant they're actually different colors.

yeah obviously if the return has to be an int
there is no better solution than this

>ada
i am so sorry.

You can have a solution that outputs a correctly rounded number. If you believe 5 and 6 rounds to 5, you must also agree .99 rounds to 0.

Hey /dpt/.

I have a quick question:

Do you know if it's possible to align labels within a GridPane in JavaFX using CSS?

Previously I have made a HBox for each label, and then aligned the labels right inside the HBox. This approach is not a problem, but I would like to do it in CSS if possible.

Here's a screenshot, I'd like the labels to align so the end of the text is next to the corresponding button.

Thanks. So Java I/O naturally reads/writes one byte/character at a time unless you use a buffer?

Shouldn't 5.5 round to 6 by convention? Not 5.