[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: 30
File: daily programming thread2.webm (2 MB, 600x338) Image search: [Google]
daily programming thread2.webm
2 MB, 600x338
old thread: >>53589797

What are you working on, /g/?
>>
>>53594690
The program isn't recursive
>>
//this prints "hello world" :D
#include <iostream>
using namespace std;

int main()
{
cout << "Hello :D" << endl;
cout << "World! XD" << endl;
//this thing says the program is done!
return 0;
}
>>
File: 1449603889287.gif (3 MB, 435x244) Image search: [Google]
1449603889287.gif
3 MB, 435x244
>>53594871
weeab fuck off
>>
>>53594893
(lambda(f)
((lambda(x) (f (x x)))
(lambda(x) (f (x x)))))

How about now?
>>
>>53594975
The program is not recursive
>>
Friendly reminder that command line editors > IDEs.
>>
>>53595276
>doing more work because you think it makes you cool
>>
>>53595292
>cool
programming isn't cool
>>
>>53595276
Pound your entirely subjective opinions up your ass, sperglord. Stop trying to derail an already shitty general.
>>
Is it possible to call JS prototype methods like static methods?

object.method(5);
// into
method(object, 5);


Latter would play a lot nicer with partial application etc. Sure I could make my own apply function too if that's not part of ES6 or anything
>>
>>53594972
here's your (You)
>>
File: not amused.jpg (20 KB, 400x317) Image search: [Google]
not amused.jpg
20 KB, 400x317
>>53594871
I saw his nipples. I'm pretty sure that's illegal on /g/ .
>>
does someone have the programming challenge picture that classifies the challenge by easy or hard, and is color coded
>>
>>53595574
>his
What's the problem?
>>
>>53595574
he's a guy, it's sfw
>>
>>53595532
here's your (You)
>>
>>53594871
Stop this programming trap meme.
>>
>>53595292
have you tried using any of those? they literally make you do less work
>>
Javascript understanding Help:

if i make a constructor with some properties (object1).
and then i make another constructor object with some properties (object2).
when i do object2.prototype= new object1().
does this mean that all of the properties from object1 are now also in object2? Are object1's previous properties deleted?
>>
Shitty BMI calculator I just wrote.

//bmi calculator 
#include <iostream>
using namespace std;

int main()
{
float weight;
float height;
int number;
double bmi;
number = 703;
cout << "~~BMI Calculator~~\n\n";

cout << "How much do you weigh (lbs.)?: ";
cin >> weight;

cout << "How tall are you (in.)?: ";
cin >> height;

bmi = weight * number / (height * height);

cout << "\nYour BMI is: " << bmi << endl;

return 0;
}
>>
File: WTFOracle.png (87 KB, 624x140) Image search: [Google]
WTFOracle.png
87 KB, 624x140
Ok, I'm losing my shit here...

I'm pretty comfortable with MySQL. It works well, and it doesn't fuck everything up metrically, every 5 goddamn seconds.

But for my database class, we using Oracle, and I'm getting so many syntax errors when following the guides EXACTLY that I'm about ready to smash my face into a wall.

Please tell me what the living FUCK is wrong with EITHER of these goddamn statements?
>pic related. What the fuck

Neither of those statements run (even though only 1 has a highlight. The other highlights when I comment the first. I don't fucking know why...)

But I'd really appreciate knowing how to fix this before I lose my fucking mind.

For reference, there is a foreign key on this ID, but the only thing I'm trying to do is make this auto_increment. Data type is STILL NUMBER NOT NULL
>>
>>53595967
#include <iostream>

int main(void)
{
float weight;
float height;
float bmi;

std::cout << "~~BMI Calculator~~\n\n";

std::cout << "How much do you weigh (lbs.)?: ";
std::cin >> weight;

std::cout << "How tall are you (in.)?: ";
std::cin >> height;

bmi = weight * 703 / (height * height);

std::cout << "\nYour BMI is: " << bmi << std::endl;

return 0;
}
>>
>>53596041
i need to see the student_t table
>>
>>53595835
me
>>
>>53596044
I have yet to learn anything other than using just cout. Something interesting I could do with the program is to create a function that detects which units the user inputs and have them convert accordingly.

Not sure how to do that yet though.
>>
File: WTFOracle_Students_T.png (22 KB, 602x305) Image search: [Google]
WTFOracle_Students_T.png
22 KB, 602x305
>>53596059
Here you are
>>
>>53596068
>enter 500
what is that?
inches?
centimeters?
>>
>>53596107
needs to be an identity/primary key to auto-increment
>>
>>53594975
what about
let a = a
a
>>
>>53596107
maybe this
ALTER TABLE STUDENT_T MODIFY STUPID INT AUTO_INCREMENT 

or
ALTER TABLE your_table_here
MODIFY COLUMN your_thing_here int AUTO_INCREMENT
>>
>>53596107
or this
ALTER TABLE STUDENT_T MODIFY STUPID INT AUTO_INCREMENT PRIMARY KEY
>>
>>53596140
that is the primary key

>>53596148
>>53596169
I'll try this, including primary key as part of it.
>>
>>53596197
MySQL doesn't think so. Check the table constraints. The column is either failing a unique constraint or doesn't have a primary constraint at all.
>>
File: computerman.jpg (13 KB, 400x226) Image search: [Google]
computerman.jpg
13 KB, 400x226
Anyone have some books on learning networking with Go? The Gentooman Library doesn't have any, last I checked.
>>
>>53596215
https://esolangs.org/wiki/
>>
>>53596215
here you go my man

https://jan.newmarch.name/go/
>>
>>53596215
https://esolangs.org/wiki/Joke_language_list
>>
>>53595967
>>53596044
Improve it so it handles invalid input (i.e. the user enters letters instead of numbers).

Accept the input as a string first, then try to read the number from the string.

>>53596068
>a function that detects which units the user inputs
If you do the above, it will be easier. In the mean time, you can practice by writing the unit conversion part.
>>
>>53596247
>>53596267

nice meme
>>
>>53596041

why does the second line say STUDID twice but the first one doesn't?
>>
File: WTFOracle_Students_T_PK.png (24 KB, 1005x219) Image search: [Google]
WTFOracle_Students_T_PK.png
24 KB, 1005x219
>>53596214
This is Oracle. I don't have this problem with MySQL.

And none of these are working.
>>
>>53595835

not trolling, but have you tried this out yourself? what happened?

this is the kind of stuff you should be testing to see what happens
>>
>>53596376
First one was an attempt at MODIFY
Second was the one I usually use with MySQL: CHANGE

If I can't get it working, I'll just input bogus data.
>>
>yes, buy our IDE. Just hand us your money each year and everything will be better, he-he-he
>>
can you guys recommend me a book to learn c++?

I've already learned quite a bit of java so I don't need an introduction to programming. Thanks.
>>
>>53596415
What's your overall skill level in the language?
Or in other programming languages?
How well do you OOP?
>>
>>53596436
Sorry, got it. Just read that.

C++ for Dummies should be fine. Just to get a feel for the syntax and get up and running with a good IDE. I recommend Code::Blocks

You could also use something a bit drier, but more in-depth: The Big C++ Book (Big C++)

Or if you prefer a more down-and-dirty approach: Problem Solving, Abstraction, and Design Using C++

My first used C++ book was the PS, A, and D. Then I used Big C++
>>
File: opinion_discarded.jpg (117 KB, 680x680) Image search: [Google]
opinion_discarded.jpg
117 KB, 680x680
>>53594972
>>
>>53596482
Thanks anon, I will take a look and check out some of these recommendations.
>>
Ok, so I (THINK I) figured it out. Oracle doesn't seem to support any kind of pre-defined auto_increment property.

I'd have to make a sequence.

Fuck it. I'll submit it with bogus data.
Goddamn, you'd think Oracle, a commercial database system, might actually be at LEAST as good as MySQL. Nope.

Holy fuck, I'm losing my shit here.
Thank God I'll be only using MySQL on my own site. I'd probably chuck the server out a window using Oracle.

Guess I'd have to expect that. really. from a company that doesn't even version its software right...
>>
>>53596695
Yes.
>>
>>53596660
>Oracle doesn't seem to support any kind of pre-defined auto_increment property
Dude... wait, what? I thought that was like, The Thing with databases. I don't have much DB experience, did a bit with MySQL a while back and SQLite recently, but that just seems weird.
>>
Anyone got something graphics related I can program that is also semi impressive? I'm trying to build a portfolio but I'm drawing a blank, preferably should be something that is actually used in games as well
>>
OK so I built the sqlite3 library and am trying to run a debug of the programming using it instead it says it's missing msvcr100d.dll but I have the latest redistributable.
>>
>>53596743
I would suggest a ray tracer, but they don't use that in games.
>>
>>53596660
>>53596728
Stop spreading misinformation, you fucking shills
>>
>>53596728
Yeah... it does. I don't fucking know. Maybe I can make a sequence at some other point, but I'm not gonna fucking deal with it atm.

Yeah, this apparently seems to be the only answer that somehow works:
http://dwhlaureate.blogspot.com/2014/08/how-to-add-auto-increment-in-oracle.html

So, fuck it.
Who in their right mind even makes a system that requires that?
To be honest, I don't know why they don't have AUTO_INCREMENT_HEX or even alpha.
I'd like something that has AT LEAST base16 for auto values. But like wtf, Oracle...? Can't even into decimal?
>inb4 Java can't even into standard float/double addition without fucking up. Needs a whole new class called BigDecimal
>>
>>53596794
This might actually not be a bad idea, I'll probably look into it, thanks
>>
>>53596795
what? shilling for what? MySQL, a non-profit (I think) thing?

I only WISH I was employed by someone that well known atm. I work part-time at a goddamn supermarket as a cashier right now...
(which innately sucks, because I don't really like people, hate tasks that don't have clear beginnings and ends, and don't like leaving my house [all of which relate to the website I'm gonna launch])
>>
>>53596743
You could make an SDL program and insert OpenGL graphics into it with raster text. Possibly just a simple UI for, say, inputting player data and a loading and menu screen
>>
>>53596660
They're called sequences. Check it out:
http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_6015.htm
>>
>>53596408
Isn't that the corporate license? Individual licenses are way cheaper.
>>
>>53596660
>>53596941
Also, sequences are a perfectly valid way to implement auto incrementing columns. I do something similar with time-based UUIDs in my schemas. You would not believe how many shitty things MySQL does compared to all the other SQL databases out there. Postgres is my favourite, though.
>>
>>53595433
JavaScript has a few things built in to do this, call, apply and I guess bind. They have been in the standard for ages so they will work wherever.
function Foo(x) {
this.x = x;
}

Foo.prototype.bar = function(y) {
console.log(this.x + ", " + y);
};

var test = new Foo(2);

test.bar(5);
Foo.prototype.bar.call(test, 5);

Both log "2, 5".
>>
>>53597219
Hmmm.

Well, I'll probably add it in at a later point. It's just some dumbass project though.

What does MySQL do, though, that doesn't work well?
(other than the 2038 date issue. Or is that fixed yet?)
>>
#include <iostream>
template <int P, int N>
struct token
{
token (bool& mult, const std::string& msg)
{
mult = (N % P) == 0;
if (mult) std::cout << msg;
}
};
template <int N=100>
struct fizzbuzz
: fizzbuzz<N - 1>
, token<3, N>
, token<5, N>
{
bool f, b;
fizzbuzz ()
: token<3,N>(f, "fizz")
, token<5,N>(b, "buzz")
{
if (!f && !b)
std::cout << N;
std::cout << std::endl;
}
};
template <>
struct fizzbuzz<0>
{ };

fizzbuzz<100> _;
int main () {}
>>
Anyone know how to install sqlite for visual studio?
>>
if c supports bitfield structs, why do people still bother with hex bit masks?
>>
>>53597589
You don't really need all that when your bitmask needs boil down to options flags
>>
File: Jwz4QlC.png (19 KB, 928x82) Image search: [Google]
Jwz4QlC.png
19 KB, 928x82
I did a thing~
>>
>>53597867
post source
>>
>>53597867
interesting
>>
>>53597867
markov chain

there's a library for that anon
>>
Alright, real talk.

Are there any large research oriented open source libraries where a non C++ alternative has has more features than one in C++? I recently started working at a research position and we use ROS, opencv, PCL, eigen, ceres, etc..

Do I just need to accept that C++ is my life now?
>>
>>53598209
yes, what else were you expecting to do heavy tasks?
>>
>>53596396
yeah i was going to, but im working on ssomething and didn't want to lol. was hoping i'd get the answer in about 5 seconds without trying it out for myself.
i had some coursera.org coursework to finish, so if nobody answers it i'm eventually going to try it out
>>
>>53598209
embrace the sub-par hybrid-OOP style anon.
>>
Okay this is gonna sound really fucking weird but I promise I have a good use case for this. Is there any way in C I can dynamically assign functions? I have a struct full of pointers to functions, and there is hundreds of them. Is there any way I can go through a loop and "replace" the /name/ of the function? This is sorta psuedocode of what I'm trying to do.

#define GET_FUNC(X) functionX()

for(int i = 0; i < 256; i++) {
GET_FUNC(i);
}
>>
Been reading up the entire Java Tutorials index. Anyone know where I can find exercises to practice Java material?
>>
>>53598321
this is not possible in compile time, with dynamic i.

you can use an array of function pointers though
>>
>>53598334
Google for a pdf of a java textbook?
>>
>>53598321
There is, it's called function pointers. Read up on it. It's actually not that weird at all, it's used in a lot of places.
>>
>>53598321
That's a cool concept, similar to dependent typing; unfortunately impossible in C.
You'd have to do a function pointer list, or maybe somehow use C++ template metaprogramming.

typedef fn_t = void (*)();
void fn1 () { ... }
void fn2 () { ... }
...

fn_t funcs[] =
{ fn1, fn2, ... };

...
for (int i = 0; i < ...; i++)
funcs[i]();
>>
>>53598392
fucked up my typdef syntax, but whatever, blame C.
>>
>>53598387
Those have exercises? I already have Oracle's Java Tutorials eBook.
>>
>>53598392
>>53598390
>>53598370
Thanks guys, it's a little more verbose than I'd like but an array of function pointers got the job done.
>>
>>53598334
>>53598474
bump
>>
>>53598774
write a compiler.
>>
File: 1456966914260.jpg (35 KB, 661x720) Image search: [Google]
1456966914260.jpg
35 KB, 661x720
>tfw even a Pytard like me can learn to FizzBuzz
Feels good to know "abstract algebra"

for I in range(1,101):
if i%3==0 and i%5==0:
print 'FizzBuzz'
if i%3==0:
print 'Fizz'
if i%5==0:
print 'Buzz'
else:
print i


Best way to shorten this?
>>
>>53599131
>range instead of xrange
>4 modulo operators
>cannot even combine % 15 case
>uppercase I
>python 2
>python
it is shit
>>
Would someone mind pointing me in the right direction, have to handle some files, which is not my strong point.

I have a directory full of regularly named files (e.g., HIB_1ME_BC_LB_NSQ_SB_0.0T_0.0050yow_0.0200000PhiX_20160218-0034Rho.dat), I need to trawl through all of these files, taking the value of PhiX specified in the filename (so in this case 0.02...), write it to the first column of an output file, output a tab, then write the value from the 4th column of the penultimate line of the subject file, and then start a new line (i.e, selectively extracting data from a load of files).

What utilities should I use for this, I'm rather unfamiliar with dealing with files?
>>
>>53599195
>fixed capital i. Typing on mobile, so i's are automatically capitalized.
>if statement changed to i%15. Not sure how I missed that.
>range() changed to xrange(). Should consume less memory.
for i in xrange(1,101):
if i%15==0:
print 'FizzBuzz'
if i%3==0:
print 'Fizz'
if i%5==0:
print 'Buzz'
else:
print i
>>
>>53599416
>still python 2
>still python
>>
>>53599444
What makes python3 > python2?
>>
>>53599416
>he didn't code his FizzBuzz with just a hex editor
Yeah, we're looking for someone with a bit more experience.
>>
>>53599399
sed or awk?
>>
>>53599454
let's ask python
>>> print("python3" > "python2");
True
>>
>>53599490
I was reading a bit on awk, and it looks like it could do the in-file stuff. Would it (or sed) be able to parse the filename too? Is this best done via regex or some such?
>>
>>53599416
First I'd like to point out that all of those if statements will fire on i==15
giving
>14
>FizzBuzz
>Fizz
>Buzz
>16
>>
so i have a shell script to compress a zip
zip *.txt && exit


this was supposed to zip all txt files and exit *but* when i run the script it zip's all the txt files
but doesn't exit the terminal <----

what do?
>>
>>53599525
heh, this is why fizz buzz is an actual thing.
>>
>>53599553
Don't worry, 99% of people who apply to jobs that do FizzBuzz can't even get it to compile at all.
>>
>>53594958
>>53595484
Gtfo >>>/reddit/
>>
>>53599536
exit ends the script. if you want to end the terminal session after runniing a script do
$ myScript.sh && exit
.
You can alias that for easier access.
>>
>>53599525
Yeah, I noticed that. 2nd and 3rd if has been changed to elif.
for i in xrange(1,101):
if i%15==0:
print 'FizzBuzz'
elif i%3==0:
print 'Fizz'
elif i%5==0:
print 'Buzz'
else:
print i
>>
>>53599633
not testable because you print to stdout rather than writing to a string
>>
>>53598122
it's really shitty though :^(
>>53598169
where's the fun in that?
>>
>>53599671
post it.

i wanna learn how you do it
>>
How the fuck i make passwords on C++? What should i use to encrypt?
>>
>>53599789
ROT-13
>>
>>53599826
rcvp
>>
>>53599826
>>
>>53599684
fine, too long for 4chan so posting to ix.io http://ix.io/uiQ/haskell
>>
>>53599901
osx font rendering is bae
>>
How do i make passwords the right way then? Everything is going to be local though
>>
>>53599951
$ for i in {1..10}; do python -c "import random, string; print(''.join(random.choice(string.printable.strip()) for i in range(16)))"; done
z9O,tZh7tU[HWiP~
T^/)>Lb.?5f3xkzp
{"M@;f<=u'J):M9L
$}DGcCK`@Q(7gbJz
qB3v}BXLz4?Fqm2C
2%XW\xoma#`'+\K*
>xfzEPa2}:bH<0R4
#7]V\y,M%$]sQxhZ
u8eH"e:0~|dC[7xV
&2+5vdZ3a#9$p->e
>>
I usually write down the parts of the software i must develop and then i just mark over what i've done. You guys know any software that does something similar?
>>
Writing a bot for some weeb MMO that emulates a party member and can fill multiple roles.

