[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: 20
File: himegoto2.webm (3 MB, 854x480) Image search: [Google]
himegoto2.webm
3 MB, 854x480
old thread: >>54389858

What are you working on, /g/?
>>
Is Scala a meme?
>>
>>54398236
of the highest order

https://www.youtube.com/watch?v=uiJycy6dFSQ
>>
I see functional programming being pushed here on /g/ more than anywhere else.
Why are people so obsessed with having zero side-effects when not even CPUs work like that?
Your computer is one giant state machine, after all.
>>
File: 1462487186.png (13 KB, 385x254) Image search: [Google]
1462487186.png
13 KB, 385x254
how do I make this regex match 'a' even in the first line?

(?<=[^a-zA-Z0-9])a(?=[^a-zA-Z0-9])


aim is making regex similar to \b but that also will consider underscore as a separation of words
>>
>>54398263
Only pure functional langugaes are about zero/near zero side effects. Functional programming can be done in most langugaes, it's just depends on whether or not it suits the problem at hand.

>Your computer is one giant state machine, after all.
Which is why almost all programming langugaes are designed to help abstract that away to varying degrees.
>>
>>54398305
btw, picture is from https://regex101.com

the best regex tester to date
>>
>>54398305
>regex
>not even a regular expression
>>
>>54398263
a few reasons.

one, its easier to reason about
two, its easier for the compiler to make optimizations
three, its fun!

seriously, try it :)
>>
What does /g/ think of this guy? I thought he was pretty good

https://www.youtube.com/watch?v=HQYsFshbkYw
>>
>>54398305
(?<=\b|_)a(?=\b|_)
>>
A lot of times, i find myself writing tiny one-liner functions to make code look cleaner, but I'd rather not have it be in the global scope if it's gonna be used in one function only.

How do I do nested/lambda functions in C?
>>
File: 1462488086.png (93 KB, 678x156) Image search: [Google]
1462488086.png
93 KB, 678x156
>>54398441
thnx, though it works on the site, it crashes my python code

>look-behind requires fixed-width pattern
googling whats up with that now...
>>
>>54398523
epic bait
>>
>>54398536
Try this then
(?<![0-9a-zA-Z])a(?![0-9a-zA-Z])
>>
OpenGL question:

If I don't request a specific version of OpenGL with glfwWindowHint, my laptop's Intel GPU (with MESA) will default to OpenGL 3.0. However, if request it to use 3.3, it will comply and use 3.3. That is, by default my graphics card uses an older version of OpenGL. Not only is this completely baffling to me, but requesting a specific version is actually a bit of a problem because my desktop's graphics card supports OpenGL 4.5, and I don't want it to be using OpenGL 3.3 for no reason.

How can I get my graphics card to use the most recent version of OpenGL available?
>>
>>54398523
Well you can use function pointers but C sadly doesn't let you define new functions inside amother
>>
>>54398231
Am I the only one on /g/ who would date a cute convincing passing trap?
>>
>>54398557
that one seems to work nicely

>Explanation: The negative lookbehind (?<!USD) asserts that at the current position in the string, what precedes is not the characters "USD". If the assertion succeeds, the engine matches three digits with \d{3}.
>>
>>54398263
>why are people moving away from assembly when CPUs don't even work like that?
>>
what are you listening to /dpt/?

https://www.youtube.com/watch?v=dAJbBIzDeV0
>>
>>54398400
>hello how is life family circumstances and everything - ah that's nice
>>
>>54398584
no
>>
>>54398523
static inline. Keeps it local to the translation unit. Allows functions to contain that name outside of the translation unit. Each instance of the function has it's own local and static variables apart from the others of the same function. It's about as close as you'll get to lambdas, maybe with gcc's nested and properly-scoped function definitions it's 80% of the way there.
>>
Hey guys, any help will be greatly apreciated.

I'm working on a line following program for my college degree, to be used on Parrot Ar-Drone 2.0 UAVs. My code is to be executed using Node.js, and the ar-drone node from FelixGe. I use OpenCV for image processing.

I have many reasons to believe my image processing is good, the red line on the floor is seen very well by the drone's camera, using color filtering, and the mass center (using contours) gives me good results as well.

However, my program doesn't work, as the drone cannot seem to follow the line appropriately. I'm looking for ideas as to how i should use my mass center to give commands (movements) to the drone.
>>
>>54398685
>My code is to be executed using Node.js
Stopped reading there.
Whatever you're doing is shit.
>>
>>54398710
I also think it is not the best tool, but i have no choice, it's the teacher's choice
>>
Could someone try this to see if it works?
#include <stdio.h>
#define lambda(return_type, function_body) \
({ \
return_type __fn__ function_body \
&__fn__; \
})

int main(void)
{
int (*max)(int, int) = lambda(int, (int x, int y) { return (x > y) ? x : y; });
printf("max: %d\n", max(192, 4));
}
>>
>>54398737
you tell us.
https://ideone.com/
>>
>>54398263
>Using a Von Neumann machine
>(current-year)
>>
>>54398737
It works.
>>
>>54398753
it works on my computer, but not on this site, and it doesn't work on https://gcc.godbolt.org/ either.

