[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: 31
Old thread: >>51689650

What are you working on, /g/?
>>
File: 1412889019408.jpg (340 KB, 716x1012) Image search: [Google]
1412889019408.jpg
340 KB, 716x1012
adventofcode.com

Daily programming challenges til xmas. Anybody else competing?
>>
>>51692601
Learning C++ again; I didn't know it very well before but not is the time, for employability and exposure reasons.
It's pretty neat but a little complicated.
>>
File: wheeeeee.gif (499 KB, 300x250) Image search: [Google]
wheeeeee.gif
499 KB, 300x250
Tell me why I shouldn't cast all my pointers before freeing them?
free((double *) arr);
>>
>>51692701
Tell me why you should
>>
>>51692711
Because it's easy to do and improves readability.
>>
>>51692701
The operating system only needs to know the address of the memory that needs to be freed, it does not need to know how that memory was used.
>>
>>51692718
bad meme
>>
>>51692718
how does it improve readability?
>>
File: 1412888648446.jpg (519 KB, 2560x1440) Image search: [Google]
1412888648446.jpg
519 KB, 2560x1440
I'm working on a website. Fake stock trading website (real stock prices, not real money or real stocks). The twist is I'm building an interpreter backend that allows users to write scripts which will constantly run, buying or selling stocks based on minute-by-minute data, allowing a user to emulate high frequency trading, though not very high frequency.

I keep a local table of stock prices minute by minute and only save day to day stocks long term to save on bandwidth cost
>>
>>51692718
>it's easy to do
I think you mean pointless
>improves readability
No
>>
>>51692744
What the fuck is your problem?
OP's pic is a girl.
>>
>>51692742
>interpreter backend that allows users to write scripts
what up proboards >:)
>>
File: 1412888955944.jpg (46 KB, 579x819) Image search: [Google]
1412888955944.jpg
46 KB, 579x819
>>51692701
functionally, it does the same thing, but casting is an extra step is processing, making it one step less efficient. It also adds nothing (readability? why do you need to know that your pointer is a double pointer?)
>>
>>51692741
You're visually reinforcing what type your pointer is.
It's the same reason why you must always cast the output of malloc.
>>
File: 1412888142440.jpg (90 KB, 930x1316) Image search: [Google]
1412888142440.jpg
90 KB, 930x1316
>>51692765
AHHHHHH WHO ARE YOU GO BACK TO FACEPUNCH
>>
>>51692775
If you're freeing it, that most likely means you won't use it again. Why would you need to know the type at that time?
>>
>>51692744
>>51692761
>>51692790
kek
>>
>>51692793
what if you're constantly free'ing and mallocing the same pointer over and over in a loop?
>>
>>51692793
furthermore, you could simply just put a comment next to it letting you know what type it is.
>>
>>51692810
>vomit.jpg
>>
>>51692699
>To what floor do the instructions take Santa?

But where are the floor instructions other than the examples?
>>
>>51692826
realloc does the same thing in the background, moving the contents to a new pointer and memory block and then freeing the old one.
>>
>>51692833
Sign up for the website and it will generate an instruction set for you. you can sign up with github, facebook, or email
>>
>>51692775
if you have a float and you pass it to a function that requires a float as a parameter, do you cast it to float again? it's unnecessary and imo makes it harder to read, complicates the code while i'm scanning over it. and the reason you cast malloc() is because malloc() doesn't know what you're allocating for, so you just get the pointer and there's no datatype associated. you cast it to specify, not for readability.

>>51692810
do you really need that visual reinforcement that bad? your pointer name should already imply the datatype associated with it. ie for your example you could just name your pointer "dPointer" instead of "pointer"

>>51692774
to be fair, probably not. compiler would probably strip it out anyway, wouldnt it?

>>51692791
___bins. ive got your name fucker! hahaha
>>
>>51692810
I still fail to see how that would benefit you. Great, you know the type of the pointer you're freeing, now what?
>>51692842
It doesn't do it repeatedly though
>>
File: 1412888709567.jpg (188 KB, 1360x768) Image search: [Google]
1412888709567.jpg
188 KB, 1360x768
>>51692851
>to be fair, probably not. compiler would probably strip it out anyway, wouldnt it?

I guess. Compilers tend to optimize everything, but your engineering choices should reflect an assumption that the compiler will fix your mistakes for you
>___bins. ive got your name fucker! hahaha
are you following me ;__;
>>
>>51692866
>It doesn't do it repeatedly though
it does if you put that realloc in the loop instead of a free+malloc
>>
>>51692849
Oh fuck it then.
>>
>>51692879
>your engineering choices shouldnt reflect an assumption that the compiler will fix
thats a really good point, never thought of it like that. and no, nothing creepy going on here i just couldnt help myself when i recognized "stock site with constant scripts" hahahaha
>>
>>51692866
vector<int> nums;
int num;
while (cin >> num) {
nums.push_back(num);
}
>>
>>51692601
Resolved a bug with my chatbot revolving around generation of pronouns that was getting in the way of a demo I've been preparing for like a century. Hoping to have it out by the end of the year, but I was saying the same thing a year ago. Nothing major.
>>
File: 1412887824250.jpg (603 KB, 1172x1500) Image search: [Google]
1412887824250.jpg
603 KB, 1172x1500
>>51692907
ah yes, shouldn't* thank you