People with no friends will pay good money for that shit, which is to say most weeb MMO players.
>>
using namespace std;

it's a meme right?
>>
>>53600202
jira, rt, phabricator...
>>
Is there anyone on Earth who really uses orthodox Test Driven Development?

Implementing tests before functionality still strikes me as bizzare and most of the time pointless and stupid
>>
>>53600392
Only in Pajoozle land
>>
>>53600392
>Implementing tests before functionality still strikes me as bizzare and most of the time pointless and stupid

I find implementing tests at ANY point to be a useless exercise. As professional golfer John Daly once said, "grip it and rip it."
>>
>mfw Python metaclasses
>mfw I have no face

This is so fucking fun. If I were using Lisp, metaprogramming would be normal, but in a language like Python that's all nice and clean it feels like I'm violating an innocent trap.
>>
>>53600473
it's usually a good idea if you're doing some big refactoring
it's great to be able to see when some code stops doing the same thing after you redesign some core part of the program so that you can quickly go back and fix it
writing tests for the sake of writing them is dumb though
>>
Does VI count as an IDE since it highlights shit?
>>
are classes in c++ hard senpai?
>>
>>53600609
Yes. Unless you're a normie who can't think in terms of programming... like most of my fucking class...
>>
>>53600658
i meant the data structure
is it hard to learn
thx :3
>>
File: 3335135.png (15 KB, 395x552) Image search: [Google]
3335135.png
15 KB, 395x552
Has anyone done Summer of Code?

