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

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 328
Thread images: 37

File: daily programming thread2.webm (2MB, 600x338px) Image search: [Google]
daily programming thread2.webm
2MB, 600x338px
old thread: >>57508333

What are you working on, /g/?
>>
>>57515556
KILL YOURSELF
>>
Nothing, I'm so desperate for a project but I can't think of what to work on.

nth for sedentary programmer.
>>
>>57515556
how do I make this work
>>> print(3/7)
0

it's python 3.x someone help pls
>>
>>57515651
Cast it as a float before dividing
>>
File: 1458981064480.png (3KB, 161x34px) Image search: [Google]
1458981064480.png
3KB, 161x34px
>>57515651
Works on my machine
>>
File: 2016-11-14-222743_598x391_scrot.png (14KB, 598x391px) Image search: [Google]
2016-11-14-222743_598x391_scrot.png
14KB, 598x391px
>>57515651
works fine
>>
>>57515669
not sure what that means but I gave it a go (not sure if I did it right)
still didn't work
>>> print(float(3/7))
0.0

>>57515676
spooky
>>
>>57515556
Thank you for using an anime image.
>>
>>57515651
You're performing division with integers, so you're getting a a truncated result. You need to cast the numbers to a double or write them as 3.0 and 7.0. Make sure to always take great care in the types of the variables you're dealing with in the future.
>>
>>57515704
Float, not double. My bad.
>>
File: 1475621483640.png (10KB, 570x273px) Image search: [Google]
1475621483640.png
10KB, 570x273px
>>57515651
Are you sure it's python3 and not just python?
>>
>>57515691
Now you are floating the result of integer division (that is 0).

You have to float one of the divided numbers, for example 3. Or just write it as float, for example 3.0
>>
>>57515704
>>57515730
>>57515735
Python does that for you. It should work fine:
>>57515676
>>57515685
>>57515732
>>
Best allocator library for C?
>>
>>57515669
>>57515676
>>57515685
>>57515704
>>57515732
>>57515735
alright I got it working lads thanks for the help
>>> a = 3
>>> a = float(a)
>>> b = 7
>>> b = float(b)
>>> print(a/b)
0.428571428571
>>
>>57515784
Try to do this
print 3.0/7

post what comes up
>>
>>57515781
cstdlib
>>
Will I get attacked by SJWs if I commit the following code?

enum gender_identity {
SEX_MALE,
SEX_OTHER
};
>>
>>57515808
>>> print (3.0/7)
0.428571428571
>>
>>57515556
Constructing graphs in memory from a string of 2 sets of tuples for my machine learning suite.
This program started so nice and simple on a sheet of paper... the code itself however is a monster.
>>
>>57515884
no, you would be praised
>>
>>57515895
Bitch did I say to put in the parentheses?
>>
>>57515884
Pretty sure you're getting gender and sex confused.
>>
>>57515929
What is gender if it is not sex?
>>
Learning about types in Haskell

triple :: Integer -> Integer
triple x = x * 3
>>
>>57515929
they're the same thing

otherwise, your decoupling of sex and gender allows you to make stupid concatenations of language such as girl (male).
>>
>>57515915
my bad tried it again without them, same output
>>
>>57515960
You're running python 2 you flaming faggot
>>
>>57515953
>>57515958
This isn't according to me, it's according to public opinion:

Sex = biological
Gender = chosen presentation

You can be male, but have a feminine gender, apparently.
>>
>>57515956
Use Num instead of Integer.
>>
>>57515969
I've got both installed, should I have uninstalled 2 before installing 3?
>>
>>57515929
Pretty sure you're getting sjw propaganda and intelligent thought confused
>>
File: nani.png (304KB, 722x768px) Image search: [Google]
nani.png
304KB, 722x768px
I want to take advantage of SSE in my C programs, should I use learn to use the SSE registers directly or use the intel intrinsic headers?

Because the latter looks pretty ugly.
>>
>>57515978
>chosen presentation
WTF is that? If I decide to be a penguin I am a penguin? That's moronic.
>>
>>57515989
Everyone has both installed.

 python 
runs Python 2.x
 python3 
runs Python 3.x

Same thing I said here >>57515732
>>
>>57516003
The former is going to look much worse.
>>
>>57516003
>use inline asm
>>
>>57515884
Use strongly typed enums for the love of god.

enum class gender_identity {
MALE,
OTHER
}

// now you have two (scoped!) values
gender_identity::MALE
gender_identity::OTHER
>>
>>57516009
shit my bad I assumed it would just use the most recent version, is there something I should put in my script to declare they're python 3?
>>
>>57516016
C doesn't have that tho.
And I don't feel like simulating namespaces for enums, I'd much rather just accept sex as a boolean value.
>>
>>57515884
typedef gender_identity float;

Correct one.
>>
>>57516033
 #!/usr/bin/python3 
right in the front

Run with either
chmod +x file.py #makes file executable. only has to be run once per file
./file.py

or
python3 file.py
>>
>>57516009
Nope

python2
runs Python 2.x
python3
runs Python 3.x
python runs the distribution default python, in case of Debian it's 2.x, in case of Arch it's 3.x
>>
>>57516051
>arch
>relevant
>>
>>57516049
>
 #!/usr/bin/python3

I'm assuming this is only for linux users?
>>
>>57515960
Holy shit what a moron
>>
>>57516076
It's futistic.
Eventually all of /usr/bin/python will be linked to python3.
Don't rely on the opposite, it's going to change someday.

>>57516090
No, that's for all Unices.
>>
File: vegeta.png (337KB, 640x360px) Image search: [Google]
vegeta.png
337KB, 640x360px
Say I want to change jobs next year.

If I have a year to prepare, what should I do?
>>
>>57516109
>No, that's for all Unices.
No. The portable way is to invoke /usr/bin/env python3, because the location of the interpreter/symbolic link to it varies across the systems.
>>
>>57516109
>No, that's for all Unices.
I'm assuming unices is another word for unixs so is there anything I should add for windows users or should I just leave it?
>>
>>57516114
You should probably obtain the skills and certifications for your desired job.
>>
>>57516179
Well I don't have a job in mind. I've been told I've been nominated for a promotion next year. I want to improve so that if I want to make a lateral shift next year then I can.
>>
I'm moving from Codeblocks to cmake for better portability, but what the fuck, makefiles don't support multiple build targets?

