[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: 90's kid with sunglasses
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: 22
old thread :::::::::::::::::::::::::::::: >>54198414
What are :::::::::::::::::::::::::::::: you working on /dpt/?
>>
nothing but thanks for asking i appreciate the thought
>>
>>54206286
i approve this non-trap anime posting
>>
File: comfy.png (167 KB, 376x328) Image search: [Google]
comfy.png
167 KB, 376x328
DAILY PROGRAMMING CHALLENGE!

Create a DEC to HEX converter!
Don't use the built-in hex operator in printf, that's cheating.
>>
>>54206286
webdev here. sucking some more dick today.
>>
>previous thread at 298

Kill yourself weebfuck
>>
>>54206385
>programming "challenge"
>it's a middle school programming exercise

I seriously hope you are not representative of the skill level in these threads
>>
>>54206392
if the trap fag gets to do it, the weebfuck also gets to do it
>>
>>54206418
for the most part, he is.
>>
>>54206418
>I seriously hope you are not representative of the skill level in these threads

Most people ITT spend all their time optimizing their fizzbuzzes in 30 languages rather than write something useful.
>>
>>54206392
I'm preventing what would happen if the trapfag posts early, half a threads worth of shitposting. Be thankful.
>>
>>54206425
You seem to think they're different people

There are only two kinds of people in /dpt/

people who have anime wallpapers and talk about fizzbuzz/fibonacci level shit and people who can program but stay out of threads started with anime pics
>>
>>54206385
There was once a time when I could convert to any base number system on paper, but I forgot, because I literally never had a use for it.
it's basically
remainder = num % 16;
num /= 16;
until num becomes zero... or something
>>
DAILY PROGRAMMING CHALLENGE!

Prove that P=NP.
>>
Should I upgrade to windows 10?
>>
>>54206440
Skilled programmers actually do challenges? You reach a point where it's all grind, I could do this but it'll take at least a month, possibly six months of my free time.
>>
>>54206576
skilled programming work is 90% collaborative planning

the actual typing is the least of your worries unless you're literally a CRUD codemonkey computer janitor who just does what he's told
>>
>>54206561
10 LET P=0
20 LET NP=1
30 IF P=NP THEN PRINT "TRUE" ELSE PRINT "FALSE"
40 GOTO 10
>>
>>54206561

>Daily programming challenge
>Unsolved problem worth a million bucks
>>
>>54206620
Yeah so any sort of challenge that's interesting at any decent skill level takes a large number of people and time.
>>
>>54206635
if(P = ((N^N)+1)*P) return true;

gib million pls
>>
>>54206661
No, it really doesn't.
You're just a braindead programming pajeet.
>>
File: thatsthejoke.jpg (22 KB, 480x360) Image search: [Google]
thatsthejoke.jpg
22 KB, 480x360
>>54206641
>>
>>54206681
So give us a short, interesting challenge then, sir, and I'll teach how to head wobble.
>>
>>54206676
#define NP ((N^N)+1)*P

int main(int nargs, char** argv)
{
int P = 1234;
int N = 1141414;
if(P == NP) printf("gib 1000000 pls");
}
>>
>>54206731
No, because you're invariably going to accuse me of posting my homework.
>>
Daily programming challenge:

Write a program that determines if an arbitrary program in the same language halts.

(Hint: it's possible)
>>
>>54206812
>(Hint: it's possible)
this

fuck smug pseudointellectual memeing shitkids
>>
>>54206812
Does this involve scanning through the binary files or source files?
>>
>>54206825
>elegant and easier to use
>>
>>54206857
Yes
>>
>>54206812

> SELECT 1

Assuming a SQL variant with no loops.
>>
>>54206877
Elegant, maybe not (but compared to C++ it is) but if it weren't easier to use why are all the pajeets doing it?
>>
>>54206939
>if it weren't easier to use why are all the pajeets doing it?
this

if java/OOP is too hard for you you're literally dumber than a pajeet
>>
>>54206812

statements = ('while', 'for')

if all(statement not in source for statement in statements):
return True
else:
raise Dunno
>>
>>54206991
Doesn't work, this says simple infinite recursion halts. Also, "dunno" isn't a valid answer, it must determine if the program halts or not.
>>
>>54206991
What if there's a loop that finishes but takes longer than the universe will last?
>>
>>54207017
>Also, "dunno" isn't a valid answer, it must determine if the program halts or not.
spergtastic

if the program relies on external input or some hypothetical magic fairy, it's obviously impossible to know so your question is malformed.
>>
>>54207043
you're the one sperging out. Can you solve it assuming no external input is allowed?
>>
>>54206939
>>54206978
Simple all the jobs are all in Java you retards
>>
Rust vs Scala.

Quick
>>
>>54207017
Infinite recursion will halt as soon as your stack space is exhausted. The program crashes if it's not possible to know.

>>54207037

An input program containing any loop causes the detection program to crash.
>>
>>54207151
both are cringeworthy but rust
>>
>>54206812
I'm here to ruin the fun
https://en.wikipedia.org/wiki/Halting_problem
>>
>>54207151
Scala because I don't know Rust and I know and like Scala. Plus it runs on the JVM so you get mature memory management with your functional goodness.
>>
File: pc.png (378 KB, 1450x1080) Image search: [Google]
pc.png
378 KB, 1450x1080
>>
>>54207328
rolling
>>
>>54207328
most of these challenges are way too hard and only for really experienced programmers
>>
>>54207353
A lot of these are pretty easy to be honest.
>>
>>54207151
Rust because no GC and not OO.
>>
>>54207353
Some of them are easy, some of them hard. The hard ones are the best, even if you give up you learn a lot in the process.
>>
>>54206286
PLEASE stop abusing sakamoto-san like that... he's too precious.
>>
File: 1459286386228.jpg (716 KB, 2448x3264) Image search: [Google]
1459286386228.jpg
716 KB, 2448x3264
 
#!/bin/bash

exec "$1" "$@"

echo "$1 halts with arguments $@"

>>
File: 1426376304274.png (889 KB, 756x715) Image search: [Google]
1426376304274.png
889 KB, 756x715
Is there a better way to serialize objects in python3 not using pickle or JSON? The security issues worry me a bit and getting my objects to dump and load JSON seems like a pain in the ass.
>>
>>54207377
liar

>>54207420
truth
>>
>>54207537
echo will never be executed, exec replaces the current process image.
>>
>>54207546
Maybe PyTables? http://www.pytables.org/
>>
>>54207328
Some of these look good actually.
>>
>>54207646
Skimming the docs it looks like it doesn't support lists or dictionaries. But I'll give it a closer look later. How is the performance?
>>
>>54207749
Re-rolling because I already did this in C on XENIX decades ago.
>>
I'm learning programming, but everytime I get frustrated with programming I have a headache that makes it almost impossible to be productive. Do I need to take pills?
>>
>>54207777
New rule, quads redo the challenges in a better design?

pls.
>>
>>54207786
quads = redesign x86 assembly
>>
>>54207768
I found it to be better than cpickle for very large arrays. I only used it once in a case where cpickle was using too much memory.
>>
File: 1443776717558 (1).gif (303 KB, 320x240) Image search: [Google]
1443776717558 (1).gif
303 KB, 320x240
Say /g/, you want a persistent singly-linked list which also has efficient last, butlast, and count operations. What you could do is define a trivial Node type with an element and a pointer to the next Node, and expose to the user another datatype which has a pointer to the first and last Nodes, and an integer with the Node count, or am I being dumb? Maintaining the count never requires traversal, nor does finding the last element, and butlast requires traversal but no copying... just realised. That could still be an interesting option, no?

Clojure made me think of that given that they advertise last as constant-time[1]. Looking at the implementation, I see that they keep a count on every node[2] because every node is a list (which is dumb, but it's implemented in Yava (TM) so I should have expected it), but no last node, and I see this function[3] which doesn't exactly look constant-time to me... what do, /g/?

>inb4 too much brackets

[1] http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/last
[2] https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentList.java
[3] https://github.com/clojure/clojure/blob/d5708425995e8c83157ad49007ec2f8f43d8eac8/src/clj/clojure/core.clj#L262
>>
>>54207786
I really can't be fucked with that right now, sorry. Looks good as it is anyway.

>>54207782
Probably. See a doctor. Could be blood pressure or something stress-related.
>>
>>54207420
>give up
lol fag
>>
>>54207782
No you do not need to take pills my friend. Learn meditation.. this will help a lot :)
>>
>>54207900
That sounds pretty cool. Since you're providing the user with another datatype, it's almost like you're indexing some of it, which kind of throws away the concept of a linked list, but I guess it works
>>
I'd like to get my github into a better shape and do some code other than univ assignments, are there cool projects lying around?
>>
Just released a new version for my webm converter at https://github.com/rzumer/Webbum/releases/tag/v0.5
Haven't done anything in a while because of work though.
>>
>>54208171
They're lying around in your head, anon.
>>
i watched hackers (1995) for the lulz

are those books real, and how do i program a gui like the gibson had?
>>
What would this look like in pseudocode?

design the logic for a program that allows the user to from 1 to 12 positive integer numbers and store them in an array. If the user enters -1 or reaches 12 numbers, do the following processing:

- display the list of numbers in reverse order from which they are entered

- compute and display the average of the numbers entered

- determine and display the highest number entered

- determine and display the lowest number entered

Exit the program after completing the above by displaying the message "That's all folks!"
>>
>>54208199
Point taken, I'll do something on my own.
>>54208189
Looks cool, what's the issue with the filenames?
>>
File: sweating.jpg (25 KB, 300x300) Image search: [Google]
sweating.jpg
25 KB, 300x300
>>54208227
>Angelina Jolie in that film
>>
>>54208227
Do you know anything about programming son
>>
>>54208279
for(;;) printf("Do your own homework faggot");
>>
>>54208305
shut the fuck up kid im THIS close to hacking you from a payphone
>>
>>54208279
It would look like the answer to your homework.
>>
>>54208286
The ffmpeg filter chain system is fucked up, so I haven't been able to figure out how to pass a file name with an apostrophe in it successfully.
>>
>>54208337
\'

:^)
>>
>>54208328
GODDAMNIT KID YOU WINNUKE ME ONE MORE TIME...
>>
>>54208352
Yeah, you would think you could just escape it somehow, but the way it works is too ridiculous. Pretty sure I searched for hours before giving up (for now).
>>
>>54208328
i hope u type as good as u fuck
>>
>>54208358
KID I'VE READ THE BIG UGLY RED BOOK I'LL HACK YOUR GIBSON'S FLUX CAPACITOR
>>
test
>>
File: eagle.jpg (68 KB, 263x225) Image search: [Google]
eagle.jpg
68 KB, 263x225
>>54208407
>>
>>54208227
tard https://en.wikipedia.org/wiki/Rainbow_Series
>>
>>54208386
how does it work?
>>
>>54208427
the only documentation is here:
http://ffmpeg.org/ffmpeg-filters.html#Notes-on-filtergraph-escaping

I tried every combination I could find in my mind and on Google to escape that shit, nothing worked.
>>
>>54208460
pass the file in double-quotes perhaps
>>
>>54208386
>>54208427
also, did you try escaping the shit out of it? Not just one or two slashes
>>
is there any reason (besides 'learning') to use opengl/directx for graphics over something like unity?
>>
How can I allocate memory for a file in C++?
>>
>>54208489
no, not really, unless you want to build your own shaders and shit and want some deeper knowledge
>>
>>54208471
Yes I did, I don't even remember how many levels I ended up trying to escape. It either fails to parse/encode or it doesn't escape the apostrophe properly.

>>54208470
Tried that too of course.

Believe me when I say it's retarded. I need to set aside a few hours to try again.
>>
>>54208504
char buf[bufsiz]
read and shit into buf
>>
>>54208489
What's your reason for doing graphics programming? If you're learning for learning's sake then learning Unity is learning to become dependent on Unity. If you're trying to make it big by making a shit-tier indie game then Unity is the way to go. But you don't really need programming to be a Game Designer either, you need an ego the size of the moon and an art department based in Eastern Europe.
>>
is it worth learning regex
>>
>>54208588
>>54208504
That's stack allocated isn't it? Need to allocate on the heap (using new) if your file is a reasonable size and your target system isn't.

For example, you'll struggle to allocate 256 bytes on your stack on a PIC microcontroller.
>>
>>54208648
no

if you ever find yourself using regex you're doing something wrong or something gay (which is also wrong)
>>
>>54208544
can ffmpeg receive anything other than a string? like pipe the content of the video directly to it?
>>
>>54208607
>But you don't really need programming to be a Game Designer either, you need an ego the size of the moon and an art department based in Eastern Europe.
this
>>
>>54208648
Yes. Anyone who tells you not to is a pajeet who tried to learn it and failed.
>>
>>54208660
char *buf = (char*)malloc( how much do u want nigga? );

test if its 0 tho
>>
>>54208489
of course there is, even in a game engine like unity you'll be using your own shaders if you aren't a shitter
>>
>>54208686
that's a string u dumb fugg
>>
Do I need to learn math to program?
>>
>>54208660
>microcontroller
>C++
>>
>>54208607
I'm learning openGL, but I was wondering if there was any reason to actually use it IRL as opposed to making stuff in an already existing engine
>>
>>54208686
That's what is done for image subtitles, but text subtitles will be displayed from the start even if you trim the video, so using the subtitle filter with the same file name as the video is the only way I found to include text subtitles without extracting them from the file (which would take longer)
>>
>>54208715
i meant other than filenames, my bad
>>
>>54208648
It's worth learning the basics and using it when you need it, then expanding over the years as you use it more and more. Over-using it makes your code unreadable, under-using or not using it means you'll tend to write error-prone string manipulation code where a simple regex would have done.
>>
>>54208721
yes unless you want to be a webdev or a CRUDmonkey
>>
>>54208725
Generally not no.
>>
>>54208695
C++ nigga. Use new, not malloc.
>>
>>54208726
you could spaghetti your way out of it by renaming the file and naming it back right in the end heh
>>
>>54208725
you get literally orders of magnitude better performance depending on the application and you can get any effect you want and not just the built in/asset store crap
>>
>>54207782
reduce the brightness of your monitor and increase the contrast of the screen, and if you are using an old monitor (CRT), increase the refresh rate.
>>
am i autism for doing
#typedef byte char

??
>>
>>54208735
>string manipulation
for you
>>
>>54208762
But then the directory might contain apostrophes too. And if I copy the file to a temporary directory it might not have enough space especially if it's a massive grainy blu-ray film.
>>
>>54208742
What kind of math will I need to be ready for workplace?
>>
>>54208725
As long as you use an open source engine with a permissive license you've basically got someone else to do the graphics work for you. If you use proprietary software then you're at the mercy of whoever owns the copyright in years to come.
>>
>>54208788
what about something like a symlink?
>>
>>54208725
for example you can make grass and shrubbery that moves with the wind, don't know if unity has anything like that that isn't shit, and weather systems with varying shadow directions depending on time of day, particle effects, post processing effects etc etc
>>
>>54208781
retarded and autistic
>>
>>54208793
Telling the time, percentages, averages and some basic algebra.
>>
>>54208781
unsigned char and no, if it makes your intention clearer then it's worthwhile. If you're using byte for strings then you missed the point.
>>
Why is it faster to use X to blit an image to a window, compared to uploading the image to GL and blitting/rendering it on the GPU?

Shouldn't doing it on the gpu be faster than going through X?
>>
>>54208897
>unsigned char
that would be a ubyte

also uint8_t
>>
>>54208857
Cool I know all of those. Okay now what kind of maths will I need to know to make real cool applications
>>
>>54208910
because X is shit

don't know how X works, is it uploading the image repeatedly?
>>
>>54208938
for games? actual games and not 2d pixel hipster fag gayms? trigonometry, geometry, linear algebra, calculus
>>
>>54208910
You'd think it ought to be faster, but you've probably got CPU and GPU side copies of the data, mipmap generation, format shifts and a load of other postprocessing going on when you allocate memory on your graphics card.

Sometimes a good old fashioned blit is what you need.
>>
>>54208988
also gpu shit has a fuckton of latency (because muh concurrency) unless you do some fuckery, so a blit might be faster in that regard
>>
>>54208917
Fair point, but uint8_t is the memory implementation and you still need to guess the data type from the context. Maybe I've just been used to fancy type systems for too long.
>>
>>54208660
>>54208760
Sooo how do i do that shit?
>>
>>54208988
this is only because x is shit of course.
>>
>>54208942
See that's what I thought. But it turns out X is way faster.
>>
>>54207328
Roll
>>
>>54209094
With a Googlewhack
>>
>>54207410
Rust can OO.
It's not required, but it can.
>>
File: 20160424_234425.png (703 KB, 1079x1594) Image search: [Google]
20160424_234425.png
703 KB, 1079x1594
>>54208128
>That sounds pretty cool.
It is. Anyone ever seen it implemented somewhere before I thought of it? Surely there must be...

as for indexation... I don't know. It's no more than an enhanced version of a Node pointer, which is your most basic baremetal singly-linked list manipulation object, and the structure sharing is still there, again enhanced. But yes I am caching and deducing the length, which we could compute anyway, so it's just optimisation. Again, classical an Anon(C) linked lists exhibit the same interface, and you should always program to an interface, Pajeet. Speaking of which, here's what I found when googling "enhanced singly linked lists"... Pajeet made my entire day.

Also I'm no better than a Pajeet since I misreading-comprehended the docs I posted earlier, since it clearly says that last is to be expected to run in *linear* time... how dumb.
>>
I have an interview tomorrow for a year long placement as a software developer
Wish me luck guys
>>
>>54209114
faster in what way and compared to what? what are you measuring, does it have lower latency (time for the image to appear on the screen) or is the frame rate smoother?
>>
>>54209184
good luck

remember not to tell fibs
>>
File: rtest.webm (2 MB, 912x780) Image search: [Google]
rtest.webm
2 MB, 912x780
>>54206286

Simple twitch explorer for the terminal
>>
>>54209248
Thanks
I (hopefully) have enough to offer to not to have to tell porkies
>>
>>54209201
Higher frame rate. Less CPU time spent in rendering and more time to do other shit.
>>
>>54209264
Looks great! bonus points if you get w3m-img in there and add thumbnails for each stream
>>
>>54209264
>>54209290
do you have that on github?
>>
>>54209155
Nice use of XOR. Can't think of a practical use for it but it's a nice trick to have up your sleeve I guess.
>>
>>54209264
What are you using to display? I use omxplayer for streaming but I'm wondering if there's something better.
>>
>>54209331
You can also use it to swap two variables without using a third as temporary storage.
>>
>>54209342
It uses live streamer with mpv
>>
>>54209361
>mpv
Ah cool thanks
>>
>>54209343
Yeah I've seen that done along with loads more of those over here:

https://graphics.stanford.edu/~seander/bithacks.html

Some real gems in there.
>>
>>54209283
that sounds completely fucked. are you the one doing the opengl programming? are you uploading on every frame?
>>
>>54209322
Nah, I use gitlab.
Don't really want to share it anyway as it's probably horribly coded
>>
>>54209394
Yes and yes.
>>
Anybody have a good chunk of text to test a markov nigger against?
>>
>>54209430
>and yes
don't
>>
>>54206385
Beginner coder, dead new to Python
def convert_dec_to_hex(decimal):
i = 0 # maximum power of 16 in number
r = 16 ** i # resultant
while r >= 1:
i = i + 1
r = decimal / (16 ** i)
i = i - 1
remainder = decimal #probably could have just used "dec"
hex = ""
while i >= 0:
if int(remainder / 16 ** i) == 0:
hex = hex + "0"
elif int(remainder / 16 ** i) < 10:
hex = hex + str(int(remainder / 16 ** i))
elif int(remainder / 16 ** i) == 10:
hex = hex + "A"
elif int(remainder / 16 ** i) == 11:
hex = hex + "B"
elif int(remainder / 16 ** i) == 12:
hex = hex + "C"
elif int(remainder / 16 ** i) == 13:
hex = hex + "D"
elif int(remainder / 16 ** i) == 14:
hex = hex + "E"
elif int(remainder / 16 ** i) == 15:
hex = hex + "F"
remainder = remainder % (16 ** i)
i = i-1
return hex
>>
>>54209436
http://www.gutenberg.org/cache/epub/19337/pg19337.txt
>>
>>54207328
stop posting this shit, you fucker. make a new thread or something instead


>>54208695
why do some fucking retards still confuse C with C++?
>>
>>54209436
Just scrape text from /g/ or other boards.
It's not that hard to write a scraper bot using the 4chan API.
>>
>>54209436
Train it on public IRC logs
>>
>>54209492
You can't teach an old fag new tricks
>>
>>54209440
Well what the fuck am I supposed to do?
I'm emulating a fucking console, I have to bit blit to something to draw, I can't let a modern GPU do it because that's nothing like the console's behaviour.
>>
>>54209621
blit then, opengl is shit for rendering text anyway
>>
>>54209621
What can't you draw with the GPU?

Just use skia or cairo or some shit. Directly using OpenGL for UI related stuff is almost always dumb.
>>
>>54209485

Woman, similarly laden with tears, they were also defective.


Sometimes it comes up with gems.
>>
>>54209458

Code review young padawan:

Not sure what you're doing with the first while loop. What's that even do? Numbers in Python are duck typed, they don't have a maximum number of bits, they could be anything.

You can remove those ugly branches by using a lookup list:

'0123456789ABCDEF'[index]


It's worth knowing that strings in Python are immutable; every time you do "hex = hex + something" you're creating a brand new "hex + something" string and discarding the old one. Better to put them in a sequence then join it all together before you return it:

return ''.join(letter_sequence)


"Magic" numbers are a no-no, even the number 16. Give it a meaningful name ("base" seems appropriate)

Also, later on in your journey revisit this and think about sequence generators and inner functions to tidy your code up.
>>
>>54209710
pls do these http://textfiles.com/messages/
>>
>>54206385
I had to look up how to do in-place string reversal for this.

char *dec2hex(int num)
{
unsigned len = uintlen(num);
char *str = (char *) malloc(sizeof(char) * len);
int i = 0;
while (num > 0)
{
unsigned digit = num % 16;
if (digit > 9)
str[i++] = digit - 10 + 'A';
else
str[i++] = digit + '0';
num /= 16;
}
str[i] = '\0';
strrev(str);
return str;
}
>>
>>54209765

I gave it a Trump speech and there's some good stuff there, too.

isis has tremendous amounts of teleprompters
justice roberts basically approved obamacare
>>
>>54206369
>I'm not a real programmer
you just don't belong anon
>>
>>54206502
>people who can program
bwahahahaha
>>
are any of you interested in collaborating on a horror game
>>
>>54209845
>uintlen
what the fuck
if you want the number of digits in a number do:
//return number of digits of number
int digits(int n)
{
return floor(log10(n))+1;
}


Also
>casting malloc
>>
>>54209086
>uint8_t is the memory implementation
get a load of this webcuck
>>
>>54209719
>Not sure what you're doing with the first while loop.
That was to determine the highest power of 16 that goes into the given decimal. It tests if 16^x goes into the given number until it can't.

>You can remove those ugly branches by using a lookup list
I didn't even think to use that. Thanks. I'm used to using multiway control structures for that stuff, and apparently python doesn't have one.

>It's worth knowing that strings in Python are immutable
Did not realise this. How would you recommend putting them in a sequence without creating a bunch of strings? I'm afraid I'm not sure how you would do that.

>"Magic" numbers are a no-no, even the number 16. Give it a meaningful name ("base" seems appropriate)
I should have known better for this one.

Thanks for the critique, I appreciate it.
>>
>>54209845
>sizeof(char)
m8...
>>
>>54209862
Hot damn it can replace trump
>>
>>54209969
not to mention casting (char*)malloc(char) kek

But wait, you'll have people saying char != 1byte on some systems lel
>>
>>54209969
You wouldn't sizeof a char.
>>
>>54209937
>n <= 0
>it fails
>>
>>54209984
>But wait, you'll have people saying char != 1byte on some systems lel
its true you cuck faggot
>>
>>54209984
wasn't there some tard that had sizeof(char)=2 on his company's custom platform
>>
>>54209984
char == 1 byte everywhere in C.
CHAR_BITS != 8 though. and char may or may not be signed.
>>
>>54210005
Yeah haha that's what I was referencing
>>
>>54210015
CHAR_BITS >= 8
>>
>>54210005
Then he's not writing C.
In C sizeof(char) == 1
>>
>>54210015
>>54210027
>>54210030
NO STOP PLEASE WEVE BEEN THROUGH THIS
>>
>>54209998
> n<= 0
-n or n it's the same faggot
>>
>>54210038
lol wut you should have abs(n)
>>
>>54210061
>number of digits of 12345 ? 5 digits
>number of digits of -12345 ? 5 digits
>>
File: IMG_20160424_161058.jpg (3 MB, 3120x4160) Image search: [Google]
IMG_20160424_161058.jpg
3 MB, 3120x4160
I'll just leave this here.
>>
>>54210072
yes, and?
>>
>>54210122
le girls can learn 2 code meme
>>
>>54210122

They'll all be gone after first year anyway.
>>
>>54210122
>Web developers there suggested she look into a degree in computer science
normies reeeeeeeee
>>
File: new rules.jpg (1 MB, 1280x721) Image search: [Google]
new rules.jpg
1 MB, 1280x721
looking for a simple yet elegant one printable page of the most common used things in java

basically a java cheat sheet.
everything i find on google is more than one page or is lacking in some way.

can i /g/et any help please?
>>
>>54210188
it's simple enough to keep in your head

like learning how to ride a bicycle
>>
>>54210202
but i'm LEARNING to ride the bike right now
>>
>>54210188
You mean standard library functions?
Maybe you should use a language with a syntax that can fit on a postage stamp, like C.
>>
const int FOO = 3;
constexpr int FOO = 3;


In C++, is there any reason to ever use the first over the second? It seems like using constexpr is just better, as it allows you to use the value in constexpr functions.
>>
>>54210231
>>54210202
what i love/hate about 4chan:
all replies are ANYTHING but what was asked for.
good luck getting an actual answer, anon
>>
>>54210202
>tfw 20
>tfw don't know how to ride a bicycle
>>
>>54210246
>ask for something unreasonable
>get reasonable responses
>waaahh i didn't get what i wanted
>>
>>54210253
it's never too late
>>
>>54210246
It's /dpt/ not stackoverflow fag
>>
>>54210272
aye.
>>
>>54210219
take this for example

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/flowsummary.html

you know those things, right? or if you don't, you could easily learn them. you don't need a cheat sheet for them.

now apply the same principle to most other things.
>>
File: 1451529962932.jpg (53 KB, 1280x720) Image search: [Google]
1451529962932.jpg
53 KB, 1280x720
What is the proper way to learn?

I've been writing bits here and here but nothing useful, good or more than 50 lines.
>>
>>54210030
Not all of the time retard. Type size isn't portable
>>
>>54210253
You're gonna have to use training wheels AS AN ADULT.
Your socially acceptable period for learning the bicycle has already passed.
>>
>>54209968

> How would you recommend putting them in a sequence without creating a bunch of strings?

The usual way to do things in the style of another language would be to create an empty list, then insert

output_chars = []
while some_loop_condition:
# then stick it at the start of the list, like so:
output_chars.insert(0, next_char)

# combine before returning
return ''.join(output_chars)


But a more "pythonic" way of doing things would be to use a sequence generator:

def number_to_hex(number):
base = 16
def num_char_seq():
while number:
pos = number % base
number = number / base
yield '0123456789ABCDEF'[pos]

backwards = ''.join(num_char_seq())
return backwards[::-1] # reverse the string

print printable_base(3735928559, 16)


Note that the inner function is 1) a variable called num_char_seq whose type is a function 2) we call it a "closure" because it "closes over" the outer "base" and "number" variables, and 3) returns a "sequence generator"; an object that contains the state of the function up until "yield" is called and you can call .next() on to make it continue.