I think I found an organization I would want to work with, but literally zero idea how to write a proposal or what they expect.
>>
Working on a pong clone in C++ Sdl 2.0.

>realize original pong uses rectangles and no circles
>pissed because of how long I spent trying to get rectangle / circle collision detection working
>going to say fuck it and use rectangles.

feels good man.
>>
>>53600669
Oh I see lel. No they're easy. They're just structs with public and private switch around. Private variables can only be accessed from within the class, so you need getter and setter functions to access the variables. This is supposedly good for program design but who fucking knows. I guess it is, it's just a pain in the ass.

There are more useful uses for classes but that's the most common.
>>
>>53600695
I'm curious about this too.
>>
>>53600738
fuck it, I'm just going to write shit and share it with them and maybe they'll give advice.
>>
>>53599505
Regex with awk. Awk is Turing complete; it can do everything you'd want to do with sed and is better at manipulating columns. Google the terminal commands cut and paste as well.
>>
Can anyone explain why either:
A) scanf isn't properly collecting my input
B) my input isn't printing properly?

char *courseName = "test";

printf("%s", "\nWhat is the course name?\n");
scanf("%s", &courseName);
printf("%s", "\nThe name is: ", courseName);
>>
>>53600923
The problem is that you are making courseName a pointer to a string literal, rather than declaring char coursename[5];
>>
File: pong.png (5 KB, 361x272) Image search: [Google]
pong.png
5 KB, 361x272
>>53600696
Now I've never done a pong clone or proper collision detection for that matter, and I haven't slept so I may not be thinking straight but you could have used rectangle collision for circle anyway. It would never come to a point where there would be any difference because of the way pong works.
Rectangle encapsulating your ball would be same width as diameter of the circle and it doesn't matter unless there's rotation involved where corners of rectangle would hit the paddle. Am I making sense here? It doesn't matter which direction ball comes from if you don't rotate this collision box or the ball. And you don't need to.