do you know anything about language interpretation because I'm learning this all from the ground up. the adventofcode.com challenges are good practice with yacc and lex
>>
>>51693002
nah not really thats part of why im heading to uni is i can code but i dont really understand theory and lower level concepts like language interpretation
>>
>>51692699
Yay! Something to do with my boring life.
>>
carried from >>51691179

>>51690607
why is that?
>>
>>51693041
It's not really low level. C is low level and compilers are low level but you could write an interpreter in javascript in a web browser.
>>
Anyone see anything wrong with the idea behind my kernel free?

http://neetco.de/ZenosCave/BamfOS/src/master/src/kernel/arch/i686/mem/alloc.c

all necessary info can be found in
http://neetco.de/ZenosCave/BamfOS/src/master/src/kernel/include/kernel/alloc.h
and
any file in
http://neetco.de/ZenosCave/BamfOS/src/master/src/kernel/arch/i686/mem
>>
From previous thread
>>51692264
>>51692500
>>
>>51693139
If you ask a specific question I can take a look and then tell you to go kill yourself.
>>
Is the tranny guy autistic?
He just posted 4 new /dpt/s within seconds of each other.
>>
>>51693159
thanks now my boss wants to speak to me.
>>
Weekly reminder:

If you're interviewing for company, don't assume you can write shitty code.

Ask the interviewer if you can skip access modifiers, comments, accessors, proper naming, unit testing, etc.

Don't assume you can.
>>
>>51693167
Butthurt faggots gonna be butthurt
>>
>>51693167
>tranny guy

You mean OP?
>>
>>51693179
no the guy literally dumping tranny porn every 30 seconds.

also the op pic is a gril
>>
>>51693191
Nah, I'm pretty sure you mean OP. It's the same attention fag fagging for attention. Being a tranny is seriously a mental disorder.
>>
>>51693174
I thought the whole point was to verify that you're not an idiot who doesn't even know what modulo is.
>>
>>51693191
>he keeps saying this
>>
>>51693290
Tranny is the new female
>>
>>51693222
That's part of it, but you should also demonstrate that you can write code that can make it into the repo in good conscience.
>>
>>51693360
I don't understand why they would expect me to know the intrinsic details of their workflow or best practices when I've never worked for them or been exposed to their source code.

It's like asking "Why should we hire you?".
>>
>>51693392
>why shouldn't I write my entire program as a single main method
You're the type of person I'm trying to keep the fuck away from the source code
>>
>>51693412
My point is that you shouldn't overengineer your solution even if it's a simple interview question.
If the interviewer didn't ask you to include access modifiers, comments, accessors, proper naming, unit testing, etc. as part of the specification, then you shouldn't assume they're required.
>>
>>51693446
So if you get a job as a programmer, do you think your manager will say "so in this project, we will require access modifiers, comments, accessors, proper naming and unit tests"?
>>
>>51693484
Wow, I'm going to be given repo write access without so much as a memo on their workflow?
What great management, I'm sure your company will go far!
>>
>>51693507
You shouldn't have to be given a memo saying "please don't write shit code".

Just ask. Either they'll say "no that's fine, but thanks for asking" or they'll say "yes please".
>>
>>51693553
Sounds reasonable.
Why should unit tests be required in interview code solutions unless they asked for them specifically?
>>
>>51693570
You don't necessarily have to write unit tests themselves, but you should never have to refactor your code to add unit tests later.

Code should always be modular and reusable, and unit tests are just a reuse.
>>
Mods need to start enforcing the board rules so your faggy trans shit will stop taking over /g/.
>>
Goodnight, /dpt/. Hopefully, I'll dream about coding again.These kinds of dreams are fun...
>>
>>51693784
You should try lucid dreaming.
>>
Are there any normal people left in the programming world or is everyone a gay/tranny hipster?
>>
NEW THREAD

>>51693808
>>
>>51693815
get out of webdev
>>
>>51693815
stick to C/C++ and java
>>
>>51693807
Thanks m8 I will.
>>
>>51693815
It's literally 1 deranged tranny who lives on /g/.
>>
If I have an algorithm that works in O(n-1) time would you just say it's O(n)?
>>
>>51693885
I mean I look at the new generation of software engineers and I'm struggling to find the straight laced normal types, but as previously mentioned I work in web dev (server side) so that's probably why.
>>
>>51693885
no, it's one guy who keeps forcing himegoto pics and another asspained tranny who dumps tranny porn in response
I don't even understand why he does it.
The tranny porn dumper can't even claim it's ironic, since he literally has gigabytes of tranny porn on his computer and he's going out of his way to switch IPs so he can evade bans.
>>
>>51693899
pretty sure it's still linear
>>
>>51693919
No, it's literally 1 deranged tranny who thrives on attention so he gives it to himself.
>>
>>51693815
Supposedly in the east coast, older people are the majority, so if you try that you may have better luck
>>
>>51693942
see >>51623600
>>
>>51693899
There's nothing wrong with saying an algorithm is O((2n+1/57)^3).
But the implication of time complexity is that the only thing that matters is how complex the algorithm is, and that the nitty gritty details don't matter in the long run.
And in that fashion, people like to simplify it.
So rather than an overly exact O((2n+1/57)^3), we simplify to O(n^3).
>>
>>51693939
what if I have something like O(VLogV+E-V) for a graph. what would that be?
>>
Idea about a certain class of proofs in my language.

