[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 33
File: ko.png (389 KB, 934x1000) Image search: [Google]
ko.png
389 KB, 934x1000
What are you working on, /g/?
>>
File: aima.jpg (27 KB, 260x325) Image search: [Google]
aima.jpg
27 KB, 260x325
post readings
>>
Just bought a cute ruffled skirt and strappy heels; what programming language should I use now?
>>
>>51990404
>cute ruffled skirt
nice
>strappy heels
gross

haskell
>>
>>51990404
become melon pan https://www.youtube.com/watch?v=seZlK_qjbao
>>
File: gpls.jpg (280 KB, 1366x768) Image search: [Google]
gpls.jpg
280 KB, 1366x768
I'm working on trying to not get my shit fucked up

Where to start /g/? Just wanna make mobile games ;_;
>>
>>51990522
Read a beginner book on Java, then read a book on Android SDK.
>>
>>51990404
You need Jesus.
>>
File: guess.png (48 KB, 1162x291) Image search: [Google]
guess.png
48 KB, 1162x291
guess
>>
>>51990654
Last blur is "with my friends"?
>>
>>51990654
its compiler is very lightweight and portable?
>>
>>51990654
>blurring out "with my friends
kek'd

___.lang.org
it's extremely lightweight and _____
>>
>>51990654
Request to add rust
>>
File: 1444602855095.png (805 KB, 1108x1229) Image search: [Google]
1444602855095.png
805 KB, 1108x1229
is anyone familiar with PostgreSQL on cloud9?
>>
>>51990839
Whatcha need?
>>
>>51990654
>Rust

Sent from my estrogen laced dildo while looking at my preferred pronouns poster.
>>
come shitpost with us /g/
https://codeshare.io/HBGOR
>>
>>51989826
what's your lowest score? Because I'm getting in the 4000s
>>
>>51991037
what website is that?

whats the best programming exercise test-your-skills website?
>>
>>51990654
definitely Rust.
>>
>>51990993
it's no fun when people are deleting shit
it needs to have a cap on how much you can paste in and disable mass deletion
>>
>>51990371
a tilebased game
>>
>>51991037
I made the par 600 because my first attempt was 600.
I also realized I left a line out of the performance scoring rules:
For every time that a tile is dirty, the performance score is incremented by 1. So, if both tiles are dirty, then in that frame, the performance score is incremented by 2.

With that last rule considered, I'm getting -40 as my best.

Here are my rules:
If the tile the vacuum is on is clean, move.
If the tile the vacuum is on is dirty, suck.

That gives 600. I modified it some to get it to -40, which I think is approaching the best score.

Make sure your tiles each have a 10% of getting dirty each frame, and that you're counting your score correctly. Is your average 4000 or your total after 1000 runs of 1000 frames 4000?

>>51991082
It's an exercise I made up based on an introduction to agents in >>51990401
>>
>>51991154
-66, not -40, I mean.
>>
>>51991186
>>51991154
Fucked up in my implementation actually, with the 10% random dirtiness. My best is actually 407, and those rules gives about 740

Tbh since I made this silly challenge up and the rules it's such a mess
>>
>>51991219
I also needed to specify that the vacuum can only detect dirt that's on the tile under it, not on the tile next to it.

Nevermind this whole thing, lmao.
>>
>>51990993
holy shit we're actually making something
>>
>>51990522
Nice collection of shit you'll never read
>>
>>51991154
what? your rules are all fucked up
there's a ton of ambiguity, for starters if you can know whether the tile is dirty or not without cleaning (I assumed not, which was why my score was so high I guess)
also your average per move couldn't possibly be as high as 600
I dunno man

next time you do this you should post a framework that defines the base problem in whatever language so that it's a much more straightforward problem, so that the only thing to be designed is the actual bot
>>
>>51991300
True that my man
>>
30th for language.
>>
>>51991349
post your github
>>
>>51991370

Don't have one.
>>
File: 1413714270318.gif (297 KB, 640x448) Image search: [Google]
1413714270318.gif
297 KB, 640x448
whats a good casual filter ?
something normies/pajeets just cannot do or comprehend
>>
>>51991418
write a program that has the ability to generate and add code to itself, as well as update itself by compiling that code
>>
>>51991418
anime

>>51991399
post your resume
>>
File: 1450503221044.jpg (799 KB, 1200x1600) Image search: [Google]
1450503221044.jpg
799 KB, 1200x1600
>>51991459
>post your resume

Not on 4chan, not ever. Here's a black woman for your troubles.
>>
it's our masterpeice
http://pastebin.com/jzz3NSvR
>>
>>51991483
Promote racemixing somewhere else, jew
>>
>>51991418
Anything that involves the tiniest bit of math will probably do, like implementing fast Fourier transform.
>>
>>51991483
nice

see you could post it if you weren't a tripfag
>>
>go to do those advent program puzzles with a different language for each one
>7 languages in start to lose steam and just solve some in a language I've already used
I'm really fucking tired of dealing with strings. There are several esoteric languages I want to use but the thought of dealing with the input character by character is really offputting.
Scratch as well because why the fuck not.
Planning C, Ada, Common Lisp, and Java. Probably will do one in Perl. Want to try Prolog and Ruby, maybe one in Clojure.
Any languages I should check out?
>>
>>51991565

Anons don't generally post their resumes, either.
>>
>>51991566
Oops, forgot I already did one in ruby.
>>
@:
blah blah
blah +@ // Jump forwards to the first @ after this line
@:
blah -2@ // Jump backwards to the second @ before this line.

What are these kind of labels called?
>>
/*
green\ is\ my\ pepper - a program with balls of pepper (balls of pepper!)
Copyright (C) >2015 de/g/enerate teenagers who think they can pro/g/ram

This program is free software (they do it for free):
You can redistribute it and/or modify it under the terms of the
ganoo General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNO/Lunix General Public License for more details.

You should have received a copy of the ganoo General Public License
along with this program. If not, see <http://www.gno.org/licenses/>.
*/
>>
>>51991566
If you really want to get the most of Lisp then I'd definitely go for both Common Lisp and Clojure (maybe even Scheme). It's fun to see all the different ways that such similar languages can be used.
>>
>>51991605
My Racket ones might as well have been R5RS. Don't think I used anything non-standard Scheme.
>>
>>51990371
Brand new to programming. Start uni next year. Been learning C for 2 months, building shitty games. I've started to learn C++ and i've got no fucking clue why people rave about this OOP concept, it just seems like i just end up writing lots more LOC. I'm guessing it makes programs easier when they're lots of people working on it, i've got no idea.
>>
>>51991573
they post their github which has a link to their website which has their resume, actually
>>
>>51991152
elaborate
>>
>>51991635
Mine doesn't.
>>
>>51991635
tfw no website
>>
>>51991664
>>51991670
maybe I should have said "which sometimes has a link"
>>
>>51991627
>I just started learning C and OOP is dumb.

Classic critique. You'll learn to love multi-paradigm programming.
>>
>>51991621
oh i missed the image, didn't see that~
i'm not trying to be a pedantic retard who thinks Racket is not Scheme
>>
>>51991702

Multi-paradigm programming is the shit.
>>
>>51991747

Exactly. There's something good about almost every style of language. Sometimes it gets a bit clusterfucky when you put it all together (à la C++), but there's a whole lot to love.
>>
>>51991747
>>51991702
All programming is multi-paradigm, unless it's only procedural.
>>
>>51991702
not being a critique bro, just kind of don't get it's advantages yet.
>>
>>51991828
>just kind of don't get it's advantages yet.

In time, my son.
>>
>>51991787
not really. multi-paradigm programming in a language that tries its best to constrain you to a single paradigm is no different than "functional programming in assembly". the fact that you have to go the extra mile just to make it possible (and likely nowhere near comfortable) means that you're losing out on the advantages and just reaping the disadvantages. even in languages that encourage multi-paradigm programming most code you see stays pretty clearly from one or more of the available paradigms. just using a single object in your code doesn't instantly transform it to being object-oriented. the paradigm is more to do with the overall design of the program and that very rarely ends up being more than one paradigm.
>>
>>51990371
>anime
>>
>>51991627
>concept, it just seems like i just end up writing lots more LOC
You're doing it wrong. Throw your book away and get a better one.
>>
>>51991870
hey pizza
I read your post and am having trouble reasoning how it's related to mine, did you mean to reply to me? Maybe I should re-state my post: all programming is procedural, and may or may not also include another paradigm.
>>
>>51991778

Ruby throws together ideas from Smalltalk, Perl, Eiffel, Python, and Lisp, and yet it manages to not be so much of a clusterfuck.

But then again, it isn't trying to maintain backwards compatibility with anything, and it isn't trying to be performant. It's just trying to be easy to develop shit in.

>>51991870

>functional programming in assembly
I want to see someone do this now.
>>
>>51991908
>But then again, it isn't trying to maintain backwards compatibility with anything, and it isn't trying to be performant. It's just trying to be easy to develop shit in.

Fair enough. That said, it seems like Stroustrup and Gang are trying to lead people away from the "act like this is C with objects" mindset with his promotion of C++ Core.

One day, you'll be able to look at a pile of C++ source without vomiting.

Life will be good.
>>
File: shakey.jpg (357 KB, 600x954) Image search: [Google]
shakey.jpg
357 KB, 600x954
>An operator types the command "push the block off the platform" at a computer console.
>Shakey looks around, identifies a platform with a block on it, and locates a ramp in order to reach the platform.
>Shakey then pushes the ramp over to the platform, rolls up the ramp onto the platform, and pushes the block off the platform.
>Mission accomplished.

Why is Shakey so based?
Should I learn a lisp?
>>
>>51990906
just some basics with joins mostly outer joins
>>
can i just say something
>>
>>51992091
yep, that was it, now you're done
>>
>>51992091
is it a meme?
>>
>>51991908
>>51991946
>But then again, it isn't trying to maintain backwards compatibility with anything
Which is precisely why I like D better than C++.
>>51991908
>>functional programming in assembly
>I want to see someone do this now.
If you expand "assembly" to mean any low-level, turing complete language then you could consider the Lambda Calculus to be a functional assembly. Or maybe if you expand the definition of "functional programming" you can consider the assembly that Lisp machines used to be functional.
>>
>>51992122

I like D. No homosexual meaning intended.
>>
File: Untitled.png (56 KB, 1228x704) Image search: [Google]
Untitled.png
56 KB, 1228x704
SFML is pretty great. I've used it a lot in C++ applications and gave it a try in a C# application with bindings this time.
>>
>>51992184
SDL here SFML a shit
>>
20 minutes til advent day 22 lads
>>
>>51990424
every time I think I've seen it all, this fucker manages to top it
how low can one man go holy shit
>>
File: screenshot.png (388 KB, 1920x1080) Image search: [Google]
screenshot.png
388 KB, 1920x1080
Starting working on my chess engine.

Progress is extremely modest so far. So far I've managed to implement a board representation using bitboards. My next task is to create a legal move generator.

My end-goal is to create an extremely aggressive chess engine optimized for playing blitz against humans (ie I'm hoping to troll lichess in a few months).
>>
10 minutes til advent day 22 lads
>>
>>51992122

>D
Yeah, but doesn't the standard library operate under the assumption that you have garbage collection turned on?

>>51992184

My only problem with SFML is that its networking library doesn't support IPv6... Although you could just use the rest of the libraries as normal, and use Curl for networking.
>>
>>51992405
>doesn't support IPv6
nigga what? How does a complete library not support it? Does SDL support it?
>>
>>51990404
haskell
python
>>
5 minutes til advent day 22 lads
>>
>>51992202
SDL2 here SDL a shit.
>>
2 minutes til advent day 22 lads
>>
>>51992405
>Yeah, but doesn't the standard library operate under the assumption that you have garbage collection turned on?
True, and I definitely haven't used it enough to make a final judgement on the language. But I've kind of learned to live without a great standard library just by using OCaml so much so if I have to re-implement a bit of the code to solve a problem I don't think that's the biggest deal in the world.
Anyways, I'm sure that if there's not a good replacement for the standard library that doesn't require GC there will be one within the next year or so. If I ever get serious about D then I might even work on one.
>>
>>51992463
I meant 2.
1 isn't even developed anymore.
>>
>Another RPG
pls
>>
>>51992419

Both SFML and SDL are multimedia libraries, and the focus of their development is on audio and graphics features. As such, their networking libraries are lacking. SFML does not currently support IPv6, although support may be included in the future. As for SDL... I'm not sure. It mostly just has a wrapper over sockets.

>>51992474

I would love to see some good D libraries that don't use garbage collection. It really does remind me of a cleaned up C++... but fuck if I'm going to use non-deterministic memory management.
>>
>>51992419
>Does SDL support it?
IIRC, SDL doesn't contain a network lib. It just manages windows and input.
>>
File: consider:.jpg (31 KB, 500x375) Image search: [Google]
consider:.jpg
31 KB, 500x375
I need a word or phrase about free speech and/ or internet freedom, written in l33tspeak, that's 4-6 characters long and valid hexadecimal.
>>
>>51992544

4F12EE
>>
>>51992281
is that really what an engine is?
>>
>>51992544
0xDEAD
>>
>>51992519
>but fuck if I'm going to use non-deterministic memory management.

you take that back you son of a bitch.
>>
can someone write me a program that represents my 3d string arrays physically? thanks. Would also like to edit them by clicking on them during runtime

thanks in advance
>>
Did anyone do the first day of Advent code in c++? I'm a bit retarded you see and can't figure it out.
>>
File: 1439757356088.jpg (25 KB, 403x403) Image search: [Google]
1439757356088.jpg
25 KB, 403x403
How does one execute a binary which only contains binary instructions and no headers with C?
>>
>>51992722
Code it however you want with headers first, compile, and then just use the assembly directly!
>>
https://www.youtube.com/watch?v=IRvGZffXhfk
>>
>>51992659

When using a systems programming language, it is important to have a fine control over all of a system's resources, including when memory is allocated, and when it is freed. Otherwise, it fails to perform the roles of a systems programming language. It may be good for other tasks, but not the task for which C, C++, Ada, and other similar languages are designed for.

>>51992722

Erm... get a block of memory with execute privileges (this may require a system call), copy the binary into memory, shove a function pointer at it, and call it. You may need some inline assembly if you've got some weird calling conventions.
>>
File: 1393563384080.png (27 KB, 582x744) Image search: [Google]
1393563384080.png
27 KB, 582x744
Thanks for the interview.
Looking forward to hearing back from you.
>>
>>51992861
>D
>Systems language

Don't fall for Andrei's memeing.
>>
>>51990371
where did that swiftbro go who was hardcoding screen dimensions into his code? dude needs some trait collection m i rite
>>
>>51992903

http://wiki.osdev.org/D_Bare_Bones
>>
>>51992947

I declare that this is STILL a meme. Neat, but still a meme.

For all other purposes D is very much suitable.
>>
man, fuck today's challenge
>>
>>51992711
Yay I did it! Who wants to see the cancerous mess I call a "solution"?
>>
File: 1359236051-gcc-llvm.jpg (106 KB, 1070x400) Image search: [Google]
1359236051-gcc-llvm.jpg
106 KB, 1070x400
Ask your beloved programming literate anything.

https://android.googlesource.com/platform/ndk.git/+/master/CHANGELOG.md

>GCC in the NDK is now deprecated.
>Time to start using Clang if you haven’t already. If you have problems with Clang, please file bugs!
>>
>>51990371
>gcc has been deprecated in android ndk

how does this make you feel?
>>
>>51993273
>Android
lmao
>>
>>51993253
You can compare it to mine if you like. I'm not entirely happy with it but it works
https://raw.githubusercontent.com/iamevn/advent-of-solutions/master/01-wordy/advent01.txt
Still need to generate the actual code for the second part of the first problem but I have it working in wimp-mode wordy.
My plan is to fill my db with christmas songs and generate code for both parts using those as my base instead of my current set of random books that are definitely old enough so that I don't have to worry about copyright stuff.
>>
>>51993256

I'll use Clang when it stops sucking on Windows!
>>
>>51993294
Oh I haven't started the second part yet, how did you find it?
>>
>>51993294
>>
Someone mention D?
>>
>>51993303
why are you using windows again?
>>
>>51993343

Drivers, sound, games, and being able to develop applications reasonably for other Windows machines.
>>
https://news.ycombinator.com/threads?id=sprash

I bet all my money this guy is posting here too
>>
/g/, I got a B+ in my data structures class

can I blame the teacher for being shit, or should i stop crying and git gud

seriously though my teacher was really trashy
>>
>>51990371

Averaging two integers.

No, I'm not kidding. I've been revisiting this off and on for days now. Requirements:

0) All integer. No floating point involved.

1) Accepts positive and negative numbers.