I've made a picture to show what I mean, b) is the bit that's never going to happen.
>>
>>53600987
Whoops, that's a remnant of testing. Here's the actual code I'm working with (same problem):

char *courseName = (char *)malloc(10);

printf("%s", "\nWhat is the course name?\n");
scanf("%s", &courseName);
printf("%s", "\nThe name is: ", courseName);
>>
How the fuck do I git gud at structuring my program? At some point I hit a wall where everything is so tangled and fucked where I can't progress anymore
>>
I miss the beginner programming threads.
If anyone else is trying to get better at programming like me, check out exercism. It's a bitch to set up (on windows at least), but the exercises are fun and challenging.
def is_pangram(s):
if s == "": return False

s = "".join([c.lower() for c in s if c.isalpha()])
letters = ""
for c in s:
if c not in letters:
letters += c
return "abcdefghijklmnopqrstuvwxyz" in "".join(sorted(letters))
>>
>>53601109
Take an object oriented programming course :^)
>>
>>53600923
There are problems with your code.
char *courseName = "test";

Strings in C are character arrays, and this code likely
a) discarded "test" entirely
b) possibly made a 5 element char array'
Anything entered that is longer than 4 characters will cause a buffer overflow.

It would be better to have a larger character array to store input (or dynamically allocate an array to store input).

