/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: x14.jpg (1046x1500, 454K)

Other urls found in this thread:

github.com/drujensen/fib
stackoverflow.com/questions/1451170/in-the-fibonacci-sequence-is-fib0-0-or-1
twitter.com/SFWRedditImages

I have placed a curse on this thread

Attached: LIGHT_WEIGHT.webm (640x640, 715K)

Employed Haskell programmer reporting in

Attached: 1474325315193.jpg (636x616, 44K)

What do you do? Why Haskell?

Daily reminder that wireless devices cause brain damage, endocrine dysfunction, DNA damage, and irreversible infertility.

Light themes are the best, but not too light!

Attached: quak.png (696x943, 33K)

First for vim is shit

Daily reminder /dpt/ causes irreversible death

Let us honor the memory of all fallen /dpt/-comrades we've lost along the way.

github.com/drujensen/fib
This github repo did 10 implementations of recursive fibonacci and has 150+ stars now.
How many stars has your most ambitious project gotten?

>github upvotes
who cares

Patrician taste

reminds me this. (pic)

Attached: tu2.png (700x2528, 127K)

Shamelessly bumping my question in the previous thread:

Any implementation other than the hackathon (jump table) is unacceptable.

Large company makes me shudder and feel all twisted up inside.

Last time I posted, I was studying for a Google phone interview.

Now, I'm getting flown out to a Google onsite interview. Studying for that rn

>current year
>still not learning how to solve fibonacci using a fibonacci matrix

Rate my C program, Jow Forums.