which is weird, because i have -std=c89 enabled and everything
>>
>>54398815
It works on ideone. I just tried it. Yeah godbolt only compiles C++ even with -std=c89, GNU C extensions aren't enabled for C++.
>>
>>54398263
bigger on HackerNews than /g/. what other programmer communities are there other than reddit anyways?
also pure FP is great because you're not constrained to the details of the underlying architecture. things like lazy evaluation with pure FP can change the way you think of data vs. code entirely (for example, lists as a control structure) or just change how you solve problems completely
it's often slower but it makes the development cycle much faster (especially when you have to debug your code)
>>54398523
GCC has an extension for nested functions and you can sort of hack them into lambdas with a lot of weird tricks: http://stackoverflow.com/questions/10405436/anonymous-functions-using-gcc-statement-expressions
of course anyone who has to work with your code will hate you if you do this
>>
>>54398737

Well, this is new to me. Never heard of these here ganoo compound statement expression majiggers.
>>
>>54398231
Stop this programming fag meme.
>>
>>54398584
Too bad they don't exist in real life. Before puberty it's illegal, after puberty they are trash.
>>
So last night an anon posted a programming challenge. There were a few people who solved the challenge, some with good time and space complexity. I thought it was fun, so I have a new challenge, which I've already solved. It requires a non-bruteforce algo to solve in a reasonable amount of time.

Imagine you have a list of numbers from 1 to 2**k - 1. You can reorder the numbers however you like. How many different sequences of the numbers from 1 to 2**k - 1 that when put into a binary search tree result in a perfectly balanced tree?

For k = 3 there are 7 nodes. Some answers are...
4 2 6 1 3 5 7
4 2 1 3 6 7 5
4 6 7 2 3 5 1
and so on
There are a total 80 different sequences that fulfill the requirement when k = 3. How many different sequences are there that fulfill the requirement when k = 4?

BONUS: k = 5?
PHD: k = n
>>
>>54398985
>what other programmer communities are there other than reddit anyways?
LtU

>>54398997
https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html#C-Extensions
There are a truly retarded amount of extensions. If you want super optimal code dig into attributes too. Shit is strictly non-portable though.
>>
>>54399087
A good chunk of those extensions are C99/C11 features that they just let you use in C89.
>>
Symbol tables for block structured languages are a mess of a data structure. Thank goodness for extended due dates.
>>
>>54399087
I use a lot of these extensions in -ansi mode and I've never had a problem getting other compilers to accept my code, especially combining declarations with initializers.
>>
>>54398737
This is GNU C only.
>>
>>54399087
guess so, but not like youd expect them to shill FP any less than /g/ or HN
>>
>>54399064
Can you draw the binary search tree for the second one? I'm a bit confused here.
>>
>>54399119
How are you implementing them? I figured it would be a random tree of maps. It doesn't seem too complicated.
>>
>>54399305

>4 2 1 3 6 7 5

         4

4
/
2

4
/
2
/
1

4
/
2
/ \
1 3


4
/ \
2 6
/ \
1 3


4
/ \
2 6
/ \ \
1 3 7


4
/ \
2 6
/ \ / \
1 3 5 7


The second doesn't represent a binary search tree. It's a list that if you put the values into a BST in order it makes a balanced tree. For an example of a sequence that doesn't work
4 3 2 1 5 7 6
>>
>>54399399
Nice dubs. So in other words, you're looking for how many sequences that, when inserted directly into a binary search tree without any rebalancing, result in a balanced tree?
>>
>>54399418
>399399
wooo

You got it.
>>
>>54399444
This is an interesting problem. I feel it grows too fast for me to "cheat" and figure it out by way of example. I'll take a crack at it and see what happens.
>>
should I learn meme languages/frameworks like PHP, JS/Node, Ruby/RoR, etc?
I realized these are the best paid jobs in my country, and I've refused to learn them until now ;_;
>>
>>54399314

Top level, built in procedures and constants go in their own BST.

For everything else, there is an array of 16 pointers to ID structs, each representing the current procedure at that nest level. A procedure has a linked list of ID structs for its parameter list, and a BST for all local variables, type names/aliases, and procedures under it.

It's not so much confusing, just a mess, especially considering I have to support overloading.
>>
File: pc.png (378 KB, 1450x1080) Image search: [Google]
pc.png
378 KB, 1450x1080
>>
>>54399610
rollin
>>
>>54399635
rollin
>>
>>54399609
Good god man. Is that the way you were taught to do it? Seems like you might be able to clean it up. For one, an array of linked list of procedures, each increasing index as a scoping level? Why? You would have to search each scoping level for the blocks you are referencing when blocks of the same nesting level really have nothing holding them together.
>>
>>54399610
roll
>>
File: lua.png (6 KB, 128x128) Image search: [Google]
lua.png
6 KB, 128x128
Is Lua a meme?
>>
>>54399756
Everything is a meme.
>>
>>54399756
No. It's very well designed, just a dozen or so concepts to it and you get a language as powerful as Python without the big standard lib. It's simple, you can learn it in best part of a couple days. A lot of applications are scripted with it: video games (source games, ComputerCraft) and text editors (vim, geany). Also there's Torch with the JIT.
>>
>>54399756
Lua is a pretty neat language if you give people the ability to create extensions for your software (mostly games) with it.

