[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 24
File: 4aX1VW1.png (819 KB, 1282x722) Image search: [Google]
4aX1VW1.png
819 KB, 1282x722
old thread: >>51810647

What are you working on, /g/?
>>
first for second
>>
File: ;D.png (57 KB, 800x334) Image search: [Google]
;D.png
57 KB, 800x334
>>51814176
D
>>
File: wheeeeee.gif (499 KB, 300x250) Image search: [Google]
wheeeeee.gif
499 KB, 300x250
C is so great. I wrote AoC day 6 in C and it came out at 174 lines of code.
I ran the program in valgrind and it gave me over 1,000,000 memory errors.
>>
>>51814240
I wrote it in Lua in 35 LoC :O
>>
>>51814231
How is D, been thinking of picking it up.
>>
>>51814240
This is why beginners shouldn't start with C.
>>
I implemented selection sort in MIPS for a class once. What else can I do to git gud at assembly?
>>
>>51814258
it's well good init
>>
>>51814240
>I wrote AoC day 6 in C

Fucks sake, man. I just gave up on this same problem in python a couple hours ago.

I need a break for my brain, I can't yet figure out how to iterate over a multidimensional array. I've not even considered setting the arrays to 999 yet, it's too damn dangerous given how shitty my code is.
>>
>>51814271
Implement SHA2-512 in assembly.
>>
>>51814288
Just use 2 nested for loops.
Iterating over a 2D array like you would a document in a typewriter.
The outer loops will only increment once the inner loop terminates.

unsigned i, j;
for (i = x1; i <= to.x2; i++) /* x */
{
for (j = y1; j <= y2; j++) /* y */
{
>>
>>51814176
Please do not use an anime image next time, thanks.
>>
Is using a terminal multiplexer less resource intensive than running more terminal instances?
>>
>>51814288
if it's a hypercube of length X and dimension D, simply iterate from 0 to X^D - 1 and convert each number into a base X numeral system
the X-ary digits will be the indices
>>
>>51814373
w-what?
>>
>>51814384
are you stupid
>>
>>51814369
it's 2015
nobody is hurting for a few kilobytes of memory
>>
>>51814369
Probably insignificant difference resources-wise but way better productivity-wise and ease-of-nagivation-wise.
>>
>>51814384
He's actually right

Or you could, you know, use MULTIPLE loops
Who'd a-thunk
>>
>>51814412
That is not what I asked.
>>
>>51814288
post what you got senpai
>>
>>51814339

Yeah, but if the inner loop is supposed to start and end at different positions, would you need three if statements nested in order to keep it on track. Like

["0", "0", "0", "0", "0", "0", "0", "0"]
["0", "0", "0", "0", "1", "1", "1", "1"]
["1", "1", "1", "1", "1", "1", "1", "1"]
["1", "1", "1", "0", "0", "0", "0", "0"]
["0", "0", "0", "0", "0", "0", "0", "0"]


Here it starts on [1][4] and ends on [3][2] but the middle iterates over a full row
>>
>>51814373
>>51814384
>>51814395

X = 5
D = 2
a 5 by 5 array
iterate from i = 0 to 5^2 - 1
(0 to 24)
convert each digit into base 5

0 -> 00
1 -> 01
...
4 -> 04
5 -> 10
6 -> 11
...
9 -> 14
10 -> 20
11 -> 21
...
15 -> 30
...
20 -> 40
...
24 -> 44

each digit is your index


>>51814418
SUBOPTIMAL PERFORMANCE GET OUT
REEEEEEEEEEEEEEEEEEEEEEEEEEE
>>
>>51814384
learn math
>>
>>51813803
I'd like to get the basics down first, then secure a job just in case I ever have to get one and then have all my fun later.

So would you say I should go with Python, Java and then Ruby?

I'm more worried about difficulty than anything, I don't think to highly of my own intelligence so I'm worried I'll struggle so much I give up.

*FOR THE DUDE FROM THE OTHER THREAD*
>>
>>51814447
>suboptimal
It's faster, mate
>>
Is it possible to make a variable an struct object?

Like, let's say I have an struct called "database" and I want to add an object based on the user input (which is a string variable), is there any way to do "database *variable here*" and then modify said custom object's details by doing
stringstream(input) >> variableHere.modifier;
?
>>
>>51814461
>it's faster
if you're shit or using like 2 dimensions
>>
>>51814176
source and pls tell me this is actually some hot chinese or japanese trap/sissy cartoon
>>
>>51814474
I'm willing to bet that a multiplication+addition is faster than a division+modulus
>>
>>51814466
I'm not sure what you mean
Types are (more or less) fixed at compilation in C++
You can't "add in" a member/attribute while the program is running.

What you can do is have an array that can store any number of a certain type, and write a function that takes a string and returns one of the items
>>
>>51814432
just trust me man
2 nested for loops is the easiest way to write this algorithm
>>
>>51814258
I enjoy it
>>
>>51814498
>can't random access jump to an arbitrary point in the for loop
kill yourself
>>
>>51814477
secret princess himegoto
it's literally sexual harassment, the anime
>>
>>51814523
What?
>>
>>51814431

import numpy as np
import itertools

grid = np.zeros( (9,9) )

grid[0][8] = 1 ##random grid cells set to 1
grid[7][1] = 1
grid[4][2] = 1
grid[5][5] = 1
grid[8][8] = not grid[8][8]

lights_lit = 0

with open('input_test6.txt') as f:
for line in f:
line = line.rstrip()
line = line.split(" ")
line.remove("through")
if line[0] == "turn":
line.remove("turn")
line[1] = line[1].split(',')
line[2] = line[2].split(',')

print line

if line[0] == "toggle":
pass

if line[0] == "on":
pass

if line[0] == "off":
pass

for x in np.nditer(grid):
if x == 1:
lights_lit = lights_lit + 1

print grid

print "Total lights: " + str(lights_lit)


I have no idea right now
>>
>>51814477
>>51814525
>>>/a/
>>
>>51814530
i = 12; // skip half of the array
>>
>>51814498
depends on compiler and x used for multiplication/division
mul and div have the same amount of cycles unless the compiler optimizes it to something easier like when x is a power of 2 and some other shit I'm tired and you can inform yourself actually
>>
>>51814542
Here's my day six solution in python. (part two)

I'm curious about day 9 though. Isn't that traveling salesman?

def day_six():
file = open('advent_day_six.txt','r')
lines = [line.strip() for line in file.readlines()]
file.close()
lights = []
for x in range(0,1000):
l = []
for y in range(0,1000):
l.append(0)
lights.append(l)
for line in lines:
tokens = line.split()
if (tokens[0] == 'toggle'): start = tokens[1]
else: start = tokens[2]
start_x = int(start.split(',')[0])
start_y = int(start.split(',')[1])
stop = tokens[-1]
stop_x = int(stop.split(',')[0])
stop_y = int(stop.split(',')[1])
for x in range(start_x,stop_x + 1):
for y in range(start_y,stop_y + 1):
if tokens[0] == 'toggle':
lights[x][y] += 2
elif tokens[1] == 'on':
lights[x][y] += 1
elif tokens[1] == 'off':
lights[x][y] = max(0, lights[x][y] - 1)
lights_on = 0
for x in range(len(lights)):
for y in range(len(lights[x])):
lights_on += lights[x][y]
print("Total brightness: " + str(lights_on))
>>
>>51814578
i = 4;
j = 3;
>>
>>51814583
forgot to mention optimizations for modulus made by the compiler but you get what I was trying to say
you can bet shit on that unless you run it with your prefered options, which may differ from programmer to programmer
>>
>>51814542
i don't even know how to read that

anyways, use an enum for the light state and the operation mode.
do something like this
enum { SZ = 1000 }; /* global arr size */
typedef enum { off, on } light_state;
light_state lights[SZ][SZ];
light_state (*arr)[SZ][SZ] = &lights;
>>
>>51814454
... You still here?
>>
>>51814615
>he uses C unironically
Are you a masochist?
>>
>>51814590
you mean
i = 3;
j = 4;

or do you
who knows because it's more than one number
>>
>>51814645
fuck off
>>
>>51814525
Sounds like an alternate plot to Hayate no Gotoku.
>>
>>51814639
If you're the guy asking, do Python, then C++. Ruby is obscure in the workplace and is far too similar to Python. You could do Java instead of C++, but Python and C++ play much nicer together.
>>
what the fuck happened to the real dpt

>people shilling python
>people not folding their loops
>noone questioning OP's sexuality
>>
>>51814749
The anime faggots took over.
>>
>>51814676
Thank you, I'll get on Python first thing tomorrow, it's 3am now so I don't want to run shit through my tired brain.

Thanks a lot man.
>>
>>51814749
Tell us how "the real dpt" was back in the good old days mate.

Don't forget to include the part where there was literally a Python ad bot in here for months.
>>
>>51814794
an ad bot isn't people
>there are people in this thread right now that actually believe python is not shit
>>
>>51814807

we just think it's good for beginners, because we are beginners and we like it. nobody here is saying it is the second coming of jesus.
>>
>>51814807
Why not make a separate /language war/ general if that's what you love talking about?
>>
>>51814831
it's not good for beginners because it ruins them forever
>>
>>51814791
Yup. Python 3 is what you want. Read Think Python.
>>
NEWFAG LEAFLET:
*** please read ***
>Python
>Java
>PHP
are shit
>>
How come this doesn't work to move files in a subfolder to its parent folder:

import os
import shutil

for foldername, subfolders, filenames in os.walk('.'):
if foldername.endswith(')'):
for f, s, fn in os.walk(foldername):
for fs in fn:
if fs.endswith(').mkv'):
shutil.move(fs, '...')
>>
File: Interviewer.jpg (17 KB, 350x244) Image search: [Google]
Interviewer.jpg
17 KB, 350x244
>interviewer asks you to write a modulo function without using the % operator, modulo member functions or standard library modulo functions

Wat do?
>>
>>51814893
x - floor(x / s)
>>
>>51814893
int mod(int n, int m)
{
while (n > m)
n -= m;
return n;
}


can i have job now?
>>
>>51814918
*s

>>51814927
>while
>-=
holy shit wtfuck
>>
>>51814893
a - (n * int(a/n))
thank you based wikipedia!!!
>>
>feel like programming
>have nothing to work on

fml
>>
File: DPTChristmas1.png (332 KB, 588x390) Image search: [Google]
DPTChristmas1.png
332 KB, 588x390
>>51814961
http://adventofcode.com

Day 1: https://paste.installgentoo.com/view/raw/770a1225
Day 1 input: https://paste.installgentoo.com/view/raw/ae0e09d8

Day 2: https://paste.installgentoo.com/view/raw/a1d7af1c
Day 2 input: https://paste.installgentoo.com/view/raw/75f7f51f

Day 3: https://paste.installgentoo.com/view/raw/0eb17a9e
Day 3 input: https://paste.installgentoo.com/view/raw/5dbccc12

Day 4: https://paste.installgentoo.com/view/raw/e1e9f76c
Day 4 input: https://paste.installgentoo.com/view/raw/ca32e94d

Day 5: https://paste.installgentoo.com/view/raw/70bcb8ec
Day 5 input: https://paste.installgentoo.com/view/raw/9af42714

Day 6: https://paste.installgentoo.com/view/raw/9f864447
Day 6 input: https://paste.installgentoo.com/view/raw/1b9aadb7

Day 7: https://paste.installgentoo.com/view/raw/1c6e7472
Day 7 input: https://paste.installgentoo.com/view/raw/3294b0fd

Day 8: https://paste.installgentoo.com/view/raw/2c33c700
Day 8 input: https://paste.installgentoo.com/view/raw/4a5e19f3

Day 9: https://paste.installgentoo.com/view/raw/ea1bce9a
Day 9 input: https://paste.installgentoo.com/view/raw/da1f96f5

Day 10: https://paste.installgentoo.com/view/raw/ed4e45e9
Day 10 input: https://paste.installgentoo.com/view/raw/39260721

Day 11: https://paste.installgentoo.com/view/raw/1221fa54
Day 11 input: https://paste.installgentoo.com/view/raw/a022514d

Answers: https://paste.installgentoo.com/view/raw/21d38d22
>>
>>51814961
>find something to work on
>start, get bored, stop
>have nothing to work on
repeat
>>
File: stack.png (13 KB, 306x261) Image search: [Google]
stack.png
13 KB, 306x261
I wrote a program calculating the time it takes for a certain glass in a stack like in the picture to fill when you add liguid in the top one and the overflow ends up in the ones below. It took some time but I think I finally got it right.
>>
>>51815009
How did you calculate the surface tension?
>>
>launch program
>no response
>try killing it
>visual studio freezes
>can't kill program in task manager
>realize I'd hit a breakpoint

This is what happens when you don't program while wearing a skirt, /dpt/.
>>
>>51815043
>launch program
>no response
>try killing it
>whole computer freezes
>I fork bombed myself with a tree data structure
>>
File: 1441386181194.jpg (39 KB, 720x575) Image search: [Google]
1441386181194.jpg
39 KB, 720x575
>>51815043
>task manager
>>
>>51814929
>holy shit wtfuck
what's wrong senpai?
>>
>>51815091
slow as fuck shit-tier python-level grad code
>>
>>51815109
>slow as fuck
you can't prove that.
>>
>>51815091
>>51815117

2, 000, 000 % 2
1 million iterations & subtractions
>>
>>51815140
#include <stdio.h>

int mod(int n, int m)
{
while (n > m)
n -= m;
return n;
}

int main(void)
{
printf("%d\n", mod(2000000,2));
}


$ gcc -O2 -ansi -o fuck fuck.c
$ time ./fuck
2

real 0m0.002s
user 0m0.000s
sys 0m0.000s
>>
>>51814258
It's slick but they need a one click ide, no gc by default, and jemalloc for heap allocation so that memory allocation is thread specific and doesn't block.

Right now thread specific heap allocation is MONSTER pain in the ass in C++, especially if you can't link in jemalloc, tcmalloc, Intel TBB, poco, or boost since they all mean bloated shared libraries for a very simple task.
>>
>>51815199
The print would be slowing this down, wouldn't it?
>>
>>51815199
if gcc supports it, show disassembly
>>
I'm about to rip my fuckin hair out.

I have Object A. Object A contains a list of Object B.

How in the name of every cunt suckling fuck mongers do I check that list of Object B's, and if any of a specific field within them matches criteria, add the Object /A/ to a list?
I've been trying every fucking linq/lambda combination I can think of and it just wants to keep fucking returning Object B.
>>
>>51815026
I'm using magical water and there is none.
>>
>>51814288

Multi-dimensional arrays? That's pretty easy in Julia.

m = rand(10,10)
for y=1:size(m,2), x=1:size(m,1)
println(x," ",y," : ",m[x,y])
end
>>
>>51815275
Now do it with 3 million dimensions, each length 1
>>
>>51815199
Why would you not use
int mod (int n, int m)
{
int d = n / m;
return m - d;
}
>>
>>51815218
>>51815217
no optimization on the left, -O2 on the right

http://pastebin.com/1XWRxunL
>>
>>51815287
r = rand()
>>
>>51815329
not 3 million dimensions of length 1
>>
>>51815329
slow as fuck
>>
>>51815342
Why don't you show us champ. Or are you afraid you will look even more retarded than you already do?
>>
>>51815365
You sure about that? With something like this Julia will run WAY faster than python.
>>
>>51815378
platform specific

int arr[3000000];
for (size_t i = 0; i < 3000000; i++)
arr[i] = rand();
>>
>>51814858
Why?

A lot of people have told me to use Python to start with.
>>
>>51815424
Don't fall for the Python cult
>>
File: your stack when.jpg (19 KB, 122x165) Image search: [Google]
your stack when.jpg
19 KB, 122x165
>>51815413
>int arr[3000000];
>>
>>51815442
would you rather I used malloc
>>
>>51815450
well, at least it wouldn't explode in your face when you try to run it then.
>>
>>51815424
Just ignore the people who tell you it's bad.

Java and PHP are memes because they're actually terrible, verbose and broken. Python is a meme because MUH FORCED INDENTATION OF CODE, which is not a real reason for it to be bad. (Braces are redundant shit.)
>>
>>51815458
i did say platform specific
compiler specific too
>>
>>51815469
Forced indentation of code is literal shit. If you don't agree with that, you should leave this thread.
>>
>>51814373
>X^D
Fuck off
>>
>>51815501
holy shit that was honestly completely unintentional
im so sorry
>>
>>51815469
FIOC aside python is literally shit
the only good dynamic languages are the lisps and lua
I'd rather be doing java than this python shit.
>>
File: 1444150333386-0.jpg (76 KB, 640x960) Image search: [Google]
1444150333386-0.jpg
76 KB, 640x960
>>51815458
#include <stdio.h>
#include <stdlib.h>

int
main(void) {
size_t stacksize = sizeof stacksize;
for (;;) {
printf("%zu\n", stacksize);
(void)alloca(1);
++stacksize;
}
return 0;
}
>>
>>51815413
Hey dickhead, 1^3,000,000 is still 1.

Also that will cause a stack overflow by default since most compilers allocate 1MB of stack memory and that array will likely take up 12MB.

I thought you might have been trolling and not have been literally the dumbest person in the whole thread.

Oh and by the way, why would think that Julia couldn't do the exact same thing (except without crashing of course).
>>
>>51815531
Lua is literally good
Why the fuck is lua good, it's got no fucking write to be
fucking lua

at least it's probably fucking slow
>>
File: thanks g.jpg (8 KB, 150x149) Image search: [Google]
thanks g.jpg
8 KB, 150x149
Hey guys I have to use visual studio for some project, and am wondering how to turn on debugging features that display which lines of code caused the crash at run time? I set it to debug mode already.

Anyways I vaguely remember being able to run a program and when it crashed seeing:
"blah blah Deference null pointer  error:
main.cpp line 56: if (*ptr)
[close window button]"


I tried Googling to find the configs, but as you know there's like a billion different config settings for visual studio and I don't know how to narrow my searches.
>>
>>51815563
>at least it's probably fucking slow
nope, it's one of the fastest dynamic languages
>>
>>51815560
yeah you just take arr[0] and done
>>
>>51815563
Lua is blazing fast, actually. It's not all that good, though, being 1-indexed and using dictionaries for everything.
>>
>>51815578
>>51815606

1 indexing is probably avoidable

for fucks sakes

someone tell me a major fault with lua
preferably an irreperable one
>>
>>51815577
#include <assert.h>
>>
>>51815560
Julia is fucking garbage, though.>>51814176
>>
>>51809832
I figured it out. I replaced
    
c <- sequence (ioList)

with
c <-  parallel (ioList)
stopGlobalPool

using the parallel-io package. After compiling with -threaded rtsopts -with-rtsopts=-N, I saw a 3 times speedup. I'm pretty happy with the result.
>>
>>51815610
The use of dicts everywhere. For instance, using keywords in functions is extremely slow because of that.
>>
>>51815616
> Haven't used Julia
> Give no reasons
> B..B..But Julia is garbage even though I know nothing about it and can't say anything to back it up
>>
>>51815639
How do you think python works?

Lua at least has a low latency gc, and LuaJIT is blazingly fast
>>
>>51815639
fair enough, do they not plan on changing that
>>
>>51815615

This was outside of the code and handled by the debugger. I know I can debug code with printfs, asserts, etc, but it was handled by visual studio for me.
>>
>>51815645
Cry me a river, shill.
http://danluu.com/julialang/
>>
>be me
>professor gives us .xls spreadsheet excel file
>try to read and write to the existing file
>don't know how to change certain values in specific location
>decide to create a new .csv file
>recreate the entire spreadsheet with the correct values and what I needed to do to the spreadsheet

It's worth 450 points. How fucked am I?
>>
>>51815666
No, it's a central feature of the language just like lists in lisps.
>>
>>51815692
excel can import csv files (.csv) into its tables.
>>
>>51815702
ha, fucking lua I knew it was shit
if anyone here likes lua they're shit
>>
>>51815691
Anything valid other than a shit blog post from 2013?
Bugs? fixed.
APIs? Multiple dispatch, they're all the same.

Have any ideas of your own?

Have you even actually used it?
>>
>>51815692

We're suppose to do this through c++.
>>
>>51815742
[shilling intensifies]
I see he wasn't lying about the devs' ridiculous cultist mentality.
>>
>>51815773
> Asking for a single original thought
> Must be a cult

I see anything except for copying and pasting is too much for you.
>>
>>51814861
pls help
import os
import shutil

fold = os.path.abspath('.')
for foldername, subfolders, filenames in os.walk('.'):
if foldername.endswith(')'):

for f, s, fn in os.walk(foldername):
for fs in fn:
if fs.endswith(').mkv'):
fil = os.path.abspath(fs)
print(fil, os.path.split(fil)[0])


I get shutil.Error : "%s and %s are the same file"
>>
>>51815815
the print is there for me to debug and is replaced with shutil.move
>>
julia looks alright
>>
>>51815946
>dynamically typed
sorry
>>
>>51815791
>if you don't like it, it means you don't have thoughts!
How much are you paid exactly?
I'll take your tears as my price for having to bear with you.
https://groups.google.com/forum/#!topic/julia-users/GyH8nhExY9I
2 0 1 5
0
1
5

S t i l l
t
i
l
l

N o t
o
t

F i x e d
i
x
e
d
>>
AoC Day 12 out
>JSON
>>
>>51816231
Am I really understanding this correctly?
Just add ALL THE NUMBERS in the document?

Has the author just lost all fucks to give?
>>
>>51816078
But you don't have any thoughts of your own.

What is still not fixed there? Some vague notion of not testing enough?
>>
>>51816231
import std.json;
done
>>
>>51815815
fil = os.path.abspath(fs)

This doesn't give you the absolute path to the file. It gives you the absolute path of a hypothetical file with that name in the current directory (because the argument is just a filename with no directory).

os.path.split(fil)[0] will always be the same as os.getcwd()

If you want the absolute path of the file, you need to use os.path.join(f, fil) (the first element of the tuple from os.walk() is the full name of the directory).
>>
>>51816270
Post a screenshot of the problem?

(If you wrote the json module yourself it would surely be slightly challenging.)
>>
>>51815978
You can put type annotations anywhere you want those checks to take place.
>>
>>51816278
i'm thinking you could just use strtok() and add the tokens if the entire token passes isdigit()
>>
>>51816273
Can you just use parseJSON() once on the file? I'm not sure how to iterate through everything after that
>>
>>51816308
my understanding is the annotations are similar to those of python or php where an error is thrown at runtime if the value passed is not of the expected type. Or is the type safety checked at compile time?
>>
how can i program $700 for a 980ti
>>
>>51816319
Wow that's fucking easy. Day 5 part 2 is kind of confusing me, but that is very straightforward.
>>
>>51816340
It's JIT compiled so it is compiled at runtime, so you have to run it.

Types on the declaration of a function are different though, they check the types but also make use of multiple dispatch.

If types are stable it ends up being very fast.

The best way to write something is to have whatever data you want to run and run a loop that re-evaluates the file you are working on. Then you can work on something with live updates.
>>
java
>>
>>51816391
sounds pretty cool - but I'm too spoiled by static type analysis to switch now
>>
>>51816412
>immutable Strings
>>
>>51816412
>no unsigned ints
>>
File: 4cha.png (16 KB, 725x335) Image search: [Google]
4cha.png
16 KB, 725x335
>>51816339
>>
How do I get strtok to give me the second token?
It gets stuck on the first one.
>>
>>51814176
I feel like a fucking moron because I couldn't find the pattern here, does anybody know what it is?

http://pastebin.com/DELKsMdi
>>
>>51816451
I have something similar, in haskell
getThread :: BoardID -> ThreadNumber -> Chan Thread
getThread board no = do
tell ["Fetching thread: /" ++ board ++ "/" ++ show no ++ "."]
text <- makeRequestSafe (getThreadUrl board no)
tell ["Thread Got!"]
case (eitherDecode (C.pack text)) of
Left err -> throwError (DecodeError err )
Right c -> return c
>>
>>51814373
XDDDD
>>
>>51816431
>>51816437
Both good things, but....

>Type erasure
>>
>>51816474
stirling?
>>
I told my dad I wanted to learn how to become a programmer and he said I was to stupid and I should just hurry up and go work for him at the factories...

How hard is learning to programme? Do you have to be especially smart to do it or can stupid people make good programmers too?

I was going to start with python because I've heared it's the easiest, then work my way through until I know all of the modern languages.
>>
>>51816569
looks like, is there any formula to find an arbitrary Stirling number?

You don't need to answer if you can't be assed to, I'm googling around now.
>>
Im making a game engine but I dont know how to handle animations. Coming out to be a real pain.
Also why arent equations used instead of polygons to draw things. That way resolution wouldnt have a limit.
>>
>>51816614
how good are you at higher level math, and pattern recognition?

if you're bad, the best you can be is a code monkey
>>
>>51816614
Don't let your dad discourage you, it'll take time and effort like anything else. Python's a good place to start, but it's good to know a few other languages depending on what you plan on doing with them.
>>
>>51816614
jesus christ don't learn python it will ruin you forever


>>51816648
triangles are faster
>>
>>51816659
faster to make? because polygons speed deteriorates quickly with the count whereas the equations stay relatively the same.
>>
>>51816614
Python is a modern language. It's easy because it's modern. You can make some great things with python, but you won't really understand a lot of what you're doing with python. It's kind of like training wheels, it helps, but it's slow.
You don't have to be really smart, you just have to be passionate or have a drive to get better.
The best way to learn is to read an introductory book.
If you want to learn Python, which will be a good idea, try Programming Python, or any other O'Rielly book. I've never read a Python book but you can find one easily.
However, learning Python isn't what I would personally recommend.
Another easy language is C. There aren't many rules to learn with C, it's pretty simple of a language, and a lot of languages are based off of it so it will be easier to learn other languages after knowing C.
A good C book I recommend is C Primer Plus by Stephen Prata.
Good luck lad.
>>
Abstracting machine language was a mistake
>>
How the fuck do I get OpenGL to stop just drawing the next thing on top of the last across multiple draw calls? Depth is enabled but it only seems to work on a per call basis.
>>
>>51816672
Read a book kid, none of what you saying makes any sense.
>>
>>51816474
>>51816569
>>51816634

Oh thank the gods
There's no way to find Stirling numbers in O(n) time. I don't feel so absolutely horrible for hardcoding them now.
>>
>>51816750
Are you using transparency?
>>
>>51816776
Alpha is enabled but not being applied.
>>
here's my solution for AoC Day 12: http://www.nask.co/L/TT6r0x1W4N?a=1

do you guys like it?
>>
>>51816614
>all
You can "know" most of the popular ones, but start by getting good at a few. Python is great, but I suggest picking up a compiled language in parallel. C/C++ would be a good choice. C#/Java would be less optimal but still much more useful than only Python.

Basically, scripting languages make things easy but starting with them and moving to compiled languages is harder than the other way around. On the other hand, learning enough Python to do a lot of useful things would be much faster than starting with C/C++. So my suggestion is both.

Also this:
>>51816655
>>
>>51816758
Is the mathematical part too confusing for you?
>>
>>51816614
Why not do both? I worked in a factory and learning to manage production helped so much with learning to develop to a schedule.
>>
AoC Day 12 part 1:
with open("Advent12.txt") as myfile:
data=myfile.read()

currNumber=""
total=0

for i in data:
if i.isdigit() or (currNumber=="" and i=="-"):
currNumber+=i
continue
if currNumber=="":
continue
total+=int(currNumber)
currNumber=""

print total


No idea how I'm going to do part 2

>>51816806
lad pls
>>
>>51816820
Do you seriously want to humiliate yourself? I literally write software that does what you are asking about.

The closest thing to what you are saying are higher order patches. In games you would have to be able to sample them from the camera projection efficiently.
>>
>>51815815
from glob import glob
import shutil
for video in glob("*.mkv"):
shutil.move(video,"test")
>>
AoC Day 12 super autismo edition!
int main(int argc, char **argv)
{
if (argc != 2)
{
printf("usage: %s %s\n", argv[0], "filename");
return 0;
}
FILE *file = fopen(argv[1], "r");
if (!file)
{
perror("Could not open file.\n");
return 1;
}
char *str = (char *) malloc(sizeof(char) * get_filelength(file));
fscanf(file, "%[^\n]\n", str);
int total = 0;
char *token = strtok(str, "[{\":,}]");
while (token != NULL)
{
unsigned len = strlen(token);
unsigned valid = 0;
unsigned i;
for (i = 0; i < len; i++)
{
/* only char allowed is negative sign */
if (isalpha(token[i]) && token[i] != '-')
break;
if (isdigit(token[i]) || token[i] == '-')
valid++;
}
/* if entire string contains valid digits, add to total */
if (len == valid)
total += atoi(token);

token = strtok(NULL, "[{\":,}]"); /* prime pump for next run */
}
printf("%d\n", total);
fclose(file);
free(str);
return 0;
}
>>
File: xmas.png (2 KB, 640x416) Image search: [Google]
xmas.png
2 KB, 640x416
>>51814971
Day 12: https://paste.installgentoo.com/view/raw/4d1d34d3
Day 12 input: https://paste.installgentoo.com/view/raw/a22ea1a7

Answers: https://paste.installgentoo.com/view/raw/fc26cf60
>>
>>51816750
Anyone? Or am I going to have to make something to manually determine which draw calls are nearest and furthest and draw them in that order? Because that doesn't sound like a fun time.
>>
File: Untitled.png (3 KB, 589x568) Image search: [Google]
Untitled.png
3 KB, 589x568
A code snippet.
glBindBuffer(GL_ARRAY_BUFFER, VBO[2]);
glBindVertexArray(VAO[2]);
scale=circleA.radius;
glUniform1f(glGetUniformLocation(shaders.shaderPrograms[2], "scale"), scale);
offset=circleA.centre;
glUniform2fv(glGetUniformLocation(shaders.shaderPrograms[2], "offset"), 1, glm::value_ptr(offset));

colour.x=0.0f;colour.y=1.0f;
glUniform3fv(glGetUniformLocation(shaders.shaderPrograms[2], "colour"), 2, glm::value_ptr(colour));


glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glDrawArrays(GL_TRIANGLE_FAN, 0, sizeof(circleMesh)/20);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
scale=ADirection.radius;
glUniform1f(glGetUniformLocation(shaders.shaderPrograms[2], "scale"), scale);
offset=ADirection.centre;
glUniform2fv(glGetUniformLocation(shaders.shaderPrograms[2], "offset"), 1, glm::value_ptr(offset));

colour.x=1.0f;colour.y=0.0f;
glUniform3fv(glGetUniformLocation(shaders.shaderPrograms[2], "colour"), 2, glm::value_ptr(colour));


glDrawArrays(GL_TRIANGLE_FAN, 0, sizeof(circleMesh)/20);
>>
reminder that haskell is the best imperative programing language
>>
Is anyone here versed in using Squarespace/jquery. I've currently got this code:

<!--Script to change what what item is selected depending on what image was clicked-->
<script>
$(function() {
$('#productThumbnails .slide').click(function(){
$this = $(this);
var idx = $this.index();
var box = $("select").attr('id');
var elem = $("#" + box);

var name = $('option:selected').text();
elem.get(0).selectedIndex = idx + 1;
});
});
</script>


It should change the value in a dropdown box when an image is selected, but there are two problems, the element (dropdown box) is initially undefined when the page loads until it is clicked, and the price/value selected isn't actually detected by squarespace. i.e, if I've selected white from the dropdown box, and click a black picture, it still thinks white is selected...

Please help me /g/, I've read jQuery docs so many fucking times but I don't have a clue how to fix it.
>>
>>51817116
And C is the best functional language, as stated yesterday in /dpt/.
>>
>>51817116
>>51817166
Finally, we are making progress as a community.
>>
File: 1438675205621.png (204 KB, 316x383) Image search: [Google]
1438675205621.png
204 KB, 316x383
>Linux kernel class
>Girl doing a presentation uploads it in .pptx

REEEEEEEEEEEEEEEEEEEEEEEEEE
>>
does anyone recommend a solid tutor site for javascript? semester is almost over and i'm starting to have trouble understanding my last few assignments. time to throw money at the internet
>>
>>51816890
>printf("usage: %s %s\n", argv[0], "filename");
>Casting malloc
>sizeof(char)
>unsigned instead of size_t
>Not declaring i inside the for loop declaration
>>
>>51817212
Missing one
>*scanf on unbounded string
>>
After doing some research on json, dicts and type-checking in python, I-I think I can do AoC Day 12 part 2

Wish me luck lads
>>
>>51817207
>Linux kernel class
Shit, I wish I had one of those
>>
>>51817212
Plus it's a pile of vomit all in main().
>>
File: jime.jpg (16 KB, 480x360) Image search: [Google]
jime.jpg
16 KB, 480x360
>>51817207
>3rd anual free software conference in my university
>libre impress craps out in the middle of presentation
>>
>>51817207
Go be an autist somewhere else. Literally a universal presentation format.
>>
>>51817248
That's fucking bullshit.
Anyone who isn't a complete faggot just uses PDF slides. Nobody needs fucking PowerPiss animations.
>>
>>51817248
>microsoft
>universal anything

Kill yourself
>>
>>51817248
PDF is better (make in PowerPoint and export). No one at computing conferences etc uses fancy animations.
>>
>>51817264
You can't put video or audio in a PDF. Presentations (and computers in general) have moved far beyond simple text streams.
>>
>>51817286
>you can't put video or audio in a PDF
>>
>>51817286
>Presentations (and computers in general) have moved far beyond simple text streams.

Not in computing. Quality conference guidelines forbid this stuff in presentations.
>>
File: child-not-listening-300x200.jpg (10 KB, 300x200) Image search: [Google]
child-not-listening-300x200.jpg
10 KB, 300x200
>>51817286
>Presentations (and computers in general) have moved far beyond simple text streams.

no no no shut up shut up shut up
>>
>>51817286
I don't think I've ever had to put audio or video in a presentation. It's usually just a lazy way to extend it
>>
>>51817286
>(and computers in general) have moved far beyond simple text streams.
Holy fuck that is completely wrong. You clearly don't know anything about computers.
>>
>not doing your presentations by opening up notepad and typing to your audience
>>
What am I doing wrong?
The way I figure, this should be able to invalidate all input contained between brackets and continue to ignore input until it finds a closing bracket.
    char *token = strtok(str, "[\":,]");
while (token != NULL)
{
unsigned len = strlen(token);
unsigned i;

for (i = 0; i < len; i++)
{
if (token[i] == '{')
br_depth++;
else if (token[i] == '}')
br_depth--;
}
br = (br_depth) ? 1 : 0; /* flip bracket flag */

if (br)
{
if (strcmp(token, "red") == 0)
{
red_found = 1;
red_depth = br_depth;
}
}

if (red_found && red_depth == br_depth)
{
total -= bracket_total;
bracket_total = 0;
token = strtok(NULL, "[\":,]"); /* ignore all input */
break;
}
else
{
red_found = 0;
red_depth = 0;
}
>>
>>51817309
The only part of computers that are not text streams is user facing. The massive popularity of the HTTP protocol proves you wrong.
>>
>>51817262
Found
>>51817262
The
>>51817263
Neets
>>
Nobody can push UNIX autists' buttons like a UNIX autist can.
>>
>>51817396
This sorta has me thinking. Why do all the internet things use text? Like JSON and whatnot. It seems much more efficient to do everything with a binary.
>>
>>51817316
>I dint do it no one else should
Literally retarded
>>
>>51817425
Read the whole post retard, I've said why it's dumb
>>
im building a web app based POS system. Is PHP a sutable language or would rails work better?
>choose pasta
>>
>>51817442
Write it in C or Forth for portability.
>>
>>51817442

>Thinking any particular language is more suitable for a particular product than any other

Make your decision based on:

* Knowledge of the language
* Suitability for web applications in general (ie, not C)

People are going to rightfully respond by shitposting about PHP's shortcomings, as they would if you suggested Python or Ruby. But nothing about "a POS system" makes a particular solution better.
>>
>>51817098
Pls help. The only way I can think to resolve this is to make everything one single VBO and that would be both wildly inefficient and basically impossible from a management perspective.
>>
People were posting about how hard and inefficient it would be to allow apostrophes in usernames and still check for profanity (in WoW), so I wrote a for loop that proved it was actually very easy and fun.

Also, just passed my Intro to Computer Science final, so I'm probably not going to have a reason to touch C++ until next semester. What should I do to learn/keep myself limber until Spring?
>>
>>51817474
In the domain of dynamic scripting languages Python and Ruby don't really have shortcomings. Only PHP does.
>>
>>51817477
Never mind I got it. Apparently the shader was baked as fuck. It just works now though.
>>
let's say I have a process called cockMuncher and its ID is 10322

$(pgrep cockMuncher)
should return 10322, but let's say cockMuncher wasn't running and pgrep's stdout was nothing. What is returned then?
>>
I'm creating a .csv file through visual studio using c++. Is there a way to change the width of a column so that it shows the entire data.
>>
>>51817510
>He fell for the visual studio meme
Enjoy your 2 gig hello world.exe.
>>
>>51817494

It's easy enough to bitch about performance.

Although IBM may be set to change that.
>>
>>51817528
They're really all about the same speed for the set of problems that they excel in.
>>
>>51817507
can't you just try it?
>>
>>51817507
It will return a non-0 exit code.

pgrep cockMuncher
echo $?


vs

pgrep bash
echo $?
>>
>>51817474
Im still learning more or less but know enough that each lang has its strong points (PHP being simple as well as ruby) but im looking for a little advice from people who have used them more than me to give some direction. with speed not really being an issue due to it being used from a local server im wondering what the best tool for the job would be.
>>51817494
aside from preformance issues that are not really an issue with this use case, what are the down falls of PHP over ruby? I know enough of both to use wither but need to stick with one and I dont want to start over halfway though this project due to something like variable types not being able to be declared for a function.
>>
>>51817583
I tried to echo it and it echo's nothing.

>>51817594
>It will return a non-0 exit code.

This is where I'm sort of confused. In expressions like (pgrep nonExistingProcess && pgrep existingProcess) I understand that the first command will issue a non-9 exit code and the next command won't execute because of it. But from what I understand
$(program)
return whatever the program's output is. So does it return both? The exit code and the stdout?

in an expression like

until [$(program)] do; blabla; done


let's say the program produced no output, will the condition then evaluate whatever the exit code is?
>>
tfw an 82 step line gradebook spreadsheet.
>>
>>51817679
$ man bash
>>
>>51817679
With a subshell, it will return the exit code of the last command I believe. So e.g.

echo "$(pgrep doesntexist; pgrep bash)"
echo $?


Returns 0, because bash exists.

With your example, I don't believe brackets evaluate exit codes at all. Consider this:

[ $(echo test; false) ]


Even though the subshell exits with a non-0 exit code ("false" is actually a command for this), as a whole it returns 0 because stdout is not empty.

If you want to go off an exit code, just do

until $(program) do; blabla; done


Also, use double brackets.
>>
>>51817755
Reminder that you should never use nested sequences directly and always made a grid data structure.
>>
>>51817771
>
echo "$(pgrep doesntexist; pgrep bash)"

Fuck, disregard that. A better example is
$(pgrep doesntexist; true)
>>
>>51817494
>In the domain of dynamic scripting languages Python and Ruby don't really have shortcomings.
Implicit variable declarations can fuck off. I'll stick with Scheme, thanks.
>>
>>51817417
When dealing with the internet, the time taken to parse or format data is trivial compared to the time taken to transfer it.

Also, with binary, there's a temptation to just use the in-memory representation as the transfer format, which doesn't work unless both endpoints use exactly the same representation (it also risks leaking information via padding bytes).
>>
>>51814240
>AoC
What's AoC?
>>
>>51817941
>>51814971
>>
>>51817941
advent of code

>>51817928
good point
wouldn't my web sites load faster if it wasn't a bunch of text though :^)
>>
>>51817941
Age of Consent, something that pedophiles often like to discuss.
>>
File: 1449756574386.jpg (3 MB, 3264x2448) Image search: [Google]
1449756574386.jpg
3 MB, 3264x2448
>this is what filthy C tard plebs too stupid to understand OOP actually believe
>>
>>51817972
>taking a picture of a screen
>using a complete novice's code to generalize
nice
>>
>>51817972
It's pretty obvious that a beginner wrote that. What the hell does that have to do with anybody else?
Also
>Picture of a screen
>>
>>51817941
Age of Consent.
>>
>>51817993
>>51818004
people in /dpt/ were telling him that it was the way to do it

https://archive.rebeccablacktech.com/g/thread/51784297#p51787418
>>
>>51817972
using interfaces and methods for this only becomes worth it when you would have the switch in multiple places
when you don't, the method declaration are effectively your cases and the interface method lookup the switch.
obviously, when you would have multiple switches like that, the effort of just implementing another interface (writing another "switch" for the already existing methods as cases) is cheaper
>>
>>51818083
void UseItemFromBag(Pokemon *team_member, Items the_item) {
the_item.use(team_member);
}


wow, so not worth it
>>
>>51818120
you need method declarations in another place instead of switches
that was my point
your method declarations behave as "cases" for an arbitrary "switch" defined by the interface
for n = 1, they're equal, and i'd argue the switch is more readable because the switch, the cases and such are in the same place
for n > 1, the version with polymorphism requires a lot less effort
>>
>>51818054
Where?
Also, for a beginner, I wouldn't berate them for that sort of code. Sure, doing it another way might be "better", but for a beginner who is trying to keep things simple, a switch is fine.
>>
>>51818154
>effort
this is only an issue in fucking tard C

if you look at the code of an apple you should know what it does and you should be able to to modify what it does. but if you have it like this you have to search through your entire code base and adjust each instance wherever you use an apple and if you add say a banana you have to jump around in your code base modify it everywhere too.
>>
>>51818154
instead of cases*
you also gain a bit of type safety with polymorphism (you are required to exhaust the cases) which isn't the case for most languages with switch case
quick rundown of what i mean:
http://play.golang.org/p/8D2JFLX8UI
>>
>>51818184
>if you look at the code of an apple you should know what it does and you should be able to to modify what it does
do you do that with the string type in other languages as well?
you're pretty much fucked either way.
in languages that only allow you to add methods to a type from the same package, you won't be able to fulfill your "requirement" later without modifying the original source code
in languages that allow you to attach methods to a type from anywhere, you've got the equivalent of a "COMEFROM" statement, which is very hard to read

>if you add say a banana you have to jump around in your code base modify it everywhere too.
i agree with this, as i said, if n > 1, polymorphism is a lot easier to use
>>
I finally did it lads. 2 part solution for AoC Day 12:

with open("Advent12.txt") as myfile:
data=myfile.read()

def deleteRed(items):
if type(items) is dict:
if "red" in items.values():
items.clear()
return items
for i in items.items():
if (type(i[1]) is list) or (type(i[1]) is dict):
items[i[0]]=deleteRed(i[1])
for c,i in enumerate(items):
if (type(i) is list) or (type(i) is dict):
items[c]=deleteRed(i)
return items

#uncomment the following 4 lines for part 2
#import json
#data=json.loads(data)
#data=deleteRed(data)
#data=json.dumps(data)

currNumber=""
total=0

for i in data:
if i.isdigit() or (currNumber=="" and i=="-"):
currNumber+=i
continue
if currNumber=="":
continue
total+=int(currNumber)
currNumber=""

print total
>>
>>51818229
m8 even if you only have one switch/case where you use the item you're going to have other places in the code where you obtain it like if you find or buy it. a system where you hardcode all items in a big list like that quickly becomes hell to manage. it might work for very primitive games but what if you have special bananas and whatnot, it's going to get out of hand.
Thread replies: 255
Thread images: 24

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.