/dpt/ - Daily Programming Thread

What are you working on Sup Forums?

Last thread:

Other urls found in this thread:

pastebin.com/FUU1hpmz
stackoverflow.com/a/11816993
pyinstaller.org/
pastebin.com/63UDZTDu
twitter.com/SFWRedditImages

Summer is kill, Sup Forums is kill.

is US ANSI the best layout for programming? it's almost as if it was literally designed by programmers? obviously you amerilards are gonna be in favor of it but even as a swede i think i will get a US ANSI-ish keyboard because the selection of good nordic ISO keyboards is almost non-existent and it seems better and more ergonomic for programming anyway

(do ((num (random 100))
(guess (progn (princ "\nguess number:") (read))
(progn (princ "\nguess number:") (read)))
(count 0 (1+ count)))
((= guess num) (format t "~%correct, took you ~D tries" count))
(if (< guess num)
(princ "\nlolnope, too low")
(princ "\nlolnope, too high")))

Can someone make a post on how to do fixed point math?

step 1
git gud

>\n before line

how do I git gud if theres no gud to see

>reverse the string

#include
#include
#include
using std::string;

//option -1
string ReverseString(string str) {
string result;
for (auto it : str){
result=it + result;
}
return result;
}

//option 0
string ReverseString(string str) {
string result;
for (auto rit = str.rbegin(); rit != str.rend(); rit++){
result.push_back(*rit);
}
return result;
}

//option 1
string ReverseString(string str) {
string result=str;
std::reverse(std::begin(result), std::end(result));
return result;
}

//option 2
string ReverseString(string str) {
string result;
std::reverse_copy(std::begin(str), std::end(str), std::begin(result));
return result;
}

//option 3
string ReverseString(string str) {
string result;
result.assign(str.rbegin(), str.rend());
return result;
}

//option Sup Forums
string ReverseString(string str) {
return string(str.rbegin(), str.rend());
}


Which is the best Sup Forums?

Error: Undefined type []

Functional autistes can't do this
#include
#include
#include
#include

int main(int c, char **v)
{
while (--c > 1 && !fork());
sleep(c = atoi(v[c]));
printf("%d\n", c);
wait(0);
return 0;
}

We know what a sleep sort is asshole.

>asshole

US Dvorak master race!

The accuracy of a non-realtime scheduler's sleep function is generally around 10ms.

do you actually use dvorak or are you memeing? seems hard to beat US ANSI for programming since you don't even have to move to type a semicolon it's on your right pinky (or ring finger if your pinky is at curly braces or something)

Create a class for it.

C's sleep function takes seconds, not miliseconds.

Dvorak is a meme, and the free market knows it. Eat shit autist.

I use [spoiler]C [/spoiler]

...

use nanosleep

make a struct perhaps?