All the work is done by the "join" method on the empty string as it calls next() on the sequence generator and gets each letter in turn.
>>
>>54210241
constexpr indicates a value that’s not only constant, it’s known during compilation.
const indicates a value that’s only constant, it’s not compulsory to known during compilation

Note that const doesn’t offer the same guarantee as constexpr, because const objects need not be initialized with values known during compilation

All constexpr objects are const, but not all const objects are constexpr.

If you want compilers to guarantee that a variable has a value that can be used in contexts requiring compile-time constants, the tool to reach for is constexpr, not const.
>>
>>54210306
read good books and reference manuals and do medium-sized projects (200-20000 lines of code maybe)
>>
>>54210333
Thanks. I don't usually get a straight answer here like this.
>>
>>54210323
oh ignore that last line, I was messing about with making it work for any base (rename the function, put base as a parameter, make a longer string than '0123456789ABCDEF' [like string.digits + string.ascii_uppercase])
>>
>>54210306
You might want to consider coding challenges like Code Abbey or Project Euler.

Ideally, you should work on a long-term project.

How much programming do you know?
>>
>>54210325
So the TL;DR is: I should always use constexpr if I can, and reserve const for when something should not change but I don't know its initial value at compilation time.
>>
File: ss+(2016-04-24+at+07.30.08).png (67 KB, 738x891) Image search: [Google]
ss+(2016-04-24+at+07.30.08).png
67 KB, 738x891
Grading undergraduate work....this person will probably pass the class