Look at Factorio, Garry's Mod, Audioshield, ...
>>
>>54399841
>you can learn it in best part of a couple days.
I feel like the easy stuff is fine but the hard stuff like embedding into C/C++, threading, metatable wizardry, flies over my head and I still can't get gud.
>>
>>54399064
xD Just got here nice problem :) starting :D
>>
is learning to code from this a good idea?
http://mindprod.com/jgloss/unmainnaming.html
>>
>>54399064
Isnt the answer k=4 6400? And for k=n P(n)=P(n-1)^2?
>>
File: 1460418170889.jpg (300 KB, 1920x1080) Image search: [Google]
1460418170889.jpg
300 KB, 1920x1080
>>54398231
    __device__ short atomicAddShort(short* address, short val)
{
unsigned int *base_address = (unsigned int *)((char *)address - ((size_t)address & 2)); //tera's revised version (showtopic=201975)
unsigned int long_val = ((size_t)address & 2) ? ((unsigned int)val << 16) : (unsigned short)val;

unsigned int long_old = atomicAdd(base_address, long_val);

if ((size_t)address & 2) {
return (short)(long_old >> 16);
}
else {
unsigned int overflow = ((long_old & 0xffff) + long_val) & 0xffff0000;
if (overflow)
atomicSub(base_address, overflow);
return (short)(long_old & 0xffff);
}
}


So the CUDA function AtomicAdd works on 32bit integers, and the function above extends it to shorts. If I change the 2s to 4s can I extend it to work on 8bit chars?
>>
>>54400039
>>54399880
>>54399064
>>54399841
:)
>>
>>54399874
>embedding into C/C++
The API does take some time to learn. The LuaJIT fixes that.
http://luajit.org/ext_ffi.html
>threading
There is no threading... coroutines are easy to understand if you understand python generators. They are more general than generators though. SOme of the whackier shit might take some time to understand. Roberto has a paper out on implementing other cooperative multitasking paradigms with coroutines if you are used to functional multitasking paradigms (continations, etc.).
>metatable wizardry
It's simple, but obnoxious at the same time. 90% of the time you are just trying to implement classes, which can learn to do if you read through the chapter on it in the PiL book. It does take a while to become a true wizard in the stuff. Or you can use the JITs ffi and just make classes the C way by declaring structs and packing functions into a table that deal with that struct.
>files
? I guess if it's your first language.

The real trick is learning to use the libraries available for it. lpeg is fucking fantastic. I've seen people just implement their own languages on top of lua with that library. There's the long-dead metalua, which added hygienic macros to the language. I also tend to use a lot of Torch's and the Kepler project's libraries.

Honestly, it seems like the language is dying. Mike Pall just abandoned the JIT, the mailing list is down to <300 posts per month and decreasing. People are really displeased with what they did with integers in 5.3 and most people are sticking with 5.1 because of the JIT.
>>
>>54400039
No, it's much much larger. The equation is close in form, but it doesn't even work for k = 3.
>>
>>54400039
Nope
>>
Does 'implementation of foo()' imply what are the literal series of statements that make up the function foo()?

If it is, where can I read the implementation of getchar();? Is it written somewhere?
>>
>>54400060
;D
>>
>>54400096
Yup saw it all :| I overlooked some stuff back on paper... :)
>>
>>54400108
>where can I read the implementation of getchar();? Is it written somewhere?
It's in the source code of your C library.
>>
>>54400108
>getchar()
https://github.com/lattera/glibc/blob/master/libio/getchar.c
Don't expect large old C codebases to be straightforward.
>>
>>54400132
If I'm on linux it's referred to as glibc, correct?
>>
>>54400174
Oh thanks, this is also on my linux system though, isn't it?
>>
>>54400191
Most likely. However, as >>54400174 says, reading the glib source code is not easy.
>>
>>54400096
k=4 -> 13344 ?
>>
>>54400219
Several orders of magnitude off. Are you trying to do it by hand or program it?
>>
>>54400212
>reading the glib source code is not easy.

I can see that now. Will further reading on glibc help me understand how to read it? Or what would I have to look into?
>>
>>54400255
Maybe it would be a little easier to try reading the source code of the musl C standard library instead. It may not be exactly what's running on your system, but it's quite a bit simpler.
>>
>>54400239
By Hand... xDDD Because of missing some *1000 in getting the solution by hand maybe i will try to program it :) didnt think it would be that much :) Im trying to find the formula not brute force it... :)
>>
>>54400061
>Honestly, it seems like the language is dying.
fugg!! :D

"flies over my head" (as in im a retard) not "files"
>>
>>54400302

Like most things, there probably isn't a closed form solution.
>>
>>54400302
It took me a week to find the closed form formula after I had spent two weeks making increasingly optimal solutions and still couldn't find k = 6 in less than my lifetime. After I finished I looked around to see if the problem had been done before, because I might be able to use it as a basis for a thesis. Turns out some shmuck made their dissertation about this problem and they found the closed form formula already. That's why I put 'PHD' next to k = n.
>>
>>54400412
>they found the closed form formula already.

