/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

strawpoll.me/12023125
lazyfoo.net/tutorials/SDL/02_getting_an_image_on_the_screen/index.php
twitter.com/SFWRedditImages

First for C

FunctIonal programming thread:

THANK YOU for using an anime image
You have no idea how grateful I am

About as functional as your spelling

You can fill out a value for the record normally, if that's what you're asking.

Having two separate lambdas with two separate environments isn't what I want here. It's suboptimal and doesn't play nicely with e.g. linear types.

I was about to create a new thread.
I want the (You)s.

Text editor poll continues
strawpoll.me/12023125

I just finished a caesar cipher program in ruby that I got from a a roll thread and it was way harder than it should have been. Mostly because I was going off the learnxinyminutes ruby tutorial to try and refresh myself, so my syntax was off, but also i forgot a bunch of basic shit and I am realizing how much I've lost in a 2 year break.

Don't you know lad? The gook tookaway all of our precious (you)s.

Vim, Emacs and Nano are the only acceptable answers.

>strawpoll.me/12023125
I chose other. I used to use vim, but now I just use pluma because it is default in ubuntu mate and has syntax highlighting, which is all I care about.

quality thread
thanks, OP
No, (You)s are back
here, have one

>Intel CPUs can do AES
Holy moly

...

Ok guys, I need some help. I need to make my program faster, but I just cant figure out how. Here is the problem, I have some numbers sorted like this:
| 7
| 4 8
| 2 5 9
| 1 3 6 10

I have to output a number depending on the input. The input is going to be two integers, think of them as x and y coordinates. The x is how many away from the left I go and the y is how many from the bottom I go. So say x and y are 1 and 1, then I would have to output 5. Now my code works and gets the correct number, but it is too damn slow.
def answer(x, y):
last_num = 1
arr_hold = [[1]]
for i in range(2, x+(y+2)):
reg_hold = []
for j in range(last_num + 1, i + last_num + 1):
if j == (i + last_num + 1) - 1:
last_num = j
if i == (x+(y+2)) - 1:
reg_hold.append(j)
print(reg_hold)
return reg_hold[x]

Is there anything I can do to speed it up?

Forgot to mention, I have to use python.

>no pico
what a fucking joke

AES is just bitwise operations and vector transforms.

this is definitely homework
do it yourself

anyone here on adderall? does it help? I have trouble sticking to a programming book so I haven't really learned anything yet

How is it different from nano?

the '90s ended 17 years ago

6
5
4
3
2
1
c++


this was actually teh language i was hoping would win.

I can promise you it isn't homework. But I do want to solve it.

2050 was 30 years ago

>implying functional difference from nano
Go be a hipster somewhere else :^)

dumb karen poster

>2015 will be 33 years from now
holy fuck that's not better
I will be a fucking old man in 2050

>C# and Java slower than V8 and LuaJIT

Please don't bully karen

Obvious newfag, We only shoot someone down if they don't try.
I am pretty sure there is an algorithm for this, can't remember the name though.

> Not including Ada to the choices
It's like you don't want to be challenged

And you will still be a virgin.

>2015
lel
2050*

...

y u heff 2 be mean liek dis

>implying the year isn't an 11-bit value
>implying you won't be an old man in year 2

def answer(x, y):
last_num, arr_hold = 1,[[1]]
for i in xrange(2, x+(y+2)):
reg_hold = []
for j in xrange(last_num + 1, i + last_num + 1):
if j == (i + last_num):
last_num = j
if i == (x+(y+1)):
reg_hold.append(j)
print(reg_hold)
return reg_hold[x]

pajeets on suicide watch

definitely a little faster, but no where near fast enough. The highest number x or y can be is 100000

the thing is with 2 loops with the range of 100000, will always be slow

so you have to use dynamic programming or some sort of memoization

also, arr_hold is defined but never used

Oops, forgot about arr_hold, I have went through about 10 different ways of doing this over the last couple of hours and this is the fastest I could come up with.

Can't you write everything to a matrix and access by index?

Here's a challenge! >:D
Write a program which, given a string representation of an integer, determines the minimum amount of bits required to represent it.

yes

seems you are challenged already
>minimum amount of bits required to represent it
I don't know what to say anymore

Wouldn't it be faster?

def lmao(value):
value,count = int(value),0
while (value > 0):
count+=1
value>>=1
return count

