/dpt/ - Daily Programming Thread

old thread: What are you working on, Sup Forums?

Other urls found in this thread:

tour.dlang.org/
wiki.dlang.org/Books
dlang.org/blog/2017/04/28/automem-hands-free-raii-for-d/
wiki.dlang.org/Libraries_and_Frameworks#Alternative_standard_libraries_.2F_runtimes
doc.rust-lang.org/std/iter/trait.Iterator.html
twitter.com/NSFWRedditImage

Delete this fag shit.

I love taking it up the ass. Can you guess what my favorite programming language is?

Rust?

>read each panel right to left
>but read pages from left to right
what is this horse shit

JavaScript

FAGLAB

Post more of this fag shit.

write a function which generates a string n characters long consisting of only the prime numbers in sequential order

ex:
n=12
'2357911131719'

What if you truncate a prime number? Also
>still baiting dpt into doing your homework

Why does she have a key around her neck?

>she
It obviously is the key to the programming club room.

To unlock your heart, user

111 isn't prime (3×37).

Or I'm misunderstanding the problem, and it is actually stupidly simple.

What happens if you ask for a 13-character string?

she wears the key to your heart on her chest.

That's 11 and 13 concatenated.

That's 11 and 13 you dumb monkey.

But 113 is prime, and still contains 11 and 13 in sequential order, as substrings. I thought it might be something fancy like that, where each substring needs to be prime too.

But it sounds like it is actually just a stupidly simple homework problem.

Are you only pretending to be retarded?

not homework. actually was the equivalent of a fizzbuzz test.

here was my solution:

length_of_string=25

#create a string n characters long composed of the first prime numbers in order
class PrimeStringSieve():

#estimate of highest prime number to search for
SEEMINGLY_MAGIC_CONSTANT=3.1415

_outString=''

def __init__(self,StrLengthToGen):
def sieveSize(str_length):
return self.SEEMINGLY_MAGIC_CONSTANT * str_length + 1
def toString(array):
string=''
for each in array:
string+=str(each)
return string
def sieve(size):
array = [True] * size
for each in xrange(3,int(size**0.5)+1,2):
if array[each]:
array[each*each::2*each]=[False]*((size-each*each-1)/(2*each)+1)
return [2] + [each for each in xrange(3,size,2) if array[each]]
self._outString = toString(sieve(int(sieveSize(StrLengthToGen))))

def fetchString(self):
return self._outString[:50]

zz=PrimeStringSieve(length_of_string)


print zz.fetchString()
>

Cock cage.

sauce manga on image please

gradating in december, when should I start applying for jobs?

A girly language like Java or Cobol.

char* primestr(int size)
{
char* primes = calloc(size, 1);
int* sieve = calloc(size, sizeof(int));
int head = 0;
for(int i=2; i size) break;
}
}
return primes;
}

Forgot to free sieve, and forgot to add one to the breaking to ensure no overflow when the number of digits increases. It works, though.

>calloc
why

zeroes the array without memset, doesn't require me to explicitly multiply by size of int

more of a scripting question, in windows cmd

I have a script executing programs in a sequence, and one of the programs prints a load of output including a key word or string that if printed i'd like NOT proceed with further executions in the script

how do i catch that?

Edit the script, or maybe run it in a debugger and step thru.