Well now, don't I have egg on my face!
>>
>>54400239
1940864 ? :)
>>
File: 1460112341119.jpg (942 KB, 1280x1627) Image search: [Google]
1460112341119.jpg
942 KB, 1280x1627
>>54400441
Yep, sorry pal. Onto the filtered list you go
>>
>>54400447
Getting there.
>>
>>54400412
Btw this problem is pure Mathematics for combinatorics... I Like it :)
>>
>>54400462
This isnt the number? XD still by hand :)
2263424? :) last time i forget one case i think :)
>>
File: tyff.jpg (76 KB, 800x600) Image search: [Google]
tyff.jpg
76 KB, 800x600
>>54400460
>>
>>54400514
dumb tripfag cancer
go back to plebbit
>>
>>54400543
>go back to plebbit

I've been here since before you were born, sonny.
>>
>>54400509
Sorry, no.
>>
>>54400580
2269184? getting closer?
>>
>>54400559
If truth, you'd already know that tripfags are the cancer of anonymous imageboard since day 1. End yourself right now, attentionwhore.
>>
>>54400000
>>
>>54400580
Hey, uh, different anon... this is probably wrong, but is 6642155520000 around the correct order of magnitude?
>>
>>54400580
xD 2274944?
>>
>>54400714
This guy is fucking with you.
>>
>>54400734
I've noticed.
>>
>>54400631
>you'd already know that tripfags are the cancer of anonymous imageboard since day 1.

I know that, but I have several mental illnesses which convince me it's a good idea.
>>
>>54400734
xD nope... still on paper btw... looking for mistakes... How big is the number anyway? :)
>>
>>54400644
Fuck, I screwed up the math, actually 15814656000
>>
>>54400761
Eh, nevermind. This must be wrong if there's such difficulty doing it for even k=6. The avenue I pursued could be done in minutes with pen and paper, so it must be wrong. Anyway, I'm close to giving up on this one. 2hard4me.
>>
>>54400749
any feedback? :)
>>
#include <stdio.h>

void main ()
{

while(getchar() != -1)
printf("%d", getchar());
}


Can anyone explain what this code is doing? The output to stdout is not the initial number I unput, but rather some random int. Does getchar try to access memory it shouldn't access to when it is called a second time?

By the way, I know how to correctly implement the code for the purpose stated. This question is entirely for educational purposes.
>>
>>54400814
It prints out every other character's ASCII code from the input (as integers, without spaces between them). If there's an odd number of characters, it finishes with a -1.

To understand this, pay close attention to how you use getchar specifically - it gets called twice per loop.
>>
>>54400814
printf is interpreting getchar() as %d which is a decimal/integer. so if you input 'a', you'l get 97. Look at an ascii table.
>>
>>54400797
Its only stupid factoriels :) btw
>>54400749
any feedback for 2274944? i think thats it
>>
>>54400580
you still here? :)
>>
>>54400412
Since it won't help anyone find an answer really. k = 6 is 2606654998899867556195703676289609067340669424836280320000000000
>>
>>54398231
So why my retard polar vector to rectangular vector converter doesn't work?
double * polartocartesian(double r, double phi)
{

static double vec[2];
double val = PI / 180.0;

vec[0] = r * cos(phi*val);
vec[1] = r * sin(phi*val);
return vec;
>>
For developing GUI's with Visual Studio is it suggested to use WinForms or WPF?
>>
>>54400960
>2606654998899867556195703676289609067340669424836280320000000000
That's an extremely small number compared to (2^6-1)!. I tried framing this in terms of the number of valid topographic sorts of the associated directed graph, but every way I look at it I get the wrong answers or an atrocious time complexity. So while I'm very interested in the final answer, I don't feel competent enough to find it. Good luck /dpt/ ;_;
>>
would converting my 2d raster engine to use entirely fixed point arithmetic be beneficial.

As in would avoiding floats and using fixed points make anything 'faster' or should I just stick to floats
>>
>>54401030
As opposed to currently single or double precision floats? Are you using SSE?
>>
>>54401066
I am using SSE but from what I've been looking up it is possible to simulate fixed point multiplication/division with SSE with all the bitshifts and such.
>>
File: accept death.png (319 KB, 680x567) Image search: [Google]
accept death.png
319 KB, 680x567
>>54401015
>>54400980
If I say
~for loop here 0->1~~
printf("%f", * polartocartesian(1, 1/2) + i);


It returns 1 and 2. I never used malloc, I have literally two days of C
Send help dpt
>>
>>54401015
>
yup
>>
>>54401097
>>54401108
Also I was told that if I return an array from a function the function will return a pointer to that array. Why should I allocate the memory for that vector if it is already defined as a static in the function?
>>
>>54401082
Floating point is inherently more intensive than fixed point arithmetic, but machines these days dedicate a LOT of silicon to it, so if you're already using float SSE, then I have a feeling you won't get much mileage from using fixed point.

https://stackoverflow.com/questions/2667397/will-fixed-point-arithmetic-be-worth-my-trouble

If your code is set up so that it's easy to change, I would still recommend testing though.
>>
>>54400981
http://www.wpf-tutorial.com/about-wpf/wpf-vs-winforms/
WPF is newer
>>
Fibonacci VM

main.c:
http://pastebin.com/iCMee4By

fib.asm:
// r0 = ip
// r1 = a
// r2 = b
// r3 = t
// r4 = i

mvi r2, 1
loop:
prt r2
mov r3, r2
add r2, r1
mov r1, r3
mvi r5, 32
cmp r4, r5
inc r4
mvi r5, loop
mvb r0, r5


fib.bin manually assembled from above:
$ hexdump -C fib.bin 
00000000 05 02 01 00 04 02 00 00 01 03 02 00 02 02 01 00 |................|
00000010 01 01 03 00 05 05 20 00 06 04 05 00 03 04 00 00 |...... .........|
00000020 05 05 04 00 07 00 05 00 00 00 00 00 00 00 00 00 |................|
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00010000


Result:
$ ./fbvm fib.bin 
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
196418
317811
514229
832040
1346269
2178309
3524578
>>
>>54401138
currently i have a "Real" type that is float. It can be float or double and I have another flag "USE_SSE" that can be defined if float is enabled that gets it to use floating point arithmetic so for the sake of multi-platform-ness I'll entertain fixed point for a bit and do some speed tests. against naive float and get some simd-ed fixed point.

I find comfort in the idea that my code can work on a fridge.
>>
>>54401030
>should I just stick to floats
Yes. SSE helps, which you've already done. Second is go through your engine and maybe rewrite portions of it to be branchless, if possible, or at least specify HOT and COLD branches and make sure you are using restrict pointers where possible. I'm hoping you've already done the obvious optimizations: unrolling loops, packing structs, inlining functions, etc.
>>
>>54400960
:D What a problem :D like it very much :) omg xD :D
>>
>>54401176
Alright, sounds fun. You're using real SSE intrinsics, right? (i.e. not trusting the compiler to do it for you?)