Why is it so goddamn hard to find good tutorials for cmake anyway?
>>
>>57516325
just write a single makefile, it's much more rewarding
>>
>>57516336
You mean to generate a different makefile with cmake for debug/release?
>>
double func1(x, y){
double sum = 0.0;
sum = x/ y;

return sum;

}
double func2 (a, b){
//sum from the first function

double total = 0.0;

total = sum + a + b;

return total;
}


how do I get the result from the first function so that I could use it in the second function? ..
>>
>>57516357
No, just create a separate target
add a target like "release" and replace some build flags to distinguish from development builds.
>>
>>57516357
http://stackoverflow.com/a/1080180/3105260
>>
>>57516378
>
sum = x / y

I think that's a quotient
>>
>>57515651
Just type print(3.0/7.0), that way it knows they're floats...
>>
>>57515556
OP's image is incorrect, sizeof is a compile time operator, unless it's applied to a variable length array. She was called a struct, not once a VLA.
>>
File: canuck-the-cuck.jpg (109KB, 650x650px) Image search: [Google]
canuck-the-cuck.jpg
109KB, 650x650px
QUCK, CREATE A LIST THAT CONTAINS THE NUMBERS 1 THROUGH 10 AND PRINT IT TO THE CONSOLE IN AS LITTLE CODE AS POSSIBLE OR BIRDO HERE IS FUCK OUR SHIT UP!!!!!!
print([x for x in range(1, 11)])
[/cdoe]
PLEASE BE PLEASED BIRDO!
>>
so in python I have something like
def one():
option1 = input("> ")
two()
def two():
print(option1)

one()

I get
NameError: name 'option1' is not defined

any one know what I've done wrong?
>>
>>57516483
What about a variable length array of structs?
>>
>>57516494
BIRDO, IT WAS A TYPO, PLEASE BIRDO DON'T HURT ME.
>>
>>57516378
Not exactly sure what you're trying to do, here are my answers to what you might be asking:

1) You're trying to add x/y+x+y, then just call func1(x,y) + x + y

This seems way to simple for you to be asking how to do this, so what are you really asking?
>>
>>57516494
int i = 1
while (i < 11)
putchar(i++ + '0');
>>
>>57516494
You didn't say language, so here is it in R:
1:10
>>
>>57516494
echo {1...10}


Can't beat that
>>
>>57516494
[1..10]
>>
Have any of you tried "Aurous" app before it got shamed?
>>
File: anal beads.png (3KB, 277x187px) Image search: [Google]
anal beads.png
3KB, 277x187px
>>57516494
Kinda pointless depending on how much abstraction is built into a language, and what people use for their own personal toolbox libraries.

Range(1, 10).ForEach(WriteLine);
>>
>>57516549
well shit, might as well fix it
echo {1..10}
>>
>>57516495
you are defining a variable in a function, so it is only available to that function. Either declare it outside the function, make it global(which is not recommended) like so:
def one():
global option1
option 1 = input("> ")
two()
def two():
print(option1)

one()

or give two() a parameter like so:
def one():
option 1 = input("> ")
two(option1)
def two(option1):
print(option1)

one()
>>
>>57516378
Just call it in the second function.
e.g.
double func2(a,b){
piss = func1(10,12);
}
>>
>>57516555
you gotta print(it)
>>
>>57516589
Repl
>>
>>57516574
whats bad about global and if I had two options would I separate them with a , ?
>>
>>57516571
Golfing in the shell
seq 10
>>
>>57516494

(1..10).each { |i| puts i }
>>
>>57516616
The data in your program ideally is on a need-to-know basis.

If the rest of your program doesn't care about that value, it shouldn't know that value even exists.

This prevents hard-to-find state changes, among other things.
>>
>>57516628
The ultimate golf
0 bytes

You have to put it in a file called "10" and call it with the interpreter "seq".

What do I win?
>>
>>57516494
print "@{[1..10]}\n"
>>
File: ku.png (17KB, 900x900px) Image search: [Google]
ku.png
17KB, 900x900px
What programming books and anime does /dpt/ recommend?
>>
>>57516661
Think I'm going to use global since ever def needs to know every value
>>
>>57516723
dumb frogposter
>>
>>57516616
basically what >>57516661 said.
Also it keeps memory filled that doesn't need to be. And yes, you would separate the two parameters by commas. If you need some inspiration on projects or maybe just need some info on how things work, here is a little project I made showing what python can do:
http://pastebin.com/LqBwd0ag
>>
>>57516725
Don't do that, just don't declare the variable in the function.
>>
How do I write a userscript to rewrite all urls on a page?
>>
>that tfw feel when you get most of your config file parsing and saving out of the way and get to work on other shit
>>
File: 2016-11-14-235915_623x337_scrot.png (14KB, 623x337px) Image search: [Google]
2016-11-14-235915_623x337_scrot.png
14KB, 623x337px
/dpt/-chan, daisuki~~

>>57516494
>tfw better at python than pythonists themselves.
>>
I want to learn Clojure but I don't have any ideas to create a useful project (this is the best way I stay interested).

I do have an idea for an app I'd like to create and I want it to be cross platform. Someone suggested Clojurescript + nwjs, which sounds OK to me, as Java/Clojure GUIs seem to be shit. But I'm no web developer so it seems like too much to learn at once (Clojurescript, node/js, figwheel, react, etc).

Which should I concentrate on learning first?
>>
>>57516812
Why? Just use a library.

