/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

First for D

>made after bump limit
this is the real thread

Thank you for using an anime image!

C# is best waifu

C++ is the sexiest.

shame about the language though

what is faster ? allocating 542 kilobytes or or setting 131'068 floats to 0?

I've made a romanian numbers converter:

#include

#define ROMANIAN_PLACE(x) r_output[ro_counter++]=romanian_numbers[x]

int main(int argc, char *argv[]) {
char romanian_numbers[7] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
char r_output[15];
unsigned char places = 0, i = 0, j = 0, ro_counter = 0;

if (argc == 1) goto exit;
while(argv[1][places++]);
if (places < 2 || places > 5) goto exit;
places--;

if (places == 4)
if (4 < (argv[1][0] - 32) && 0 > (argv[1][0] - 32))
for (ro_counter = i = argv[1][0] - 32; i > 0;)
r_output[--i] = romanian_numbers[6];

for (i = !!ro_counter; i < places; i++) {
switch (argv[1][i]) {
case '9':
ROMANIAN_PLACE((places-i-1)*2);
ROMANIAN_PLACE((places-i)*2);
break;
case '8': case '7': case '6': case '5':
ROMANIAN_PLACE((places-i-1)*2+1);
for(j = argv[0][i] - 5; j > '0'; j--)
ROMANIAN_PLACE((places-i-1)*2);
break;
case '4':
ROMANIAN_PLACE((places-i-1)*2);
ROMANIAN_PLACE((places-i-1)*2+1);
break;
case '3': case '2': case '1': {
for(j = argv[0][i]; j > '0'; j--)
ROMANIAN_PLACE((places-i-1)*2);
break;
}
case '0':
break;
}
}

printf(r_output);
printf("\n");

exit:
return 0;
}

It doesn't work properly, though. I will debug it later.

>not ruby or vb

Baby's first Racket:
#lang racket
(define lower 0)
(define upper 1)

(define (start n m)
(set! lower (min n m))
(set! upper (max n m))
(guess))

(define (guess)
(quotient (+ lower upper) 2))

(define (smaller)
(set! upper (max lower(sub1 (guess))))
(guess))

(define (bigger)
(set! lower (min upper(add1 (guess))))
(guess))

pedo

>but it is a very fundamental question which will influence the design of the whole program
Explain

MPEG-1 Decoder, then an encoder. Just finished a Transport Stream multiplexer/demultiplexer.

set!s everywhere. It's OK using them on Lisp's dialects, but you should avoid writing imperative code when not needed.

too imperative

>goto
instead of "return 1"

Setting the floats if they are packed contiguously and is done with a memset(). malloc() requires a syscall and would be somewhat expensive.

It's collection of snippets I typed over from the book I'm reading.

I want to marry that perl girl

ok that was maybe too much pathos. but I only want to write the whole paging shit only once and I dont want to change later because I made a shit decision.

it's java and the floats are sitting in a direct bytebuffer.

try making a less imperative version

float *yourmem = calloc(542 * 1024);
Done.

Best language and best waifu.

Ruby a close second in waifu. Shit language though.

542 * 1024 * sizeof(float)
Oops.

Just set the floats then.

Is SQL the only commonly used database and query language?

Its kinda ugly tbqh.

Yes

doesnt calloc need a number of elements too?

calloc(num,size);

>Is SQL the only commonly used database and query language?
There are many dialects of SQL, but it is pretty much the only database language that matters, other than abstractions to actual programming languages.

It's not that bad. Pretty expressive for working with sets of data.

perl is literally me
i'm 1,63m and 50 kg

Why do I need its own errorlevel? It's not like this program is intended to handle input errors (now).

Why use that abomination of syntax when you can just use a "return" keyword?

Care to give my a hint? I don't see how I can remove the lower and upper variables.

have guess take two parameters

Where is Lisp?

On my dick

I'm working on a f# file explorer but stuck on creating functions that will

1) Get a directory from a string
2) list all dirs in it that matches my free text query
3) list all files in it that matches my free text query
4) Return it as my own type which has a name, path and type (file or dir)

Right now I have 1, 2, 3 but I can't combine the two lists of different type to one list of my own type.

f# is kind of fucked if you come from a OO background.

She's coding.

Something like this:
(define (guess lower upper)
(if (guess-ok)
(do-guess-ok-thing)
(guess (new-lower lower) (new-upper upper))))

(guess (your-lower) (your-upper))


I don't know what you are trying to do, but something like that should work.

If you're thinking a recursive call is too expensive, most Lisp compilers optimize them to efficient loop-calls (if they're called at the end of the procedure/function).

>stuck on creating functions that will get a directory from a string
Stop trying to make a file browser

I think neither is necessary. due to the nature of the buffer it's irrelevant if there is old data beyond its limit.

Does anyone know how to compute the upper limit on the number of edges in an Aho-Corasick automaton? While it does find dictionary word in a string in O(n) I'm worried about space use. A trie would consume a lot less space, but would run in O(n*m) (m being length of diction words) because of the need to keep up with with up to m current unterminated partially matched words.

>))))

>I don't know what you are trying to do, but something like that should work.
Now, let’s think about the strategy behind this simple game. The basic steps are as follows:
Determine or set the upper and lower limits of the player’s number.
Guess a number halfway between those two numbers.
If the player says the number is smaller, lower the upper limit.
If the player says the number is bigger, raise the lower limit.

Ugly but it works