>>54401173
Good job, but why do you call it a VM?
>>
>>54401250
>restrict pointers where possible
>restrict
explain
>>
>>54401258
>You're using real SSE intrinsics, right?
yes
pmmintrin.h and such.
>>
>>54400643
>bst thread
what a waste
>>
>>54401258
>but why do you call it a VM?
Because it is a VM.
What would you call it?
>>
>>54401261
C restrict pointers. A pointer that doesn't to alias another pointer (restrict is a pointer modifier). Probably unlikely in your codebase. I just mentioned it because.
>>
is there a better alternative to armsim for arm assembly development.
>>
>>54401173
Where is your assembler?
>>
>>54401285
Oh, my bad. I scanned over the assembly and didn't realize it wasn't x86 intel syntax. I read too fast.

That's very cool, anon.
>>
>>54401255
Solution for k=4? :)
>>
>>54401301
don't have one, I manually assembled it using a hex editor.
>>
>>54400960
Solution for k=4? xD will try to figure it ouy tommorow its 4am here xD must get up at 7 :)
>>
>>54401310
Good god man.
>>
>>54400980
Read a book
>>
>>54400174
but it's very straightforward
it just wraps getchar with a mutex so it's thread-safe
>>
>>54401404
It's just that it's not straightforward for someone who is just learning C trying to look at the stdlib for examples.

It gets worse. And somehow this looks better than most of the code in glibc.
https://github.com/lattera/glibc/blob/master/libio/genops.c
>>
>>54399740

It's the "suggested method". The reason for an array with increasing scope levels is so that when we stop parsing some procedure, we are able continue parsing the procedure it was nested in. Each array index only holds information for the current procedure being parsed at that scope level. It's not an array of linked lists, it's an array of pointers to procedure structures. Part of the procedure structure is a linked list of other ID structures that represent the parameters. The choice of a linked list here is for a quick (to write) stack so when code generation is done, the args can be pushed in reverse order.
>>
Haven't seen a non-anime dpt image in a while

Feels great

The normies lost
>>
>>54398263
Functional programming is equivalent to procedural programming, the difference is the level of abstraction. Functional programming allows the programmer to manage state more cleanly -- good functional languages (like clojure) recognize state for what it is: a pure function relating a common identity to time.
>>
>>54400960
Anon please help just tell me the value xD i want the value im making a mistake somewhere because there are soo many possibilities :) And im interested is there a formula or algorithm? :)
>>
>>54401460
I still don't think I understand. If each index is a increasingly nested procedure then there is maximum depth of 16 nestings (which is fine), but you can't define more than one nested procedure inside each procedure? There has to be some tree-like structure there somewhere...
>>
>>54401599

You can define multiple procedures inside a procedure. Assuming A is our array and L is our nesting level, when we encounter a new procedure in parsing, we create a new struct for it on the heap and add it to the BST stored in A[L]. Now we set A[L+1] to point to this new procedure, increment L, and start parsing it. When we reach an end statement, we decrement L. If we find a second procedure at this level, we repeat the process and overwrite the A[L+1] with the pointer to this new procedure. Since the pointer at this level is already in A[L]'s BST, we can trash it. The data is still on the heap.