Like this one: http://www.hyperrealm.com/libconfig/
>>
>>57516845
too much don't need it
>>
>>57516830
Can you make it a website or does it have to have some more access?
>>
File: wow anon.jpg (78KB, 884x574px) Image search: [Google]
wow anon.jpg
78KB, 884x574px
>>57516812
>not using a homoiconic programming language from the Lisp family.
>>
>>57516860
Too much of what?
>>
>>57516878
It's a dependency. That's too much, my program is small.
>>
File: braveclojure.png (104KB, 900x900px) Image search: [Google]
braveclojure.png
104KB, 900x900px
>>57516830
http://www.braveclojure.com/
>>
>>57516494
map(print, range(1,11))

Why doesn't python have syntax to force evaluation of lazy constructors? I suggest
*map(print, range(1,11))
>>
>>57516889
That's just retarded.
I can import many python libraries for a couple of lines of script
>>
>>57516861

It could be a website, but I prefer desktop apps.
>>
>>57516898
see >>57516822

[*map(print, range(1,11))]
>>
>>57516905
I'm not using python, I'm using C++

My parser is one source file and a header, if I can do that without a lot of effort and with decent efficiency I'm going to over adding an entire new dependency hell for the different distros others are running
>>
The more I study cmake the worse it seems. Should I just stick to my IDEs' project files?
>>
>>57516935
Surely it can't be worse than GNU autohell
>>
>>57516910
Why would you use nw.js then? It's just Chromium, you are using the same HTML.
>>
>>57516949
I know it's irrational, but it doesn't feel like a website.

Can you recommend a better alternative then? Everything I've seems to point to using Swing (Seesaw) in Clojure. Surely there's a better way...
>>
>>57516925
https://github.com/dropbox/json11/blob/master/README.md

Just git submodule it.

Why are you doing duplicate work, I don't get it.
>>
>>57516948
Mainly it has a terrible Codeblocks project generator, which is the IDE I'm using

Heard it works better with VS
>>
>>57516987
>submodule the entirety of a relatively large library
>deal with writing up the different licenses and disclaimers to make it compatible with my work
>rewrite build scripts and add in functionality to code
>all for about 15 lines of code
>don't learn a thing in the process

lol sorry didn't realise I stumbled into stackoverflow
>>
>>57516979
I would recommend making it a single-page web application. The web is the future, and Clojurescript exists for a reason.

It will feel like a website when creating it anyway. You could always "port it" to the desktop by copying it to a Electron/nw.js app.
>>
File: Bobby Cannavale.jpg (14KB, 247x394px) Image search: [Google]
Bobby Cannavale.jpg
14KB, 247x394px
> go to shitty state school for CompSci and Math
> got a pretty good job 3 months out of school at a unicorn

> little brother goes to similarly shitty state school for Environmental Science
> now works in a factory 6 months out of school
> asks me how to become a programmer so he can move out of parents house

Who /rightdecision/ here?
>>
My bot is making progress.
>>
I've been trying Common Lisp recently.

One thing I don't understand is how do I read argc/argv? Seems like there's a way to read the POSIX argv, but I'm not sure how I'm supposed to use it at all.
>>
>>57517046
I was going to ask about "porting" it like that when I made my first post actually. It removes one of the learning steps, I guess, but still have to get my head about reagent or whatever's trendy these days as well as clojurescript. They assume JS knowledge when you're reading the docs on these things, and I have none.

So then I think maybe I should learn JS first so I can understand why React (and therefore Reagent) is a good idea.

But I just want to learn Clojure.

Analysis paralysis, I think this is called.
>>
>>57517090
Oh, I should mention that I'm planning to compile the thing to a single binary with sbcl (using the save-lisp-and-die method).
>>
File: eff.jpg (47KB, 1067x600px) Image search: [Google]
eff.jpg
47KB, 1067x600px
How do I program a gf?
>>
>>57517041
>>relatively large library
>one header and one source file
>>deal with writing up the different licenses and disclaimers to make it compatible with my work
>MIT
>>rewrite build scripts and add in functionality to code
>literally just
#include

>>all for about 15 lines of code
>not getting the power of the single compatibile file format, that is JSON
>>
>>57516822
You're not the real one. Stop impersonating senpai!
>>
so in python I want to do
>enter your first and second values
>1 2
so can I make it with one input I can have two values separated by a / or a space?
>>
Learning how to code, lads.

Is JavaScript a good first language to learn?
>>
File: A7NsC.gif (60KB, 1024x874px) Image search: [Google]
A7NsC.gif
60KB, 1024x874px
>>57517114
Already done it, learned a bunch about the stdlib in the process, did not have to write in a single #include from anyone else's code, have not had to adopt a cancerous file format that changes over time. Sorry dude but I'm not going to download your library lol
>>
>>57517140
Yes, once you get good at it also move on to Java.
>>
>>57517165
Are they pretty much the same thing?
>>
>>57517111
while(true) ; do
echo "You will never be loved ;_;"
sleep 1
done
>>
>>57517171
entirely unrelated by every single aspect other than the fact that they're programming languages and both have "java" in the name out of sheer retardation on the creator of javascript's part
>>
File: 1475775680718.png (319KB, 505x413px) Image search: [Google]
1475775680718.png
319KB, 505x413px
>>57517140
>Is JavaScript a good language
hmm
>>
>>57517138
a, b = input("enter your...").split()
a == '1'
b == '2'


You can also call split with an argument, refer to the docs.
>>
>>57517190
thanks <3
>>
>>57517177
>C-style syntax
>Garbage collection
>Objection orientated
>>
>>57517171
just like a car and a carpet
>>
>>57517177
No

>>57517171
They're complety equivalent but JavaScript is a scripted version of Java. Obsiously my answer is the best ignore the other angry faggots
>>
http://www.businessinsider.com/what-is-rokos-basilisk-2014-8
>>
>>57517205
he will learn about this in time but for now it is best not to delude the man into thinking they're somehow interchangeable
>>
File: yodabait.jpg (147KB, 500x378px) Image search: [Google]
yodabait.jpg
147KB, 500x378px
>>57517218
>JavaScript is a scripted version of Java
TROL
>>
>>57517205
>>C-style syntax
>>Garbage collection
A lot of languages those days share these traits.
>>Objection orientated
Javascript couldn't even inherit properly until ES6.
>>
>>57515556
decentralized TV system
>>
>>57517341
haha is this daniel?
>>
>>57517341
You stole my idea :^)
>>
Going to program a meme generator
>>
Am I just retarded or something?
>>> a = range(1,10)
>>> b = str(a)
>>> c = "odds" + b
>>> print(c)
oddsrange(1, 10)

