/dpt/ - Daily Programming Thread

What are you working on?
Previous:

Attached: d04ec36f6a511818d8f83fb96fc280a7.jpg (1417x920, 450K)

Other urls found in this thread:

ideone.com/Tx9zmW
youtube.com/watch?v=rqX8PFcOpxA
twitter.com/NSFWRedditVideo

as in your standards for yourselves get higher and higher the longer you go, and yesterdays decent is todays mediocre?

C++ and python are the only two useful languages
And why was the previous thread deleted?

It was just like you.

i look at js as a prototyping language.
i can work out the logic quickly and simply without worrying about much syntax, using statements, etc...

plus i'm guess my first job will be js.

like getting a regular license before getting a CDL. (i'm a former trucker)

shilling for Ruby
thanks for using an anime image unlike last faggot that tried and failed

C#/xamarin are my goal.
baby steps

go back to trucking
yeah, i'm drunk shitposting. deal with it.

Working on an MMO. For fun.

but to be serious...
just stick with C#. You'll get the syntax, etc. down soon enough. If you're learning, no reason to burden yourself with the bullshit of two languages.
And Javascript and C# promote a bit different programming styles (especially when you get to more complex things).
Maybe if you want a prototyping language, learn you some visual basic.net

>js as a prototyping language

Prototyping for what? Why would you rewrite web apps in another language?

what are you using for networking between the server and clients?

N-no problem, user.

Attached: ae5cb66eb6629612431bca6dec52728a.jpg (1440x1055, 117K)

websockets

can't
legally not allowed.

i still use C# + XAML for the app i'm building. (which is my passion project)

the project euler thing i am doing in js this time around.
i may do it all again in C#.
later if i learn another lang, i'do that too.
my gists will be h'huuuuuge

Attached: Wilford-Brimley-Diabeetus.jpg (500x617, 44K)

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?

about to start on #7
let's see if y'all can keep up :p

Yes, exactly.
It's also that project ideas that I deemed worthy of being made had to be far less interesting or profound before - if I had an idea to do something simple like graph points or a barebones shmup game, I would do it as soon as the idea came to me. Now I feel like something is only worth doing if it would fit on my resume. I don't like having this kind of attitude, so I hope you/all anons keep the gusto that seems to invigorate newbies to get them to work on seemingly pointless projects.
/rant

C/C++
classic rock

everything else fuck off

d-dad?

Attached: just utterly sad i cant explain.jpg (660x716, 40K)

dumb frogposter

it is you!!
:')
on topic:
why do people use rust when C++ is widely adopted?

>dynamic types
>frogposting
No son of mine

Cute
Sauce?

daily reminder that the best indicator of programming success is an absent father

>why do people use rust
literally who?

ayy, I was literally doing PE in Javascript too

go spend the night at your friend's place kid
me and your mom have some idris to drop if you know what I mean heh

ez, next

function getNthPrime(n) {
var primes = [2];
var p = 1;
while (primes.length < n) {
p += 2;
var isPrime = true;

for (var i=1; i

Oops, sorry. Change this line
(var i=1; i

Why the fuck are you using an array?

Use your brain for a few seconds and you'll realise.

already did the first 100 problems in assembly though

here's #7
include 'lib/macros.mac'
global _start

section .bss
lim equ 500000
bs resb lim

section .text
_start:
mov ecx, 2 ; n
mov ebx, 1 ; count
.l:
lea eax, [2*ecx]
.l1:
mov byte [bs+eax], 1
add eax, ecx
cmp eax, lim
jb .l1
.l2:
inc ecx
test byte [bs+ecx], 1
jne .l2

inc ebx
cmp ebx, 10001
jb .l

printd ecx
endp

Actually, setting a limit of sqrt(p) would speed it up a lot.

function getNthPrime(n) {
var primes = [2];
var p = 1;

while (primes.length < n) {
p += 2;
var limit = Math.sqrt(p);
var isPrime = true;

for (var i=1; i limit) {
break;
} else if (p % primes[i] == 0) {
isPrime = false;
break;
}
}

if (isPrime) {
primes.push(p);
}
}

return primes[primes.length - 1];
}

ur light years beyond me, user.
but serious thanks for these.
i'll be studying them for a while.

Sir,
i'm not a mathfag, can you explain why the sqrt helps?

Attached: patty_and_marci_by_rock_zilla.png (900x829, 212K)

Done in C! Approx 15 mins


void setupPrimeFn(long nPrimes)
{
if(nPrimes < 1)
{
printf("Sorry... Enter a correct number, dipshit");
exit(-1);
}
long* primeArr = (long*) calloc(nPrimes, sizeof(long)); //zero out array
primeArr[0] = 2; //The first prime

long primesFound =1; //keeps track of how many primes we've found
long currNum = 3;
while(primesFound < nPrimes)
{
if(isPrime(currNum, primeArr))
{
primesFound++;
// printf("Prime #%5d Found:%5d\n", primesFound, currNum);
}
currNum++;
}

printf("FINAL PRIME: %ld \n", currNum-1);
free( primeArr );
}

int isPrime(long testNum, long* primeArr)
{
long currNum;
int primeInd ;
for( primeInd =0 ; (currNum = primeArr[primeInd]) != 0; primeInd++)
{
if(testNum % currNum == 0) // divisible
return COMPOSITE;
}
// printf("Current primeInd: %d\n", primeInd);
primeArr[primeInd] = testNum;//update our array -- we found a new prime!
return PRIME;
}

Forgot to include my times:

Because you know that
sqrt(x) * sqrt(x) = x
So when checking for things that divide evenly into x, you don't need to check anything above sqrt(x), because if 2 was a factor, then n / 2 would also be a factor.
If no number before sqrt(x) was a factor, then you know that you already ran the gamut of all the possible factors of x

Attached: Screen Shot 2018-05-06 at 12.26.28 AM.png (2226x1638, 199K)

perspective projection

Attached: tos.webm (638x478, 1.62M)

Brainlet here, how do you increase the size of the array without realloc?

Once you pass the square root, you will have already performed the check on the other factor. Example for 15:

1 x 15
3 x 5
>
5 x 3
15 x 1

See how the equations invert after passing the square root?

noice

Because of the way I structured my algorithm (I needed the nth prime, so I create enough space for n primes), I don't need to increase the size of the array.

There really isn't a way you can resize an array without using realloc or (free + malloc again), unless you want to use linked lists or some similar structure.

nice time

Attached: 2018-05-06-033724_1920x1080_scrot.png (1920x1080, 1.7M)

i see now

can someone please unpajeet my code?
private boolean hasCycleHelper(Node visiting, ArrayList visited, Node parrent) {

System.out.println(visiting);

visited.add(visiting);
for (Node iter : visiting.getNeigbours()) {
// recursively traverse graph if new node
if ( !visited.contains(iter) ) {
if (hasCycleHelper(iter, visited, visiting))
return true;
}

// visited and not parrent -> cycle
if (!iter.equals(parrent))
return true;
}

return false;
}

boolean hasCycle() {
ArrayList visited = new ArrayList();
for (Node n : nodes) {
if (!visited.contains(n)) {
if (hasCycleHelper(n, visited, new Node(""))) {
return true;
}
}
}
return false;
}

I'm getting true for
a.addNeghbour(b);
b.addNeghbour(c);
//c.addNeghbour(a);

How old is too old to get into programming?

Attached: Toroidal_Sphere.gif (312x235, 226K)

1

1 uranus year

>visited
more like

i'm a smart 37 year old
i was a smart 34 year old when i started trying to learn.
it's slow going.
but it seems each step i take forward is bigger than the previous step.

nvm, I'm a dumdum
it needed an else between the two ifs in the helper

Be careful with returns inside nested ifs, this could be what threw you off - if it only satisfies the outer if, it goes to the next block/doesnt return
I know you know this but~

Is everyone here just going to ignore that open terminal window next to emacs?

if you want a fun one, try 12
get that one to work efficiently

i'll get there eventually :)

fellow 37 year old.
Jow Forums can seem bizarrely young these days. I guess I don't know your experience, but if it's like mine, wasn't it bizarre watching the internet come into existence and then be completely taken for granted?

I used "bizarre" twice, but it's not because I'm old, it's because I'm drunk. And old.

Solving it is one thing
Getting it to compute effectively is
the real hurdle especially with javascript

yep. my first exp was number crunchers/oregon trail on apple ii. then on the OG mac, playing with hypercard animations.

later came AOL. and then woosh!

kind of miss firetalk/paltalk.
that shit was ahead of its time.
it was the discord of the early 2000s.

I started with a local BBS, then prodigy/aol and ICQ and so on. I haven't heard of firetalk/paltalk. Number crunchers and oregon trail of course were early, but my folks got an apple IIe in the house which probably kickstarted everything. But I'd still attribute the BBS to the longterm interest. Well, and stupid script kiddie "aohell" shit, which was crack for delinquent teens slightly ahead of the game.

This is the Northrop MADDIDA, a computer for solving differential equations.

Attached: MADDIDA.jpg (3025x2139, 575K)

cool story bro

>first computer whose entire logic was specified in Boolean algebra.
mistake
analog computing was robbed

now it's on your pocket phones

the real question is:
what's next? and how to get a head of it?

Post your favorite IDE / text editor color scheme / color palette.

Mine : classic emacs CLI-style

Attached: Classic emacs cli.png (988x687, 10K)

Attached: could-you-fucking-not-14187082.png (500x522, 124K)

that's always been the question though
if only there were some time and era independent techniques that proved better than luck. I didn't really see VR making a come-back.

Who knows, maybe holography. Holography is actually pretty cool but nobody's looking there for future tech. Probably wisely.

Dracula confirmed best theme.

Attached: dracula.png (802x585, 36K)

too late for self-driving cars. if we got in 10 years ago...

>what needs technical innovation?
medicine
law
home automation
agriculture
environmental shit
education

>law
deontic logic + automated theorem provers + regressions on what people find adequate consequence of similar cases

Solved

Attached: gavel.jpg (306x165, 5K)

>education
yes!
find the BEST teachers in each category.
have them teach via video tutorials.
pay each $1m to do it.
(take that money from the money we save paying public school teachers by the hour = net profit galore, hell there'd be more than enough funds to cover the cost of free hardware and internet access for every kid.)
every student has access to the best education.
each can be fairly judged on their own merits.
if your kid fails; can't blame teachers for favoritism.
can't blame the economy.
can't blame it on race.
etc...

why would someone force himself to program with obsolete technologies from the sixties?

Attached: hYMIItH.png (511x564, 142K)

where's the /prog/ MUD

I want to read 4 bytes from an ifstream in sepples.
those bytes could be for example: 1F 00 00 00
but when i do stream >> someInteger it gives me 0. what am I doing wrong?
stream >> hex >> someInteger doesnt work
I really dont want to do it with byte array

Attached: 1473550131786.jpg (500x375, 48K)

? ideone.com/Tx9zmW

Attached: Fedora.png (1067x800, 730K)

the input is just regular bitstream from a file. I only wrote it in hex so its shorter

Do you open the file in binary mode? And you don't need std::hex on the stream in that case either.

yes and I read a bunch of chars before and they work. then I read an int and I get 0

it is pretty unnecessary to allocate memory for a possibly huge array of primes that we don't even care about. we're only interested in the last one

Maybe you're reading more than you should prior to that. Really hard to tell with a more reproducible example.

here the whole relevant code

[...]
std::ifstream file(_file, std::ios::in | std::ios::binary);
file.seekg(0);
[...]
char c = 0; //1 byte
assert((file >> c, c) == 66); //ok
assert((file >> c, c) == 77); //ok
assert((file >> c, c) == 70); //ok
assert((file >> c, c) == 3); //ok
[...]
int blockType = (file >> uc, uc); //ok
int size = (file >> i, i); //zero

I want to make a game in Nim using SDL, but I don't know SDL in C at all, would it be a good idea to learn Nim and ask at once or should I do SDL in C first (I only know the basics of C)

Are you positively sure you're not hitting an eof after reading into uc? What's the type of uc? How does the file look like?

here a view of the file. the highlighted part is the problem. it's just some byte code format for bitmap fonts.

uc is unsigned char btw. and when I read a char instead of an int I get the 37.

Attached: file.png (1608x277, 60K)

Are you taking care of endianess?

Does other languages have their Hoogle analogues?

Hoogle is shit.

It's the best shit I've seen for any language.

I'm writing a small NFC read/write app for Android as part of a bigger project. The main activity would launch secondary activities to read or write to the tag, then return the tag data in the return intent. However, I'm not sure which activity should be receiving the implicit intent from Android. If non of them have it, scanning a tag open the standard android "New Tag Found". If the main activity has it, when I open the read activity and scan the tag, it reopens the main activity.

Hopefully I explained that correctly. I'm pretty new to Android programming, if this belong to /sqt/ I'll go ask them.

who here?

meh

just you

youtube.com/watch?v=rqX8PFcOpxA
is this your life?

daily reminder that Java is the best language ever created

I know premature optimization is bad and all, but it's the most comfy way of procrastinating while feeling productive.
You're still technically working on the thing, but you're only making it go nowhere a bit faster.

Attached: 1509383167788.png (128x128, 30K)

it still feelsbad when you spend an hour optimizing a function only to realize that it doesn't actually do what it's supposed to do

"premature optimisation" is a shitty meme. It's just a term that terrible programmers throw around to justify their shitty, slow programs.
Micro-optimisations is usually where you're wasting your time, but even those are sometimes justified.

comfy.png