%:include
int main(argc,argv)
int argc;char*argv[];;
for (int i=0;i

not valid

What isn't valid?

I'm working at a startup and I've noticed my code slowly transition from startup to large company mode. The math PhD one makes no sense, why would they prefer function notation to binary? t. Not quite math PhD yet.

i[array]

None of these scale very well for large n.

It's absolutely valid. i[a] and a[i] both work in C.

That's valid C, n00b.

i[array] translates to *(i + array)
array[i] translates to *(array + i)

As addition is commutative, those two are equivalent.

desu it is wrong to write things to be scalable and generic when they only have one limited use; look at the comment of the hackathon code

>gcc doesn't support destructors for classes that are thread_local in c++11

It can be written scalable and generic with less code than any of those examples.

public int getFibonacciNumber(int n) {
int[] fib = {1, 1, 2};
for (int i = 3; i < n; ++i) {
fib[i % 3] = fib[(i - 1) % 3] + fib[(i - 2) % 3];
}
return fib[n % 3];
}

It needed neither of those qualities, and now the
code looks worse.

>the code looks worse.
If you think any of those except the very first one looks "good", then I hope I'll never encounter your code in my life.

Also, where the fuck is it stated that none of those are needed?

I never claimed that. Don't make such baseless assumptions. Also the code you wrote is a totally niggerlicious way of doing fibonacci.

Look at the comment in the hackathon piece, it implies it doesn't need them given the context it is used it.

i have 3-4 ok projects of medium size i can upload on github but i'm afraid they might get stolen

>Also the code you wrote is a totally niggerlicious way of doing fibonacci.
Enjoy your stack overflow

>Look at the comment in the hackathon piece,
What kind of retard answer is that? Look at the comment in the enterprise edition.

You're just insanely butthurt you couldn't come up with a non-recursive method of calculating Fibonacci numbers, lol.

Just use the math one without the retarded redefining of basic operations, it's F(n) = round(phi^n / sqrt(5)), that's it.

what's the reason given?

All right. I have gotten tired of all the ridiculously complicated build systems.

A program should be able to build as gcc main.c deps/*.c -Ideps/.
To this end:
Projects which only produce one binary should name the .c source file containing the main() function either main.c or {name of binary}.c
Projects which produce multiple binaries should have one .c source file named after each binary in the root folder, which in turn include the needed headers.
Libraries must work both by #include and linking, unless they are header-only libraries, in which case the latter is optional.
This means that libraries must avoid defining the same identifier across multiple source files. Such identifiers should instead be put in a common header with an include guard. If this is not possible, the identifiers should be made locally scoped by a prelude which redefines them.
Example
#define id1 file_id2
#define id2 file_id2
#define id3 file_id3
...
#undef id1
#undef id2
#undef if3

All source code and header files must have include guards, with the exception of files that define a main() function, or which are intended to be included multiple times.
If the project contains a makefile, it should not require GNU make, nor should it be required to compile the project without taking more than a cursory look at the structure.

Did I miss anything?

math phd would be using matrices not the one with the golden ratio, because that one is actually slow

>Enjoy your stack overflow
>You're just insanely butthurt you couldn't come up with a non-recursive method of calculating Fibonacci numbers, lol.

lmao, No I am not. This proves you wrong:
int fibonacci(int n)
{
int foo = 0;
int bar = 1;
int tmp;

while (n--) {
foo += bar;
tmp = foo;
foo = bar;
bar = tmp;
}
return foo;
}


It is a shitton better than your nigger solutionĀ½

#pragma once or good old header guard?

Your implementation of fibonacci(n) will return 0 for n=0, which is wrong retard.

By definition, the first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the previous two. Some sources omit the initial 0, instead beginning the sequence with two 1s. For n = 0 it is clearly 0: F(0) = (1 - 1) / sqrt(5) = 0.Sep 20, 2009
In the Fibonacci sequence, is fib(0) 0 or 1 ? - Stack Overflow
stackoverflow.com/questions/1451170/in-the-fibonacci-sequence-is-fib0-0-or-1

#pragma once for your own stuff, old header guard if you're writing a library.

>no one here
Employed computational scientist, AMA.

>while (n--)
Pass in -1 to your function, and it now iterates until it wraps (undefined behaviour for signed ints).

Good job at making a "generic" solution....

No, both are correct.
(pow(phi, n)-pow((1-sqrt(5))/2, n))/sqrt(5) is equivalent to floor(pow(phi, n)/sqrt(5)+0.5f).

Yeah, I realized that after posting. Thanks for correcting me user.

>scientist
hi have you considered quitting rather than continuing to endanger the human race

Not really. The only other field that may interest me at this point would be HFT.

>FEniCS
Simula faggot detected.

You should ensure valid arguments before calling the function.
>Good job at making a "generic" solution....
Never claimed to have done that. For that you would also need something like the java BigInteger

Pragma once can be trivially converted to header guard with a two line shell script.

A negative integer is a valid argument to something that expects a signed integer.

I've been found

I meant in the same sense that it is your job to ensure that you are not dividing by zero when dividing.

Yes, you have. It's stupid to post RL projects online, especially when you're boasting about your e-peen.

What about using binomial expansion and (1/2 + sqrt(5)/2)^n?

Next you're going to say you were merely pretending

Why would I say I'm merely pretending? I'm not the one boasting about working on FEniCS (which is a pretty done project by now tbqh).

#include

template
class sample {
public:
sample()
{
printf("sample\n");
}

~sample()
{
printf("~sample\n");
}

public:
T member;
};

static thread_local class sample mysample;

int main()
{
mysample.member = 10;
return 0;
}


g++
/usr/bin/ld: /tmp/cctQLO7o.o: in function `__tls_init':
sample.cpp:(.text+0x5b): undefined reference to `sample::~sample()'
collect2: error: ld returned 1 exit status


clang++ just werx

Oh, it (gcc) needs -pthread to even use tls
That's why

>I'm not the one boasting about working on FEniCS
Where did I do that you mongoloid? Please spend more time focusing on your mouth-breathing and less on making retarded comments on Jow Forums.

The fact that you're getting mad and upset about this proves to me that I found you out.

You are retarded, a negative number is a valid argument since the general sequence is ...,-8,5,-3,2,-1,1,0,1,1,2,3,5,8,...

So in that case it should actually be:
int fibonacci(int n)
{
int foo = 0;
int bar = 1;
int tmp;

if (n < 0) {
int tmp = fibonacci(-n);
return (-n & 1) ? tmp : -tmp;
}

while (n--) {
foo += bar;
tmp = foo;
foo = bar;
bar = tmp;
}
return foo;
}

>(-n & 1)
Implementation specific behaviour. Into the trash it goes.

Where am I fucking up?
def MArray( i, j ):
#Produce an Array of size i, and dimensions j
#MArray(2,3)
#>>>[ ['1','2','3'], ['4','5','6'] ]
arr = [None] * j
arr2 = [None] * i

for c in range(len(arr2)):
for k in range(len(arr)):
arr[k] = input('enter your data')

arr2[c] = arr

return arr2

On which platforms does it not work?

Name?

Platforms that uses one's complement.

yeah well you just keep using your imaginary system, while I program for real hardware.

Any good resources for learning machine learning and deep learning in depth? I mean the actual math and algorithm creation.

The results I keep coming across keep saying just use these AI libraries, rather than actually learning the underlying technology.

it's a meme technology, if you have a brain get into something useful that isnt a fad

Or, you could just write % 2 like a sane person, and let the compiler handle your silly microoptimisation.

told

Was meant for

of what?

I looked a bit at it again and I think you're wrong.
-n comes before the bitmask.

Theme you dum dum

You're probably right, but still you should do imo

>trusting the (((compiler)))

what are they about

Premature (micro)optimisations are the root of all evil.
- The D.

It doesn't have a name.

background: #CFCFCF
text: #000000
comments: #9E0C0C
strings: #009456

please help I have no idea why it's only indexing the last element of my outer array.

you just making your js apps with electron

Because [None] * j doesn't do what you think it does.

Do this instead:
arr = []
arr2 = []

for c in range(i):
for k in range(j):
arr.append(input('enter your data'))

arr2.append(arr)


Lists are not arrays.

I'm serious though, if you ever examined the assembly from your compiler, you'd realise that it does this """optimisation""" for you.

There is no excuse for writing non-portable code unless you're dealing directly with hardware (which you're not in this case).

>not trusting the compiler
Until you tell me how ROB, load/store buffers, instruction retirement and cache synchronization work you really don't know more than a good optimizing compiler does. Don't forget about register renaming and data hazards.

>programming without trusting the compiler
Let me guess, you're one of those people who write your own string functions too, because the standard library can't be "trusted", am I right?

i've been out of the loop for a while
can you give me an update on rust

is it more popular now
is it still fast

Get a loads this (((compiler dev)))

It's a step up, but not quite what I want to do since it copies my inner array to each element in the outer array.

How do I use SDL2 to stream to an indexed texture with a custom palette?

Here's the problem. There doesn't seem to be any way to access the palette of an indexed texture. You can create one, by passing an indexed pixel mode to SDL_CreateTexture, but since you can only pass the flag for the pixel mode, not the entire pixel mode data structure, you can't specify a palette.

You can create a texture with an arbitrary palette by first creating a surface with that palette (since there are functions available to freely manipulate the palette of a surface) and then using SDL_CreateTextureFromSurface. However, SDL_CreateTextureFromSurface is documented as always allocating and returning a static texture. I need a streaming texture. There also do not seem to be any functions for creating a texture from an existing texture, except SDL_RenderCopy[Ex] with a texture as the render target -- which would defeat the purpose, as neither pixel mode nor streaming mode would not be preserved, so in order to create an indexed streaming texture to copy to, I'd be faced with the same problem as before.

Pls. All I want is to directly manipulate the pixels on my 8-bit emulator.

Current workaround is to store the texture as RGBA8888, have a separate 8-bit indexed pixel array in static memory as well as a palette for it, and manually convert every pixel from indexed 8-bit to RGBA8888 every frame. This works but it would be more efficient to just have the texture itself be indexed 8-bit with the palette I want.

Still ugly, compiler still exceeds the 32-bit address space when being linked, still pushed by loud, insufferable people who ride on Haskell's coattails.

You are right about light themes being patrician, bul low contrast increases eyestrain

This but unironically

That's still good contrast.

How do I get good haskell integration with emacs?
I'm trying to setup haskell-ide-engine but it's not working. I'm on archlinux btw

Just get hlint and ghcid, you don't really need anything else