end my life please
>>
>>54207156

void infinite_loop() {
infinite_loop();
}

int main(int argc, char *argv[]) {
infinite_loop();
return 0;
}


Shouldn't cause a stack overflow if compiled with the right optimization flags.
>>
>>54210426
He's loop unrolling. It's an advanced optimization technique. You shouldn't be grading assignments that are beyond your depth.
>>
>>54210426
>Grading undergraduate work
are you his professor?

if so, it is your fault
>>
>>54210475
HOLY KEK

BTFO
>>
>>54210476
No silly I'm just a lowly teaching assistant, this fucker doesn't show up to lab so there's nothing I can do for him.
>>
>>54209264
That's pretty cool anon
>>
>>54210445
int main() {
main();
return 0;
}
>>
>>54210445
My program was written in Python, no tail recursion optimizations there from what I understand. Though I may be wrong as I only really know cpython in depth, those crazy pypy bastards are pretty slick.
>>
>>54210475
well if the program _at least_ works he should have the mark.

you could probably leave a note though
>>
>>54210475
not_sure_if_joking.jif
>>
>>54210426
Im a code noob, however, I can tell this is the most eye rape code in the whole world...
>>
File: 1374864421273.jpg (35 KB, 224x220) Image search: [Google]
1374864421273.jpg
35 KB, 224x220
>>54210426
>>
File: too fat to hit it.jpg (37 KB, 396x344) Image search: [Google]
too fat to hit it.jpg
37 KB, 396x344
since smartphones have text editors, and prolly some app for programming,
how many if any of you actually program on you phone?