This could arguably be replaced with a pointer to a parent procedure in the procedure's struct data.
>>
I just want to learn to code games but I'm so fucking lazy.

If I could get a job making games I would learn in a heartbeat because the pressure's on me to do it but I can't get a job in the industry with no experience and I can't get experience without a job
>>
>>54401744
gaming industry is literally the asshole of software development, where good developers go to die (slowly).
>>
>>54401744
>>>/v/
>>
>>54401700
Ahh, that makes more sense. Seems like a beast though. Wishing I had a compilers course at my Uni. The CS department here is trash. Thank god I'm in glorious EE.
>>
>>54401760
unfortunately I'm only creative in very narrow directions. I can come up with stories nobody's ever thought of before or pen recipes off the top of my head, but when it comes to programming I can't come up with a unique idea for a startup if my life depended on it
>>
>>54401844
successful game developers enjoy the implementation details of their game much more than the creative side of things
>>
>>54401792

>Seems like a beast though
It pretty much is. The language we have to compile for, and the VM we have to target, are relatively simple though, which is nice (they have to be, since the assignment is "you have 8 weeks to build a compiler for this toy language I made up").

And my CS department is rather alright, albeit small. We don't offer as many courses as I'd like, but the professors we do have are rather amazing, especially for anyone into machine learning.
>>
>>54401876
I do enjoy implementation, but I can't force myself to work unless it's my job to do so
>>
>>54401913
Then you aren't gonna make a game.
Enjoy CRUD development.
>>
File: bash.png (10 KB, 588x371) Image search: [Google]
bash.png
10 KB, 588x371
/dpt/, why is BASH so comfy?
>>
>>54402362
Because you like sleeping in beds made of sharp nails pointing upwards with no sheets or clothes.
>>
>>54399610
Rolling
>>
>>54402362
so ugly

it's like PHP had a baby with every birth defect possible
>>
>>54402580
My favorite has got to be the syntax for a switch statement in bash:
case $var in
foo) run_foo ;;
bar) run_bar ;;
esac


>esac
>>
>>54402829
At least it makes logical sense. If is terminated with fi.
>>
Is Handmade Hero a meme or a good way to learn C? The graphics are underwhelming for a one year development and I can't find any gameplay videos.
>>
>>54402914
>1 year development
he's literally walking through the entire thing tho
it's slow as hell when you're doing a show for people
>>
File: image.png (323 KB, 2048x1536) Image search: [Google]
image.png
323 KB, 2048x1536
Any extra setting you would like to see on a scientific calculator, /g/?
>>
>>54402968
RPN notation and a stack.
Also, some stack manipulation commands, like drop, dropn, dup, dupn, pick, swap, rot, unrot, etc.
>>
>>54401173
Is it turing complete?
If not, then my 3-instruction instruction set (FIB, SHOW, HALT), is just as valid.
>>
>>54402843
and while is terminated with elihw. NOPE JK it's actually `done` :^)
>>
>>54398584
>cute
>trap
pick one
>>
>>54398584
probably because everyone else on /g/ wants to be a cute convincing passing trap
>>
>>54403152
It's cute if you don't know it's a trap.
>>
A friend told me if I use a command line program that I could treat it as a terminal after I cout.
Is this true?
Like if I wanted to change directories could I just
cout<<cd..<<end;
>>
>>54403244
no
>>
>>54403222
> claims to be a cute trap
> doesn't prove it
I bet you're a disgusting fat trap
>>
>>54403259
We're all cute traps in /dpt/ anon.
>>
>>54403283
>>54403222
i bet you don't even wear a skirt to improve your programming ability
>>
>>54403283
no we're not fucking fag

>>54403309
absolutely disgusting you're not passing at all
>>
>>54403309
pls post pen0r
>>
>>54403326
please don't
>>
>>54403310
I was a girl in a play in elementary school, does that count?

>>54403326
>>54403351
God damn that's hilarious
>>
>>54403376
they know, they just aren't socially retarded enough or giving a shit enough to say you have a dick
>>
>>54403385
kill yourself fag

despite the myspace angle and you can still tell by the shape of the body and the texture of the skin that it's a guy
>>
>>54403395
>i am at work at 1:30 AM
>>
>>54403376
people are very good at discerning deformities and trannies never quite look like women in person.

you can fake it on the internet by cherrypicking your camera angles, but that shit can't save you in real life.
>>
>>54403426
this
>>
>>54403236

Deck... as in to hit? I have no beef with OSGTP. He's a pretty chill dude.

Also, thread seems to be getting pretty fucking gay right now, so let's bring the discussion back to programming. Why is it that VB.NET is still used? It's arguably more verbose than C# while offering no significant benefit.
>>
>>54403309
> fat
checked
> disgusting
checked

Yeah... I was right.
>>
>>54403427
That's very understandable... so please describe it to us in text.
>>
>>54403385
eeww, you can tell it's a man's ass because it doesn't look soft like a woman's.