but that's what he's doing, i'm afraid

Sorry I forgot to say no snarky nihilists please :O
By all means go back to doing nothing with every day of your life ;-)

I'm afraid not.
memetrix = [[1],[2,3],[4,5,6]]
print memetrix[y][x]

I'm actually pretty excited.

function bits( str )
local num = tonumber(str)
return math.ceil(math.log(num)/math.log(2))
end

I don't know this meme. Will it make GNOME stop leaking like crazy?

def nigger(x,y):
x = x + 1
z = x + y
fag = ((z*z + z)/2)-y
return int(fag)

asd = ""
for y in reversed(range(10)):
for x in range(10):
asd = asd + str(nigger(x,y)).zfill(3) + " "
print(asd)
asd = ""

That's assuming the number fits into your numeric type!
*hands your function a VERY long string*

Nope, I actually got the fastest possible
def answer(x, y):
n = x + y + 1
n * (n + 1) // 2 - y

whats this?

Well, this is them putting a toe in the water. It's hardly jumping in. The good news is you have to go out of your way to leak in Rust. Basically you need to either have a reference counted cycle, or do something stupid by using something like std::mem::forget()

>type
>python

hmmm what's python

pls be troll

Looks like Lua can handle up to about 1024bit numbers, after that it's INF

Lua uses doubles for its numbers.

tell me why LLVM is inferior to GCC or the kot gets it

lua 5.3 and up has integers, too, although they are abstracted away.

>GCC supports languages that clang does not aim to, such as Java, Ada, FORTRAN, Go, etc.
>GCC supports more targets than LLVM.
>GCC supports many language extensions, some of which are not implemented by Clang. For instance, in C mode, GCC supports nested functions

>such as Java
GCC dropped Java support

ok

Must be using 2 doubles in extreme size numbers?

I meant to say that it must split very large numbers across multiple doubles (seemingly up to max 16?)

THE OBSERVABLE UNIVERSE!

#include
int
main
(void)
{
printf
("Hello ");
printf
("world!\n");
return
0;
}

The IEEE double-precision floating point number can represent numbers up to 1.7976931348623157 * 10^308. If stored as an integer, this would be 1024 bits.

So, no. It uses only one.

This is a very aesthetic indentation scheme.
Could you show me a FizzBuzz example using it?

Do I want to implement bitwise instructions or shift/rotate instructions for my VM next?

"IEEE 754". Forgot a number.

SOMEBODY CLONED MY SHIT

This is not absolute optimum
That is literally the fastest way possible.

>tfw 4 unique visitors.

Ah, it rounds out the ends

Yes, doubles (and ofc floats too) are less precise at the ends of their range.

Yeah I just got confused about the output one of the scripts made, made it seem like it was a monstrous int. (i printed the original string)

yeah I don't really remember what I was thinking when I posted that already
it's really late and I feel dumb now
I was going for that exact solution at the beginning and it ended up as a cheap hack with for loops
why did I do all that, I don't remember

So's SHA256 and Twofish, but Intel doesn't support either.

SHA256 is not the standard, there is no standard hashing. Twofish is not used.

Bitwise is probably more important.

Blowfish is used a lot?

Mom made an account to cheer you up.

Your mom blows a lot.

Great minds think alike, eh?

No. Nothing besides AES is very used. When other things are used they are used together with AES.
AES has been more audited, but those other ciphers are probably as secure. They are usually just slower.

the NSA did that of course

Stop using one of my images to start a thread on Sup Forums, you autist.

This image has nothing to do with Programming even.

type(5.0 + 1)


why is the type 'float' and not 'int'?
is there an order of operations (beside the obvious) in Python too?

Trying to learn SDL/AnyFuckingGraphicsLibraryForC++AtThisPoint

I'm following this tutorial lazyfoo.net/tutorials/SDL/02_getting_an_image_on_the_screen/index.php
but using a PNG (and so am using the SDL_image library), but the only way the image loads properly is if I fullscreen the window (as in pic related)

Is there an easy way to resize the image/window to make it fit?

Because it would be insane if floats were constantly checked to see if they're integers and then converted if so. 5.0 is a float, 5 is an int.

int gets promoted to a float so that it doesn't lose information. Imagine if you had an operation like 5.7 + 2 and the 5.7 was cast to an int.

that makes sense, thanks lads.