[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
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: 1422385664777_6.jpg (438 KB, 2500x1000) Image search: [Google]
1422385664777_6.jpg
438 KB, 2500x1000
Old /dpt/ at >>51862294

What are you working on?
>>
First for averaging 2 ints in C!
>>
A pure functional programming language that runs like C or C++.
>>
daily averaging two ints in C thread
>>
>>51866116
Jesus Christ. Shut the fuck up about this challenge. Here's your inefficient methodology. Move on.

int avgC(int a, int b) {
if ((a < 0) == (b < 0)) {
return a/2 + b/2 + (a%2 + b%2)/2;
}
return (a+b)/2;
}
>>
>>51866130
What if I want to average N integers in C?
>>
>>51866150
Call it in a god damn loop.
>>
fuck off with your averaging meme
>>
First for how to average 0 ints in C
>>
>>51866120
This was the original

bool even(int x)
{
for (int i = 0; i <=x; i++)
if (x==i)
return(true);
return(false);
}
>>
>>51866130
>webfag still mad for the rape he got
>>
guys, averaging 2 ints is old now. now i'd like to see /g/ averaging 3 ints
>>
>>51866176
I literally have no idea what you're talking about.
>>
>>51866174
int avg(void)
{
return 0;
}


>>51866176
He's not the webfag. I am. I'm still trying to solve it.
>>
File: pls.png (96 KB, 1918x1070) Image search: [Google]
pls.png
96 KB, 1918x1070
never encountered this problem before, anyone have any idea on what to do?
>>
>>51866203
Me here.

>>51866176
>>51866191
Were you this guy? If so, not a webfag here.
The question has LITERALLY been:
>average two ints in C
Boom. Done. Move on.
>>
let's talk about something not involving averaging numbers lads

how about full stack? anyone involved?
>>
>>51866203
>pretending
>maximum damage control
ishyggy csstard
>>
>>51866229
see if you're not defining the methods in two different places
>>
>>51866242
See
>>51866217
Dumbass...
>>
Elegant solution to average two ints in python:

def avg(x,y):
for i in range(999**999):
if (i * 2) == (x + y):
print("Average is "+i)


C fags will never have a solution this elegant and fast
Stay mad
>>
>>51866269
>samefagging for damage control
>>
>>51866150
> What if I want to average N integers in C?
Then the accumulator needs ceil(log2(N)) more bits than the values being averaged..
>>
>>51866249
nope just the once
>>
>>51866291
No, I am literally the webfag. You told me to go do webdev or go flipping burgers. I have progressed into the challenge and my decision now is not to give an opinion in something I don't have a higher level of skill in.
>>
>>51866291
I've got better things to do than samefag all damn day.

>>51866308
gl with your challenge.
>>
Any other algorithms we can talk about?
>>
>>51866229
Presumably you're trying to define the function in a header (causing it to be defined in each translation unit which includes that header) without making it "inline".
>>
>>51866308
>>51866348
>samefagging with no shame
>>
>>51866380
Probably taking the troll bait here, but seriously.
>>
>>51866410
>falling this hard
>>
>>51866380
right, if you don't believe me it'll stay like so.
>>
File: ciaindianiggers.jpg (4 KB, 200x200) Image search: [Google]
ciaindianiggers.jpg
4 KB, 200x200
how do i average 2 memes in /g/
>>
>>51866364
Reverse a string in O(1) complexity.
>>
>>51866421
Yup. Onto actual programming talk now...

>>51866080
Still working on that launcher rewrite here. Requirements are a mess but hey, getting there slowly but surely.
>>
>>51866376
thank you, this helped me fix it
>>
>>51866439
will the memes ever end?
>>
>>51866439
std::string s = "Hello, world";
std::reverse_iterator<std::string::iterator> r = s.rbegin();
>>
what site can i use to upload a zip so someone could help me with an error, too many lines to post here
>>
>>51866475
This guy
>>
>>51866543
>too many lines
Are you trying to average 2 ints in C as well?
>>
>>51866439
Make strings a doubly linked list. Use a coloring system to denote whether to follow the 'next' or 'prev' links. To reverse a string then you just toggle the color and set the pointer to beginning of string to the last character.
>>
>>51866439
Create a struct that holds a char and 2 pointers, one for previous item and one for next.
If reading the string in reverse, just follow the back pointers.
Boom
>>
File: memes.png (14 KB, 640x640) Image search: [Google]
memes.png
14 KB, 640x640
>>51866428
my Photoshop implementation
>>
>>51866274
Bravo.
>>
>>51866572
nah just trying to unscrable this image, really need help not memes my friend
>>
>>51866636
Upload a Git repository so we can clone it and see what the problem is.
>>
>>51866428
I would go with interlacing two strings and returning the middle two quarters, but I can't be assed to do it
>>
File: advent tree.jpg (111 KB, 703x657) Image search: [Google]
advent tree.jpg
111 KB, 703x657
anyone else know this feel?
>>
>>51866543
>zip
pomf.io

but if it's just text, use past ebin
>>
>>51866703
>>0<<<@>*>*>>>o>>0<<@<<
>implying
>>
File: dicks.png (76 KB, 734x483) Image search: [Google]
dicks.png
76 KB, 734x483
>>51866703
=[
>>
https://u.pomf.io/lihthi.rar

please someone try solve my issue, i've tried googling it many times
>>
>>51866813
What issue? I don't download random rars
And why would you use rar instead of a common format such as .tar.gz?
>>
>>51866176
this
>>
>>51866784
here's my solutions if you want:

https://github.com/vinheim3/AdventOfCode
>>
>>51866554
correct answer though
>>
File: mthis.png (80 KB, 1216x770) Image search: [Google]
mthis.png
80 KB, 1216x770
>>51866843
>>
>>51866868
Nah I usually look up solutions after I solve the challenges just to compare mine against others, the reason I didn't solve the part 2 of day 9 is because I didn't feel like dealing with so much nested json and p2 of today's challenge because I've been distracted by work.
>>
>>51866901
>dealing with so much nested json
i seriously hope

it's the same algorithm for every level
>>
>>51866843
https://u.pomf.io/haddjc.tar

theres the .tar
>>
>>51866080
Writing some utility functions in Lua to emulate the itertools library from Python. The only thing that's bugging me is that all tables are passed by reference so yielding a list to a for loop means that the contents of the table can be altered by the library user within the loop, inadvertently and without warning. I could copy the entire list on yield, but that's incredibly slow. Rather than copying the entire list I just want to yield the list temporarily read-only.

To make a table's read-only-ness temporary I've written a class that wraps any table that allows you to freeze and thaw a table easily go between read-only and not read-only.

To do this I've had to use proxy tables because there is no metamethod to control access to existing fields (__index and __newindex are only invoked if the key is not already in the table). The proxy table only have two members, a reference to the original table and a boolean for whether the table is currently frozen or not so the freeze and thaw methods work.

I don't like this at all. Why don't they just give us a __get and __set and they can get rid of the miserable hacks called proxy tables, __pairs, and __ipairs? Not being able to control access means there can be no meaningful OOP in this language.

local Freezable = {}
setmetatable(Freezable, {__call = Freezable.new})

function Freezable.freeze(f)
if f.__frozen__ then
f.__frozen__ = true
end
end

function Freezable.thaw(f)
if f.__frozen__ then
f.__frozen = false
end
end

function Freezable.extract(f)
return f.__table__
end

local access = {
__index = function(t, k) return t.__table__[k] end,
__newindex = function(t, k, v) if t.__frozen__ then error("Cannot modify read-only table") else t.__table__[k] = v end end,
--[[
__pairs?
__ipairs?
__len?
--]]
}

function Freezable.new(t)
assert(type(t) == "table", "Freezable must be a table")
return setmetatable({__frozen__ = false, __table__ = t}, access)
end

return Freezable
>>
>>51866901
err i meant day 12, not 9
>>
>>51866970
Thought it was weird 'Freezable' was being syntax highlighted, it's a .NET class, lol.
>>
>>51866873
input_data is probably not big enough.
>>
>>51867055
With no survivors
>>
>>51867055
I fucked up, that one
Here:
_M*_N= 512 * 512 * sizeof(int) = 1MB
>>
>>51867081
where should i put this?
>>
>>51867072
Yep
double* input_data = 0;
...
Matrix shuffled_logo = Matrix(M, N, input_data);
...
Matrix::Matrix(int sizeR, int sizeC, double* input_data)
{
_M = sizeR;
_N = sizeC;

_data = new double[_M*_N];

for (int x = 0; x < _M*_N; x++)
{
_data[x] = input_data[x];
}
}
>>
>>51867081
>>51866873
Also, it's an array of doubles, so it would end up as 2MB, not 1MB

>>51867122
You shouldn't, I was trying to make a point.
You're causing a stack overflow when creating your _data array
>>
>>51867081
>blowing the stack
>new
k
>>
>>51867159
so...how dont i stack overflow? sorry to sound like a retard but im tired af and need to get this done, thanks
>>
>>51867190
he is bullshitting.
>>51867123 is right instead
>>
>>51867201
so what do i need to change then?
>>
>>51866229
sup peter leatherbarrow
>>
>>51866229
>utorrent
>>
help im stuck in a averaging factory
unsigned long long int average(unsigned long long int x, unsigned long long int y) {
return ((x-y)/2)+y;
}

average(2,4) //returns "9223372036854775811"

why am i so retarded
>>
>>51867376
That looks correct to me, must be your compiler; could you try another one?
>>
>>51867376
Might want to look up what unsigned means
>>
I figured it out I wasn't testing if y was less than x.
long long int average(long long int x, unsigned long long int y) {
if(x==y)return x;
if(x>y)return(x-y)/2+y;
if(x<y)return(y-x)/2+x;
}
>>
>>51867376
>unsigned
>2-4
>-2
>>
>>51867229
allocate it
>>
>>51867440
allocate what?
>>
>>51867474
it
>>
>>51867474
*it
>>
>>51867474
it
>>
>>51867474
it
>>
>>51867497
>>51867524
>>51867562
stop IT
>>
>>51867609
stop what?
>>
>>51867474
it ofc
>>
>>51867609
all me
>>
>>51867617
it
>>
>>51866970
So it works at least. Did a performance test on it with my Combinations function. About 3 times faster than copying, but twice as slow as not doing it at all. Seems too high a price, I was hoping for at most a 25% slow down. ANy optimization tips?
none: 25 choose 12 took 0.619000 seconds
freezable: 25 choose 12 took 1.120000 seconds
copy: 25 choose 12 took 3.063000 seconds
>>
>>51866080
Continuing work on my rendering engine. Stepping away from graphics to do important boilerplate.
>>
Can someone explain why, in F#, "'let' and 'do' bindings must come before member and interface definitions in type definitions"?

Basically you can't use the class's fields/properties in the constructor or any of the methods? Why? How the fuck do I get around this?
>>
In my C# project I have a data class that stores stuff like this...
String
String
String
ObservableCollection<Groups>

GroupName
String
String
ObservableCollection<Modules>

ModuleName
String
String

etc., I'm sure you get the point. In my main window I declare a new public instance of this class, and then add shit to it.

However I want to bind my listboxes and such on my Window to the data. How the fuck do I do it? I've read everything I can on the subject of binding but right now all I get is NameSpace.Group as opposed to the Group.GroupName property. I'm not sure how the fuck I'm supposed to call any of this.

Data binding is bending my brain.
>>
using netbeans for comp sci class, whenever I make a new class in a project it gives me a "This class already exists", and makes an empty class. What did I manage to fuck up? This hasn't happened before.
>>
>>51867779
winforms or wpf?
>>
>>51867748
because those let and do bindings are really just considered things that happen in the constructor of the class you are defining.

What are you trying to accomplish exactly?
>>
>>51867813
WPF. Never did binding in Winforms because it seemed like an utter waste of time.
>>
File: 406041_1269697481265_full.jpg (41 KB, 800x441) Image search: [Google]
406041_1269697481265_full.jpg
41 KB, 800x441
>>51867497
>>51867524
>>51867562
>>51867608
>>51867609
>>51867631
>>51867634
NO! STOP SAYING THAT WORD!
>>
>>51867813
>>51867821
I can pastebin some code if you think you can help.
>>
>>51867821
Did you set an instance you your data class to be the data context for the window?
>>
>>51867821
The thing you're binding to needs to be a public property. Also show your xaml code for the binding...
>>
>>51867844
I did, still returns NameSpace.Group.

>>51867849
It is.

http://pastebin.com/WewiXbbS
this is all the relevant code.

I've never done data binding before so I'm sure I'm way off the deep end here.
>>
I want to make the sqlite3 sections of my codebase smaller but I don't know how to pass around sqlite3 objects successfully or what 'bindings' are.

I'm using c++, does anyone have some help/links I can read up?
>>
>>51867820
I tried to recreate my problem with a minimal example, but magically it was working. I have no idea wtf is going on, but for some reason type inference can't figure out the type of my members.
>>
>>51867898
public static Mod mod;

do you actually instantiate this field someplace?
>>
>>51867898
oops, forgot to include the code where I actually add a group.

                    Group tempGroup = new Group(txtAddGroup.Text, (rboSelectAny.IsChecked ?? false) ? "SelectAny" : "SelectExactlyOne");
mod.Groups.Add(tempGroup);
>>
>>51867898
You need to either write a ToString for Group, or add a datatemplate to control how the class is displayed in the xaml.
>>
>>51867942
>but for some reason type inference can't figure out the type of my members.
post code
>>
im working on a kijiji bot and how can I check on only one of the radio button if they have the same ID? Help
<label>
<input id="forsaleby_s" type="radio" value="ownr" req="req" name="postAdForm.attributeMap[forsaleby_s]">
Owner
</label>
<label>
<input id="forsaleby_s" type="radio" value="delr" req="req" name="postAdForm.attributeMap[forsaleby_s]">
Business
</label>
>>
File: 1446384248722.jpg (77 KB, 503x700) Image search: [Google]
1446384248722.jpg
77 KB, 503x700
tfw just became a cute anime girl
>>
>>51867977
Well the name of the group should be stored in the group object, but for some reason I can't actually call it. It should all be stored in the mod object right?

>>51867963
I have no idea what I'm doing. I need spoonfeeding.


Been working on this so long that my mind has completely warped.
>>
wanting to go from python to c#, besides reading books and following random tutorials are there any good resources anyone would recommend?

also, is there like a python to c# cheatsheet like i've seen for other languages anyone knows about? the two aren't really related much at all, but it'd just be a good way to convert my knowledge if i knew what python idea linked to what c# idea
>>
>>51867983
type QuoteStream(account:string, venue:string) as this =
let Connect = fun() ->
(this.quoteWs : WebSocket).OnMessage.Add(fun e ->
(wsQuoteResponseProvider.Parse e.Data).Quote
|> (this.quoteArrived : Event<wsQuoteResponseProvider.Quote>).Trigger)
this.quoteWs.Connect()
()

let Close = fun() -> this.quoteWs.Close()

member this.quoteArrived = new Event<wsQuoteResponseProvider.Quote>()
member this.QuoteArrived = this.quoteArrived.Publish
member this.quoteWs = getQuoteStream(account, venue)


With the annotations it works, but if I remove it I get "Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program......
>>
>>51868062
On the other hand this is perfectly fine:

type test() as this =
let foo = fun() ->
printfn "%s" (this.X.ToString())
()

member this.X = getQuoteStream("","")
>>
>>51868062
QuoteStream(account:string, venue:string)

those annotations?

I would expect it would figure it out based on
getQuoteStream(account, venue)

presuming it has a signature of
string -> string -> Stream
>>
Okay I give up; is there ANY language that is able to average two ints?
>>
>>51868132
No, in the Connect method.
>>
>>51868132
string * string -> Stream
I mean.

Like, the type signature for that function isn't ambiguous is it?
>>
>>51868163
Haskell can, because in Haskell integers are n-bit. Any number that can be validly submitted into a machine can be validly computed as an average through Haskell.
>>
>>51868163
Just use a frob.
>>
>>51868225
What's a //FROB\\
>>
type QuoteStream(account:string, venue:string) =
member this.quoteArrived = new Event<wsQuoteResponseProvider.Quote>()
member this.QuoteArrived = this.quoteArrived.Publish
member this.quoteWs = getQuoteStream(account, venue)

member this.Connect = fun() ->
this.quoteWs.OnMessage.Add(fun e ->
(wsQuoteResponseProvider.Parse e.Data).Quote
|> this.quoteArrived.Trigger)
this.quoteWs.Connect()
()

member this.Close = fun() -> this.quoteWs.Close()


This was what I was trying to do, I'm retarded.
>>
>>51867997
pls help
>>
>>51868235
Yeah what is a â–»FROBâ—…?
>>
>>51868170
you mean this?
this.quoteWs : WebSocket

Yeah, pretty sure F# type inference only works downwards. The type of this.quoteWs hasn't been declared yet, so there's not yet enough information to determine what type it is. It's a little bit confusing when doing classes, because it's one of the few places where you can access field names that are declared in lines below were you refer to them. It can figure out that quoteArrived exists in lines of code further down the file, but it hasn't yet figured out what the type is.

This is why
this.quoteArrived.Publish

works. It's written after the this.quoteArrived definition, and after the compiler has inferred what the type is.
>>
File: custbal.png (51 KB, 1313x764) Image search: [Google]
custbal.png
51 KB, 1313x764
Programming Advice!

Hey, so i'm working on studying arrays and i tried to set up this little program to run, and it works fine but when i enter a value that returns over 100 and it should print the customer's balance, it instead just prints $0.00, and i don't know why, could anyone help with this?
>>
>>51868255
You can change the first line to
type QuoteStream(account, venue) =

and last one to
    member this.Close = this.quoteWs.Close
>>
>>51868354
Ah so the inference works for the parameters as well, that's nice. Thanks.
>>
>>51868347
Why don't you have the stuff below the loop inside the loop itself?
>>
>>51868389
no probs F# bro
>>
File: dog_PNG2422.png (80 KB, 351x342) Image search: [Google]
dog_PNG2422.png
80 KB, 351x342
What programming language should I learn and how should I go about learning it?
>>
>>51868543
Depends, what do you plan on doing with it?
>>
>>51868347
>>51868422
I made a really bad mistake.. it was cause i defined custBal as an int instead of a float... sigh... silly me
>>
>>51868543
If you want to master it, start with something barebones like C, and move to C++. Honestly, programming is one of those things where the more languages you know, the better.
>>
>>51868559
Everything.
Cross-platform, too.
>>
>>51868573
you literally posted that RIGHT as I finished copying the code into vs
>>
>>51868594
i'm sorry ;-; thanks though
>>
>>51868347
You are using an array of ints instead of an array of doubles.
>>
>>51868592
You could really go with anything then
>>51868589 has good advice, starting with C before moving onto a higher level language like C++ or D
>>
>>51868543
learn Python or Ruby

>>51868589
don't start with C, it's really meh and boring

I started with C and didn't really feel programming was fun
>>
Does fscanf stop at whitespace?
It seems to only scan in the first line from my file.
Yet it doesn't say anything about this in the man pages for some infinitely retarded reason.
>>
>>51868676
So what do I do?
Cross platform, well-documented, powerful language. Web, game, everything.
>>
>>51868705
JavaScript is the only option for the web.

C# for everything else.
>>
>>51868705
>web
welp, that's not C or C++ then
>game
welp, that's not C or Python

learn Rust
>>
>>51868696
It does, you'll want fgets
>>
>>51868696
scanf scans one of the variables you give, like integer, float or char. for it to scan it you need to define what type it is you are scanning, and then you need to assign which variable it is, for instance, the ones you defined at the top. after that, to see the result you need another printf function that shows the new existing variable
>>
>>51868729
faggot

>>51868676
I started with C and I love it, remove yourself.
>>
File: typical.png (34 KB, 716x334) Image search: [Google]
typical.png
34 KB, 716x334
>>51868729
We don't need more tripfaggots here, especially ones who shill shit languages such as memesnake, javascript and pic related.
>>
>>51868762
holy shit can someone just help me
>>
>>51868705
Not every language will be able to do all those things well, which is why it's good to learn multiple. C is good if you want to learn basic stuff (and want to do low-level programming), then a higher-level language like C++, C#, Java, D, etc...
>>
>>51868705
>Cross platform, well-documented, powerful language. Web, game, everything.
What you are asking for is like asking a carpenter to only use "one ultimate tool".
>>
>>51868728
>C# games

wut, I'm sure a lot of games would run fine, but most game programmers can't leave performance on the table by choosing C# in the first place
>>
>>51868800
You're never available weekdays though.
>>
>>51868705
C

>>51868589
>move to C++
This is the most retarded thing I heard today
Also, knowing languages is just reading a manual. Knowing programming is the difficult thing.
>>
File: Hard Modo~.jpg (52 KB, 501x417) Image search: [Google]
Hard Modo~.jpg
52 KB, 501x417
>>51868543
Are you a fucking wimp?
>Type into google "how to program gaem"
>Porgram gaem
>Post dogshit code here (or on stackoverflow or irc etc)
>Get shat on
>Learn something
>Code gets less dogshit
>gaem v0.02
>Repeat process until gud

For starters, try this problem in C.
>>
>>51868802
>>C# games
He probably means shit like Unity, where non-performance critical code/game logic is written in C#.
>>
>>51868826
 print "2"
>>
>>51868821
The problem with C is that I think it's too low-level.
>>
>>51868826
You want it to print an infinite amount of numbers? Or is that the joke.
>>
>>51868840
0/10, not C
>>
>>51868610
well here, not wanting to put all that work to waste I cleaned up some of your code for you.
#include <stdio.h>

int main()
{
int ctr, idSearch, found = 0;
int custID[10] = {313, 453, 502, 101, 892, 475, 792, 912, 343, 633};
double custBal[10] = {0.00, 45.43, 71.23, 301.56, 9.08, 192.41, 389.00, 229.67l, 18.31, 59.54};
printf("\n\n*** Customer Balance Lookup ***\nWhat customer number do you need to check?");
scanf(" %d", &idSearch);
for(ctr = 0; ctr < 10; ++ctr)
{
found = idSearch == custID[ctr] ? 1 : 0;
if(found) break;
}
if(!found)
{
printf("** You must have typed an incorrect customer ID.\nID %3d was not found in list.\n", idSearch);
return 0;
}
if(custBal[ctr] > 100.00)
{
printf("\n** That customer's balance is $%.2f.\n No additional Credit.\n", custBal[ctr]);
return 0;
}
printf("\n** The customer's credit is good!\n*");
return 0;
}
>>
>>51868865
puts("2");
>>
>>51868862
>prime numbers that are not odd
>infinite amount
Do you know what a prime number is?
Do you know the difference between even and odd numbers?
>>
>>51868826
I was gonna ask about a limit, but then I realized...
#include <stdio.h>

int main(void)
{
printf("2\n");

return 0;
}
>>
>>51868821
yes and no

look at this program:

>>51868347

compare it to the equivalent Rust declaration:

https://play.rust-lang.org/?code=fn%20main%28%29%20{%0A%20%20%20%20let%20x%3A%20[i32%3B%201]%20%3D%20[1.0]%3B%0A}&version=stable

it won't let you make the same mistake, it knows the types don't match
>>
>>51868802
>but most game programmers can't leave performance on the table by choosing C# in the first place
Fez
Bastion
Transistor
Axiom Verge
TowerFall

Are all 100 C# with monogame.

Unity's primary scripting engine is also C#, so you can count that too.

>>51868839
Not just unity. Monogame is pretty popular and is 100% C# that hooks into OpenGL directly.
>>
>>51868347
>>51868872
the problem is with scanf you niggers
>>
>>51868872
i noticed you made some differences like using the !found instead of else.. is that a memory management thing or just preference?
>>
File: 1443028669411.png (68 KB, 605x525) Image search: [Google]
1443028669411.png
68 KB, 605x525
>>51868884
You're like Desi 2.0 so I'm going to jump right to it and ask you to off yourself right now.
>>
File: Untitled.png (10 KB, 739x534) Image search: [Google]
Untitled.png
10 KB, 739x534
>>51868840
Get gud
>>
>>51868855
>low-level
This is a meme

>>51868884
>fn main() { println!("Hello, world!"); }
What are you trying to compare? I don't get it.

Anyways, any self-respecting compiler would show an error, mine does.
>>
>>51868888
most game programmers don't work for indie game developers, the vast majority of game development is done in C++

anyway, I changed my mind, if you want to be able to do everything the only answer is Javascript (web, game, etc.)
>>
File: 1419316347260.jpg (143 KB, 640x1136) Image search: [Google]
1419316347260.jpg
143 KB, 640x1136
>>51868929
>>
>>51868898
Preference, as it makes the code look cleaner. Having less branches in your code is theoretically faster but realistically that doesn't mean much.
>>
>>51868927
what? No, my link should say

fn main() {
let x: [i32; 1] = [1.0];
}
>>
>>51868882
oh, mistook them for integers. english is not my first language
>>
File: 1439590011623.jpg (259 KB, 1000x1502) Image search: [Google]
1439590011623.jpg
259 KB, 1000x1502
>>51868946
>>
>>51868943
it wouldn't be faster, but it reduces rightward drift
>>
>>51868946
>
[i32; 1]

for what purpose?
>>
>>51868929
>most game programmers don't work for indie game developers
arguably, most game programmers don't work for anyone and are just hobbyists. Unless you're working on a very large game for a large game dev company, C# is going to be a pretty decent language for you.
>>
>>51868946
Well, it doesn't for me.
But still, my compiler informs me of the mistake.
>>
File: 1432747484276.png (116 KB, 957x482) Image search: [Google]
1432747484276.png
116 KB, 957x482
>>51868973
>>
>>51868826
WinMain(){puts(2);}

One line, compiled with gcc on windows 7.
What now dad?
>>
>>51868826
printfn "2"
>>
>>51868976
I'm making an array of length 1 to compare to the other program

so I'm showing that Rust has inference not only in the case of
let x: i32 = 1.0;
but also inference from inside of arrays

>>51868977
well, it depends on what your goals are

if you really want to work in Blizzard you should learn C++
>>
>>51868977
>most are just hobbyists
This. Even big companies don't employee programmers in a consistent fashion for more than a year at a time.
>>
File: 1443797243390.png (269 KB, 600x500) Image search: [Google]
1443797243390.png
269 KB, 600x500
>>51869016
>>
>>51868987
Actually wait this segfaults. Don't think I can get a nonsegfaulting version in less than two lines, so this is all I've got right now:
#include <stdio.h>
WinMain(){printf("%d",2);}
>>
>>51869016
Another trip into the graveyard.
>>
>>51868883
The image said nothing about being POSIX complaint or returning an exit code. You wasted a WHOLE line of code on it.

3/10
>>
>>51869016
>if you really want to work in Blizzard you should learn C++
sure. but I wouldn't assume anyone who want's to learn a language they can use for games will have that as a primary goal.
>>
>>51868987
>>51869046
>winmain
why
>>
>>51869046
Wow I'm an idiot.

WinMain(){puts("2");}


This compiles and runs properly on Windows 7 using gcc.

I challenge any fool here in /dpt/ to create a print-the-number-2 program that has less lines than this one and still runs properly.

>>51869077
on Windows, WinMain() functions similarly to _start() on linux. That is, main() implicitly gets mapped to WinMain() on compilation. By bypassing main() itself, the resulting executable will be that much smaller.
>>
extern int puts(const char *);int main(){puts("2");}

C99+ version
>>
print"2"

muh lua
>>
>>51869092
non-standard, gtfo
>>
>>51869107
Nobody ever said it had to be standard, senpai.
>>
File: 1282604412029.png (6 KB, 204x215) Image search: [Google]
1282604412029.png
6 KB, 204x215
>>51868826
#include <stdio.h>
#include <unistd.h>

void _start(void)
{
printf("2\n");
_exit(0);
}
>>
File: Untitled.png (2 KB, 170x331) Image search: [Google]
Untitled.png
2 KB, 170x331
How long does it take the programming geniuses of /dpt/ to figure out how to write something like this, any language? Took me longer than I'd like to admit.
>>
>>51869120
>printf()
>not syscall(1)
>>
>>51869117
>For starters, try this problem in C.
Non-standard = not C
>>
>>51866080
Was 4chan being a shit for anyone else just now?
>>
>>51869130
How many nested loops did you use?
>>
>>51869145
If GCC compiles it as C code, it's C and there's nothing you can do about it.
>>
>>51869200
Depends what you mean by C though.

I could write a C compiler that allows all kinds of shit. That wouldn't mean anything it compiles is valid C.
>>
>>51869184
Everything happens inside a single loop that iterates through the characters of the input phrase. Well, I create the padding with loops inside that, but there are other ways to do it. This is written in sh.
>>
>>51869226
There's no such thing as "valid" C because Dennis Ritchie isn't around to go door-to-door manually transcribing C into machine code.
C is whatever the C compiler you're using happens to say C is. As GCC is the most used C compiler, and generally considered to be pretty decent, it's safe to say that the GCC dialect of C is "real" C. You can write your own compiler and that'd be your own dialect of C, I'm not disputing that at all.
>>
Can someone sum up the average 2 ints thing?
>>
File: geckoe.jpg (430 KB, 1024x683) Image search: [Google]
geckoe.jpg
430 KB, 1024x683
>>51868927
>>51868821
>>51868800
>>51868782
>>51868752
>>51868729
>>51868728
>>51868705

Alright. Let's say, for a website backend to be more specific.
What's the best language to do the job?
>>
>>51869307
C#
>>
>>51869312
this is a joke right
>>
>>51869307
C# on ASP.NET.
>>
>>51869305
It's a meme lad
>>
>>51869324
nope. It's by far the least shit option.
>>
>>51869130
keep dividing the distance between the 3 characters until you get to the middle, in which you print reversed and regular string.
And then you muliply the distance between characters for the last part.
This shouldn't take more than 3 for loops to accomplish.
>>
>>51869305
sum2 :: Fractional a => a -> a -> a
sum2 x y = (x+y)/2
>>
>>51869333
>>51869367
I just don't see where the controversy is

Add the ints and divide by the number of ints
>>
>>51869145
much of the C standard is 'implementation defined behavior' meaning there really is no standard
>>
>>51869305
>sum up
>sum
wew lad
>>
>>51869418
Srsly, this. The original K&R was essentially "this is what C should probably be like, now go and make a compiler to actually do this shit" and then nobody did so the second edition was completely different.
>>
File: Screenshot_2015-12-14_21-00-39.png (21 KB, 579x513) Image search: [Google]
Screenshot_2015-12-14_21-00-39.png
21 KB, 579x513
>>51869130
import sys

def template(n, i):
return " "*i + "{0}" + " "*(n-i-2) + "{0}" + " "*(n-i-2) + "{0}"

if __name__ == "__main__":
text = sys.argv[1]
n = len(text)

for i in range(2*n-1):
if i < n-1:
print(template(n, i).format(text[i]))
elif i > n-1:
print(template(n, 2*n-2-i).format(text[2*n-2-i]))
else:
print(text + text[-2::-1])
>>
>>51869200
>>51869284
C is what ISO defines it.
Faggot.
>>
>>51869397
Go back to your fizzbuzz, kid, the adults are talking.
>>
>>51866117
>what is ur
>>
Speaking of K&R, does it go into memory how memory is handled at all? Or what book should I read to really understand memory management in C.
>>
You can't average two ints without returning a double
>>
>>51866439
str1 = "hello world"
str2 = "dlrow olleh"
return str2
>>
File: FirstFixie.jpg (17 KB, 241x319) Image search: [Google]
FirstFixie.jpg
17 KB, 241x319
Steve Jobs once said computers are like bicycles for the mind.

If that's true then this is C.
>>
Learning how compilers compile
>>
>>51869519
C isn't high-level though
>>
>>51866590
Then it's O(n), n being the amount of pointers.
>>
>>51869522
4U
http://neetco.de/languagedev/language
>>
>>51869505
it would be worthwhile to learn asm and by learning asm you will also learn how whatever CPU and OS you use handles memory
>>
>>51869535
based post
>>
>>51869062
fair enough

>>51869307
Haskell
>>
File: 1282745654005.png (16 KB, 500x500) Image search: [Google]
1282745654005.png
16 KB, 500x500
>>51869141
#include <unistd.h>

void _start(void)
{
write(1, "2\n", 2);
_exit(0);
}
>>
>>51869541
O(1) to reverse, not O(1) to actually read the string.
All you'd need to do is change the direction pointer that takes you to either the first or very last character and then start reading from there without manually swapping all the chars in O(n) time.
>>
>>51869546
Damn when was this site made? Sick

Anyone have the announcement thread link?
>>
>>51869552
asm means assembly, right? Any good books on that that you recomend?
>>
>>51869565
neetcode was made forever ago.
>>
>>51869570
Assembly Language: Step-by-Step
>>
>>51869570
SICP
>>
>>51869570
yes

https://www.youtube.com/watch?v=1p6LfUkWPKI&index=1&list=PL4C2714CB525C3CD7
>>
>>51869579
>>51869565
what reason does anyone have to use a hobbyist site like neetcode or gitgud when github exists and github holds the distinction that it won't suddenly disappear tomorrow because the owner got bored with it.
>>
  codesnips  ./gchallenge "meme master"
m m m
e e e
m m m
e e e

m m m
a a a
s s s
t t t
eee
meme masteretsam emem
eee
t t t
s s s
a a a
m m m

e e e
m m m
e e e
m m m


Code:
import System.Environment
main = getArgs >>= putStr . memeString3 . (!!0)

memeString3 s = unlines $ inOrder ++ [s ++ drop 1 (reverse s)] ++ reverse inOrder
where inOrder = zipWith aLine (take (len - 1) s) [1..]
aLine c n =
let divider = replicate (len - n - 1) ' '
in replicate (n - 1) ' ' ++ [c] ++ divider ++ [c] ++ divider ++ [c]
len = length s


Took 6~7 minutes
>>
>>51869620
If you use neetcode you affiliate yourself with /g/ and make sure you'll always be a NEET.
>>
What's the answer for day 14 AoC part 1?
I'm getting 2640 and the site says I'm cheating.
>>
>>51869633
response to
>>51869130
>>
File: 1304302976006.jpg (28 KB, 512x384) Image search: [Google]
1304302976006.jpg
28 KB, 512x384
>>51869562
.global _start

.section .data
prime: .ascii "2\n"

.section .text
.code32
_start:
movl $4, %eax
movl $1, %ebx
movl $prime, %ecx
movl $2, %edx
int $0x80

movl $1, %eax
movl $0, %ebx
int $0x80
>>
File: 1446773814947.gif (1 MB, 500x281) Image search: [Google]
1446773814947.gif
1 MB, 500x281
I have a syntax error and can't fucking find it. Anyone can help me. (;$$ is my delimiter)

CREATE DEFINER=`root`@`localhost` FUNCTION `ajoutFormation`(`p_titre` VARCHAR(100), `p_duree` INT(11), `p_niveauEtude` INT(11), `p_quota` INT(11), `p_idSpecialite`, `p_local` VARCHAR(30)) RETURNS int(11)
NO SQL
begin
declare v_form varchar(50);
declare v_rep varchar(50);
declare v_retour int(11);
declare compteur int(11);
declare v_speci varchar(50);
set compteur =0;
select intitule into v_speci from specialite where idSpecialite = specialite;
if v_speci is NOT NULL
then
set compteur=compteur + 1;
set v_rep = CONVERT(compteur,char);
set v_form = SUBSTRING(v_speci,1,3);
INSERT INTO formation (codeFormation,titre,duree,niveauEtude,quota,idSpecialite)
VALUES ((CONCAT(v_form,compteur)),titre,duree,niveauetude,nbplace,specialite);
INSERT INTO peutsederouler(numLocal, codeFormation)
VALUES
((CONCAT(v_form,compteur)), p_local);
set v_retour = 1;
else
set v_retour =0;
END IF;
return v_retour;
END;$$
>>
>>51869681
>AT&T
>>
File: 1449902438494.png (444 KB, 800x600) Image search: [Google]
1449902438494.png
444 KB, 800x600
>>51869688
>>
>>51869620
Github delete projects they don't like, such as if you make a program to filter words like faggots and cunt, well clearly the words faggot and cunt are misogynistic, but you need these words in a list somewhere to censor them, so your project gets booted.
Moreover, github tracks you everywhere whereas neetcode doesn't. It's a lot safer to use for side-project, thus.
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.