2) Rounds away from zero. i.e. 0.5 ==> 1. 1.4 ==> 1. -0.5 ==> -1.

3) No overflow.

4) No converting to even bigger number types.

I thought I solved it. I ran through a million random inputs and they all worked. Then I remembered that I'd restricted my random inputs to a particular subset, and actually it fails on various input.

So much elation gone in an instant...
>>
>>51993517
You passed, who gives a shit?
>>
>>51993517
was the teacher a pajeet?
Every time I have a pajeet teacher I go down to a B.
>>
File: 1380162401815.jpg (32 KB, 627x682) Image search: [Google]
1380162401815.jpg
32 KB, 627x682
>>51993517
>complaining about a B+
>>
>>51993522
whats the problem here. Just divide both numbers by 2 and add. then test if the original numbers were both odd and if true add 1 to your result.
What result are you expecting to get when you average 1 and 2. Ive never understood this problem. You cant get a float in integer format.
>>
>>51993522
double avg(int a, int b)
{
int sum = a + b;
return (double) sum / 2;
}
>>
>>51993517
strange...
>>
>>51993570
overflow carry bit
>>
>>51993592
w-what?
>>
>>51993522
def intavg(a, b)
sum := a + b.
if sum is odd and positive, sum +:= 1.
else if sum is odd and negative, sum -:= 1.
return sum / 2.
fed.