It's just a skeltal trap disgusting ass, I hope you just get aids
>>
>>54403426
>trannies never quite look like women in person.
I think that's part of their charm.
>>
>>54401015
If it's static it isnt on the stack though. Isnt returning something from BSS fine?
>>
>>54399064
If someone could help me derive the general forumula for even C(n,n) that would be super.
/* # of combinations you can make out of
two strings of length n and m, while retaining
individual order

e.g. for strings 'ab' and 'AB'
combinations: abAB aAbB aABb AabB AaBb ABab
thus C(2,2) = 6
*/
int C (int n, int m)
{
if (n == 0) {
return 1;
} else {
int a, i;
for (a = 0, i = 0; i < m + 1; i++) {
a += C(n - 1, i);
}
return a;
}
}

/* number of permutations of inputs of
all integers in the range [1, 2^k - 1]
that create a balanced binary tree */
int P (int k)
{
/* derived from recursive definition
P(k) = C(n,n) * p^2
where n = 2^(k-1) - 1
p = P(k-1)
P(1) = 1
*/
int i, n, p = 1;
for (i = 1; i < k; i++) {
n = (1 << i) - 1;
p = p * p * C(n, n);
}
return p;
}
>>
>>54403492
didn't microsoft end support for it? or are they really still updating that crap?
>>
>>54403707

They ended support for VB6. VB.NET is still alive and well and getting new versions made.
>>
>>54403792
why....?
>>
>>54403812
Apparently because >>54403573
>>
>>54401126
because its frame is pooped and memory now is filled with other stuff
>>
>>54403643
Anon, i think the formula is really simple. its going to be
(n+m)!/(n+m).
So in your example: (4)!/4 = 24/4 = 6
Tell me if im right
>>
>>54403902
Well C(3,3) = 20
(3 + 3)! / (3 + 3) =
6! / 6 = 5! = 120 =/= 20