#define MAX_STRING_LENGTH 51

char courseName[MAX_STRING_LENGTH];

printf("%s", "\nWhat is the course name?\n");
scanf(" %50s", &courseName); // <-- will ignore leading whitespace (if any) and read a max of 50 characters.

printf("%s", "\nThe name is: ", courseName);


If there is interest, I can write a brief tut on better use of scanf()
>>
>>53601047
I was honestly thinking that as well. I was just not sure if the pong ball ever actually literally intersects or if the bounding box just intersects (e.g. if there will always be some space). What you are saying makes sense.

I was trying to find a slowed down version of pong soemhwere to see if htey ever actually intersect or just "overlap."

>>53601052
This will work:
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {

char *courseName = (char *)malloc(10 * sizeof(char));

printf("\nWhat is the course name?\n");
scanf("%s", &courseName[0]);
printf( "\nThe name is: %s ", courseName);

}


There are several problems in your original code.

Line 1. Printf can print a string literal ("What is the course name") without a format string (%s). Giving it a format string s and then giving it a string literal is redundant.

Line 2. You scanf into the &courseName, but really what you want to do is scanf into &courseName[0]. This is because arrays are pointers in c and you want to tell it to start putting your string at the 0th index of the array.

Line 3. This will not work because I THINK printf will take two parts: the strings and format strings, and then a comma separating them from the variables you are trying to format. So you should just put all of your string in one string literal using format strings, and then specify the variables you are formatting with the comma and then the variable names.
>>
>>53601052
>printf("%s", "\nThe name is: ", courseName)
For printf, %s prints a string that is supplied as the next parameter. To print the string courseName, you would need:
printf("%s%s", "\nThe name is: ", courseName);
// second %s is required to print the second string
// alternative:
printf("\nThe name is: %s", courseName);
// ^ would work better
>>
>>53601047
The difference is if the ball passes over the top or bottom of the paddle. There are cases where the circle collision will miss completely but the rectangle will still hit.

If your worried about calculating collision normals, those change as well.
>>
>>53601204
Im the OP he replied to and I was thinking using a rectangle would give you more precise collision detecion?
>>
>>53601159
oops, there is a mistake:
scanf(" %50s", &courseName);
// ^incorrect!!
// should be
scanf(" %50s", courseName);
// the name of the array is the address of the first element
>>
>>53601185
Thanks for the advice. Coming back to C after a long break and it's taking a while for it to all come back to me.
>>
>>53601216
Sure, If you're drawing your ball as a square rather than a circle then of course it does.
As you point out, you can of course assume that the sides of the boxes are aligned to the axes which simplifies it alot. You don't need to do general box collision like something like box2d would do.
>>
>>53601258
Ok, cool. thanks. Ill probably switch it to rectangle cause I want to be faithful to the original and also dont want any weird behaviors.

>>53601244
Sure thing.
>>
any of you anons up late/early working?
>>
>>53601525
late here, but not working on much :^( playing around a bit with various things but no project i feel like committing to rn
>>
>>53601525
Not all of us are American you know.
>>
>>53601539
I know :^) I'm Canadian but sleep schedule is a bit fucked so i'm working now instead of later (remote work).

Specified "early" in case any eurobros were up.
>>
>>53601552
Fair enough, It's just that it's the middle of the day in Australia.
>>
>>53594871
>That webm I made is STILL being posted.
You guys probably all hate me now.
>>
>>53601578
I'm sorry ausbro i didn't mean to exclude you, got any projects you're working on?
>>
>>53601578
It's 5:15 here you stupid cunt, that's not the middle of the day.
>>
>>53601657
Halfway between when you wake up and when you go to bed, seems like the middle of the day to me desu.
>>
>>53601623
I wrote a really shitty preprocessor for JavaScript in bash. Now I guess I should probably actually do something in JavaScript.
>>
>>53601672
>preprocessor for JavaScript in bash
Oh god, I feel so sorry for you.
>>
>>53601109
iterative refactoring
fix your shit as soon as you realize it can be fixed
instead of waiting until its a problem
and eventually you'll figure out how to fix things before they can be fixed
>>
>>53601691
It's not so bad, bash is actually pretty good at handling strings and stuff.
>>
>>53601109

as

>>53601720
said, iterative refactoring is a great way to keep your shit unfucked, or to unfuck it. This is where a strong case of having tests implemented comes in - you can generally change shit and know if it broke something else.
>>
>>53600500
>it's usually a good idea if you're doing some big refactoring
I think the idea is that leaves you free to do big refactoring at any time
So you still want to do it ahead of time, even if you're not currently planning to refactor

And of course, if you're working in a group, those tests are your program's lifeline in regards to edge cases. People will read your random if statement, can't see a purpose for it, and now you've got to figure out why your program deadlocks .01% of the time all over again
>>
>>53601737
What do you do when you need to refactor the interface though? Often test suits will be tightly coupled to the interface of your program. When you need to change your code and your tests, you've entered unchartered territory.
>>
>>53600715
>This is supposedly good for program design but who fucking knows
It's just meant so that you have a consistent interface for classes. mostly unifying when you have to do some awkward manipulations or verifications when setting and getting