Am I missing something?
>>
>>51993599
you dont know how the hardware that runs to software for your code works. Theres a max integer. If both a and b are the max integer than it doesnt work.
>>
>>51993600
oh, the problem spec implies ints can overflow so just change a bit:
def intavg(a, b)
aa := a / 2.
bb := b / 2.
if a is odd and a is positive, aa +:= 1.
if a is odd and a is negative, aa -:= 1.
if b is odd and b is positive, bb +:= 1.
if b is odd and b is negative, bb -:= 1.
return aa + bb.
fed.
an integer, n, is odd if n != INT_MAX and n != INT_MIN and n % 2 == 1.
an integer, n, is positive if n > 0.
an integer, n, is negative if n < 0.


This cannot overflow/underflow.
>>
>>51993600
see>>51993634
>>
>>51993763
I got it senpai. I've gotten too used to programming in languages that automatically adjust the size of numbers for you.
>>
>>51993567
>whats the problem here.

I can tell you haven't actually tried this.

>test if the original numbers were both odd and if true add 1 to your result.

Enjoy your negatives.

>Ive never understood this problem.

Probably because you've never actually tried it, or didn't pay attention to the requirements.

> You cant get a float in integer format.

Nobody is talking about a float. But I am talking about a rounded (away from zero) result.
>>
I want to pick up Ruby.
Any recommendations?
>>
>>51993717