Take proving that forall x. x+0 = x, i.e. finding a value for that type. If you use an inductive type such as Nat, you can prove it entirely constructively. However if you're using a native representation with native operations, you can't constructively prove anything. So I'm going to add a class of theorems (proof types) called hypotheses, which are checked using randomly-generated cases a la QuickCheck at compile time. So while I suppose you can't have 100% certainty that a hypothesis is a theorem, you can be pretty confident.

-- theorem
rightIdentityNat : (x : Nat) -> x + Z == x
rightIdentityNat Z = Refl Z
rightIdentityNat (S x) = cong S (rightIdentityNat x)

-- hypothesis
rightIdentityI32 : (x : I32) -> x + 0 == x
rightIdentityI32 = ?
>>
>>51693978
Does your execution time grow linearly based on the amount of input it receives?
>>
>>51693978
In certain situations it may be worthwhile to include the extra variables.
Here's precisely a situation in which your example is used:
https://en.wikipedia.org/wiki/Master_theorem
An example of complexity that involves the master theorem would be Quicksort.
>>
>>51693991
this
>>
>>51693957
>I deleted

So he confirmed that he's a single tranny who's been posting all this shit nonstop.
>>
>>51693991
I'm trying to analyze an algorithm I made that will take a vertex of a graph and check if it's a 'ring vertex' which means that all of it's adjacent vertices are form a cycle of their own.
>>
>>51693899
Yes. You only care about the degree of the function as it approaches infinity.
>>
I wish I could understand higher inductive types.
>>
>>51694033
The easiest way to visualize this is the following.
Does the amount of operations required increase as your input increases?
If no, it's O(1), if it grows linearly, it's O(n), if it grows exponentially, it's O(n^2), and so forth.
>>
File: tyutyu.jpg (33 KB, 673x423) Image search: [Google]
tyutyu.jpg
33 KB, 673x423
pls help with this senpai.