so you don't go directly variable manipulating without realizing the class wants some particular methodology first
so just burn the whole fucking bridge of convenience
fuck programming
>>
>>53601812

>When you need to change your code and your tests, you've entered unchartered territory.

absolutely, I in this case you'll need to do quite a bit of manual testing to make sure you didn't totally fuck everything, this is where the single responsibility principle comes in handle, hopefully everything is split up enough that there is a wide array of tests that don't need to be changed and you can be sure they're still working.
>>
>>53601812
You can always write an adapter function between the old interface and the new one, and thus verify the correctness of your refactoring.
If it succeeds, your code's refactoring can be assumed sufficient

Then start changing the test-cases to use the new interfaces instead
and given that your code succeeded on the old test-cases
then any failure now can be presumed a result of an error in the test-refactoring.
>>
>>53600026
Vanilla random in python shouldn't be used in security sensitive contexts. Read the docs, educate yourself.

>>53599951
Assuming you are on Linux, google for password generators. They are tested and have proper design. Alternatively you can build your own solution by reading high quality random data from /dev/urandom and filtering or converting it to a stream of printable characters. Google will help you with this too
>>
>>53601947
this is not a sensitive context
>>
Okay so when i do this code
int num = 10-ran.nextInt(20);
System.out.print(num+" ");

I get values -9 to 10 but no -10

and when i do
-10+ran.nextInt(20);

it prints -10

why? this is also in java, and im new so no hurt
>>
>>53602150
oh great now im only getting -10, no positive 10!?
>>
>>53594871
I'm unironically interested in what's written in the editor's note. What's packing?
>>
>>53602173
According to the docs,
nextInt(input) returns a random value between 0 (inclusive) to input (exclusive)

so ran.nextInt(20) gives you a random value 0 to 19

10 - ran.nextInt(20);
10 - 19 = -9
10 - 0 = 10
so your range is 10 to -9.

-10 + ran.nextInt(20);
-10 + 19 = 9
-10 + 0 = -10
range: 9 to -10.

“Who are you going to believe, me or your lying eyes?”
>>
anyone ever successfully embed typeahead into ui grid before? fuck this.
>>
struct each_day {
string date;
float open;
float high;
float low;
float close;
float volume;
float mov_avg[1];

};

each_day *day = nullptr;


void SMA(int movingAvg, int mv_num)
{
deque <float> sma;
float smaSize = (float)movingAvg;

float sum_of_elems = 0;

for (dayNumber = 0; dayNumber < numberOfDays; dayNumber++)
{
cout << day[dayNumber].date << " " <<dayNumber<<endl; //USING TO TEST DATE

if (dayNumber <= smaSize - 1)
{

sma.push_front(day[dayNumber].close);

//day[dayNumber].mov_avg[mv_num] = 0; leads to error



if (dayNumber == smaSize - 1)
{
for (float n : sma) {
sum_of_elems += n;
}

day[dayNumber].mov_avg[mv_num] = sum_of_elems / smaSize;

// cout << day[dayNumber].moving_avg[mv_num] << endl;
}


}
else
{
sum_of_elems = 0;
sma.pop_back();
sma.push_front(day[dayNumber].close);

for (float n : sma)
{
sum_of_elems += n;
}

day[dayNumber].mov_avg[mv_num] = sum_of_elems / smaSize;

}

}

}

I'm porting this program I wrote in in visual studio c++ to linux. But after a few hundred accesses to the structure ( just to read the date for each day) I get the following segmentation fault. What the actual fuck? It works in windows just fine...
0xb7f42ac5 in std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /usr/lib/i386-linux-gnu/libstdc++.so.6
>>
>>53595727
how do they make you do less work than IDEs for fuck's sake? and reminder that this is the tripfag that thinks haskell isn't shit
>>
>>53602819
less productive work
>>
>>53602609
Compile with -g and learn to debug your own programs.
>>
is there a tl;dr of the dragon book
i just want to write a parser for simple math expressions
>>
>>53603243
Just read the relevant chapters about lexing and parsing.
You don't have to read the whole thing.
>>
>>53602609
Where and how are the following variables defined?
>dayNumber
>numberOfDays
>day //<-- defined, but not filled in the code posted

Also, this line:
day[dayNumber].mov_avg[mv_num] = sum_of_elems / smaSize;

is interesting, because you defined the struct each_day as follows:
struct each_day {
string date;
float open;
float high;
float low;
float close;
float volume;
float mov_avg[1]; // <-- here will cause problems with...
};
.
.
.
void SMA(int movingAvg, int mv_num); // <-- here if mv_num is anything other than 1


There was something else I saw but I am hammered af and cba
>>
How's this piece of code?
string::size_type count_vowel(const string &str)
{
const auto size = str.size();
decltype (str.size()) vowels = 0;
for (decltype (str.size()) i = 0; i < size; i++) {
if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' ||
str[i] == 'u' || str[i] == 'A' || str[i] == 'E' || str[i] == 'I' ||
str[i] == 'O' || str[i] == 'U')
vowels++;
}

return vowels;
}
>>
>>53603416
It's shit/
>>
>>53603416
Absolutely disgusting.

Here is some sane code:
size_t count_vowels(const char *str)
{
static const unsigned char lut[UCHAR_MAX] = {
['a'] = 1, ['A'] = 1,
['e'] = 1, ['E'] = 1,
['i'] = 1, ['I'] = 1,
['o'] = 1, ['O'] = 1,
['u'] = 1, ['U'] = 1,
};

size_t n = 0;
for (; *str; ++str)
n += lut[(unsigned char)*str];

return n;
}
>>
>>53603476
How does ['x'] = 1 work inside an array of unsigned chars?
>>
i finally solved the outlook.com skype cancer, filtered cdn.skype.com in ublock origin
>>
>>53603611
It'll just cast to an integer.