Fails for

> -1825011787, -2044618467
>1174402418, -1336547653
>-601057759, -878121207
>1343910166, -1428917325

Do you people ever test your code before posting it?
>>
>>51993937
why would I test my code?
>>
>>51993522
> 2) Rounds away from zero.
Okay, that's just someone being awkward, given that C's integer division rounds towards zero.
>>
>>51993968

No, dumbfuck, that's someone trying to match round( ((double)a + (double)b) / 2.0 );

>given that C's integer division rounds towards zero.

And a computer's natural state is off, so I guess we should never attempt to do anything, ever.
>>
>>51992463
GLFW here SDL2 a shit
>>
>>51990522

Bro, learn Java first then just start somewhere. I've learned that you can do all the collecting you want, but at some point you just gotta dive right in.
>>
hey, someone unban me from /pol/
>>
>>51994127

Pretty sure you just have to look in a mirror and say the n-word backwards ten times.
>>
>>51994134
it didn't work
>>
>>51994127

no
>>
>>51993992
You might have a point ... if the original problem didn't require the use of integer arithmetic.

Also, the two cases aren't strictly equivalent. With the FP version, if the sum isn't exactly representable (i.e. it has more bits than the significand), it will be rounded according to the current rounding mode before round() gets involved.
>>
>>51993717
is this real or pzuedocode
>>
FUCKING MODS. STOP DOING IT FOR FREE
>>
>>51994259
pseudocode that is heavily inspired by a few different declarative languages I've been playing with.
>>
>>51994199
>You might have a point ... if the original problem didn't require the use of integer arithmetic.

Ever heard of fixed point math?

>Also, the two cases aren't strictly equivalent. With the FP version, if the sum isn't exactly representable

*eyeroll* dipshit, think about how averaging two numbers works. How exact a representation do you need?

Hm. Think hard.

Seriously, stop trying to sound like you know what you're talking about. 1) you never actually tried it and 2) you're just spewing complete shit in a backpedaling attempt to cover up your ignorance.
>>
File: 1450771382026.gif (2 MB, 480x270) Image search: [Google]
1450771382026.gif
2 MB, 480x270
>Pic depicts pyfags when c# > python
>>
Python Programmers.
How do I make my programming folder that is on my desktop one of the paths that python checks to look for modules?
>>
>>51994369
Literal shitpost
>>
>>51994369
Stop shitposting, Sanjay.
>>
>>51993931
Play around in IRB, look at the Ruby docs and start playing around.