even if it's just on the bus ride home and you think of an idea and type it up on the phone maybe transfer it to pc later
>>
>>54210525
I-I just don't know what to say...He got full marks for it
Maybe: "Work on implementing for loops."
>>
>>54210306
Find something that makes you itch and scratch that motherfucker for ages. The main barrier to being an excellent programmer is getting thousands of hours of programming done, the second one is avoiding pissing those thousands of hours away on stale code and projects that don't stretch you.

Find a problem that is just above your skill level and spend 10-20 hours programming a solution, then throw it away because the code is shit. Keep doing that until you're writing 500-1000 line projects that are becoming difficult to maintain, then focus on learning project structure, refactoring and good design.

People will say that the best way to learn those things is by reading books, that's partly true but it doesn't beat real world experience. Do dogsbody work for open source projects while hanging out on GitHub and IRC and you'll be mentored by some of the finest autists in the land, and learn a lot as everyone argues about their code.
>>
>>54210587
Get a laptop?
>>
>>54210609
you take your laptop everywhere? grocery, gym (yeah g in a gym lmao), on a date?
>>
>>54210621
yeah i wear cargo shorts
>>
>>54210587
Not me. Fuck that. I need at least two monitors, or at least two desktops, and a real keyboard.

That's not to say I don't think about programming problems and on the bus and write down algorithms.
>>
>>54210621
Everywhere I go I bring my backpack which usually has my laptop in it.
>on a date?
;_;
>>
>>54210642
guess i need to get a small netbook for taking everywhere. my main pc is a laptop, but it's very expensive so i don't let it leave my desk.
>>
>>54210316
wrong
>>
As someone who is just getting into learning about classes in c++, could somebody tell me if I got my default constructor right? I don't really feel as if I know what i'm doing when creating one.

Question.cpp (class file)
Question::Question()
{
triviaQuestion;
answerOne;
answerTwo;
answerThree;
answerFour;
correctAnswer;
}

Question::Question(string question, string one, string two, string three,
string four, int answer)
{
triviaQuestion = question;
answerOne = one;
answerTwo = two;
answerThree = three;
answerFour = four;
correctAnswer = answer;
}
>>
>>54210587
I've tried. It's painful as fuck. If i really want to program somewhere remote i just bring my laptop.
>>
>>54210655
Get the cheapest laptop you can find and switch out it's hard drive for an ssd.
>>
>>54210587
What is the point? I spend most of my time thinking on the problem, not writing code. I can always type it later in more comfortable environment
>>
File: tree fiddy.png (179 KB, 500x213) Image search: [Google]
tree fiddy.png
179 KB, 500x213
POLL:

what city, state, country do you live in and do your public schools teach coding to children?
>>
>>54210679
>could somebody tell me if I got my default constructor right?
it's wrong.

that top portion (default constructor) is unnecessary... I guess it will technically compile but it looks retarded.

the bottom portion is correct, but look up initializer lists and how to use them
>>
>>54210708
so you are one of the few who have an eidetic memory. good for you
Thread replies: 255
Thread images: 22

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.