found this(what i'm going to assume is malware) on Sup Forums, does anyone know what it does? I am guessing it's obfuscated but I have never worked with javascript so i wouldn't know.

pastebin.com/FUU1hpmz

str[::-1]

python is a lovely thing

desu
>>> str = "This is in reverse"
>>> str[::-1]
'esrever ni si sihT'

Prelude> let str = "This is in reverse"
Prelude> unwords . reverse . words $ str
"reverse in is This"

>use nanosleep
i'll use TURBOSLEEP

what about stackoverflow.com/a/11816993 this didn't make very much sense though, i just want something to learn right now and i've decided I want to learn this

senpai
(require srfi/13)
(string-reverse "This is in reverse")
;=> ".esrever ni si sihT"

rate my extremely limited verbose and awkward row polymorphism (order is important)

Creates an ActiveX object and uses it to download and run an .exe payload. Probably a virus but virustotal found nothing and I'm not going to run it myself obviously so I can't be sure of what it is.
ActiveXObject only works on IE8 and below though so it's kinda pointless.

lads...

reverse=.|.
reverse 'Fuck this shit'
tihs siht kcuF

Wow, finally someone usefull, thank you.

Repostan

What is the best C build system and why?

>reinhard
kys

I found the thread it was posted in. It's in a downloadable .zip so if you ran it on your desktop it would work and run the file.

Those threads are posted/bumped by spambots trying to spread malware, if you haven't realized it yet.

>types
>in [current year]
function addToSecond(array) {
array[1]++;
}


>inb4 muh purity, muh autism

>c

Literally the best, most useful, most popular language.

that's not the same thing

also
>addToSecond(notAnArray)
>runtime error
>addToSecond(lengthOneArray)
>runtime error

So a lot of people like OOP just because it gives them something to hold onto. A method for designing programs. You construct your classes based on the real world and say 'fuck it'.

So are there any good alternatives to this that I can learn?

FP

i need to build a graphical interface for accessing shit off a server. I want to use python because anyone can download and use python on any computer. I was planning on using TkInter but I don't think that module comes shipped with python, which means it is going to be a bitch to set up for the user (the people I'm making this for are not very computer savvy, hence why i'm making a gui).

If I compile the python script will it automatically import TkInter? That way I don't have to deal with installing TkInter on dozens of machines.

Jshit is just not expressive enough for that.

(defun add-to-second (seq)
(declare (type (satisfies seq-with-2nd-elt) seq))
(incf (elt seq 1)))
(defun seq-with-2nd-elt (seq)
(and (typep seq 'sequence)
(> (length seq) 1)))


There, this should do compile-time computation and prevent code that calls it with a wrong type from being compiled.

Does that satiate your autism?

how can I make my average' function faster?

It doesn't guide you. It's a method for writing parts of a program.

ghc -o2 -threaded -rts-opts=-N4

OOP doesn't guide you, it's a silly method for writing parts of a program

You don't overload the stack with useless data for the sake of muh purity, and switch to a real language.

b-but you can use evaluation in haskell using seq
b-but evaluaiton has nothing to do with purity

You start using state, use SIMD and do threaded programming.
>OOP doesn't guide you
Well it does. It's a poor guide. But I'm looking for a guide that's better.
OOP guides you by arbitrarily saying you should model things after the real world. FP doesn't say anything like that. Procedural programming has nothing like that either.

How does OOP guide you?

>i want to make a calculator
>a calculator is an object and it probably has messages n shit
>thank you for the guidance senpai

OOP is nothing like the real world

Working on becoming a better linux user,
added a plugin to vim for rust syntax highlighting, updating the JDK because I have version without swing.
Simple sounding stuff but I still don't know a lot!

>I want to make a calculator
>I can make an object representing the memory/CPU of the calculator, and input panel object and a display object
>Display object presents the user with the data via rendering
>Input processes user input into a format the memory can accept
>Upon certain input the memory/CPU object handles what it has in memory and creates output which it sends to the display that presents the data to the user every frame
And there we have a calculator.

A calculator is a silly stupid example of course. Should be way simpler. But I want a generic guide. We don't have to discuss how viable OOP is. It's a very common feeling among OOP users though.

Where's the OOP?

You can't seriously say every object is OOP. The word object in C describes an instance of a struct or union. Structs or unions are not OOP objects.

Where's the message passing?
Why did you decide the calculator has memory and CPU? It might not. What makes you think it's got an input panel and not a text input?

Whoops, looks like you need some AbstractInputOutputFactoryInterfaces!

Threadly reminder that if you need comments in order to understand your code then you're not using descriptive enough function and variable names.

can someone explain this, there's a whackton of errors.

can somebody time how long it takes to average 1 to 10000000 in their respective language?

O(1), in pretty much every language.

the thing is, most people write generic functions so descriptive variable names makes no sense

ill test it out for you

>we segmented our problem arbitrary based on our perception of what parts make up a calculator
>computer (cpu/memory), display, input
>we gave them corresponding roles
>everything is done through message passing, input is not directed directly at the place that requires the input.
It's certainly object oriented. Its a terrible method. But in contrast to a sensible procedural solution that'd be something more straight forward it has been a guided process.
>someone talks about time, he responds with big-O
Not a programmer.

>string firstCommandLineArg
>string firstCommandLineValue
>string secondCommandLineArg
>string secondCommandLineValue
>string thirdCommandLineArg
>string thirdCommandLineValue

does i good variable names?

const startTime = Date.getTime()
const average = (1 + 1000000) / 2
const endTime = Date.getTime()
console.log('Elapsed milliseconds ' + (endTime - startTime))

Time to refresh your basic math

Name them after what they do, not what they are

Make two arrays containing the two and just index instead?
Maybe ignore naming until you've found convenient solutions to your problems.

1 to a 1000000, i.e. all the numbers from 1 to 1000000
not 1 and 1000000

You are assuming so much that has nothing to do with OOP.
Deciding that a calculator consists of a cpu + memory + display + input isn't OOP
The only OOP part is the idea that they themselves have "roles" rather than being part of a system that acts upon them, which would give you the exact same thing

The majority of OOP taught today is probably 10% OOP.
The OOP part is shit like desgin patterns.
This is why you get people who think C++ is an OOP language. It's not.

OOP doesn't even need to be procedural, and it shouldn't be. It's just message passing, with potentially ordered messages.

i don't even understand what you want. the average of what? the previous values? the average of i and 1000000 ?


for ( i = 1; i < 10000000; i++ ) {
???
}
.

Lol, you're serious, aren't you?

>CS majors in charge of not being retarded

>OOP doesn't even need to be procedural
Shows that you can't read/don't know OOP. OOP is not procedural period. Which is one of the reasons I contrasted it to OOP.

it's (n+1)/2
even if you summed all the elements and divided by the number:

the sum of [1..n] is n(n+1)/2
the number of elements is n
n(n+1)/2n = (n+1)/2

google
import qualified Data.Vector.Unboxed as U

data Pair = Pair {-# UNPACK #-}!Int {-# UNPACK #-}!Double

mean :: U.Vector Double -> Double
mean xs = s / fromIntegral n
where
Pair n s = U.foldl' k (Pair 0 0) xs
k (Pair n s) x = Pair (n+1) (s+x)

main = print (mean $ U.enumFromN 1 (10^7))

>>OOP is not procedural
>Shows you don't know OOP. OOP is not procedural.

ok you fucking niggers
what if you want to calculate the average of all the primes betwen an arbitrary range
there's no easy formula for that,

user

main = print $ (10^7 + 1)/2

>OOP doesn't even need to be procedural
Rather than
>OOP CAN'T be procedural.
Again, those reading skills are being problematic user.

OOP can be procedural though.
You just enforce an ordering on the messages.

Actually, why is this displaying 85 seconds (85k miliseconds)
clock_t begin = clock();
double average = avg(); //function that does the work
clock_t end = clock();
double time = double(end - begin);

Haven't used this ctime library before.

how about for an array of arbitrary length and arbitrary integers

in the form [1..n] ?

arbitrary integers, so no

I know that you stupid nigger
try to understand that im averaging a list of integers that can be not in the form of [1..n]

*also averaging

2 seconds on google:
pyinstaller.org/

>graphical interface
>accessing shit off a server
>anyone can download and use
java

python 3.4

>Anonymous 08/20/16(Sat)03:08:23 No.56171
YOURE DOING THIS ON PURPOSE AREN"T YOU

rude

I wish I was that clever.

cout

.5

Ok
pastebin.com/63UDZTDu
My attempt. Using O2 on MSVC
Doesn't fit your specification exactly though.
9594 ints.
12520 cycles
1.30498 cycles per int..
I'm not very good at this i think. I'l have to look at the throughput in detail though..

so the last column is in miliseconds?

Last column is the rdtsc timestamp. Basically the processor has a counter it increments every time it goes through a cycle.
My processor says it's a 2 300 000 000hz processor in windows. So straight up trusting that, and assuming my process isn't being messed with in any way.
0.00000544347 seconds
Or
5.44347 microseconds

cpp? or c

This is C++. I'm using a std::vector. But what makes this kinda fast is using SIMD intel compiler intrinsics.

I prefer writing C-like C++ code but for some silly thing like this I just don't care to write my own dynamic array or whatever. So yeah. But it's pretty close to C-code. You could easily rewrite it. Not that it matters because MSVC only compiled C++ anyway.

def histogram(a, qtPasso):
passo = (max(a)-min(a))/qtPasso
final = []
for i in range(0,qtPasso):
resultado = []
for x in a:
if(x > ((min(a)+passo)*i)-1 and x < (min(a)+passo)*(i+1)):
resultado.append(x)
final.append(resultado)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.hist(final,qtPasso,alpha=0.8)
plt.show()

im sorry, i tried to run ur code
but, pic related

Also that first run is a bit slower because there were some cache-line misses. That's likely the most accurate result honestly.

Alright Sup Forumsuys, give me advice and r8 muh gaymen