Also helps to do
.methods
on any object to see what methods are available.
>>
>>51993522
int average(int a, int b)
{
int s = a/2 + b/2;
int c = a%2 + b%2;
if (c == -2 || (c == -1 && s <= 0))
s--;
if (c == 2 || (c == 1 && s >= 0))
s++;
return s;
}
>>
>>51994374
Set the PYTHONPATH environment variable, or modify sys.path from within Python.
>>
>>51993522
unsigned int average = (a / 2) + (b / 2) + (a & b & 1);

the fuck? what was so hard about that? DURR
>>
>>51994635
>usigned int
It's like you fucks can't even read
>>
>>51994742
it doesn't even make a difference durrrrrrrr
>>
>>51994757
>average(-3,0) -> -2
Seems like you're wrong faggot.
>>
>>51994832
WHY THE FUCK WOULD YOU ROUND THAT WAY
>>
>>51994579

Congratulations, you're the first person to get it right.

Your code made it through 100,000,000 iterations of random number pairs, matching the floating point reference version.
>>
>>51994899

BECAUSE THAT IS THE CORRECT WAY TO ROUND. Away from zero. As has been mentioned multiple times in this thread.
>>
File: This is your future.jpg (39 KB, 500x400) Image search: [Google]
This is your future.jpg
39 KB, 500x400
Suppose that two competing bitcoin blocks with equal viabilities get mined within a very short time of each other, and one half of the network starts to adopt one block, while the other half adopts the other block. How does the network avoid a blockchain fork and ultimately decide on which of the two equally valid blocks to go with?
>>
>>51994635
Using & on negative integers is implementation-defined (and the implementation is allowed to "define" it as being undefined behaviour). And, no, we don't care if it happens to work with a particular version of a particular compiler on a particular system.

>>51994899
It was stated in the problem description.

FWIW, the round() function is specified as rounding ties away from zero, so it's not entirely without precedent (even though that behaviour isn't even one of the options for fesetround(); FE_NEAREST rounds ties to the nearest even value).
>>
>>51991581
they are called retard_labels

#include<stdio.h>


#define retard_label }case __COUNTER__:{c_++;
#define retard_label_start int t_=__COUNTER__+1; int c_=t_; l_: switch(t_){ case __COUNTER__:{ c_++;

#define goto_retardedly(x) do{c_=t_=c_+((x)>0?(x)-1:x); goto l_;}while(0)

#define retard_label_end }}

int main(){
int f, f2;
retard_label_start;
f=0;
retard_label;
f++;
if(f == 10)
goto_retardedly(+1);

goto_retardedly(-1);

retard_label;
printf("%d\n", f);

f2 = 3;

goto_retardedly(+2);
f2++;
retard_label;
f2++;
retard_label;
f2++;
retard_label;
printf("%d\n", f2);

retard_label_end;
}

use retardedly
>>
>>51994954
If there was one correct way to round, we wouldn't have rounding modes.

There are actually 10 distinct rounding modes, of which fesetround() (C99 and C++11) supports 4:

1. Upward (toward positive infinity)
2. Downward (toward negative infinity)
3. Inward (toward zero)
4. Outward (away from zero).
5. To nearest, ties upward
6. To nearest, ties downward
7. To nearest, ties inward
8. To nearest, ties outward
9. To nearest, ties to nearest even
10 To nearest, ties to nearest odd

fesetround() supports 1, 2, 3 and 9. round() uses 8. FP-to-integer casts and integer division use 3.
>>
>>51990654
yep definitely looks like rust. nice spelling faggot, probably typed it with one hand with the other one up your ass
>>
File: 1441496478503.gif (4 MB, 512x384) Image search: [Google]
1441496478503.gif
4 MB, 512x384
>>51995006
I've never seen anyone goto these lengths to call someone a retard on the Internet before.
>>
>>51990654
>http://rust.lang.org/
>Rust
>Mozilla
>???
>lightweight and portable
>Rust
>with my ???
>>
I have a question about Mutexe's that's been bothering me. Lets say I have the following code.

std::list<int>some_list;
std::mutex some_mutex;

void add_to_list(int new_value){
std::lock_guard<std::mutex> guard(some_mutex);
some_list.push_back(new_value);
}
bool list_contains(int value_to_find){
std::cout <<"This runs no matter what"<<'\n';
std::lock_guard<std::mutex> guard(some_mutex);
std::cout <<"I'm not sure if this will run"<<'\n';
return std::find(some_list.begin(),some_list.end(),value_to_find) != some_list.end();
}


So say I had two threads A, and B. One thread acquires the lock on add_to_list and begins the process of of pushing that new value onto the list. The whole point of the mutex is that if thread B begins the process of running list_contains it can't get a lock on the list right? However the cout after the lock_guard will also not run? Or will it run up until it tries to access some_list, realizes thread A has a lock, and wait?
>>
>>51995006
nice
>>
I'm writing an NES emulator, and it's really fun. Turns out I enjoy translating hardware into software.

What emulator/interpreter should I make when I'm done?
>>
>>51994926
I'm not sure that random numbers are the best approach to testing.

I'd suggest that exhaustively testing all pairs from the (inclusive) ranges [-3,+3], INT_MIN..INT_MIN+3], and [INT_MAX-3,INT_MAX] should suffice for any plausible algorithm.

In particular, some of the most awkward cases are where the correct result is equal or almost equal (within +/-1) to zero, INT_MIN or INT_MAX, and 1e8 uniformly-distributed random pairs *probably* won't hit any of those cases.