:(
>>
>>54403950
I quoted wrong.

>>54403950 meant for >>54403921

But @ >>54403902
Static things exist for the lifetime of the program, so the static array will not be popped of when you return it. It will be valid.
HOWEVER, if you call the function twice, the data from the static array will be overwritten, since static data only exists in one single place.
E.g.

int* scary_thing (int x) {
static int A[2];
A[0] = x * 2;
A[1] = x * 3;
return A;
}

int main () {
int* B = scary_thing(3);
printf("%d, %d\n", B[0], B[1]);
int* C = scary_thing(4);
printf("%d, %d\n", C[0], C[1]);
printf("%d, %d\n", B[0], B[0]);
return 0;
}
>>
>>54403643
C(n,m) = (n+m)!/n!/m! it seems
>>
>>54398263
F# has side effects
>>
>>54404054
and that simplifies to
product from (n+1) to (n+m) divided by m!
so you don't need to count n!. (or swap if m > n)
>>
>>54398523
seriously why are you still using C
C++ allows lambdas, etc
>>
>>54404113
seriously why are you still using C++
C allows nested functions etc.
>>
>>54404130
*GNU C but still
>>
>>54404130
>C allows nested functions etc.
That's a GNU extension, not a part of C. However, there are still plenty of reasons to not use C++.
>>
>>54404090
Wow. So that simplifies it to
int C (int n, int m)
{
int i, p = 1;
for (i = 1; i <= m; i++) {
p *= n + i;
}
for (i = 1; i <= m; i++) {
p /= i;
}
return p;
}

So much more efficient.
How on earth did you derive that?
>>
say i wanted to read the contents of eg. `/proc/loadavg' every n seconds
would i have to open, read and close the file before it could 'update'?
>>
>>54404219
you're reading a copy into memory, it won't update while you're working with it
>>
>>54404171
>How on earth did you derive that?
The first formula or the simplification? Anyways, I'll explain both.
There is (n+m)! total ways n+m characters can be placed into n+m string; there is n! and m! possible permutations of each string respectively, but we're only using one of each in our case so that makes the total number n!*m! times smaller.
The simplification is also straightforward: (n+m)! = n!*(n+1)!*...(n+m)! -> divided by n! gives us the result.
>>
If I have two rectangles given by their top left coordinate (x, y) along with their width and height, and assume they are plotted on a quadrant with the origin at the top left corner, how can I calculate if they overlap?
Right now my method is to check if either ones corners are contained in the other, but it doesn't work if the rectangles are in a cross formation where each corner is outside the other.
>>
>>54404239
so i will have to close and re-open it later for it to be updated?
>>
>>54404243
>(n+m)! = n!*(n+1)!*...(n+m)!
Oops.
(n+m)! = n! * (n+1) ... * (n+m) 

obviously, it's not factorials all they way down
>>
>>54404257
yeah, basically
>>
>>54399610
rell
>>
I implemented the battleships game with React. JS, coffee and ES6 versions for comparison. I like coffeescript the best, but ES6 is also not bad.
I used Angular for several years, and I was skeptic about React, but react is actually quite good and pleasant to use.
>>
>>54404333
this isn't programming related
go to >>>/wdg/ you webdev monkey
>>
>>54404333
cool, link?
>>
>>54398231
what animu?:o
>>
>>54404418
It's fucking shit, and only the worst kind of degenerate fucks like it.
Also, don't encourage OP's faggotry.
>>
>>54401030
>As in would avoiding floats and using fixed points make anything 'faster'
Not on today's machines.
Things like floating point division and multiplication is actually faster than the integer ops, and fixed point arithmetic would require multiplication + shifts/fixups.
The only reason to use fixed point today would be for consistent precision over the whole range (which can actually be useful for things like absolute time and position)
>>
>>54404418
himegoto

also the manga is better
>>
>>54404539
thanks!
>>
>>54404595
Hope you like trap bulges anon.
>>
>>54398263
functional programming is a shitty meme.

but generally you want to minimize side effects whenever possible (or feasible without reducing performance). as an obvious example, if you just want to calculate 2 + 2, it's just 2 + 2 with no side effects.
>>
>>54404501
>Things like floating point division and multiplication is actually faster than the integer ops
no they're not, unless maybe if you're already doing a fuckton of integer ops and no float ops
>>
File: Cattura.png (14 KB, 696x568) Image search: [Google]
Cattura.png
14 KB, 696x568
Why thia shit "return" always c==1??
>>
>>54401030
>2d raster engine
just use opengl
>>
>>54404748
>if you want to calculate 2 + 2
What constitutes a side effect then?
What if I want to store the result of 2 + 2?
What if I want to display the result on the screen?
What if I want to pass the result to a function?
>>
>>54404778
a side effect would be like

int add(int a, int b) {
++pointlessGlobalVariable;

return a + b;
}
>>
>>54398737
>>54398753
It's specific C for loonix and ganoo, no?

doesn't work on those sites
>>
>>54404808
Would mutexes be a form of side-effect?
They're pretty essential for atomic operations.
>>
>>54404778
You can't remove all side effects, you can just limit them.
>>
>>54404833
this is starting to sound like a meme
>>
>>54404775
God damn, those are some unhelpful variable names.
I'm not really sure what your code is trying to do.
>>
>>54399610
lets see
>>
>>54403068
I'm not a CS student, I'm self taught, so I don't understand what turing completeness means.
If you explain it to me, I can tell you if it's turing complete or not.
>>
Any clojure fans wanna help a nigga out?

I have this comparator function
 
(defn a-star-compare [x y]
(compare [(:cost x) (:heuristic x)]
[(:cost y) (:heuristic y)]))


And this snippet of code here I want to work
(sort-by (a-star-compare)                                                                        
(cons
(zipmap headers
[(set-travelled (state :map) (first positions))
(first positions)
(state :goal)
(+ (state :cost)
(cost-calc (first positions) (state :position)))
(heuristic (first positions) (state :goal))])
output))))))))


It seems to work when I test the function in isolation on the repl but something is making it tell my I have to pass 2 args to the comparator when I want to use it in the snippet.
>>
Anyone else here doing intern work for a top company yet doesn't feel like they know anything?

I'm really confused at the moment of understanding cost functions. I undersstand i get this number .65 or 2.4 and I'm trying to minimize it but i don't get what that number represents.

Is "It is .65 standard deviations away from from what it should be" or what cause until i get that it's not making sense to me
>>
File: some variables.png (283 KB, 1143x2138) Image search: [Google]
some variables.png
283 KB, 1143x2138
>>54404859

Would you prefer these?
>>
>>54404859
I need to check if a fiscal code is correct(syntactically)
>>
>>54404823
acquiring/releasing a lock on a mutex is not a side effect it just guarantees atomicity and memory visibility
>>
>>54399610
I'll do this in Java tomorrow.
>>
>>54404922
>lolidev

POST
PROGRESS
>>
>>54404947
Too easy, reroll.
>>
>>54404922
That example isn't even bad. You probably just wanted to post the loli code.
I have nothing against short variable names, but they still need to be able to convey enough information through context.
x, y and z are perfectly fine for Cartesian coordinates or arguments to mathematical functions. i and j are perfectly fine from (nested) loop counters. Something like "struct thing *t" is perfectly fine, if the function mainly works on t.
Perhaps because I didn't see the declaration and intent of the variables, the single letter names mean nothing to me.
>>
>>54404775
The code is ill-formed.
It shouldn't even compile, but I guess you're a windows retard who ignores warnings.
>>
File: assocationscode.png (287 KB, 2560x1440) Image search: [Google]
assocationscode.png
287 KB, 2560x1440
>>54404951

Here, it's what I coded tonight. I'm trying to see if I can make lolis associate concepts together, that way if you rape them with an orange dildo then later dildos or the colour orange even might trigger them. I hope this doesn't cause the lolis to get triggered 24/7.

...all this was just because I wanted to make the lolis have a favourite colour, then I thought "What determines a loli's favourite colour?", which would be affected by what kinds of things they associate with that colour!
>>
>>54405018
You're doing God's work.
>>
>>54404912
>
(a-star-compare)

literally a call to the function without arguments.
You want
sort-by a-start-compare ...
m8

Clojure is nice
>>
>>54405018
>float FlavorProfile::*axis
>f.flavor.*axis

I've never seen this in C++, what's with this syntax, is axis a pointer of some kind ?
Thread replies: 255
Thread images: 20

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.