Ideally I want the output to be
odds1 odds2 odds3 etc.
>>
What do you guys think of this fibonacci program I just learned?
Trying to get better every day.

public int fibonacci(int n) {
if(n < 2)
return n;

int [] array = new int [n+1];
array[0] = 0;
array[1] = 1;

for(int i = 2; i <= n; i++)
{
array[i] = array[i-1] + array[i-2];
}

return array[n];
}
>>
>>57517557
for n in range(1, 10):
print('odds' + n)
>>
>>57517557
alternatively
a = range(1, 10)
c = map(lambda n: 'odds' + n, a)
print(' '.join(c))
>>
>>57517583
>>57517605
thanks
>>
Is there something as simple as System.exit(0); that would just restart the program rather than exit completely?
>>
>>57517567
Effectively inefficient.
>>
>>57517642
If this is C++, then you can throw an exception that is caught at main(), and then restart it from there
>>
>>57517642
Yeah, just call exec with the same arguments as main.
>>
need some help fellas, working on a project concerning csv files and dictionaries. I'm going to try and strip the context out of my question and just show the bare bones of what I'm trying to do, as I'm pretty bad at explaining. I'm stuck on how I would do the following.

So I have a list with strings like this:
[' "a", "b", "c", "d" ', ' "a", "e", "f", "g" ']
And I have a for loop reading the list, and splitting by the newlines. Essentially reading through as :
[' "a", "b", "c", "d" ']
[' "a", "e", "f", "g" ']

How would I make a dictionary where it would be formatted as:
{'a': [('b', c, d), ('e', f, g)]}
note: reason for some why dont have quotes is that they need to be ints/floats for the output, altho I know how to do this aspect.

Hopefully I explained well enough?
>>
https://docs.python.org/3/library/stdtypes.html#str.split
>>
>>57517658
How so? I know that I can reduce the array size to 2 using mod 2.
>>
>>57517662
java
>>57517674
mind giving me an example?
>>
>>57517706
Instead of storing everything, you can just store the last three in an array, and slide the variables down one position and update the latest with the new one.
>>
>>57517583
>>57517605
think I legit might have a disability
def bet_num():
a, b = input("> ").split()
a = int(a)
b = int(b)
for n in range (a, b):
c = ('odds' + n).split()
print(c)

    c = ('odds' + n).split()
TypeError: Can't convert 'int' object to str implicitly
>>
>>57517741
You mean like what I just said? Using mod 2 to toggle between two places in the array?
>>
>>57517567
If you're trying to memoize by storing every result calculated, you'll need to make the array static and make a couple other changes.
>>
>>57517780
yeah, I don't see how modulo as anything to do with it
>>
>>57517674
>>57517738
Actually, I figured it out thanks
>>
>>57517749
str(n)
>>
>>57517780
>>
>>57517678
Reposting my problem, this time with syntax. (Hoping I use the tagged right).

 dict = {}
f_ref = open(filename)
str_cont = f_ref.read().split("\n:")
for line in rang(1, len(str_cont)):
line_split = str_contents.split(',')


so again, essentially if someone where to give me a file formatted as:
"a", "b", "c", "d"
"a", "e", "f", "g"

how would I finish my code to give me an dictionary output like {"a": [("b", c, d), ("e", f, g)]}? Ignore the fact some of my output variables have quotes and others dont and the fact my range starts at 1.
>>
>>57517790
Yeah I should have made it static looking back at it. What else should I have changed?
>>57517796
array[i%2] = array[i%2] + array [(i+1)%2];
To toggle between the two spots on the array.
>>
>>57517827
changed it to
def bet_num():
a, b = input("> ").split()
a = int(a)
b = int(b)
for n in range (a, b):
n = str(n)
c = ('odds' + n).split()
print(c)

now it outputs
['odds9']
instead of
odds1 odds2 odds3 etc.
>>
PROJECT DUE AT MIDNIGHT, IM FUCKED SENPAI. HOW DO I PRINT HELLO WORLD IN PYTHON? SO FAR I HAVE THIS.

 hello world.print() 