Another viable option would be to test on a platform with a 16-bit int and just exhaustively test all 2^32 possible pairs (which should only take a couple of minutes).
>>
>>51995006
std::lock_guard is a scoped lock. once it is inited, all other threads has to wait until it is out of scope.

If thread A calls add_to_list and not return yet, thread B will enter list_contains, print "This runs no matter what" and then wait until A finishes its job.
>>
>>51995108
It waits when you request the mutex. Once the mutex has been released it will proceed.
>>
>>51995147
whoops, this was for >>51995108
>>
>>51995147
meant for >>51995108
>>
>>51995108
It will run each statement up to the point that you acquire the lock. Then after it acquires it, it will run the cout statement and everything after that.
>>
>>51995108
It will wait until it can obtain the lock.

If you just want to attempt to obtain the lock and do something else if you can't, you need to use the try_lock() method explicitly.
>>
>>51995057
>If there was one correct way to round, we wouldn't have rounding modes.

Those are all ridiculously contrived. What does rounding mean? It means bumping .5 and higher to the next whole number. Clearly, negative numbers would bump downward.
>>
>>51995139
>I'm not sure that random numbers are the best approach to testing.

It's as good as any.

>I'd suggest that exhaustively testing all pairs from the (inclusive) ranges [-3,+3], INT_MIN..INT_MIN+3], and [INT_MAX-3,INT_MAX] should suffice for any plausible algorithm.

Or I could just test some edge cases, then throw millions of random numbers at it.

Randomized testing is underrated.
>>
>>51995176
autist
>>
>>51995147
Thanks that makes more sense. Concurrency in action has this habit of providing one example and then moving on tot he next subject in the chapter. I think a nice improvement to this book would be some practice problems at the end of each chapter. I usually work better with those kind of books.

The painting for the cover is pretty at least. Usually it's a fucking animal or fruit.
>>
I'm hacking into speed-dreams to implement a better joystick support.
>>
>>51995187

Wait, it's autistic to simply round the way that everyone learns rounding, as opposed to naming ten non-rounding ways to round?
>>
>>51993522
int avg_round_outward(int a, int b)
{
if(a == -b) {
return 0;
}
if((a < 0) == (b < 0)) {
return a / 2 + b / 2 + (a % 2 | b % 2);
}
if(a % 2 != b % 2) {
return (a + b) / 2 + ((a + b) > 0 ? 1 : -1);
}
return (a + b) / 2;
}
>>
File: 1441928948598.png (317 KB, 546x700) Image search: [Google]
1441928948598.png
317 KB, 546x700
>>51994349
>*eyeroll*
>>
>>51995202

Fails immediately on 3, -1.
>>
>>51994926
i wrote >>51995202 weeks ago

>>51995196
there are more ways to round than you learn in your first year of school. if you only round in one direction you're prone to accumulate large rounding errors over subsequent calculations, retard
>>
>>51995211

If you're not smart enough to see that you don't need a whole lot of precision to represent all cases of (a + b) / 2, then maybe YOU should fuck off to Tumblr where you can bikeshed open source projects and promote your code of ethics.
>>
>>51995176
>What does rounding mean? It means bumping .5
No. There are different conventions for a reason. Sometimes you need one over another depnding on your data and how you work with it.
Imagine you need to get a sum of your calculated rounded averages over several tries: if you always round 0.5 to the next number and you get a lot of odd+even inputs your sum will be a far cry from an actual sum of averages. (for [[1,2],[3,6]] sum of averages should give 6, when if you round the average to the next number it will give you 7, this is where you should consider other types of rounding which could give you better results, e.g. rounding to next even/previous odd which would give 2+4) A contrived example, but I hope it demonstrates the point.
>>
>>51995222
>if you only round in one direction you're prone to accumulate large rounding errors over subsequent calculations, retard

Nope.
>>
>>51995176
> Those are all ridiculously contrived.
Five of them are required in some form by C99 and C++11 (four for fesetround(), one for round()). The default mode on most platforms is FE_NEAREST (round to nearest, ties to nearest even).

Outward rounding (away from zero) is only used by the round() function; it isn't even an option for fesetround().
>>
>>51992040
Also listening, shoot; buddy.
>>
>>51995230
>A contrived example, but I hope it demonstrates the point.

Contrived examples only demonstrate the value of your approach in contrived situations.
>>
>>51995232
fucking retarded

3/2 rounds up to 2
2 + 3/2 rounds up to 4
so you have 3/2 + 3/2 = 4

when rounding to the nearest even would have given you the correct answer of 3
>>
>>51995251

What's your point? Yes, if you feed in special cases, you can make a point that's worthless in the general case.
>>
>>51995244
kill yourself fucking assburger retard
>>
>>51995251
You must round at the end only. Are you retarded?
>>
>>51995244
It's not "my" approach. It's everybody's who cares about rounding errors approach. W/e
>>
>>51995258
in a computer program you will generally do many, many calculations if you do anything more complicated than fizzbuzz. why do you think the default float rounding mode is "round to nearest, ties to even"? because anything else would be numerically unstable unless the program was specifically designed for it
>>
>>51995272
Because language designers suck at math.
>>
>>51995232
Yep.

That's why nearest-even is often used: it's unbiased (given randomly-distributed values, statistically half of them will get rounded up while half will get rounded down).

However, with floating-point computer arithmetic, there's a disadvantage to nearest-even in that a a value of +/- 2^n-epsilon will get rounded to exactly 2^n, changing the exponent. Using nearest-odd would avoid that (rounding would never change the exponent).

