[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: 17
File: yuki.jpg (113 KB, 984x927) Image search: [Google]
yuki.jpg
113 KB, 984x927
What are you working on, /g/?
Old: >>51837369
>>
1st for this is the legitimate thread.
>>
>>51843675
Why is coding in C like dragging my balls through molten glass while eating Carolina Repears whole?
>>
>>51843713
because youre a woman
>>
>>51843713
Because you're a web 'developer'?
>>
>>51843675
first for gay D
>>
>>51843675
4th for elixir
>>
File: magic.webm (208 KB, 342x306) Image search: [Google]
magic.webm
208 KB, 342x306
>>51843675
made this: http://pastebin.com/84N7Y8kE

Improvements? Suggestions?
>>
Basic point of sale webapp in django. Also trying to get into some android app development for a super secret app idea
>>
>>51843725
no
>>51843729
No
>>
>>51843667
Oh, when I wrote brute force, what I meant is that rather than cycling through every single permutation of seating arrangements, I cycled through every single unique seating arrangement such that no arrangement is a rotated version of another arrangement. My bad, it's still brute forcing, but not as much. A little detail that adds a bit of code, but shortens a bit of the time running(just in case it takes too long to fetch an answer)
>>
http://learnpythonthehardway.org/book/ex16.html

>Copy this code
>now google everything instead of me explaining it
Seriously?
>>
>>51843736
Needs a more feminine penis
>>
Rust Vs Go

Go
>>
>>51843772
Both ares SJW cancer. At least Go has a wacky logo.
>>
>>51843764
just do a simpler tutorial, take part in coding challenges and study the documentation, use it to be creative and find ways to make your solutions more elegant

>>51843772
Go is shit, never tried Rust, but if it's at least decent, it'll win
>>
>>51843713
because you're a currynigger, Sanjeep.
>>
Threadly reminder that coding is the improper way to refer to the act of programming, which is the proper way to say it.

You are a programmer not a coder
You aren't coding you are programming
You write code while you program
>>
>take intro Python course online
>take intro C course online
>don't know what to do now
>most projects seem too difficult
>especially when thinking about the payoff of putting in the time (learning the stuff doesn't seem like a good use of my time either, as I don't know what i'm supposed to do now)
how do i get gud and make something?
>>
>>51843809
This.
magazine != clip
>>
>>51843809
fuck off autist
>>
>>51843772
>Rust is a systems language, Go is not
>Rust does something interesting, Go does not
>>
>>51843812
> $ git gud
That's all you need
>>
>>51843809
>caring about proper/improper usage on an indonesian basket-weaving forum
>>
>>51843812
You have to have an idea. Something that can actually help you either solve a problem or work more effectively..

wrapping your head around a project can be overwhelming so doing something you have some 'passion' for, will help to see you through the finish.
>>
Looking at Kerberos, it's possible to have an authentication system without the use of SSL.
Why nobody uses it?
>>51843812
Introduction to algorithms.
>>
>>51843812
>wanna program
>don't wanna program
probably choose something else to use your time on
>>
Hey /g/, I would love some help on something. I applied for an internship during wich I'll be optimizing the parallelization of an algorithm for signal processing. I'm familiar with signal processing, coms, and embedded systems, but I kinda fall short on the parallelized part.
Do any of you would have some nice documentation on optimizing for manycore architectures?
>>
Reminder that Rust doesn't really give you any more static verification than is possible with C++.
>>
>>51843899
ok
>>
>>51843871
>internship
More like slave labor.
>>
>>51843675
Fuck me these threads are fast, I didn't even notice that I posted in the last one as it was dying, anyway... I need something pathetic.

Because job, I need to more or less master Excel and V Basic, preferably very quickly, sadly however I've not touched Excel in 4 years and I don't know any program languages whatsoever, the most I've ever done is mod games and use R (statistical program).
>>
>>51843809
Honesty this, tired of cs freshman calling themselves coders
>>
>>51843871
I'd add that I read already quite a bit on multicore optimization. But if I understand correctly, the manycore term imply a great number of cores and a system oriented only on multicore use? Does that change the base principle?
>>
File: wat.jpg (801 KB, 2000x1500) Image search: [Google]
wat.jpg
801 KB, 2000x1500
MY CODE COMPILES

I FINALLY COMPILES
>>
>>51843968
Finally got hello world working?
>>
File: ann.webm (3 MB, 640x360) Image search: [Google]
ann.webm
3 MB, 640x360
Ask your beloved programming literate anything.
>>
>>51843772
Go is nothing that a refreshed version of C that's still the same garbage as C and doesn't bring anything new to the table while also being cluttered with lack of proper versioned dependency management and sane error checking mechanism. Rust is C++ with even worse syntax in some cases and memory safety and is managed by SJWs. So I vote... neither, vote D!
>>
>>51843871
wait wait wait

you applied for an internship for which you have not done the crux of the position?
>>
>>51843925
more like trial period for a job actually, 35h/w is not what I consider slave labor desu
>>
>>51843995
Is that anime any good?
>>
>>51844037
What's the wage?
>>
>>51843863
Why nobody uses it?
Apple
>>
>>51843871
Look at Open MP.
Basically, you split your input data into many chuncks, and each parallel unit does the same algorithm on different data, and combine all at the end.
>>
>>51844015
It's actually not listed as one of the most important required skill, and I do have 3 months to get some head start. Internship looks really nice and the location is perfect for me
>>
>>51844041
Better than most shit from fall season
>>
>>51844070
Can you tell me more?
>>
>>51844062
Don't know yet, probably aroud 1200-1500 euros
>>
>>51843764
You are a mental fucking midget. Nobody in this thread recommends that book so you have no business posting about it here.
>>
>>51844085
that's good, the way you worded it made it sound like the key criterion was parallel computing.

3 months gives you enough time to learn if you commit to it. that's essentially a semester's worth of time.

>>51844081 suggests an implemenation but you need to understand parallel computing as a whole. Allow me a minute to do some research so I may provide advice.
>>
>>51844128
Thats bretty gud. I got 1k euros a month for 40h/w.
>>
What's wrong with this template class?
#pragma once

#include <vector>

namespace Project
{
template <class T>
class Parent
{
public:
Parent();
virtual ~Parent();

void AddChild(T * child);
void RemoveChild(T * child);
const std::vector<T *>& GetChildren() const;
protected:
std::vector<T *> mChildren;
};
template<class T>
inline Parent<T>::Parent()
{
}
template<class T>
inline Parent<T>::~Parent()
{
}
template<class T>
inline void Parent<T>::AddChild(T * child)
{
mChildren.push_back(child);
}
template<class T>
inline void Parent<T>::RemoveChild(T * child)
{
mChildren.erase(child);
}
template<class T>
inline const std::vector<T *>& Parent<T>::GetChildren() const
{
return mChildren;
}
}
>>
>>51844163
>template
>>
>>51844163
Why not just define the methods inside?
>>
>>51844160
What country/study? It's decent yeah, but doesn't beat the internship I made in switzerland... Those people have a different conception of money.
>>
>>51844205
The arabic Netherlands.
>>
Any good language agnostic book/tutorial on async programming?
>>
>>51844139
Well I don't really know, the title made it sound like it was, but the description doesnt. Anyway imma try to get it and if I do, I'll work hard on it for 3 months and it should be decent.
>>
>>51844214
>The arabic Netherlands.
What part of Netherlands is that?
>>
>>51843675
I'm adding a thumbnail view mode to my file manager
It will be a lot of work to find enough non-pornographic images to make a screen shot
>>
>>51844139
>>51844085
>>51844226

Find an operating systems book that covers process synchronization and read up on that stuff. You should understand process synch problems (http://perugini.cps.udayton.edu/teaching/courses/cps346/lecture_notes/classical.html and there's a page on wikipedia iirc), the basis of the problem, the multiple different solutions to these problems, why some "solutions" fail, where some that succeed fall short, etc. If you know these "classical problems" then you should have no trouble in an interview. From here you can go on to explore things like >>51844081 suggests. I do recommend knowing the basics though, for they are better interview questions for interns rather than some esoteric question.
>>
>What are you working on, /g/?
Just got around to solving Day 13 of AoC, it was basically a very similar solution to Day 9 with the data math modified a bit, kind of disappointing.
>>
>>51844323
what happened to your folder of smug anime girls?
>>
>>51843848
i want to do something finance related tbqh
like analyze stocks and choose what to buy. but it seems so daunting. what if i can't find data, or my system doesn't even work in picking good stocks

>>51843863
i've thought about this, but will it help me in creating my own project?
>>
>>51844278
I live in the north western part.
They're everywhere m8.
>>
>>51844372
you're not going to make anything ground-breaking. accept that fact. financial algorithms are complex and merely implementing one will be a feat in and of itself. When you're learning, it's about the journey, not the result.
>>
>>51844349
They're somewhere inside my Pics folder with 72,573 other images
>>
>>51844409
>They're everywhere m8.
I know I'm a french fag
>>
>>51844349

I don't even like anime and I've started collecting them
>>
>>51844330
Many thanks man
>>
>>51844163
inline is redundant
>>
In Visual Studio 2015 my c++ app sometimes uses 52MB and sometimes 75MB of memory, what could be causing this?
>>
>>51844519
What kind of app?
>>
Can anyone show me a small haskell program they've written? I'm just looking for small stuff, explore/trending/haskell on github is just huge stuff that doesn't make sense to me
>>
>>51844519
debug/release mode?
>>
>>51844519
>>51844543
Optimisation flags?
>>
I want to go back to school in a year or two. Is CS a good major to pick if I want to get good at programming or how software works?
>>
>>51844462
You guys are even more fucked that we are. Want to join me to the promised land (insert high tech Asian country here)?
Anyway, my internship was for my bachelors degree. I had to write a live recording app for Android.
>>
File: software_terminology.jpg (19 KB, 460x345) Image search: [Google]
software_terminology.jpg
19 KB, 460x345
>>51844519
>app
>>
>>51844519
>app
>>
>>51844529
sfml, the only thing I'm doing is opening a window and drawing a cube
>>51844543
It does that in both configurations, there doesn't seem to be a pattern.
>>
>>51844415
thanks, i will try to just make something simpler first
>>
>appOS, your whole computer is an app
>>
>>51844583
Actually considering Norway actually.
>>
>>51844596
I had the same problem once with another framework and came to the conclusion that it is a graphics driver issue related to OpenGL context creation
>>
>>51844665
Why Norway? Is it because of the wealth or the smaller amount of Islam?
>>
>>51844688
Do you have some references to where you found that answer from?
>>
>>51843809
python users are users or coders, not programmers
>>
href="//i.4cdn.org/penis"
>>
>>51844733
I found mostly found out myself
Right after creating the context the memory usually increased by 15MB but sometimes it did increase by 30MB for no apparent reason
Apparently the temporary context you create sometimes isn't disposed correctly
Or maybe the driver is just doing stupid optimizations

Do you have an Nvidia GPU btw?
>>
hey /dpt/, is software engineering really engineering or not?
>>
>>51844699
Wealth, (i don't really care about islam), mentality and culture (my gf is in arts). Oh and it's beautiful
>>
>>51844884
it's not what people typically think of when they say engineering but it is engineering in a sense
>>
>>51844884
If you think comics are literature, yes.
>>
File: Untitledasdasd.png (16 KB, 879x151) Image search: [Google]
Untitledasdasd.png
16 KB, 879x151
>>51843675
Trying to compile my steam bot on windows but i have no idea what can i do about this error
>>
>>51844926
*(this is just the curlpp dependency, i only want a x64 static build)
>>
>>51844926
>my program isnt portable
shoulda used java
>>
>>51844907
how so?

>>51844922
Why would someone want to learn software engineering when you can learn CS or EE?
>>
>>51844794
that isn't going to work...
>>
Why was my thread deleted?
>>
>>51844894
Not taking wealth into account, that's why I want to leave and move to China, Japan or Korea. Especially in China, software development is booming.
Western Europeans are lazy and arrogant in general. Not saying that I'm the perfect citizen, but I'm far from being the worst. Having a flood of immigrants doesn't make life any better.
>>
I don't understand when to use flush(), I just use it every time I write something because if I don't some things won't work unless I flush(), but I don't know why

so when do you flush()?
>>
>>51844994
I was testing to see if it'd get caught by a grep thing but it doesn't matter because I changed it.

>>51843736
curl -s >>51843675 | grep -Poh "<a class=\"fileThumb\" href=\"//i.4cdn.org/.*?\"" | cut -c30- | sed s/\"// | xargs wget


This is the best I could come up with.
>>
>>51845059
depends on the application, correct answer is usually 'never'
>>
>>51844972
I've chosen only multiplatform libraries (curlpp, curl, https://github.com/nlohmann/json) which should work on anything with c++11.
>>
>>51845103
why never? and when do you know you gotta flush other than 'shits broken yo'?
>>
>>51845101
don't you love how >>51843675 gets automatically converted, despite the fact you put it in a code block and it shouldn't be fucked with?
>>
>>51845125
When you write to a file handle (like stdout), it actually goes in a buffer, and it doesn't actually get written out until the buffer is flushed (the buffer gets cleared and all the data is written). You can turn this off, so that things are immediately written, but this can make things slower if you're doing a lot (more than in an interactive program) of output. If you want the buffer to be flushed immediately, you use flush.
>>
>>51845131
Yeah.
>>
>>51845157
I forgot to mention, the buffer gets flushed automatically if it reaches a newline (line buffering) or if it gets full (any kind of buffering)
>>
Post AoC day 8 solutions

data=open("Advent8.txt").read().split("\n")

print sum(len(i)-len(eval(i)) for i in data)
print sum(2+i.count('\\')+i.count('"') for i in data)
>>
>>51845213
now try w/o eval fuccboi
>>
>>51844975
software engineering is more for actual software development. CS is more theoretical and can be pretty much just math depending on the school. EE has more to do with hardware electronics rather than software
>>
>>51845157
>>51845184
ah that explains a lot, can you give some example of what kind of work would really make flush slow down stuff? I can't think of anything and the impression I got from googling around is that flush is bad but rather than bad it just seems like it just depends?
>>
>>51845234
>try without a standard language feature
>>
trying to learn. does anyone have "The object-oriented thought process", preferably the 4th edition?
>>
what's the fastest way to make $150k for someone who knows a bit of java, C, and python from a few courses at a mid-level university
>>
>be me
>CC
>Intro to c++ programming
>professor ask me how I read an excel file using virtual studio for c++

Should I be worried?
>>
>>51845275
sell people's organs on the black market
>>
>>51845240
so if someone wanted to be a programmer, they should go with SE, right?
>>
>>51845277
no. it's just stream operations.
>>
>>51845277
You've been posting this for the last week, just fucking do it already, or drop out.
Programming isn't for you.
>>
>>51845310
yes or CS
>>
>>51845333
no luck. nice numbers though.
>>
>>51845422
google library genesis and use the first mirror that works, if that one is blocked in your country
>>
Learning clojure. It looks cool but I'm getting frustrated very often
>>
>>51845101
do the periods in i.4cdn.org not mess up your regex?
>>
>>51845322

I already did it. I recreated the excel sheet using .csv. I never figured out how to read and write into .xsl files.
>>
>>51845460
i mean as in it only has the 3rd edition. maybe i'll just have to survive with that.
>>
>>51845546
Nope probably because it's matching them with the actual periods. D'oh.
>>
>>51843764
Zed Shaw is a hack.
Learn C the hard way is even worse, he asks you to copy 200+ line programs and then asks you to break it and then explain why it does that.
Around chapter 20 is when he starts going full retard.
>>
>>51845253
If you were doing file I/O, like copying a file to another file, it would be slow to not use buffering. Typically block buffering is used with a large buffer size (~1M is standard?), because it's faster to write a bunch of data to disk than one byte at a time.


For standard output, if you were writing a clone of cat, for example, and you used no buffering on a large file, it would take longer to output. Obviously you wouldn't do this to look at it with human eyes, but you might want to pipe it into another program for processing.
>>
>>51843713
Because you're not limiting yourself to rewriting fizzbuzz all day.
>>
Did anyone make a cs grad of this from last night
bool even(int x)
{
for (int i = 0; i<=x; i+=2)
if (x==i)
return(true);
return(false);
}
>>
>>51843871
OpenMP or GPU stuff depending on what algorithms exactly. For FA and post-FT stuff, mostly GPU. See arrayfire, or just plain cuda and opencl.
>>
>>51845719
eww
>>
>>51844519
did you actually debug your app or did you just look at what the task manager said?
>>
>>51844519
>app
>>>/reddit/
>>
As a cs tutor this makes me so salty to see
void func(bool x)
{
if (x==true)
do stuff
else if (x==false)
other stuff
}
>>
>>51845719
bool even(int x)
{
string xx = x.ToString().SubString(x.ToString().Length - 1, 1);
if ( xx == "0" || xx == "2" || xx == "4" || xx == "6" || xx == "8") {
return true;
}
return false;
}
>>
>>51845936
im new to cs, but whats wrong with this? Is it that that function will run only if the boolean is true? So theres no point of checking it inside?
>>
>>51845975
Since x is a boolean, it can be simplified to
if (x) {

} else {

}
>>
>>51845996
oh I see, thanks.
>>
>>51843772
Crystal
>>
>>51845936
so what's the right way to do this?
void func(bool x)
{
if (x)
do stuff;
else
do other stuff;
}
}
>>
>>51845936

void func(bool x)
{
if (x==true && x!=false)
do stuff
else if (x==false && x!=true)
other stuff
}
>>
How do I implement a stack with a hard limit, such that exceeding the limit causes the bottom item to drop out?
>>
>>51845936
void func(bool x)
{
while(x == true)
{
/*do stuff*/
return;
}
/*do other stuff*/
}
>>
>tfw family needs gift ideas, but I just bought a bunch of programming books recently
>>
>>51846059
Make it a circular buffer instead and push the start/end pointers along when it becomes full.
>>
>>51846059
Ideally you would implement a check in the add item method that would remove the bottom item if the size is at maximum.
>>
>>51845719
Is there a more elegant non modulo even/odd test than this
bool even(int x)
{
if ((x/2)*2==x)
return true;
else
return false;
}
>>
>>51846082
Just let them surprise you.
It's not like you're at their mercy to buy you something you needed, you're an adult.
>>
>>51846059
Heres the logic

if (example.getStackSize() > (yournumber)){

example.dropBottomStack()

}

}
>>
>>51846099
bool odd(int x)
{
return x & 1;
}
>>
>>51846038
void func(bool x)
{
if (x)
do stuff;
return;
do other stuff;
}
>>
>>51846115
winrar
>>
bool func(bool x)
{
return !x;
}
>>
>>51846115
do most languages have bit and ors to do that.
>>
new lurker here, how are you pasting in the code?
>>
>>51846115
me like
>>
>>51846115
odd=lambda x:x&1
>>
>>51846160
Nigga just make an array of all the odd numbers and then check against it.
>>
>>51846168
[code ][/ code] without spaces
>>
>>51846104
>not maintaining a numeric pointer that is manipulated by a K-group over +
KEK
>>
>>51846168
>>>/reddit/
>>
>>51846168
read the fucking sticky you retarded piece of shit
>>
>>51846180
haskell / clojure lazy eval means you'll always be 100% sure with your result
>>
>>51846182
 

String x = "thanks";

>>
>>51846210
chill bruh, I just had 1 little question. Dont want to read a manual
>>
>>51846182
Commit suicide.
>>
>>51846059
1. extend an existing stack, eg, MyStack<T> extends Stack<T>
2. overwrite the existing push method:
public push(T toAdd) {
return super.push(t);
}

3. add a private field to keep track of the number of elements and do so by overwriting the push and pop method of Stack<T>
private int size = 0; 

public T push(T toAdd) {
this.size++;
return super.push(toAdd);

public T pop() {
this.size--;
return super.pop();
}
}

4. Once the size is big enough, drop the next element
private int size = 0;
private int MAX_SIZE = 50;

public T push(T toAdd) {
if (this.size >= MAX_SIZE) {
this.pop();
}
this.size++;
return super.push(t);
}
>>
>>51846241
>>>/tumblr/
>>
>>51846210
bool UMAD(string x)
{
string y = "read the fucking sticky you retarded piece of shit"
if (x==y)
return true;
return true
>>
>>51846260
where is that board, i dont see it
>>
>>51846186
why do we need to do all that?
>>
>>51846168
>new lurker here
Nice to see new people interested in programming coming here, especially youngsters to succeed us old goats.
How old are you this year?
>>
File: LiQNoad.png (295 KB, 934x552) Image search: [Google]
LiQNoad.png
295 KB, 934x552
>>51846241
>I didn't want to read the one fucking thing that I'm supposed to read when I go to a board
>>
>>51846305
>all that
POO IN LOO: the post.
>>
>>51846305
>we
>>
>>51846335
>> Lets do something the harder way
>> Therefor my way is correct
>>
When will you realize that everything you're doing is a waste of time, that some feminist indian programmer is going to get your job instead, and that you're a loser sitting by yourself writing throw-away code that's already been written before?
>>
>>51846379
>>>/india/
>>
>>51846115
L U A
>>51845719
function even(x)
if type(x) ~= 'number' then
return false
end
return x & 1
end


Requires 5.3 though.
>>
>>51846320
>expecting anyone but /g/ regulars to read the sticky or know the rules in the year 2015
>>
File: imgres.jpg (11 KB, 243x208) Image search: [Google]
imgres.jpg
11 KB, 243x208
>>51846408
can you at least answer the question?
>>
>>51846409
>weak types
truly vile
>>
>>51846320
I forgot about the sticky, sorry bud
>>
>>51846445
refer to >>51846408
>>
>>51846409
R U B Y
def odd(x)
x.odd?
end
>>
>>51846517
Stackoverflow?
>>
>>51845253
You only need to flush if you need that data to be sent to the underlying stream before you write any more data.

One example is if you're displaying a prompt on the console, and you'll wait for input from the user before writing anything else. If you don't flush (and circumstances don't cause the stream to be flushed automatically), the prompt won't be shown.

Similar issues apply to network connections. If you write a request to a socket then wait for the response, the server will wait for the request before sending a response.

Basically, if you have this kind of synchronous closed loop, where each step produces output in response to input, failing to flush can cause it to stall (deadlock).

If you're performing several writes in sequence, where each one will actually be executed sooner rather than later, there's no need to flush in between them.
>>
>>51846517
S C H E M E
(define (odd x)
(odd? x))
>>
>>51845631
Copying files is typically done by mapping a chunk of the source file to memory then write()ing the mapped chunk to the destination file. This means you only perform one copy rather than two.
>>
>>51846186
>>51846335
>>51846408
Could you please do this, I have no idea what a K group is and would like to see your solution.
>>
>>51846586
H A S K E L L
odd
>>
>>51846621
http://dogschool.tripod.com/groups.html
UUUU
>>
>>51846641
S C H E M E
odd?
>>
File: 1.jpg (60 KB, 500x495) Image search: [Google]
1.jpg
60 KB, 500x495
>>51846652
>>
>>51846620
Oh, that's neat
>>
>>51846115
no workeeâ„¢
>>
>>51846652
That doesn't answer my question you ugly cunt.
>>
>>51846710
thats cause he doesn't know
>>
I'm working on averaging 2 ints in C. Hard problem. Most people on /g/ can't solve it.
>>
>>51846731
void main()
{
int a, b = 10, 20;
int average = a + b;
average = average / 2;
printf("%d", average);
}
>>
File: autism intensifies.png (154 KB, 888x488) Image search: [Google]
autism intensifies.png
154 KB, 888x488
Flag autism with GreaseMonkey

Adds a button to start a guessing game as to what nationality made what thread

Could someone give it a whirl?

If you have GreaseMonkey just go here and press install:
https://github.com/chvrn/4chan-whose-post-is-it/raw/master/4chan-whose-post-is-it.user.js
(no botnet, just read source)

Not sure what it looks like on something other than my miniscule laptop screen (pic)
>>
>>51846756
You're one of the people I was referring to.
>>
>>51846710
It literally does you inbred bitch.
>>
>>51843736
Give it a side view and make the penis move to the function instead.
>>
File: just power my shell up.jpg (612 KB, 662x728) Image search: [Google]
just power my shell up.jpg
612 KB, 662x728
>>51843736
>>
>>51846731
 a >> 1 + b >> 1 + (a & 1 + b &1) >> 1 

It's solved. It's patented. It's a waste of time.
>>
>>51846731
#include <limits.h>
#include <math.h>
#include <stdio.h>

#define TEST(a, b) printf("avg %d %d = %d\n", (a), (b), avg((a), (b)));

int
avg(int a, int b) {
return round(a/2.0 + b/2.0);
}

int
main(void) {
TEST(INT_MAX, INT_MAX);
TEST(0, 4);
TEST(16, 32);
TEST(0, 0);
TEST(1, 1);
return 0;
}
>>
>>51846875
Shit. (b - a) >> 2 + a >> 2 is better.
>>
File: 1449540001742.jpg (4 KB, 250x194) Image search: [Google]
1449540001742.jpg
4 KB, 250x194
>>51843995
>>51844041
>>
>>51846896
1* 1*
>>
>>51846875
lel
https://www.google.com/patents/US6007232?dq=6007232
>>
File: 3879739.jpg (48 KB, 150x191) Image search: [Google]
3879739.jpg
48 KB, 150x191
I want to learn FP but I can't decide on a language to start with.

I'm stuck between OCaml and Haskell, though I'm leaning more towards OCaml at the moment. I keep hearing Haskell is notoriously difficult to learn, is overly complex and not really that practical. Is there any truth to this?
>>
>>51846731
Used php, wasn't able to completely solve
function averageFinder($x1,$x2){
if($x1 == 1 && $x2 == 1){
return (1+1)/2;
}
if($x1 == 2 && $x2 == 2){
return (2+2)/2;
}
if($x1 == 3 && $x2 == 3){
return (3+3)/2;
}
if($x1 == 4 && $x2 == 4){
return (4+4)/2;
}
if($x1 == 5 && $x2 == 5){
return (5+5)/2;
}
if($x1 == 6 && $x2 == 6){
return (6+6)/2;
}
if($x1 == 7 && $x2 == 7){
return (7+7)/2;
}
if($x1 == 8 && $x2 == 8){
return (8+8)/2;
}
if($x1 == 9 && $x2 == 9){
return (9+9)/2;
}


//code breaks, still haven't learned to do
else{
echo "Haven't figured out how to do this, coming soon though!";
}
}

>>
>>51846896
dumbass. what would yours output for a=4 and b=2?
>>
>>51846875
>>51846896
Overflow errors

>>51846894
best one here, would be better if it didn't return int since there'll be the occasional 0.5, or the function should be renamed so users know you can only average 2 even or 2 odd numbers
>>
>>51846919
Au contraire, this version prevents any overflows. Stay retarded, though.
>>
>>51846911
inb4 fractal
>>
>>51846919
>>51846875
how does it overflow?
>>
>>51846934
>>51846944
I was merely pretending
>>
>>51846731
a/2 + b/2 + (a & b & 1)

Only works properly for positive ins though.
>>
I want to be a C programmer but I can't average two ints. What should I do?
>>
>>51846875
(a & 1 + b &1) >> 1 

It would be shorter to just
(a & b & 1)
>>
>>51846975
yeah. whoops.
>>
does anyone here know intel SSE intrinsics?
I'm trying to load 4 chars from an array and convert them into 4 packed floats. For some reason this motherfucker won't work.

__m128i bufi;
__m128 buff;
...
bufi = _mm_set_epi32(0, 0, 0, image[i*image_w + j]); //load 32b (4 char) from memory
bufi = _mm_unpacklo_epi8(_mm_set1_epi16(0), bufi); //unpack to short int length
bufi = _mm_unpacklo_epi16(_mm_set1_epi16(0), bufi); //unpack to int/float length
buff = _mm_cvtepi32_ps(bufi); //convert int to float
>>
>>51846969
It's ok, none of us can
>>
>>51846910
Yes, it's 100% true. Use OCaml. Pretty much got tier FP.
>>
>>51846803
Where does it implement it?
>>
ITT:
F A G G O T S
A
G
G
O
T
S
>>
>>51846875
>>51846894
>>51846896
>>51846934
>>51846944
>>51846967
>>51846975
>>51846988
These don't work.
>>
>>51846998
Name 3 ways Ocaml is better than haskell
>>
Just finished the Python course on codeacademy.com, what to do next?
>>
>>51847026
Still a waste of time. But go on, show us yours.
>>
>>51847026
The only thing that doesn't work is your brain.
>>
Daily reminder that the self-proclaimed C gururs in /dpt/ that know the standard through and through can't even write a function that properly averages two numbers.
>>
>>51846967
That's patented by Samsung
>>
>>51847058
Unlearn everything and learn a real language.
>>
>>51847080
i like this meme
>>
>>51847026
Wrong, >>51846967 works exactly as stated.
>>
>>51847089
>>51847100
>>
>>51847058
Write a function that takes a string and returns the number of identical letter pairs in the string.
string[8] = "abbcdefg;
identical_pairs(string);


It should return 1 for that example.
>>
>>51847089
like which? C++? C#?
heard java, javascript, php, perl, ruby are all shit
>>
>>51846731
>all these faggots not understanding how integer division works
double findAvg(int first, int second)
{
return static_cast<double>((first + second)/2);
}double findAvg(int first, int second)
{
return static_cast<double>((first + second)/2);
}
>>
>>51847082
Link?
>>
>>51847027
- Much faster
- ref, !
- Can express a range of ints, convert it to float, and still get a range of floats that correspond to the same int range
- No lazyness by default

Oops, that's 4 :3c
>>
>>51847135
missed the point my man
also, that's not C
>>
>>51847129
Gambit scheme, haskell, ocaml.
>>
>>51847151
The propagandists at Jane st capital have got to you.
>>
File: fizzbuzz_fb.png (172 KB, 2010x1404) Image search: [Google]
fizzbuzz_fb.png
172 KB, 2010x1404
I made this fizzbuzz program in the graphical FBD language. This graphical programming language is often used to program PLC devices. I used free software for making this one.
Any ideas for other (preferably small) PLC programming projects?
>>
>>51847171
lol?
>>
>>51847217
lol.
>>
>>51843736
Cute and saved
Thread replies: 255
Thread images: 17

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.