wat do?
>>
>>51694125
your own homework
>>
>>51694125
Java mills everybody
(might be C# I have no clue)
>>
>>51694125
I hope you didn't pay money for this course.
>>
>>51694081
O(n^2) is not exponential.
>>
So I made a browser based media player for all of my music using Sinatra a few years ago (it reads the directory structure of my music library off my hard drive). I made a JSON API for it and never did anything with it. This past week I've been learning Swift by making an iOS app that pulls in all of the song data from the API and then lets you play the songs. It's rough around the edges still but I got it to actually play audio last night. Just need to add controls for the audio and add searching.
>>
>>51694125
Is this what Windows users actually believe?
>./subtract 10 20
>>
>>51694125
take sleeping pills and sit on a ledge
>>
>>51694144
>>51694148
>>51694150

i dont have a c:/cubtract.exe thats why im confused
>>
>>51694164
my mistake
O(2^n)
>>
>>51694185
how much money did you pay for this diploma mill course?
>>
>>51694125
this cannot be real
>>
>>51692699

>To play, please identify yourself via one of these services:
But I don't want to identify myself...
>>
>>51693982
This paves a way to prove totality of recursion over native values.

Basically, a recursive function is total if, for all values that it might recurse over, the number of steps is countable. And how do you prove that a quantity is countable? Well, because of the halting problem, you need to be conservative. So really, you have to prove that the number of steps is less than or equal to some value (which may depend on the input).

So proving totality of recursion over the unsigned integers is actually quite trivial, once you add the ability to use checked hypotheses instead of just theorems.

-- hypothesis
recTotalityU32 : (x : U32) -> steps x <= 0xffffffff
recTotalityU32 = ?
>>
>>51694185

I'm gonna be nice and go against my better judgement and help you out: "subtract.exe" is a hypothetical program.
>>
File: terrain_sample.jpg (298 KB, 512x512) Image search: [Google]
terrain_sample.jpg
298 KB, 512x512
>>51692601
Working on a terrain generation algorithm using perlin noise.

Picture related.
>>
>>51694307
This is pretty cool.
>>
This is what I came up with in C# for the first Advent of Code challenge.
 
string directions = "THE LONG ASS DIRECTIONS THAT ARE 7000 CHARACTERS LONG";
char[] upOrDown = new char[directions.Length];

int up = 0;
int down = 0;

using (StringReader stringReader = new StringReader(directions))
{
stringReader.Read(upOrDown, 0 , directions.Length);
}

for (int i = 0; i < directions.Length; i++)
{
if (upOrDown[i].ToString() == "(")
{
up = up + 1;
}
else if(upOrDown[i].ToString() == ")")
{
down = down + 1;
}
}

int destination = up - down;

Console.WriteLine("Your destination is floor: " + destination);
Console.ReadKey();

What do you guys think?
>>
>>51694389
This is mine in Lua:
local str = '__your_input__'
local floor = 0
local ch

for i = 1, #str do
ch = str:sub(i, i)
if ch == ')' then
floor = floor - 1
elseif ch == '(' then
floor = floor + 1
end
end

io.write(('%d\n'):format(floor))


Doing Day 2 Part 2 atm.
>>
>>51694403
My god that looks sexy. I need to learn Lua
>>
File: srjysr.jpg (37 KB, 622x412) Image search: [Google]
srjysr.jpg
37 KB, 622x412
>>51694339

i think i got it thnx
>>
File: 1434229519851.png (210 KB, 871x900) Image search: [Google]
1434229519851.png
210 KB, 871x900
>>51692701
If anything you should cast it to (void*) but I'm pretty sure most compilers would make the conversion implicitly so it doesn't matter.

Also, good style is purposeful, and being explicit just for the sake of being explicit is not purposeful.
When you hear of QSP and QOOP, it's usually because of people doing things out of some perceived adherence to a set of coding guidelines or standards without properly understanding the intentions thereabout.
>>
>>51694389
What does the using do in C#? is stringReader gone after that block or something?

>>51694341
Nice. Just the image or some sort of actual usable data? I suppose one could use the image anyway.
>>
wait im not sure if I'm doing this correctly

i've got this:

void loadEntityPrototype(lua_State *vm, int prototype, const char *path) {
luaL_dofile(vm, path);
lua_pushnumber(vm, prototype);
lua_getglobal(vm, "prototype");
lua_settable(vm, LUA_REGISTRYINDEX);
}


I assume I use it before anything else (like use it in my main function)

I ran it like so:

loadEntityPrototype( LS, 0, "./objTest.lua" ); 


inside that objTest.lua is

prototype = {
new = function()
return {
name = "Sample",
foo = 0
}
end,

update = function(self)
self.foo = self.foo + 10
end,

draw = function(self)
return "%s(%d)":format(self.name, self.foo)
end
}


anyways, i've made me a new entity but it crashes because the table index is nil. so im sure it's not the code, im sure i'm not putting something in correctly
>>
>>51694484
Using just sets up an IDisposable object. IDisposable objects have their memory space opened up when they are no longer in use. And to access using you have to use the System.IO namespace.
>>
>>51694549
Or excuse me I'm dumb. You only need the System.IO namespace for the StringReader
>>
>>51694564
>>51694549
So it's no different than just deleting it after that one line instead?
>>
>>51694586
No not exactly after only when you call IDisposable.Dispose();
>>
>>51694649
I'm saying
using (thing t = new thing()) {
t.whatever();
}

is the same as
thing t = new thing()
t.whatever();
delete t; // t.Dispose()? I don't know C# but you get my point
>>
>>51692601
I'm meganoob at java and trying to figure out how to get loops to fill arrays before my assignment is due at midnight tonight
>>
>>51694586
Using is really not needed in my script at this point. I made stringReader an IDisposable so I can get rid of it later when I implement another StringReader.
>>
>>51694258
Create a fake account
>>
How would you find two smallest numbers given 3 input numbers?
>>
>>51694674
Yeah, it's pretty much the same and t.Dispose would be the correct way to use it.
>>
>>51694712
Doing the advent thing I see. I just sorted them.
>>
>>51694712
put the 3 numbers in an array and sort them from least to greatest.
Return the first 2.
>>
>>51694686
 for (int i=0; i<40; i++) {
thearray[i] = 40;
}
>>
>>51694712
I've done it this way, the part where I pick the second min is a tad bit ugly but it works:
local getTwoMin = function(a, b, c)
local min = math.min(math.min(a, b), c)
local max = math.max(math.max(a, b), c)

-- Perhaps can be simplified?
local mid
if a > min and a < max then
mid = a
elseif b > min and b < max then
mid = b
else
mid = c
end

return min, mid
end
>>
>>51694712
sort then just print array items 0 and 1
>>
>>51694771
is this a language or just psuedocode? it's perfect
>>
>>51694799
lua
>>
>>51694799
That's Lua. But I just figured out my solution is broken because for inputs 1, 1, 10 it will output 1, 10, not 1, 1.
>>
>>51694799
wait until you see tables/metatables
>>
>>51694770
Thanks, but I'm still lost on how to integrate that into my assignment. http://imgur.com/a/C9AJa

I can't seem to figure out how get the loops/arrays to work when I don't know how many numbers I'm going to be using for it
>>
>>51694830
>>51694813
>>51694804
Oh, nevermind then.
>>
Is there any practical use for arrays larger than 3 dimensions?
I can imagine 3D arrays as a cube of values, but what would a 4D array be?
>>
>>51694839
Good luck dude. You should have started this job many weeks ago.
>>
>>51694855
A 4D array is a list of lists of lists of values. Thinking of it in spacial dimensions is limiting.
>>
File: CSKP.png (1 MB, 1920x1080) Image search: [Google]
CSKP.png
1 MB, 1920x1080
>>51692601
I made this yesterday to keep from having to install some shady 3rd party shit in order to save myself 6 keystrokes.
I call it MessAffect.bat and feel free to use & improve upon it if you find it helpful. *requires cecho https://code.google.com/p/cecho/
Tell me what you think for I really want to know.
@echo off

cd "C:\Program Files\Pale Moon"
start "" palemoon.exe -p default "origin://launchgame/OFB-EAST:56694"

TIMEOUT /T 15 /NOBREAK > NUL
cecho {\u07} {71}{\u003C}--------{79}Shifting to single core{71}--------{\u003E}{8A}{\u002A \u002A}------{#}{\n}
PowerShell "$Process = Get-Process ME2game; $Process.ProcessorAffinity=3"
Powershell "Get-Process ME2game | Select-Object ProcessorAffinity"

TIMEOUT /T 10 /NOBREAK > NUL
cecho {\u07 \u07} {71}{\u003C}--------{79}Shooting for high score{71}--------{\u003E}{8A}{\u002A \u002A \u002A \u002A \u002A \u002A \u002A \u002A }{#}{\n}
PowerShell "$Process = Get-Process ME2game; $Process.ProcessorAffinity=255"
PowerShell "Get-Process ME2game | Select-Object ProcessorAffinity"

TIMEOUT /T 5 /NOBREAK > NUL
Powershell "Stop-Process -processname palemoon"
cecho {\u07}{#}{\n}
>>
>>51694855
1D - line
2D - square grid
3D - cube
4D - line of cubes
5D - square grid of cubes
6D - cube of cubes
7D - line of cube of cubes
8D - grid of cube of cubes
9D - cube of cubes of cubes
10D - idk lol
>>
>>51694931
>that image
Is that kern.log in comic sans?

I don't think I've ever felt this particular brand of disgust before
>>
Anyone else love solving really trivial fucking problems in the most retarded and simple way? Makes me feel like a real code-monkey, like I'm actually programming for a shitty dead-end job and not just because I'm bored.

>>51692699
Just solved problem 5: http://pastebin.com/AwKkmtW1
>>
>>51694933
10D - line of cubes of cubes of cubes
>>
Are "manager" classes bad? I have a Product class, and I need to "register" new products by storing them in a collection somewhere. My solution is to have a ProductManager class, which would be responsible for registering new products and accessing already registered products. Is this bad design?
>>
>>51694978
Classes are bad. Full stop.

Everything you're doing with classes could be better done with structs.
>>
>>51694978
You're gonna want to go with a ProductFactoryBean
>>
>>51694978
Doesn't seem bad to me
>>
>>51694972
10D == line of cubes3
ftfy
>>
>>51694933
>>51694855
the computer doesn't care about euclidean space

you could even treat a multi-dimensional array as just a series of columns for a data grid, but you'd probably be better off making a separate array for every column of data
>>
>>51694855
>>51694933
>>51695027
>>51694896
These things are also known as: Databases
>>
>>51692718
But it's even easier to not cast it though.
>>
>>51694993
nah

lots of structs come with functions that are to be used for that struct

a class is just syntactical sugar for that

FILE is a struct, fopen, fgets, fprintf, etc, are all functions for it
it literally is a class, just not syntactically
>>
>>51695036
What if you want compatibility with C++?
>>
>>51695050
this is for free, not malloc
>>
>>51695061
Who the fuck casts free? What the fuck?
>>
How does one do multidimensional pointer arithmetic?

Something like arr[3][2] would be expressed as *(*(arr+3)+2) or am I being dumb?
>>
NEW THREAD

>>51695084
>>51695084
>>51695084
>>
>>51695068
I am not trying to answer for everyone, but I bet a few successfully use a calculator.
Hope that helps.
https://www.youtube.com/watch?v=jbZusVDBf4A
>>
>>51692601
Where can I get a maid outfit to improve my programming skill?
>>
>>51695063
follow the chain of posts that the post you reply to is part of
tip
>>
>>51693807
>>51693878
lol wut it's not that easy. i've only lucid dreamed like a few times in my life and probably only when i was doing drugs
>>
is it ok to put multiple classes in one header if they're related and in the same namespace

like
namespace Auto {
class Vehicle {
//...
};

class Truck : public Vehicle {
//...
};
}
>>
>>51695143
No, we've been over this anon. There's no good reason to use classes -- structs work better in every scenario.
>>
File: apostle john.jpg (230 KB, 753x999) Image search: [Google]
apostle john.jpg
230 KB, 753x999
>>51693899
Since the 1 is constant there would be no point.
O(n^3) is good because even though 3 is constant, the function n^3 is proportional to n (n * n * n), and n is not constant.

If you have:
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

int main(int argc, char *argv[])
{
if (2 != argc)
return 1;

char *endptr;
uint_fast64_t n = strtoul(argv[1], &endptr, 10);

for (int i = 0; i < n; ++i)
for (int j = 0; j < i; ++j)
for (int k = 0; k < j; ++k)
printf("%" PRIuFAST64 "\n", n);
}


Then you have a best case running time of c1 + c2 + c3 + n + ⌊(((n * (n + 1) / 2)(n * (n + 1) / 2) + 1) / 2)⌋ * c4 ∈ Θ(n^4)

If we cared about the actual total running time, then we wouldn't bother abstracting the cost of each statement into constant terms, since doubtless not all subroutines (strtoul for example) run in constant time.
We only care about the running time inasmuch as it is a function of the input; that is, the asymptotic computational complexity.
>>
>>51695156
But structs and classes are basically the same thing in C++ (except for default member visibility level).
>>
2 years into programming in Vim and I discover text completion
>>
>>51695176
Congratulations, you're retarded.
>>
>>51694855
A matrix you dip.
>>
>>51692601
Learning 6502 assembly. Could somebody point me toward a good book? I've got down the basics but I'd like to learn more specifics, and techniques/tricks.
>>
>>51695182
Pretty much. I never did vim tutor, just went with "It's a text editor" and rolled with it. I know about plugins and tried some out and whatnot but I didn't think this was built-in.
>>
File: 1448474986516.jpg (16 KB, 225x255) Image search: [Google]
1448474986516.jpg
16 KB, 225x255
https://github.com/apple/swift/pull/165/files
>>
>>51695200
kek
>>
File: 1432323884812-0.png (26 KB, 431x499) Image search: [Google]
1432323884812-0.png
26 KB, 431x499
>>51695156
This is wrong.

>>51695167
This is wrong.

#include <iostream>
#include <vector>
#include <map>
#include <string>

class Durr {
std::string name_;
public:
Durr() : name_("fag") {}
Durr(const std::string& name) : name_(name) {}
const std::string& name() const { return name_; }
bool operator<(const Durr& rhs) const { return name_ < rhs.name_; }
};

int main() {
std::map<Durr, std::vector<int>> ahue;
auto& a = ahue[Durr()];
a.push_back(1);
a.push_back(2);
auto& b = ahue[Durr("gayloard")];
b.push_back(3);
for (const auto& durr: ahue) {
for (const auto& v: durr.second) {
std::cout << durr.first.name() << " " << v << std::endl;
}
}
}
>>
>>51695143
Yes it's okay. I normally do this for helper classes that are only relevant to that specific class.
>>
>>51695209
>This is wrong.
So the other difference being?
>>
int arr[3][3][3];
int *arr = (int *)malloc(sizeof(int)*3*3*3);

Are these equivalent?
>>
>>51695234
To expand on this, I'm not sure what your snippet is meant to prove because it works just fine with structs when you swap the visibility around:
https://ideone.com/jZNpeS
>>
>>51695257
kill yourself
>>
>>51695050
Then you're doing it wrong.
>>
>>51695265
those tan lines are fucking disgusting
>>
>>51695272
Sorry, but all the big game engines are natively C++.
>>
>>51692701
retarded and disgusting. if you were to cast it then you'd cast it to void* since free takes void* but that would also be disgusting. you have no idea what you're doing fucking stupid ass anime poster
>>
Seriously need to stop it with the tranny OPs. It's just inviting this shit.
>>
*(*(*(*(*(*(*(*(arr+1)+2)+3)+4)+5)+6)+7)+8)

This is syntactically valid C.
>>
getters and setters are the stupidest thing on the world
>>
op@4chan ~> git clone https://4chan.org/g/dpt
op@4chan ~> cd dpt
op@4chan ~/dpt> ./configure --enable-memes --enable-yuki --disable-faggotry
op@4chan ~/dpt> make
op@4chan ~/dpt> sudo make install
op@4chan ~/dpt> thread-launch --board g dpt
thread-launch: error while loading shared libraries: libfaggotry.so.1: cannot open shared object file: No such file or directory
>>
>Day 4 of the advent code.

That shit is taking ages even on a fucking Xeon.
>>
>>51695475
But anon, how else will you protect your interfaces between version updates? :^) :^) :^^^^^^^^)
>>
>>51695496
Are you retarded? What language are you doing it in? It literally took me less than a second.
>>
>>51695496
Actually nevermind, I'm a dumbass, I was subing wrong string range :^).
>>
>>51695475
not if you have your shit properly encapsulated because then it's like instead of having a function called nigger() you have a method called getNigger(), it's not stranger than that
>>
>>51695475
It's literally only like 5 extra instructions. If you're that hammered for processor time that you can't afford the extra abstraction, you have much more problems than your finding getters and setters annoying.

>not being able to debug every set or get instruction in only one place
All you're doing asking for pain at debugging time.
>>
>>51695508
I was accidentally checking for zeroes in range [counter, 5] instead of [1, 5].
>>
>>51695475
You can't do proper OO style without them. Don't expose your privates.
>>
>>51695537
>>51695546
he means when disgusting shitcunts use get/set for every variable and do logic on them without any encapsulation
>>
If I have a friend function in class A, and class B inherits from class A, and I want class B to have a friend function that calls class A's friend function before executing some other things, how do I do that?
Also, I thought friend functions had access to protected members?
What the fuck.
>>
I swear g++ gives me an error on every single line I wrote. I hate learning C++.
>>
>>51695558
No, any use of getter/setter is retarded. Just like any use of class. It's the dumbest fucking paradigm.
>>
>>51695558
get/set should only happen at the interface boundary. Inside the interface, you're welcome to use whatever you like. Although if you're doing the same thing inside the interface at about 3 or so places, you should make a function out of it. Get/Set/information hiding/abstraction/deduplication is merely an exercize in writing a custom notation. Skillfully writing a good notation usually leads to a good api. So you are not wrong, but misguided. get/set can be a very useful abstraction when your application is even slightly complex.
>>
I think that anon's problem with getters/setters are languages like Java that don't let you write macros to automatically generate them, so you're stuck either typing all of them out manually, copy-pasting, or using templates/snippets in your IDE, all of which are shitty options.
>>
>>51695816
This was my original reason, yes.
>>
>>51695741
nice meme tard
>>
>>51695813
how am i misguided? the fuck

>>51695816
you shouldn't be making getters and setters with such frequency that writing them becomes an issue worth mentioning
>>
File: 1428353112994.jpg (37 KB, 286x256) Image search: [Google]
1428353112994.jpg
37 KB, 286x256
>>51695883
>his IDE doesn't generate getters/setters for every object
>>
>>51695883
>you shouldn't be making getters and setters with such frequency that writing them becomes an issue worth mentioning
Like how? I have a struct with 10 attributes oh wait Java doesn't have structs, so I make a public class with 10 getters and setters.
>>
why the fuck cant my friend function access the god damn private members
this language is fucking bullshit
I fucking google it and have exactly what I fucking should
>>
>>51695907
>Java
Get out. This thread is not for memers.
>>
>>51694933
1D - column
2D - row
3D - page
4D - book
5D - shelf
6D - bookcase
7D - library
everything after this point is completely arbitrary, 8D could be the county library system of libraries, or the planet full of libraries, or the universe full of libraries, and so on.
>>
>>51695894
>>51695907
absolutely fucking retarded

and my IDE can generate getters and setters for me but i don't use that feature because i'm not a programming 101 babby
>>
>>51694855
don't think of it only in terms of spatial dimensions. but you could think of a 4D array as an array of cubes of values, or a cube of arrays
>>
>>51696093
>array of cubes of values
Like a bookshelf full of books?
>>
>>51696119
yeah kinda
>>
>>51696093
is it even practical to have a multi-d array represent something that isn't spatial?
Wouldn't it be easier to have a bunch of 1D arrays in a struct?
>>
If I create a temporary node in a link list, do I need to set the next pointer to null before deleting the node?
>>
>>51696315
not really, it's gonna get deleted anyway
>>
>>51696315
This is the average poster on /dpt/.
>>
>>51696315
yes
don't forget to cast the node pointer before using free.
free((node *) temp);
>>
Do I need to know how to write all my own data structures from scratch in C? Am I a pleb programmer if I can't?
>>
>>51696399
yes and yes
>>
>>51696399
You really should know how to implement your own data structures no matter what language you're working with.
Otherwise, you're just a codemonkey that mashes together other people's libraries indiscriminately because they can't implement anything worth a damn.
>>
File: 5q17DQS.webm (1 MB, 848x480) Image search: [Google]
5q17DQS.webm
1 MB, 848x480
Ask your beloved programming literate anything.
>>
>Posted in new thread but it appears to be dead.

I'm using XDocument to generate an XML output, but I need to add something within the long ass nest using loops.

How do I get stuff into the middle of an XDocument nest with a loop?

http://pastebin.com/nCxxDJPV

I wish to add stuff as a child of the XElement in line 9 but I have no idea how to get data in there.

Is there a simpler way to do what I'm doing there?

http://pastebin.com/2MXJ6ez8

This is a part of what I'm trying to achieve.

I need to do a loop to take all the user input stored in a list and create an XElement for each and insert it into my XDocument in a very specific place.
>>
>>51696511

char array[length][width][height];

char element = array[x][y][z];


or

size_t size = length * width * height;
char array[size];

char element = array[
(x * width * height) +
(y * height) +
z
];


?
>>
>>51696593
first
>>
>>51696270
one example would be a lookup table for a function with multiple arguments. of course you could say a table is sort of spatial but these data structures are just an idea to help us humans understand them. like a tree, you visualize a tree spatially but the data it holds isn't spatial
>>
>>51696584
Does anyone here know anything about LINQ at all?
>>
>>51696650
Right, a lookup table where the elements looked up are themselves arrays. If you have two lookup keys, and the values are images (3D arrays with the axes being width, height, and color channels), then the entire lookup table will be a 5D array.

If you are using a sophisticated N-dimensional array library, you can do tricks with the array stride specification to make arrays seem larger than they actually are. Say you have a 2D array, and you want to get a "rolling window" of every 100x100 elements of that array. Create a 4D array with the same data pointer as the 2D array, set the stride values for its first two axes to something small (the spacing between the 100x100 windows), and set the stride values for the next axis to the width of the array minus 100.

Now, instead of iterating over the width and height of the original 2D array, subtracting 100 and dividing by the height and all that, you can just iterate over the lengths of the first two axes of the 4D array.
>>
>>51692601
Final exam for 300 level course.
Writing a recursive function that generates points to make a mountain in gnuplot. Pretty fun.
>>
>>51696708
I use it for accessing SQLite db's in my .NET apps
>>
>>51695247
No, the latter is equivalent to
int arr[27];
>>
>>51696895
how do you malloc a multidimensional array then?
>>
>>51696908
just getgle it
http://stackoverflow.com/questions/1970698/using-malloc-for-allocation-of-multi-dimensional-arrays-with-different-row-lengt
>>
>>51696791
How would I add something to an existing XDocument?

ModuleConfig.Root.Element("files").Add(new XElement("file", new XAttribute("source", "filename here")));



I'm trying to use this to put something into an existing XDocument, but it's just constantly throwing an error.

I can't find anything online that tells me how to insert a new XElement into an existing XDocument's XElement.
>>
>>51696974

Holy shit, SO is fucking retarded.

>>51696908

Don't follow the advice of the SO shitposters. Seriousy, mallocing a multidimensional array is a really fucking bad idea. You end up with a _lot_ of fragmentation and you'll rape your CPU cache.

Just malloc an array of size x*y and traverse it using pointer arithmetic.
>>
>>51696998
so you're saying >>51695247 is acceptable?
>>
>>51696998
>>51696974
>>51696908

I forgot to say,

malloc(x*y*sizeof(data))


is just a single malloc() call for storing the same amount of data. What is suggested on SO is calling malloc() for every single array, which is slow as shit.

>>51697013

Yes. You can traverse it fairly easily, using pointer arithmetic:

data + y * width + x


Assuming that y and x are iterators in a nested loop.
>>
>>51696998
i want to record a series of floats of arbitrary length. i was thinking of doing it with a float** so that the float** gets realloced but the float*'s get kept so the bulk of the data doesn't have to get copied over. do you think i should use a single float* for the entirety of the data and realloc it when it needs to expand or do you think the float** will be fine?
>>
>>51697013
Barely. It's still limited to exactly three dimensions. A true multidimensional array will have ndim, shape[] and strides[] alongside the array's data pointer for full control over the array's dimensions and major ordering.
>>
>>51696908
you don't

malloc gives you a chunk of memory
how ever you interpret than memory is your bid
>>
>>51697078
traversing a 3 dimensional array using pointer arithmatic
int *arr = (int *)malloc(sizeof(int)*3*3*3);

should be accessible using the following right?
*(*(*(arr+0)+1)+2)
>>
>>51697110
No.
>>
>>51697110
ok how about
int ***arr = (int ***) malloc(((sizeof(int) * 3) * 3) * 3);
>>
>>51696990
I've never worked with XDocument
Why don't you include the element when creating the XDocument?
Why are you trying to add it later?
>>
>>51697144
No.
>>
>>51697158
ok then, how do you malloc a multidimensional array, assuming I actually want to do it in the idiomatic C way.
>>
>>51697167
See >>51697078
>>
>>51697149
Yup, figured that out, creating the XElement first now and then just referencing it when I need it in the XDoc
>>
File: 1413676870411.png (11 KB, 439x293) Image search: [Google]
1413676870411.png
11 KB, 439x293
I've been dabbling in Node, and now that I've started making an actual program, I'm adjusting to the asynchronous programming paradigm.

What I'm wondering is why I don't see anyone talking about ES6 generators. It seems like it solves callback hell without promises, but I haven't seen any buzz about it whatsoever. What am I missing?

I know that Node is unpopular on /g/ but it looks good on a resume to have a published project in it.
>>
>>51697195
I loved that game until I beat it...
>>
File: 1430836565514.png (462 KB, 682x682) Image search: [Google]
1430836565514.png
462 KB, 682x682
>>51697216
>>
>>51697231
Mars for days...
>>
>>51697167

If you want it to be three dimensions, just change the maths a bit. I just posted a 2D array in the earlier post.
>>
>>51697195
Just started with Node, care to explain what are these generators?
>>
>>51697268
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*
>>
>>51697275
So, exactly like python generators?
>>
>>51697149
>>51697184

Seems I can't do that, I need to actually create a new XElement for each value in a list, which I can do, but I can't seem to make each XElement go anywhere. It seems I need to add it in after, which I don't know how to do.
>>
How can we make D more progressive/inclusive?
>>
>>51697268
>>51697275
basically, functions that can be suspended and wait for another function to return before continuing, which my mildly-alcohol-addled brain thinks is like waiting for a thread to complete in another language.

>>51697296
Probably.
>>
>>51695096
I hear learning to sew and make your own maid dresses improves your feminine grace and programming ability.
>>
I need some help with C.
How do I make my app open a file, and filename is entered by user through std::cin?

std::cin >> filename;
FILE *level;
char bfr[0x255];
bfr = ("d:\\Technology\\%s.txt", filename);
level = fopen(bfr, "r");
Thread replies: 255
Thread images: 31

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.