Inward rounding (toward zero, truncation, as used by C's integer division and casts) and outward rounding (away from zero, as used by round() for ties) have the disadvantage of creating a discontinuity at zero. For a floating-point value X and and integer N, it's not necessarily the case that truncate(X+N)==truncate(X)+N, whereas that's always true for rounding toward positive or negative infinity.
>>
>>51995260
>>51995266
>>51995272

I don't think you guys have stopped to think about what rounding away from zero means in the context of averaging pairs of numbers.

Go try it. Generate random numbers, do it a million times, and compare the sums.
>>
>>51995287
the sad part is that you're not baiting since you're a fucking assburger and are just refusing to be wrong
>>
>>51995299
The sad part is that you're a moron who defend that silly way of rounding during computation and you think that you can produce good code.
>>
>>51995287
It's not actually from the language. The FE_* modes are taken directly from the IEEE-754 floating-point standard.

If anyone sucks at math, it's the moron who thinks that there's only one way to round.
>>
>>51995299

That wasn't me. And no, the problem is that you retards haven't stopped to think about what AVERAGING TWO NUMBERS means.

>>51995305

Also not me.
>>
>>51995296
>average a pair of numbers
>call it day
>>
>>51995308
Implying IEEE was well designed.
>>
>>51995317
you're the one clinging to the "MUH ONE TRUE DEFINITION OF ROUNDING - ALL OTHERS ARE PHONEYS" that you learned in pre-school
>>
>>51995308
>If anyone sucks at math, it's the moron who thinks that there's only one way to round.

Dumbfuck, pay attention. There is one way to round THAT IS RELEVANT TO THE PROBLEM AT HAND.

>>51995319
>not paying attention to the thread
>regurgitating second year CS trivia
>not realizing that it's completely irrelevant
>>
>>51995328
Mathematicians have choos that definition for 3000 years. Are you saying that they're dumb and you're a genius?
>>
>>51995328
>you're the one clinging to the "MUH ONE TRUE DEFINITION OF ROUNDING - ALL OTHERS ARE PHONEYS" that you learned in pre-school

No, actually, I'm saying that the method of rounding that everyone learns IS EXACTLY THE METHOD APPLICABLE TO THIS PROBLEM.

Whatever retard first went off on his rant about rounding methods he can recite was completely off-topic. It's utterly irrelevant.

Again, how about you faggots put up or shut up. Generate millions of numbers, average them, and compare the sums.

When you bring me evidence of a problem, then I'll listen. Otherwise, you're just a bunch of retarded faggots clinging to some shit you memorized from a textbook and bikeshedding because you can't actually write code.
>>
>>51995263
> You must round at the end only.
That's not an option for floating-point (or fixed-point, for that matter). Each arithmetic operation produces a result which can only have as much precision as the FPU's registers provide.

For +,-,*,/, rational arithmetic is an option, but a bloody expensive one. And it's not even an option once you throw square roots or transcendental functions into the mix.
>>
>>51995329
how you be this fucking thick

if you're going to use the function to solve a relevant problem you will expect truncation by default (since that's how integral types normally get rounded in C) or some other clever solution such as rounding to the nearest even. you have this inane fixation with rounding away from zero. if you specify in your documentation that it rounds away from zero then fine, but don't try to tell us that it's the only correct/relevant way to round.
>>
>>51995342
That's not rounding, that's approximation.
>>
>>51995340
>the method of rounding that everyone learns
in fucking pre-school. you're ignorant of your own ignorance.

K I L L Y O U R S E L F
I ᠎ I
L ᠎ ᠎ ᠎ L
L ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ L
Y ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ Y
O ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ O
U ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ U
R ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ R
S ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ S
E ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ E
L ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ L
F ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ ᠎ F
>>
>>51995350
fucking kill yourself fucking sub-100 IQ retard faggot
>>
>>51995339
> Mathematicians have choos that definition for 3000 years.
Mathematicians haven't chosen any one of those over the others. Your pet method isn't even all that common (*everything* except round uses something else).
>>
>>51995345
>if you're going to use the function to solve a relevant problem you will expect truncation by default

Which is the point of the exercise, to average integers WITH ROUNDING away from zero.

>since that's how integral types normally get rounded in C

Completely fucking irrelevant. How can you be bitching about introducing errors when you're content to just truncate signed integers?

> you have this inane fixation with rounding away from zero

i.e. matching the behavior of round().

>if you specify in your documentation that it rounds away from zero then fine

Go back and read the fucking thread.

>>51995355

Didn't read the thread. Doesn't understand the problem. Can't create a solution. Kill yourself.
>>
>>51995367
I'm sorry, if I refuse to ignore 3,000 years of history. The problem with IT, it's that it's full of pretentious brat like you. Learn what, and why, mathematicians did for 3,000 years.

>>51995378
Yes they have. You're just ignorant. Try to say that round(2.5) == 2 or round(3.5)==3 to good mathematicians, they will laugh.

Since when ignorance is an opinion?
>>
>>51994926
>Congratulations, you're the first person to get it right.
numerous solution have been posted since day one,
>>
>>51995389
good mathematicians are open-minded, unlike assburgers like you. if you define your rounding function in such a way then that is perfectly valid.
>>
>>51995402

I've never seen a single one that actually works.

None of you fuckers ever test your shitty code before posting it. The ones that do usually misread or ignored the problem definition.
>>
>>51995408
No they have one definition of rounding. But you can redefine anything, they will just translate to approximate in their mind. They're just condescending whit child like you.
>>
how do you motherfuckers find time to do any programming inbetween these dumb arguments?
>>
>>51995350
No, it would be "approximation" if it was allowed to choose any result which was "close enough". But that isn't how floating-point works (at least, not for primitive operations).