filterFunction @"c:\temp" "*"
;;
val it : Item [] =
[|{Name = "AMD";
Path = "c:\temp\AMD";
Type = DirType;}; {Name = "demo";
Path = "c:\temp\demo";
Type = DirType;}; {Name = "Downloads";
}|]

let filterFunction dir freeText =
Array.concat [ Array.map mapDir (listDirs freeText (getDir dir)); Array.map mapFile (listFiles freeText (getDir dir))]

Take your tags and reformat the post.

(define (guess lower upper)
(case (read-answer)
('bigger (guess (1+ lower) upper))
('smaller (guess lower (1- upper)))
(else
(result-is-here lower upper))))

OH FUG.
[-code-][-/code-] tags and remove hyphens and reformat the post.

Where can I find the tags? For example pre tag

Thanks, but I'm not logged in so I can't reformat.

Only code tags, sorry.

and lurk moar newfag

let mapFile (foundFile:FileInfo) =
let f = {
Name=foundFile.Name
Path=foundFile.FullName
Type=FileType
}
f

let mapDir (foundDir:DirectoryInfo) =
let f = {
Name=foundDir.Name
Path=foundDir.FullName
Type=DirType
}
f

let filterFunction dir freeText =
Array.concat [ Array.map mapDir (listDirs freeText (getDir dir)); Array.map mapFile (listFiles freeText (getDir dir))]


I want to make mapDir and mapFile into one method, that shouldn't be that hard should it?

>Thanks, but I'm not logged in so I can't reformat.
You have to go back.

Remove your name. This isn't reddit.

F# is probably one of your better choices if ya come from an OO background I guess, considering if you really feel the need to you can basically use it as C# with minimalist syntax

why are they called mapDire and mapFile?

also, what language? OCaml?
OCaml has row polymorphism so you might be able to do that

More of a fun project so I can learn F# than anything. I plan on making a F# microservice (because why not) and call that from a UI program that will display the results.

I hate thread synchronization.

Well, I'd be willing to bet that thread synchronization isn't particularly fond of you either.

I'm trying to implement mutexes in my kernel, I'm using atomic operations to check-and-set the mutex, yet i'm still getting some desynchronisation, one time a thread took a lock on a mutex that was already locked!

>tfw my programming prof is an old coot who doesn't know python
Best books on C++? I've familiarized myself with the main() and cout stuff. I don't need a book that'll teach me programming all over again, just the syntax and keywords of C++. Something like a reference book, I guess.

also python a CUTE!

Is he teaching a python class?

Learn C syntax, then C++ OOP, templates, etc. will be easier to understand.

A class on programming. Majority of the other kiddos are turning in psuedocode/flowcharts. I want to be
>that guy
and do it all in coding. For one, I already know Python. And imo it's easier to just code the shit out.

Is pic related a good book? It is pretty old.

how do I become a webdev? I can write python

>Majority of the other kiddos are turning in psuedocode
>I want to be that guy and do it in pseudocode that happens to be interpretable

Lofty goals user

kek.

if it's not assembly it's always pseudo code

...

Assembly is the pseudocode too.

You can do it!

beginner-beginner c programmer here

the exercise is so the number you input tells you if the year is a leap year
this is what it says "A leap year is any year divisible by 4, unless the year is divisible by 100, but not 400".

if I do:
if (year % 4 == 0) {
if (year % 100 == 0)
printf("This year is not a leap year.");
else
printf("This year is a leap year.");
}

what am i doing wrong what the fuck

Are you implying that Assembly is low-level?

400 is divisible by 100 as well.
Figure it out on yourself what happens.

I always pseudocode in BASIC.

Transfer to another class with another language and use .IsLeapYear.

&

>no x86 ASM waifu in list
shit pic

>go become a code monkey
nigger, please, we already have enough

Agreed, now that's a woman.

XML is a fucking joke

C is classy and top choice

2old4me

Are you implying this chucklefuck who literally CAN NOT DETERMINE IF A YEAR IS A LEAP YEAR is going to be anything but a codemonkey?

Abstraction: The Biggest Mistake in Programming?

He's learning now, don't bully him.
We weren't born professional fizzbuzzers, we had to learn the stuff.

The greatest success.

PHP, Javascript, Visual Basic, R, and Scala are the best

define abstraction
define """""""""""programming"""""""""""

if i add after the year % 4 == 0 to print that the year is a leap year and % 100 with % 400 (and switch what the printf statement says accordingly) 2000 is a leap year, 2004 is a leap year however 2200 is a leap year now but according to the instructions 100 is divisible by it and 400 is not

what the fuck is this difficult curve in this book

Remembering syntax isn't what makes you a great programmer.
Pseudocode exists for a reason.

Abstraction is not a mistake, but something happened and now lots of people prefer making abstractions to actually programming.

If you can pass your work on someone other, you'll probably do it.
The same with computers, at one moment it became cheaper to spend extra cycles instead of having people to write machine code.
And what would you think, programmers initially were punchcard punchers, when engineers had the real work.

He had his chance to learn at the same time I did. He should have thought about the consequences before he fell behind.

>tfw don't pre-plan my coding projects
>just jump in with a simple hello world and its trial and error after that

This.
Good programming logic is everything you need.

>Pseudocode exists for a reason.
Why? Are you not capable of "thinking in" an actual programming language?
I've never found it to be useful. I always just go straight to code.

>Antifragile programming

thanks for posting anime

> not dreaming in code