I KEEP GETTING INVALID SYNTAX ERROR. FUCK.
>>
>>57517921
>HOW DO I DO THE MOST SIMPLE THING IN THE MOST GOOGLEABLE LANGUAGE ON EARTH
hard to say
>>
>>57517921
Why are you trying to access a member function of an undeclared object?
>>
>>57517885
the full script (http://pastebin.com/F6J4tQJR)
I should mention I want it to allow the script to have as many inputs as the user wants so like they can type 5 and it'll ask them for the names of the 5 bets, the odds of the five bets, the stake of the 5 bets then it'll print all the bets and what the winnings would be - if that's incredibly difficult or impossible I'd like it to loop or something and the user picks how many times it loops before it prints all the betting information I'd even settle for the script just restarting itself X times
>>
>>57517992
I think you've just been meme'd
>>
File: cute anime pic 0493.jpg (38KB, 362x346px) Image search: [Google]
cute anime pic 0493.jpg
38KB, 362x346px
How do you lads pronounce xor?
I say ksor
>>
>>57518021
Nah, but >>57518004 has.
>>
>>57517921
def hello_world:
if(! __main__) exit(print(error_message()))
elif(print() and __main__) print(hello.world())
else:
exit(1);
>>
    char *text;
static char formal[] = {'T', 'h', 'i', 's', ' ', 'y', 'o', 'u', 'r', ' ', 'i', 'n', 'v', 'i', 't', 'a', 't', 'i', 'o', 'n', '.', '\0'};
formal = *(formal+3);
text = &formal[2];

AY SENPAI, assignment due at midnight, why the fuck isn't this running, this is code provided by the prof thats already supposed to be running, but he is a senile guy that makes a lot of mistakes.
>>
>>57518063
formal = *(formal+3);

You're pointing formal to the numeric value of 's', which is an error. Don't use the * operator in the third line
>>
>>57518034
Ex-or, or Zor
>>
>>57518034
X-KLUSIV
OOOOORRRRR
>>
>>57517567
What he meant was you were storing every single Fibonacci number (n+1 numbers) when you only wanted the last one.
You could, instead, store three numbers plus a counter.
For example:
#include <iostream>

int main(){
int i[4] = {0,0,1,0};
std::cout << "Enter number of fibonacci numbers to print: ";
std::cin >> i[0];

while(i[0]>0){
i[3] = i[2] + i[1];
i[1] = i[2];
i[2] = i[3];
i[0]--;
}

std::cout << i[3];
}
>>
>>57517921
I got you.

#Haiiiiii ^_^

#This program will show "Hello World!" on your screen :DD

#Follow the instructions very carefully or things might go south xD tee-hee

print("eyo senpai got any ganja")

#There you go!!

#<3 <3
>>
C primer plus(6th edition) or C programming : modern approach ?
>>
>>57518152
I mentioned that earlier a couple of times. I could just have used an array of size 2 and toggle between them.
>>
I'm downloading emacs for the first time ever. i'm supposed to be at work in 7 hours.

what's wrong with me?
>>
>>57518163
Modern Approach.
>>
>>57517111

Just make a program that goes into your bank account and spends all your money on useless shit.
>>
>>57518163
Modern Approach
Heard the other one was good, but I never read it
>>
>>57518034
kzor, like the hard z sound.
>>
>>57516830
If you're wanting to learn Clojurescript, look up reagent. It's React with hiccup syntax (start a vector with :div, and it will return a <div> content </div> etc)

Can recommend (It's what I started with)
>>
I'm good, not great at python. Taking a course on c (pretty sure its c) next semester. Is being "just" good at this stage troubling? My major is ee and thats all the cs I'll need to take at my uni.
>>
>>57518325
Yep, have already had a quick play with reagent. I like the hiccup syntax a lot. Need to figure out components, though. I don't get them yet.

Currently going through the brave clojure book someone recommended up thread. then will start with cljs after that I think.
>>
>>57518341
ee learns code so you can write drivers for hardware if needed. most ee are really shit at it, as it takes a long time to git gud.
everyone sucks, so don't worry about it
>>
File: 1382116870201.jpg (30KB, 640x575px) Image search: [Google]
1382116870201.jpg
30KB, 640x575px
>>57518187
>array[i%2] = array[i%2] + array [(i+1)%2];
>array[0] = array[0] + array[1]
>array[1] = array[0] + array[1]
>It actually works
I'm actually surprised, Anon.
>>
Learning Java for 1 month now, looking good, nice progress... doing the MOOC course, almost finished it.

I was thinking to move to Android development next, with Google's Android IDE.

But a friend recommended me to switch to C# and join him and a friend with a Unity project on C#

I'm conflicted because on the one hand, I'm really an anti-Microsoft kind of guy but on the other, I think I'd learn a ton from joining them making those games on C# , them constantly correcting my code and teaching me... they are comitted to 3 hours a day doing this

what would you do /g/ ?

I should add that I'm not even sure I want to be a game dev, I guess I just want to be an all around dev probably specializing in mobile apps
>>
>>57518384
Components update whenever a referenced atom changes. During compile it notes which atoms a component references, or that's my understanding anyway.

I'm currently making a combined ring server backend with reagent frontend, with .cljc files in the middle (cljc files can be read as both .clj and .cljs). You can define your model and structure manipulators, then call those functions from both. Google closures will cull unused functions at production time (lein cljsbuild once min)
>>
>>57518434
idk about mobile since android is java and apple is swift?
but C# is java done right.
>>
>>57518465
That makes sense, thanks.

How long did it take you to get to where you are? What other experience did you have?
>>
>>57518434

what course mate?
>>
>>57518194
>>57518203
Thanks!
>>
>>57518497
It's been about a year of casual clojure (uni eats up most of my time). If I was doing it full time it would be about a couple months total. Other experience is just screwing around with code generally, plus uni code (c and java).

I would highly suggest watching Rich Hickey's talks, they're very illuminating. Also, if you're having trouble remembering your data structures (so many nested maps), check out clojure.spec in the current alpha. It's stable, and you can specify your data structure plus assert an in item matches said data structure in a {:pre :post} function map. Extremely good for when you walk away from a project then come back and go "how the fuck is this thing structured again?"

[spoiler]I have to head to an exam, but message me at https://github.com/lsenjov and I'll help wherever I can[/spoiler]
>>
>>57518570
I forgot spoilers aren't active on /g/, fuck it.
>>
>>57518570
cheers man, good luck!
>>
>>57518418
I was too when I learned about memoization and dynamic programming today.
>>
>>57518534
University of Helsinki, excellent Java Course
http://mooc.fi/courses/2013/programming-part-1/
>>
>>57518640

Thank you. I'm into pluralsight path to Java but i see here are a lot of tests which is great for learning.
>>
>>57518187
Also, I would suggest a better way of toggling between them would be to use a boolean... but then I tried it myself.
Java doesn't let you use true and false as 1 and 0.
You instead end up with:
public static int fibonacci(int n){  
int [] array = new int[2];
boolean b = false;
array[0] = 0;
array[1] = 1;

while(n>0){
if(b) array[1] = array[1] + array[0];
else array[0] = array[0] + array[1];
n--;
b = !b;
}

return array[b ? 1 : 0];
}
>>
>>57516494
'(1 2 3 4 5 6 7 8 9 10)
>>
>>57518011
alright heres what I've done for some reason it's looping infinitly and I'm not sure why
#!/usr/bin/python3
def start():
global x
print("How many bets would you like to calculate?")
x = input("> ")
x = int(x)
inputs()
def inputs():
print("Please enter your odds '10/1'")
odd1, odd2 = input("> ").split('/')
odd1 = float(odd1)
odd2 = float(odd2)
print("Please enter your stake '10'")
stake = float(input("> "))
maths(odd1, odd2, stake)
def maths(odd1, odd2,stake):
odds = odd1/odd2
multi = odds*stake
winnings = multi+stake
output(odds, multi, winnings)
def output(odds, multi, winnings):
winnings = str(winnings)
print("£" + winnings)
for i in range(x):
inputs()

start()
>>
is this enough for a java implementation of linked list?
package LinkedList;

public class LinkedList<T> {
public T head;
public LinkedList<T> tail;

public LinkedList(){
this.head = null;
this.tail = null;
}
public LinkedList(T t){
this.head = t;
this.tail = null;
}

}
>>
>>57518804
(range 1 11)
>>
I have a question about the BSD license specifically
Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

does this mean it'd be ok for me to comment in the code based on theirs giving them credit and providing a link to the original project?
>>
>>57516723
Programming in C by Royce and Sword Art Online.
Both as dumb as you.
>>
>>57518833

inputs calls maths, maths calls outsput, output calls inputs, inputs calls maths, maths calls outsput, output calls inputs, inputs calls maths, maths calls outsput, output calls inputs, inputs calls maths, maths calls outsput, output calls inputs, inputs calls maths, maths calls outsput, output calls inputs.....
>>
>>57518868
euh no
>>
>>57518804
>>57518894
my nigga
(displayln (string-join
(map ~a (range 1 11))))
>>
>>57515556
its a trap!
>>
Starting a new job tomorrow, what should I expect?
>>
>>57519419
To work
>>
>>57519419
Depending on your work ethic, you'll either be intimidated by your peers or grow to hate your idiot coworkers almost immediately.
>>
In python I want to make it so a script write to a text file but if it's used more than once it just writes on a new line rather than overwriting what already exists in output.txt

string = input("Enter your string: ")
with open("output.txt", "w") as text_file:
text_file.write("Your string is %s" % string)
>>
>>57519515
with open("output.txt, "a") as text_file:
>>
>>57519545
alright that's working thanks one last question if I had a value (float) that's 10.0 how would I convert it to just 10?
>>
File: mad.jpg (99KB, 1280x720px) Image search: [Google]
mad.jpg
99KB, 1280x720px
I HATE OOP
>>
File: 9512428.jpg (52KB, 500x500px) Image search: [Google]
9512428.jpg
52KB, 500x500px
Mummy started shouting at me because I was programming in Python and she says it's a stupid meme language because 3.0 isn't even backwards-compatible. She said she will never make me tendies ever again if she catches me programming in Pyhton a second time.
>>
if( op.image.isAnime() == "true" )
reply("suck a dick weeaboos\n>>>/a/")
>>
>>57519579
I HATE OP TOO
>>
>>57517341
You mean your own videos site?
>>
>>57519582
Use a real language instead
>>
File: 1469764157477.jpg (35KB, 519x517px) Image search: [Google]
1469764157477.jpg
35KB, 519x517px
>>57519579
>>57519582
>>57519593
nice to see quality content here on four chane
>>
>>57519609
> implying >>57519593 is wrong
>>
>>57519609
>lain
excellent taste

>>57519579
I agree
>>
File: 1c6.jpg (43KB, 515x600px) Image search: [Google]
1c6.jpg
43KB, 515x600px
Why is mummy forcing me to learn assembly?
>>
File: s.png (107KB, 800x388px) Image search: [Google]
s.png
107KB, 800x388px
/dpt/ is so slow at this hour

really uncomfy
>>
>>57519694
slow = comfy
stupid newfrog
>>
So In python I've got it outputting
0.2857142857142857
but I want it to be shifted so it outputs just
"28.57"
how do I do it?
>>
File: dsz.jpg (52KB, 600x602px) Image search: [Google]
dsz.jpg
52KB, 600x602px
>>57519706
too slow = uncomfy

too fast = uncomfy

and I'm not a fan of the frogophobia
>>
Working on my terminal emulator, just finished implementing visual block selection.

Now I can actually use it as a terminal for the bottom too!

Next up, vimperator like hints to open URLs.
>>
>>57519723
do you have an aversion to multiplying by 100?
>>
File: output.webm (612KB, 526x310px) Image search: [Google]
output.webm
612KB, 526x310px
>>57519751
Derp, wrong video.
>>
>>57519723
>>57519751
>>57519758
stupid nerds talking about actual programming
>>
File: code.png (39KB, 534x579px) Image search: [Google]
code.png
39KB, 534x579px
>>57519758
That will make it less accurate
>>
File: 1479135954012.png (139KB, 1100x1100px) Image search: [Google]
1479135954012.png
139KB, 1100x1100px
>>57519741
>>
>>57519758
did not think of this that'll work but how do I crop it to just the first 4 numbers?
>>
What are the benefits of using uint64_t as opposed to unsigned long long?
>>
>>57519775
Stop fucking shitposting.

What is your favourite anime, /dpt/?
>>
>>57519800
%.02f
>>
>>57519808
welcome to NHK, as someone with psychosis it was quite relate able
>>
>>57519806
unsigned long long isnt guaranteed to be 64 bits long, and it fots nicely woth uint8_t and the rest
>>
>>57519808
Texhnolyze or Lain
>>
my linked list java implementation was so clean until i got to making a remove function. now i have to make a node datatype and it fucks up all my sleek functional code and now i have to do pajeetloops
:(
>>
>>57519843
Wrong
>>
>>57519843
What the fuck is a pajeetloop
>>
>>57519603
No, im making a decentralized streaming platform, and the image is the menu system i just made and talked about in the last dpt.
>>
>>57519853
a while or for loop
>>57519851
no, it's right
>>
>>57519898
No, you don't need loops. You can do it with recursion.
>>
File: 1374576817989.jpg (4KB, 190x190px) Image search: [Google]
1374576817989.jpg
4KB, 190x190px
>>57519843
>Pajeet-lang does even have pointers
>You can't use double indirection to create a very clean remove function
>>
>>57519906
where do i put that method...
>>
>imperative fags can't even do mathematical induction, and they're proud of it
computer science is doomed

>>57519646
child abuse
>>
>>57519843
>copy the list except the removed element
It's like you aren't even using python.
>>
>>57519898
>a valid loop is a pajeetloop
>>
File: cs-question.png (40KB, 735x366px) Image search: [Google]
cs-question.png
40KB, 735x366px
Can you solve this question, /g/?

If not, then how can you even call yourselves programmers?
>>
>>57519905
>>57519898
>>57519843
Pajeet-lang doesn't have TCO.
Doing it recursively would be stupid.
>>
>>57519967
There comes a point where math is so far removed from practical application that it becomes a waste of time.

As a programmer, you only deal in applied mathematics.
>>
>>57519982
>I'm definitely going to overflow the stack with my shitty CS homework linked list in Java that's going to hold 10 elements at absolute maximum
>>
>>57519967
Never needed to use that in my 15 years of programming.
>>
>>57519989
That doesn't look like a solution to me.
>>
>>57520000
what a waste of quads
fuck you and fuck math majors
>>
>>57519991
tail recursion doesn't overflow the stack
>>
>>57520004
I'm a CS major.
>>
>>57519991
I don't know about your shitty CS course, but most of my papers would test our solutions on somewhat large inputs.
>>
>>57520006
Java doesn't perform tail-call optimisation.
>>
>>57519967
it's funny to me that i can tell where this is from immediately. maybe just a good guess
>>
>>57520017
CS is basically a dumbed down math degree.
>>
>>57520027
Are you a tab?
>>
>>57520044
i'm not sure what that means. anyway, i'm a mathematician and i've read a lot of the papers from that tripos
>>
>>57520025
see >>57519579
>>
>>57520104
I don't see how that's relevant, although I can agree that OOP is fundamentally flawed.
>>
>>57519967
b) Let's abbreviate D(k) to mean d(p_1^a_1 ... p_k^a_k) because I'm lazy
Initial: D(0) = d(1) = Prod[i=1 -> 0] (1 + a_i) = 1
Assumption: D(k) = Prod[i=1 -> k] (1 + a_i)
D(k+1) = D(k) + (a_(k+1)) D(k)
since we inherit the divisors in D(k),
and for each of those divisors, we gain a
new divisor for each of new in D(k+1):
p_(k+1), p_(k+1)^2, ... p_(k+1)^(a_(k+1))
We then rearrange and prove the inductive case
D(k+1) = (1 + a_(k+1)) D(k)
= (1 + a_(k+1)) Prod[i=1 -> k] (1+a_i)
= Prod[i=1 -> k+1] (1 + a_i)
>>
How can I prevent becoming a code-monkey?
>>
File: cs-question-2.png (108KB, 737x939px) Image search: [Google]
cs-question-2.png
108KB, 737x939px
>>57520092
tab is short for cantabrigian

>>57519989
If you prefer impure mathematics then perhaps this question will be more to your liking?
>>
>>57520127
Learn C, an assembly language, and at least 1 purely functional language.
>>
>>57520140
>at least 1 purely functional language
Such as?
>>
>>57520149
Haskell, Scheme, etc.
>>
File: 1460829088434.jpg (98KB, 500x400px) Image search: [Google]
1460829088434.jpg
98KB, 500x400px
>>57520129
>hurr I'm going to skip to the middle of this chapter on System F and impress /g/ with all of this fancy wording!
>>
>>57520156
>Scheme
>pure
>>
>>57520156
Alright. Thanks.
>>
>>57520123
>D(k+1) = D(k) + (a_(k+1)) D(k)
>since we inherit the divisors in D(k)
So all the divisors of 12 are also divisors of 13?

>>57520158
Your CS course doesn't cover System F?
>>
>>57520127
learn haskell. ignore >>57520140
C is still imperative and will still taint your pure mind
>>
>>57520182
C is pure, it's just implicitly in the IO monad. Semicolons are monadic binds.
>>
Lets say I have a dictionary like this:

{'Author1' : [("BookA", 1998, usa), ("BookB", 1994, usa)],
'Author2' : ["BookC", 2005, canada)]}


Where the 2nd value represents a year, how would I make it to get a dictionary where I only get I get the values with that are under a specific year range? So If I were to say between 1997 - 2006, I get

{'Author1' : [("BookA", 1998, usa)]
'Author2' : ["BookC", 2005, canada)]}
>>
EVERYONE should learn a functional programming language, preferably first, so that they can write less spaghetti and more mathematically sound code.
Then they should all learn C so that they can learn what a big mistake 90% of computing is based on.

>>57520175
>So all the divisors of 12 are also divisors of 13?
No, remember I said that D(k) means d(...)
What I mean was that
(p_1^a_1 ... p_(k+1)^a_(k+1))
inherits all of the D(k) divisors of
(p_1^a_1 ... p_k^a_k)

I wasn't being 100% formal, next time I will be more clear.
Not sure how to prove the fund. theory of arithmetic but I think it must be a proof by contradiction?

>>57520175
>Your CS course doesn't cover System F?
I'm a freshman, I'll take PL as soon as I have enough credits
>>
>>57520197
dict.filter { case (_, (_, year, _)) => year >= 1997 && year <= 2006 }
>>
>>57519577
int(10.0039) = 10
>>
>>57520200
>contradiction
that's a good start for existence, yes
>>
>>57520182
Complete purity comes with all sorts of efficiency problems, but purity is a good thing to strive for.
I write C while favouring pure functions.
>>
>>57520200
>No, remember I said that D(k) means d(...)
Ah yes, sorry, I mixed up D and d. Yes, I think you've got it.

>Not sure how to prove the fund. theory of arithmetic but I think it must be a proof by contradiction?
Yeah, that would do it. For 4 marks they probably don't want anything super fancy.
>>
why do i end up in an infinite loop?
while (something)
{
//a bunch of shit happens including the loop terminating condition
//then:
ParseNode* mom = s.top();
s.pop();
ParseNode* kids = get_kid_array();

for (int i=kids.length, i>=0, --i)
{
if ( !(kids[i].is_dummy_node() )
{
mom->kids.insert(top->kids.begin(), &kids[i]);
kids[i].mom = mom;
s.push(&kids[i]);
}
}
}

//then
void traverse(ParseNode* root)
{
if (!root) return;
cout << some shit about root;
for (int i = 0; i < root->kids.size(); i++)
traverse(root->kids[i]);
}
>>
The EOF in the middle of my program kills everything.
string quit;
cin >> quit;
while (quit == 'y')
{
double x;
while (cin >> x)
// EOF ends this loop.

cin >> quit;
}


What do?
>>
>>57520271
Because something is never false
>>
>>57520271
>//a bunch of shit happens including the loop terminating condition
Did you not think that would be important to include?
>>
>>57520207
Thanks for the help , but I don't think I can use the code you provided. Pretty sure it's not python and I cant seem to figure out what the equivalent of .filter and case are in python.
>>
>>57520292
Oh - in that case you should rewrite your project into Scala, filtering is impossible in Python.
>>
>>57520290
>>57520279
sorry, the while loop terminates successfully

it's the tree traversal that ends up in an infinite loop

i posted everything that involves manipulating the ParseNode pointers.
>>
>>57520292
No idea what scala is unfortunately. This work is due in a few days, I'm just completely stumped on how to do it besides hard coding something ridiculously long. Stack overflow has no similar questions to it.
>>
GCC extensions are in fact good
// GCC
_Bool eatws(char **res, const char *cur, const char *end)
{
static void * const tbl[0x100] = {
[0x00 ... 0x08] = &&err,
[0x09 ... 0x0A] = &&next,
[0x0B ... 0x0C] = &&err,
[0x0D] = &&next,
[0x0E ... 0x1F] = &&err,
[0x20] = &&next,
[0x21 ... 0x7E] = &&exit,
[0x7F ... 0xFF] = &&err
};
goto loop;
next:
cur++;
loop:
if (cur == end)
goto exit;
goto *tbl[(unsigned char)*cur];
exit:
*res = (char *)cur;
return 1;
err:
*res = (char *)cur;
return 0;
}
>>
>>57520182
>>57520254
In this context, what is meant by purity?
>>
>>57520370
No side-effects, i.e. no modifying of any state (including I/O) outside of a function.
The function should return exactly the same result, with the same arguments, no matter where it's called.

A good example of pure functions are mathematical functions. 'sin' will always return the same result with the same input, and will not modify anything else.
>>
>>57520370
How much white developers the language has compared to colored ones.
>>
File: haskell.png (786KB, 1000x1300px) Image search: [Google]
haskell.png
786KB, 1000x1300px
>>57520370
1) virginal
2) no side effects
>>
>>57520394
I also forgot to mention that pure functions should not depend on global state.
>>
>>57520321
I was just messing with you man, I'm sure there's a way you can do it in Python.