lut['k'] isn't guaranteed to be 0 though, it'll be uninitialized.
>>
>>53603705
it'll be 0 because it's static
>>
>>53603476
why size_t ?
>>
>>53603741
Y not nyukka?
>>
>>53603741
size_t is supposed to be able to hold the size of any object in bytes.
>>
>>53603747
size_t is the type returned by the sizeof operator, it's for representing the size of an object.

>>53603769
exactly, his function doesn't return the size of anything.
>>
>>53603714

Why yes.

You learn something every day.
>>
>>53603611
1 is a completely valid value for a char to have. I'm really just treating them as integers, but 'int' is wasteful, so I used the smallest type, which is unsigned char.

>>53603705
>>53603714
It is guaranteed to be zero, even if it isn't static. Elements of a struct/array/union which aren't explicitly initialised in a designated initialiser are set to zero.

>>53603741
It makes the most sense for the situation. The function can take a string of any arbitrary length (up to size_t), so it should return a value which makes sense for its maximum.
>>
>>53603788
D E S I G NA T E D
>>
Does anyone have the programming roll image (You post, your number matches with one in the image, you do it)
I downloaded it once about a year ago but forgot where i put it
Never really programmed in my life but i want to give myself some small projects to try and achieve
>>
File: 1454733046971.png (378 KB, 1450x1080) Image search: [Google]
1454733046971.png
378 KB, 1450x1080
>>53603972
https://better-dpt-roll.github.io/
>>
>>53604024
Thanks, ill use this but i think the one i saved was even older than that, was just black with green writing
>>
Suppose I have a rectangle divided into uniform squares. Some squares are Full while others are Empty. Given a point within the rectangle in cartesian coordinates (i.e. x and y as applied to absolute distance, not squares) and a radius what is the most efficient way to figure out to which Empty squares within the radius a line originating from the point can be drawn such that it intersects only with the edges of Empty squares?
>>
>>53604251
wot

can you draw an example
>>
>>53604024
tfw I wouldnt even know where to start with any of these.
>>
Why is 60 evaluating to less than 1? This has been fucking with me for hours. Anyone got a guess?
>>
File: why60lessthan1.png (37 KB, 674x587) Image search: [Google]
why60lessthan1.png
37 KB, 674x587
>>53604316
fuck forgot my image
>>
How do you disable the close button on a program's window (Windows 10) ?

I want to make sure the user doesn't accidentally close out of my installer, so it would be useful.

I know i need to make a call to user32.dll, but what are the function i need to call? I am trying to look on MSDN but can't find it
>>
>>53604333
you got a semicolon after that
if (overlap_results < min_protection)
>>
>>53604251
Sounds like some sort of line of sight-type deal.
You could just find all empty squares within the radius and then cast rays from your point to (each corner, edge midpoints) of each empty square.
>>
>>53604379
I always suspected I was retarded, but I know for sure now. Thanks.
>>
File: Example.jpg (253 KB, 2622x1208) Image search: [Google]
Example.jpg
253 KB, 2622x1208
>>53604288
Yeah, sorry.

Suppose the radius is roughly equal to the length of three squares. If you can draw a line of length R originating from the point so that it intersects with an Empty square without intersecting with a Full square that square is added to the list of items. The list is what you want to return in the end. In the picture squares which would be added to the list are marked with a star. Empty cells are left white while Full cells are filled with orange.

I probably got the proportions and the lengths work but I hope you get the idea. I don't blame you if you don't since I'm awful at explaining things haha.
>>
>>53604575
http://www.roguebasin.com/index.php?title=Ray_casting
>>
>>53604450
Thanks. That's a neat solution. Is it really guaranteed to give a correct answer given a very large board e.g. tens of thousands of squares with a radius of a few hundreds? My intuition could be (and probably is) wrong but I get the feeling that there are some edge cases where a very distant ray might be able to intersect with the edge of an empty square but not with its mid point or either vertex.

>>53604575
length R or less*
>>
>>53604625
Well thats where throwing rays to every open squares (edge/center/corner) comes in. Doing that guarantees coverage, but takes ages to compute.
>>53604623
This link has implementation examples, as well as alternatives that trade accuracy for speed
>>
Hey /g/, programming newfag here, im doing a course in my college called 'introduction to programming'. it's going pretty well with the learning curve, so far ive gotten the hang of variables (int,float, boolean,etc..) conditions, (if, else). we're focusing on a language called Processing. i was wondering if you guys had any tips for a beginner and maybe some tips on what language i should look to start practicing. im kind of torn between java or c++.
>>
>>53604625
i think you're right about the edge cases. you might need some sort of sweep line algorithm
>>
>>53604668
also i think the best advice ive gotten from my lecturer is that there is no easy way to becoming a good programmer, it takes countless hours of practice and dedication.
>>
C++ here

Can I build a n x 2 2d array that has chars in the first column and doubles in the second?
>>
>>53604678
not in the way you seem to be implying

you could use a struct with a char array followed by a double array
>>
>>53604678
Not directly.
struct {
double d;
char c;
} arr[10];

char arr_c[10];
double arr_d[10];
>>
What do you do when you encounter an optimization problem with far too many permutations?
I've got a matrix in random order and I need to get it to a specific order in as few steps as possible, but at each step I can only swap adjacent elements or pass them on in a cycle.
Obviously breadth first search would give me the optimal solution, but that's not feasible considering that there are c*n! possible permutations for just one step.
>>
>>53604668
java is the best for beginners imo but C++ is ok too

check these out
https://docs.oracle.com/javase/tutorial/
http://en.cppreference.com/w/
>>
>>53604623
>>53604667
>>53604670
Thank you very much.
>>
>>53604721
Graph traversal can be a tricky business. The idea is to introduce a heuristic and choose likely paths before unlikely paths based on the heuristic.