I couldn't be bothered to make it cleaner, this is dumb.
int is_prime(size_t n)
{
if (n < 2)
return 0;
else if (n == 2)
return 1;
else
{
size_t i;
for (i = 2; i

char* primestr(int size)
{
char* primes = calloc(size+1, 1);
int* sieve = calloc(size, sizeof(int));
int head = 0;
for(int i=2;; ++i) {
if(sieve[i]) {
continue;
} else {
for(int j=i; (j+=i) < size;) sieve[j] = 1;
head += snprintf(&primes[head], (size-head)+1, "%d", i);
if(head>=size) break;
}
}
free(sieve);
return primes;
}

>Forgot to free sieve
Of course, C tard

I don't even know why you'd bother to use freestore memory here when you can just allocate it on the stack

Trying to work with libsensors. Is there a way to select only the CPU thermal sensors? I would be surprised if the library itself was capable of that, but maybe someone knows where I could find a list of all possible CPU sensor names?

Apples and Oranges.

If I use stack it segfaults on very large values.

Threadly reminder that dlang-chan has RAII; she's quite fast in execution and compilation; she's becoming fully memory-safe; and she's super duper cute! Say something nice about her, /dpt/!

>Tour
tour.dlang.org/
>Books
wiki.dlang.org/Books
>GC
dlang.org/blog/2017/04/28/automem-hands-free-raii-for-d/
wiki.dlang.org/Libraries_and_Frameworks#Alternative_standard_libraries_.2F_runtimes

import std.algorithm, std.range, std.stdio;

void main()
{
//fib
recurrence!("a[n-1] + a[n-2]")(1, 1).take(10).writeln;

//fact
recurrence!((a, n) => a[n - 1] * n)(1).take(10).writeln;

// triangluar
static size_t genTriangular(R)(R state, size_t n)
{
return state[n - 1] + n;
}

recurrence!genTriangular(0).take(10).writeln;
}

$ ./main
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
[1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
[0, 1, 3, 6, 10, 15, 21, 28, 36, 45]

>Freeing memory
>Before the program closes
Aaaaaaaye

back to

difficulty++;
Make it so that you have to match the string length n exactly, and the primes doesn't have to be sequential, but just in growing order.
example: n=5
worng: 235711 (6 digits, too large)
right: 23511

Looking at programs written in dlang-chan gets me hard.

I'd want to free it if I was using it in a loop or something.

sequential versus growing order? What's the difference?

Can Rust and C++ do these?

samefag pls
the difference is you can skip numbers.

>samefag pls
Please, user, not even I'm that pathetic. There's two dfags itt

Only one me

pythonfag pls

idk, both of your requirements seem kinda dumb. Why would I want to skip numbers? Why is it harder to write the exact amount? The C code above does that pretty simply.

Rust can do these nicely using list stuffs that I haven't bothered to learn.
doc.rust-lang.org/std/iter/trait.Iterator.html

>dumb
>I don't understand it therefore it's dumb
Read the example I gave.
The code above does not give a right answer.

has anybody here had sex with a woman

Why does this matter to you?

having sex with women will make you a worse programmer

i guess that answers the question

Yes, your mum

Now

>she

why is golang so godlike

>doc.rust-lang.org/std/iter/trait.Iterator.html
That's a decent collection of higher order functions. Still lacks a few things tho. Maybe I'll try out Rust some day

>3DPD
>when glorious 2D exists
Laugh at this fag.

Yes, why?

He was probably just seeing who would lie.

Anyone?

I was raped by a faggy emo kid once, does that count?

Yes.

I'm a girl by the way ;)

fag

Me too~
We're all lolis here!

I don't even see the appeal of lolis, yet I can't help seeing a room full of them debating programming on a message board as anything other than incredibly fucking adorable

As long as you think we're cute, it's all good. Though "debating" is an overly nice way to put it.

Doing one of the labs from CS:App.
/*
* getByte - Extract byte n from word x
* Bytes numbered from 0 (LSB) to 3 (MSB)
* Examples: getByte(0x12345678,1) = 0x56
* Legal ops: ! ~ & ^ | + >
/*


I was messing around and can do:
#include

int main(void)
{
int a = 0x12345678;
int b = 0xFF; // Bit mask.
int n = 1; // The nth byte of 'a'.

b = (n * 8); // Shift the nth byte to be LSB.

printf("%x\n", a);

return 0;
}


But multiplication using * isn't an allowed operation. What do, /dpt/?

Think about what

Multiplication by 8 is equivalent to left shifting by 3.

Hey guys new to programming as a whole so sorry if this is a dumb question. How can I decode DTMF signals from an audio input in python? I see a lot of solutions online but all of them only decode wav files, I need this to be done in real time.

I know, I'm more enamoured with the image than the reality

And there's just this one over in the corner yelling about haskell

Speaking of fucking explain something to me here about the functional fags

I'm a diehard lisper, I love lisp, I mean I REALLY love lisp, out of all the languages I've ever written a line in half of them are lisps, I know Scheme, Clojure, Racket, Common Lisp, I use fucking emacs for a reason

I do me some functional programming, I gets it

What I don't quite gets is why these memers gotta come all up in here ranting about their monads and bashing mutable variables and object orientation

It's just a different way to do things

Coming from a guy who will tolerate
(((((((((((((((((((((((((((((((((((((())))))))(((((((((()))))))))))))(((((((((((((((((((((((((((+ 2 2)))))))))))))))((((((((((()))))))))))))))))))))))(((((((((((((())))))))))))))))))))


I just don't get it

>Reddit spacing

don't bully daiz, user

How the fuck do you declare a new type and then create an array of that type in javascript?

>What I don't quite gets is why these memers
This is your first mistake.

Anyone know why the fuck Netbeans is such a piece of bloated trash? I'm trying to work through this MOOC but the entire time it's been constantly freezing up for 10-30 seconds at a time or just completely crashing. I tried turning off some of the 50+ plugins it had, but every time it said it would have to disable the 2-3 plugins that I actually need due to dependency issues or whatever. It's really driving me fucking crazy, I want to do the second part of the course but I can't deal with this shit anymore, it's killing my productivity to have to sit there waiting for it to unfreeze every time I type a bit too fast or run something. Seriously, even a "hello world" freezes it for a good 20 seconds before running.

>inb4 "lmao java"
your gay

import primes

def cat_primes(length) -> str:
s = ''
for i in primes.sieve((length = length:
return s[:length]
Hard to establish an accurate bound on the sieve.

Netbeans is written in Java, Java has GC, GCs make applications pause, use a language without GC, like C/C++ or Rust

Try literally any other IDE?

Why not alloca now?
How long a string can you generate where if you pop the front of the string it remains a prime until its an empty string or

I would but you gotta use this netbeans plugin to turn in assignments for the course. Normally I wouldn't care but you can't access new assignments until you turn in something like 95% of the ones from the previous week.
Yeah C is pretty nice, I gave C++ a try for a while but it's that's a massive fucking language, I don't even have foundational knowledge, I wanted something dumber.

Bonus:
Any base.

saved

>How long a string can you generate where if you pop the front of the string it remains a prime until its an empty string or How long a string can you generate where if you pop the front of the string it remains a prime until its an empty string or

Good work blocking out your name, Caleb

How can I learn to write nice, modern and idiomatic C++?

Software for software developers is among the worst software on the planet. Strangely enough.

Fuck off with your faggot shit back to

1061 is the highest I can think of right now.
I expect it to be very short too. So I'd just evaluate primes as you go.

the code monkey is you

i can relate, caleb

I'm doing some coding challenges to teach myself javascript, is this good practice?
If I was doing this in a C-like, I'd just make a simple anonymous struct array and sort it in place, but apparently this isn't possible in JS, it forces you to create a bunch of redundant intermediate arrays.

function order(words)
{
var find = function(str) {
for (var i = 0; i < str.length; i++)
if (str[i] >= '0' && str[i]

DFC a best!
With regards to your problem: there's probably a better way.

I can't believe I had to ask you guys this.

>inserting values with known indices, then sorting them based on these indices
>not just inserting them into their index right away

What I have malformed input with multiple values having the same index?