The result produced by primitive floating-point arithmetic operations is "as if" the result was calculated exactly then rounded according to the current rounding mode.

That is the case for +,-,*,/ and square roots (because in those cases it's actually possible to produce the correct result with only finite intermediate precision). That isn't possible for transcendental functions (trig, logs, etc) due to the "table-maker's dilemma" (look it up).
>>
>>51995340
> IS EXACTLY THE METHOD APPLICABLE TO THIS PROBLEM
You couldn't really have been saying that because the problem was not about summing the averages, it was finding the average once. No one method of rounding is applicable specifically to that problem because if you don't do anything with the averages after it doesn't matter how you round them. The argument has started with "THIS IS THE ONLY WAY TO ROUND" which would be applicable to the later posed problem of summing averages of random number with a uniform distribution, but again that wasn't the problem. That's why you were wrong - people were just pointing out to you that you may need to choose another rounding method, if, for example, you need the sum and the numbers aren't uniformly distributed, e.g. you get only positive numbers as input.
>>
>>51995416
> No they have one definition of rounding.
No, YOU have one definition of rounding.
>>
>>51995416
>they have one definition of rounding
https://en.wikipedia.org/wiki/Rounding#Rounding_to_integer

literally mcfucking killyou'reself
>>
>>51993517
Wow I got a B+ in my data structures and algorithms class too and I am happy with it
>>
>>51995419
i haven't had my fap and coffee yet so i'm easily distracted right now. but usually i will just ignore /dpt/ for hours at a time while i do my work, maybe glancing at it once in a while.
>>
>>51993517
>murrican grading system is this inflated
>a C is unironically considered dog shit retard tier
>>
>>51993517
how he was thrashy
>>
How do you make dosh off of programming with C or C++, that isn't getting a job or hunting for "freelancer projects" on those pajeet sites?
>>
>>51995428
>it was finding the average once.

No, fuckhead, it was about averaging two integers.

If you want to talk about finding an average once, fine, my method is perfectly valid. Your contrived case required summing TWO averages. So make up your mind.
>>
>>51995471
My current job is video games with C++, previously I worked in embedded systems that runs C and C++
>>
>>51995471
>How do you make dosh off of programming with C or C++

You don't. You make money off Java and C#.
>>
>>51995486
time to switch gears then
any recommended C# books that don't treat you like a retard? Well, any good C# books/resources nevertheless?
>>
C++ project,

Using different PDF's I need to generate thousands of objects belonging to a certain class. Only a fraction of them (1/10000) will be valid but I can't modify the pdfs to just get valid object. Should I generate a large list of these objects and than check or write a loop in the constructor to only generate valid objects?
>>
>>51995479
>No, fuckhead, it was about averaging two integers.
You know what I meant, but I appreciate your brilliant retort, nigger.
>Your contrived case required summing TWO averages
How retarded do you have to be, it was an example for you to understand why other kinds of rounding may be needed if the results of averaging are used after and inputs aren't the same perfect for your rounding method you expect.
>finding an average once, fine, my method is perfectly valid
So is rounding everything to 0. It's not a real problem if the results aren't used for anything at all and inputs are always random and uniformly distributed across all integer space.
>>
>>51995504
And speed is important.
>>
Is it possible to host a "dynamic" webpage using C#/.NET, as in update it live for all connected clients? If so, what is that called? I can't think of anything to google.
>>
>>51995497
Richter, C# via CLR
then Jon Skeet's book
Wpf unleashed if you're going for desktop (not recommended)
something (whatever) about MVC if web.
>>
today python babbies learned that their is more than one way to round a number to an integer

https://en.wikipedia.org/wiki/Rounding#Rounding_to_integer
>>
File: aJjjkYo.webm (1 MB, 720x404) Image search: [Google]
aJjjkYo.webm
1 MB, 720x404
Ask your favorite programming literate anything

>>51995412
what was the problem ?
>>
>>51995531
>You know what I meant, but I appreciate your brilliant retort, nigger.

No, actually, I have no idea what you mean. It appears that you completely ignored the entire problem definition, and now you're hopping around between averaging many numbers versus averaging only two to suit your argument.

>How retarded do you have to be, it was an example for you

...an example that flies in the face of your retarded claim as the what the fucking problem IS in the first place, which I pointed out only to make you recognize how stupid your "it was finding the average once" statement was. Not only did your statement go against the problem in the first place, it goes against your own example!

>So is rounding everything to 0.

Again, read. The. Problem. Definition.
>>
>>51995600
average two ints in C with non-integer results rounded to the nearest int in the direction away from zero
>>
>>51995600
>what was the problem ?

Holy shit, how lazy are you?

>>51993522
>>
>>51995570
websockets - At a guess?

"Dynamic" isn't very descriptive, sadly.

No idea if you can do it in C# if it's anything like Java, you can, but that doesn't mean it's particularly easy.

So far my favourite language to write web-sockets in is Go.

Although I hear rather perversely IO.js/Node.js is good at it.

Clojure too.
>>
This is my first stack, tell me how shit it is.
typedef struct stk{
int *data;
int index, allocated;
}stk;

int stkPop(stk *input){
return input->data[--input->index];
}

void stkAdd(stk *input, int data){
if(input->index+1 > input->allocated){
input->allocated=input->allocated*5/3+1;
input->data=realloc(input->data,input->allocated*sizeof(int));
}
input->data[input->index++]=data;
}
Thread replies: 255
Thread images: 33

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.