Look up A*
>>
>>53594871
Continuing progress on chess engine. I was finally able to successfully debug my White pawn capture generator.
>>
File: 1432860473789.png (40 KB, 335x342) Image search: [Google]
1432860473789.png
40 KB, 335x342
>>53604726
>java is the best for beginners
>Forced OOP is good for beginners
>""Design Patterns"" are good for beginners
>>
>>53604668
I would recommend against C++ if you are a beginner. Java is a good option imo. You might want to look into scripting languages like Python as well.
>>
>>53604797
>memes
start off with variables and control flow in the main method, then do static methods, then do objects
>>
File: 15 puzzle.png (19 KB, 220x220) Image search: [Google]
15 puzzle.png
19 KB, 220x220
>>53604771
I know what you mean and I've tried thinking about it, but I'm not sure how I would implement it. To use a heuristic, I would need a fast way to even generate the paths.
Pic related: For the 15 puzzle, generating the paths is intuitive for me. At the start, you can move two tiles to the blank space. At every step, there is a maximum of 4 possible paths.
However, with my problem, I've got an exponential number of possible paths (for just one step). Do you know what I mean?
>>
>>53604809
If you allow more moves, of course your branching factor is going to be higher and hence your search is going to be slower, there isn't a way around that.

A simple heuristic for this kind of thing is the sum of distances (with the manhattan metric) between a tiles current position and its final position.

(btw, I'm not sure what you mean by cycles as legal moves)
>>
>>53604881
Essentially, you are allowed to pass each element onto an adjacent cell, but one cell cannot have no element or more than one element. This means you have to either swap adjacent cells or pass elements on in cycles, for instance A -> B -> C -> D -> A. This way, cell A gives its element away and gets the element from cell D.
>>
>>53604935
Well, that certainly does complicated things.
Still, this is just increasing your branching factor (alot more) and I don't think there is a good way to get around that if you want to guarantee optimal solutions. A* is still probably your best bet, although admittedly, there are people who know alot more about this than I do.
>>
>>53604473
This is why everyone is ought t use 1tbs instead of allman
>>
>>53605009
The solution doesn't have to be optimal, just good enough. I like the idea of A*, but from what I understand it picks the neighbour with the best value? But determining that neighbour already takes a ridiculous amount of time. I think the runtime would just blow up.
I've also considered a greedy heuristic, but there's no guarantee it would even give me a solution at all because it might get stuck.
>>
>>53603404
Other than 0.
>>
>>53605046
If you want to do this faster, your going to have to restrict allowed moves. You might have some luck with restricting to a maximum length.
Or maybe pruning branches that overall lower the heuristic (only consider progressive paths)

Roughly how big are these matricies you want to work with?
>>
>>53605111
The biggest matrix I need to be able to deal with is 10x10=100 cells big. Restricting the number of allowed moves is a good hint, I just wouldn't know how. The problem is that even really good solutions have steps that seem like they're shitty locally but that ultimately improve the result.
>>
>>53605175
Well, I don't know. 10x10 isn't that big so you're probably not going to run into tooooo much trouble without pruning.

I'm going to go sleep, hope you come up with something.
>>
>>53597561
you just need to download a dll and add it as reference in your project
>>
>>53601047
Why even use a bounding box.
We're not on Atari gaming consoles and we've learnt how to do collision detection much better.
One event of Pythagoras every cycle is nothing and technically you're not even supposed to calculate collisions every cycle for every object.

Read Wikipedia on physics engines and get something out of how they calculate physics using time estimates and other forms of estimation.
>>
Hi people newfag here. I want to learn Java so that i can generate a passive income making Android apps. I have some basic knowledge and i want to learn more so where do I learn it from? There's just so many resources out there that I'm overwhelmed.

Or alternatively what are good ways to generate a passive income using programming?
>>
I'm not sure how I feel about Tuples

tempMachines.Add(new Tuple<int, string, string, string>(tempID, tempName, tempLocation, tempLastLogon));
>>
>>53606108
what's there not to like about tuples?
>>
Java Quandary.I want to sort a hashset. Wondering it makes more sense to push it into a List and sort that, or to just push the hashset into a Treeset and let it do its magic. Just want to sort the list before I display it, so I was thinking to either return a treeset or a list.
>>
>>53606108
>I'm not sure how I feel about Tuples

You aren't supposed to feel anything about them.
>>
Let's say I have a sequence of numbers that adds up to a 100.
How would I roll a random number so that each number in the sequence represents the chance for it to occur?

Say I have:
[20, 20, 30, 10, 5, 5, 2.5, 2.5, 2.5, 2.5]

Now, I'd like to pick an item from the sequence so that the first item has 20% chance to be picked, so does the second, the third has 30% chance and so on...
>>
>>53606414
for each member in the list to randomly select, copy the element from that list if rand() % 100 < chance at the same index in that chance array you have.
>>
>>53606414
What you are looking for is weighted randomization.
>>
>>53606414
Generate a random number r from 0 to 99.

If 0 <= r < array[0], select array[0].
If array[0]+1 <= r < array[1], select array[1]
etc.
>>
>>53606414
The easiest way is to create a list with the # of elements proportional to what their weight is.

You could also do a random to pick the element, then a random out of 100 to see if the roll succeeds. For example, you randomly pick '30', then the Random of 100 must be less than 30. If not, reroll and retest until success.
>>
>>53606414
I have a code to do that in Python. Are you interested?
>>
>>53606482
*should be array[0]+1 <= r < array[0] + array[1]
>>
>>53594871
That's not the actual dialogue is it?
>>
>>53606553
No, retard.
>>
>>53606557
a man can dream senpai
Thread replies: 255
Thread images: 30

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.