If nothing else you can loop over the dictionary, and construct a new dictionary containing only the elements you want and return that.
>>
>>57520365
>*res = (char *)cur;
Disgusting.
Why even make the argument const if you're just going to cast it away?
>>
>>57520427
its the correct way. see memchr for example
>>
>>57520502
Yes, I know the standard library is not const-correct.
That doesn't mean that you have to disregard it.
>>
File: 1385810106218.jpg (28KB, 265x305px) Image search: [Google]
1385810106218.jpg
28KB, 265x305px
How long did it take you get good?

Sometimes I look at some CS graduate memes and I don't find what's wrong with them. It scares me. I'm in CS myself (2nd year).

What can I do to relearn everything the proper way once I'm done with CS?
>>
>>57520576
>How long did it take you get good?
A few years programming in your free time.
>>
>>57520400
shes cute! i might learn her!
>>
New thread: >>57520781
>>
Whats the easiest way to make an infinite print in python that will never stop even if someone does ctrl break/ctrl c? I remember my prof showing us once and the only way to stop it was thru task manager. Anyone know it? Just curious thats all
>>
void Printer (int x){
int turns = 1;
string spacing1 = "";
for(int i=x/2;i>0;i--){
spacing1 ="";
string spacing2 ="";
string line = "";
for (int z = 1; z<turns; z++){
spacing1+=" ";
}
for (int y=-i+turns; y<x/2 ;y++){
spacing2 += " ";
}
line = spacing1 + "*" + spacing2 + "*";
Console.WriteLine(line);
turns++;
}
if(x%2==1) Console.WriteLine(spacing1 + " *");
turns = 1;
for(int i=0;i<x/2;i++){
spacing1 ="";
string spacing2 ="";
string line = "";
for (int z = turns + i; z>0; z--){
spacing2+=" ";
}
for (int y=x/2- turns; y>0; y--){
spacing1 += " ";
}
line = spacing1 + "*" + spacing2 + "*";
Console.WriteLine(line);
turns++;
}
}
Printer(99);
>>
>>57516494
(map display (range 1 11))
>>
MyClass my_array[5];
for (i=0; i<5; i++)
{
MyClass obj;
obj.foo = i;
my_array[i] = &obj;
}

for (i = 0 to 5)
cout << my_array[i];

// output: 44444

I understand why, but how do I overcome it?
>>
>>57521021
err,
cout << my_array[i]->foo;

but nonetheless you get my point
>>
>>57521021
the MyClass obj is only valid within the scope of the loop.

the objects in my_array are default-initialized so you can set foo without making a new object like
my_array[i]->foo = i;
>>
>>57521199
if I have them all initialized to NULL for reasons, and I do
my_array[i] = new MyClass;

will I have to worry about deallocation later?
>>
>>57521733
yes, you will have to loop through the array and delete each allocated element separately
>>
>>57521845
I oversimplified things. It's actually a tree. I assume I would delete post-order?
>>
>>57521860
yes
>>
>>57521933
thanks my anon!
Thread posts: 328
Thread images: 37


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.