[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: 29
File: 12-most-influential-programmers.jpg (146 KB, 1024x768) Image search: [Google]
12-most-influential-programmers.jpg
146 KB, 1024x768
[Daily Programming] thread

Genius Edition.

Previous thread: >>51800627

What are you working on, Anonymous ?
>>
First for averaging 2 ints in C.
>>
Second for anime
>>
Third for Java
>>
>>51806401
I just recognize 8 of those guys :/
>>
>>51806413
int avg = (int1 + int2) / 2
>>
>>51806401
>john carmack
>richard stallman
>that guy in the bottom right

>>geniuses
>>
>>51806401
? ? ? ?
? ? ? Linus
Zuckerberg, Stallman, ? ?
>>
>>51806456
Freedom hater spotted.
>>
File: sa.webm (3 MB, 720x405) Image search: [Google]
sa.webm
3 MB, 720x405
Ask your beloved programming literate anything.

>tfw no question

>>51804679
>GDC (the GNU D compiler) is a lot better

D DMD:                          9.432905226 seconds time elapsed
D GDC: 25.970303586 seconds time elapsed
D LDC: 6.347934615 seconds time elapsed
>>
>>51806456
Richy ``The Stallion'' Stallman literally changed the way software is perceived and is arguably one of the most influential people in the world of software development. He's also said to be the last true hacker and he has created the best piece of software ever written -- GNU Emacs.
>>
>>51806505
You misspelled vim.
>>
>>51806520
But rms didn't write vim, fried. Otherwise it would have had a real chance of being good.
>>
>>51806413
(a >> 1) + (b >> 1) + (a & b & 0x1)
it's patented, but it just werks.
>>
uriel, faggot, bjarne, faggot
faggot, faggot, carmack, linus
jewberg, stallmanu, faggot, faggot
>>
>there are people here who would be up at 5am christmas day just to compete for the 50th AoC star
>one of those people will be me
who else lads?
>>
File: kitten_says_gtfo.jpg (79 KB, 960x750) Image search: [Google]
kitten_says_gtfo.jpg
79 KB, 960x750
>>51806564
>greatest software writer in history
>faggot
>pic related
>>
>>51806676
enlighten me who you're talking about

>>51806590
my sleep schedule is usually fucked up beyond repair and yet ive been up at 6 AM for 11 days straight just to get to the leaderboard
>>
Day 11 python beginner solution. Commented password is original, the one underneath is used for 2nd answer:

#password="cqjxjnds"
password="cqjxxyzz"
digits=len(password)
numPass=[]

def checkPass():
cons=False
found=False
doubles=0

for i in range(digits):
if numPass[i] in [105, 111, 108]:
return False

if i < digits-2:
if numPass[i+1]-numPass[i]==1 and numPass[i+2]-numPass[i+1]==1:
cons=True

if i < digits-1:
if found:
found=False
elif numPass[i]==numPass[i+1]:
doubles+=1
found=True

return (cons and doubles>=2)

#a-97,i-105, o-111, l-108, z-122
for i in range(digits):
numPass.append(ord(password[i]))

while True:
for i in range(digits):
if numPass[digits-i-1]==122:
numPass[digits-i-1]=97
else:
numPass[digits-i-1]+=1
break

if checkPass():
break

print "".join(chr(i) for i in numPass)
>>
>>51806401
?, Eich, Stroustrop, ?
Knuth, ?, Carmack, Torvalds
Zuckerkek, Stallman, ?, ?

Who are the ?s ?
>>
>>51806793
2, 2 is thomspon, but the rest...
>>
>>51806793
they are the proof you should lurk more before posting, newlord
>>
>>51806826
>not caring too much about famous people make you a newfag
>>
>>51806793
Bottom right is Bailey Jay.
>>
>>51806843
It's cute how you try to change the subject. Shows that there is some shame and righteousness in you.
>>
File: DPTChristmas2.jpg (316 KB, 797x530) Image search: [Google]
DPTChristmas2.jpg
316 KB, 797x530
>>51806401
http://adventofcode.com

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

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

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

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

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

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

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

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

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

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

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

Answers: https://paste.installgentoo.com/view/raw/21d38d22
>>
Yes, I'm the same faggot as yesterday
Yes, I still can't make this simple as fuck shit work
Yes, I hate myself for it

http://pastebin.com/Tq80n2eR

Why doesn't it work. I can post a version in English, but I doubt the language barrier is a problem when the variables are in english.
>>
I keep seeing python code and it just looks so simple and seemless. Is it actually, or am I just being fooled because I only ever see beginner code in python?
I've known C for a while and have been learning C++ but I'm feeling for something different.
>>
>>51806952
You can write neat stuff in Python, but everyone here gives it shit for being Python.

I used to use Python a lot but now I'm digging Ruby more.
>>
>>51806952
>I've known C for a while and have been learning C++
No, you haven't. Stop lying to us and, most of all, stop lying to yourself.
>>
>>51806900
How am I changing the subject? I don't know what these people look like, I've just seen their names. And I'm a newfag because I haven't googled what they look like? Your a fucking kek dude. Watch less TV.
>>
Anybody have a link to that page full of bit-twiddling techniques to do things in C? The page was full of them and I can't find it.
>>
>>51807013
Why did you abbreviate your name tripfag?
>>
>>51807013
C is completely worthless, just learn Python and call it a day.
>>
>>51806952
yeah it's pretty tight
isPrime=lambda x:len(i for i in range(2,int(x**0.5)+1) if x%i==0)==0
>>
>>51806986
???
I've spent the past two years learning to program in C and have spent the past month or so learning C++. What's the problem?

>>51806983
I don't really care about what the people here think, but I'll check out some other easylangs before getting too into it I suppose; thanks.

>>51807046
nice
>>
>>51807035

It's been this way for about 2 weeks now.

>>51807038

:)
>>
>>51807013
check out Hacker's Delight
>>
>>51807075
That's still no answer to my question burger.
>>
Bram Cohen
>invented BitTorrent
>genius status: yes

Brendan Eich
>created javascript
>genius status: fat loser who followed ECMA

Bjarne Stroustrup
>created C++
>genius status: created an almagamation of previous concepts, a horrible language in the end

David Hansson
>created ruby on rails
>genius status: hipster enabler (not a genius)

Donald Knuth
>wrote compilers, invented algorithms
>genius status: yes

James Gosling
>created java
>genius status: yes

John Carmack
>made a video game
>genius status: why is he even on here??

Linus Torvals
>created Linux
>genius status: yes

Mark Zuckerberg
>created Facebook
>genius status: no, he got lucky

Richard Stallman
>created GNU
>genius status: GPL is the opposite of progress, fuck this guy srsly

Sir Tim Berners-Lee
>invented HTTP
>genius status: yes

Solomon Hykes
>created Docker
>genius status: ?? okay thanks we had VMs already
>>
We're pleased to inform you that your 4chan ban appeal (#5650175) has been accepted

Thanks.
Now, back to business.
40th for C.
>>
File: 1312180763294.png (1 MB, 1280x720) Image search: [Google]
1312180763294.png
1 MB, 1280x720
>>51806993
You changed the subject from your newlordship to the debatable worthlessness of recognising famous people.
>I don't know what these people look like
Which is precisely why it's so obvious that you are very new and should refrain from posting before familiarising yourself with the culture surrounding these people and their passion. Also, yes, a newfag would ask before researching the gentlemen in question, as he would be pursuing the attention, lacking genuine interest in the subject matter.
>>
>>51807108
>Accepts Java but not C++
>labelling Doom as "Just a videogame"
>lel GPL

Kill yourself
>>
>>51807075
>using an outdated and unsafe language like C when you can use a superior language like Python
Nobody teaches C as first language for a reason: its no longer needed.
>>
>>51807013
You mean:
https://graphics.stanford.edu/~seander/bithacks.html
?
>>
>>51807159
It's only unsafe if you are bad at it. Not that a talentless codemonkey like you will understand. ;^)
>>
>>51806993
Holy fucking newfag. This isn't about who's famous. These men are the legends of the industry.
>>
>>51807176
Give me three good reasons why I should ever learn C.
>>
>>51807187
>muh data structures
>muh algorithms
>muh freedoms
>>
>>51807108
>Richard Stallman comment
Consider me triggered
>>
>>51807202
like I said, completely unnecessary. Python is the future.
>>
>>51806475
Should I watch Yuki Yuna?
>>51807108
>James Gosling
>>created java
>>genius status: yes
>>
where's dijkstra
>>
>>51807108
Anon
>invented shitposting
>genius status: maximum autism
>>
>>51807222
snakefags actually believe this
>>
>>51807296
you're yet to give me reasons why I should learn C as my first language.
>>
First for clojure
>>
>>51807187
>greatest support ever
decades worth of libraries, compiler optimisations, spread, lessons/tutorials, etc.
>able to do anything
You are positively able to do literally anything you want. This also opens room for probably the greatest optimisations you could make to your code.
>speed
It's not a secret that C is able to achieve the greatest execution speeds of all other general-purpose programming languages, save for some very limited applications where FORTRAN is slightly faster.

BONUS
>it's the heart of Linux
You literally can't use a computer nowadays without knowing at least some C.
>>
>>51807222
Enjoy your forced indentation.
#include <stdio.h>

int

main(


void)

{
puts(


"suk my diks"


);
return


2


-


2;


}
>>
>>51807108
>Richard Stallman
>>created GNU
>>genius status: GPL is the opposite of progress, fuck this guy srsly
regardless of your opinion, he IS a genius
>>
File: 1323123123.jpg (141 KB, 803x688) Image search: [Google]
1323123123.jpg
141 KB, 803x688
>>51807222
> Python is the future.

Oh no.. another one
>>
>>51807314
Also enjoy your forced concept structure.
asm(".global _start");


>tfw this compiles
>>
>>51807322
in what way is he a genius? he's just a famous hippie
>>
File: got_muh_eyes_on_you_faggot.gif (17 KB, 140x192) Image search: [Google]
got_muh_eyes_on_you_faggot.gif
17 KB, 140x192
>>51806713
>>
>>51807329
>that pic
kek'd

>>51807338
>in what way is he a genius?
ignorance is bliss
>>
>>51807338
Without stallman and free software such the GPL, Linux would remain proprietary and wouldn't be what it is today. Pressure had to be put on Linus to re-release the Linux kernel under GPL.
>>
>>51807061
>What's the problem?
>not reversing that order exactly
>>
>>51807338
>gcc
>actually made Linux popular
>GPL enforcing shits to contribute back
Nice try BSD fag.
>>
>>51807338
Disregarding his software distributions, disregarding GNU/FSF and his passionate philosophy, you have to acknowledge all the LISP magic he's done at the MIT labs.
>>
File: count.png (117 KB, 1256x628) Image search: [Google]
count.png
117 KB, 1256x628
I'm learning some PLC programming with Beremiz. For some reason I fail to understand how the counter function blocks operate.
When I apply a 1 Hz on/off (BOOL) pulse signal into the CU (count up) pin, the output just stays at 0 at all times. Assigning on or off BOOL value into the Reset input has no effect. What gives? Pic related
>>
>>51807108
>>genius status: created an almagamation of previous concepts, a horrible language in the end
>yet far smarter than you, even in the beginning

I doubt most of these men would claim any genius personally.
> except ofc Torvalds.
>>
>>51807373
>I doubt most of these men would claim any genius personally.
Of course, an actual genius would be humble about their intelligence. People who think they're hot shit aren't as smart as they think they are.
>>
>>51807337
>forced concept structure
what?
>>
>>51806822
lel, no. it's james gosling.

https://en.wikipedia.org/wiki/James_Gosling
>>
>>51807165

Thank you, my man.
>>
>>51807371
check how this block operates in the manual, maybe you confused enable pin with clk pin or something like that
>>
Why isn't this working?

#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main()
{
//Variables and stuff

string key = "MURCIELAGO";
char values[] = {'1','2','3','4','5','6','7','8','9','0'};
int check = 0;

//While loop
while(true)
{
cout << "Inserte palabra en mayusculas: ";
string encode;
getline(cin,encode);

//For loop
for(int loops = 0; loops < encode.size(); ++loops)
{
if(isupper(encode[loops]))
{
if(encode[loops] == key[check])
{
++check;
encode[loops] = values[check];
cout << encode[loops] << endl;
}
else
{
++check;
encode[loops] = encode[loops];
}
}
else
{
cout << endl << "ERROR: Use palabras en mayusuclas" << endl;
break;
}
}
check = 0;
}
return 0;
}
>>
>>51807456
¿que?
>>
>>51807456
This isn't stackoverflow.
Fuck off, or tell what part of the code isn't working.
>>
>>51807456
you way wanna mention what error you're getting
>>
>>51807473
I'm studying in Spain and I have to do this bullshit in Spanish.
>>
Wait shit that didn't work.

This is valid C and compiles properly:

_start();

[~/Devel/limited]% cat limited.c
_start();
[~/Devel/limited]% gcc -nostdlib -o limited limited.c
limited.c:2:1: warning: data definition has no type or storage class
_start();
^
limited.c:2:1: warning: type defaults to ‘int’ in declaration of ‘_start’ [-Wimplicit-int]
/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 000000000040010c
[~/Devel/limited]% ll
total 12
-rwxr-xr-x 1 eric eric 968 Dec 11 14:23 limited
-rw-r--r-- 1 eric eric 23 Dec 11 14:17 limited.c
[~/Devel/limited]%


fucking kek'd
>>
>>51807337
>>tfw this compiles
yes, why wouldn't it?

a = 5
print(a)

>tfw this doesn't interpret
>>
>>51807475
>>51807476

Yeah, I forgot about that. I'm retarded, sorry.

After the program checks if encode is uppercase , it just absolutely ignores the second if.
>>
>>51807456
encode[loops] = encode[loops];

?
>>
Which OS is better for programmers?
>>
I'm working on the PCI basics for my OS. Does How do you detirmine the bus, slot, and function of a PCI device?
>>
>>51807500
Linux, of course.
>>
>>51807497
That's something I left behind for testing, I was curious is that shit would work.

It's still not the cause of the problem, though.
>>
>>51807500
Linux. Windows programming is terrible unles you're doing .NET.
>>
>>51807500
Arch Linux
>>
>>51807500
Linux. if your computer can't run linux, just install a VM and use that for linux.
>>
>>51807526

>Arch
>Good for anything other than shitposting about how much of a l337 linux user you are
>>
File: emacs@arch_037.png (74 KB, 752x611) Image search: [Google]
emacs@arch_037.png
74 KB, 752x611
>>51807526
Confirmed.
>>
>>51807554
>>51807526
No, anon just install a distro like linux mint if he only cares about programming.
>>
>>51807500
>>51807517
>>51807522
>>51807526
>>51807532
>Using Linux instead of NetBSD
?!
>>
>>51807456
what is that code even supposed to do
>>
>>51807546
I use arch as my main OS along side windows 10. Say what you want, but the OS usually isn't the problem; the use is.
What I'm saying is that you're projecting your incompetency
>>
>>51807486
>This is valid C and compiles properly:
>fucking kek'd
yes, and?
>>
>>51807566
I've considered moving to FreeBSD but I care too much about popular program support. I figure if I ever get a cheap toy laptop or something I'll put FreeBSD on it.
>>
File: aFASEFASEFG.png (3 KB, 312x101) Image search: [Google]
aFASEFASEFG.png
3 KB, 312x101
>>51807496
looks like it worked to me
>>
>>51807456
Nice comments, I would otherwise had no clue that a while loop or a for loop was there. It really made me understand the code a lot better
>>
>>51807576
You can't blatantly disregard the standard and more or less every compiler directive in Python.
Snakefags BTFO.
>>
How do I pass a 2D array by reference in C?
This segfaults immediately.
void adjust_lights(char (*arr)[SZ][SZ], P_MODE mode, POINT from, POINT, to)
{
/* nothing lol */
}
>>
>>51807588
Yeah, but I want it to work for entire strings
>>
>>51807573
*user
Well that spelling surely didn't help my point. .
Either way, you're incompetent
>>
>>51807500
Depends on the type of projects
>>
>>51807596
>POINT, to
>>
>>51807596
shoulda used Python
>>
>>51807596
char **lol;
>>
>>51807573
>Not wasting my time making a Linux OS almost from scratch when I can just download Xubuntu and modify it to my liking
>Projecting my incompetency

Ebin
>>
>>51807496
What? It ignores the inner if? Are you sure it's even going inside the if block? How did you check it?
>>
>>51807611
Streaming software.
>>
>>51807617
I might be wrong about this, but arrays don't decay into pointers recursively. I think you could do *blah[SZ] or blah[][SZ] though.
>>
>>51807596
>C.uck still using an obsolete
Top lel, python programmers laugh at you
>>
>>51807108
currynigger spotted
>>
>>51807596
>How do I pass a 2D array by reference in C?
The type declaration and function signature is correct.
>This segfaults immediately.
Then you're doing something else wrong.
>>
>>51807622
>Ubuntu
>dated packages everywhere
No thanks.
>>
>>51807622
>Missing the point that arch isn't the problem and neither is xubuntu or any OS; It's your stupid ass.
>>
>>51807456
I think you want a nested for loop, so you can check each character in encode against each character in key. As it is you are checking encode[0] == key[0], then encode[1] == key[1], etc.
>>
>>51807648
>Arch
>unstable packages everywhere
No thanks.
>>
>>51807546
I use Arch as my main OS for programming. I laugh at niggers like you who feel the need to bash one distro simply because too many retards here (you included) can't use it. The point of Linux is not the distro itself, it's the kernel and Unix philosophy.
>>
File: 1.png (30 KB, 200x193) Image search: [Google]
1.png
30 KB, 200x193
>>51807671
>>
File: aFASEFASEFG.png (6 KB, 340x333) Image search: [Google]
aFASEFASEFG.png
6 KB, 340x333
>>51807604
what?
you're trying to match strings?

still looks like it works

also
>encode[loops] = encode[loops];
>>
>>51807671
>arch
>unstable
nice meme mang
>>
>>51807691
>>51807702
>>51807648
>>51807573
arch c.ucks in suicide watch
gentoo > arch
>>
>>51807713
Uh, weird, it doesn't work on my machine. Maybe it's my compiler being a shit.
>>
I'm learning Java coming from a C background
I have a problem with keyboard listeners
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_W) {
x += 1;
}


when you press the key it goes on for loads of ticks, how would you get it to only increment by one?
>>
>>51807731
At some things, yes, gentoo is better. at others: arch, or ubuntu and even fucking vista beets it out. You guys need to stop being lemmings. Just do you.
>>
>>51807762
what errors are you getting?
is it just your "ERROR: Use parabalas..."?
>>
>>51807787
for fucks sake. I can't spell today. *beats
>>
>>51807773
do keyUp instead of key pressed?
>>
>>51807801
Nope, I actually get no errors at all, nothing.
>>
What extension should I append to bash filenames in linux?
>>
ok, so how do I have diferent workspaces in eclipse?

I don't want to have lots of diferent projects in the explorer tab.
>>
>>51807845
sh
>>
What is the best language code for a streaming software?
>>
>>51807845
#!/usr/bin/env bash
>>
>>51807857
Befunge
>>
>>51807857
Streaming chinese cartoons?
>>
>>51807857
Like a video streaming/encoding backend? Erlang, Node.js or Haskell.
>>
>>51807845
.sh is generally used for bash scripts

You don't have to put any extension though. If you want it to be executable you have to do
chmod +x myscript.sh
(alternatively, your file manager may have a "properties" dialog where you can set it to be executable)
>>
>>51807731
>updating your kernel takes twenty years

JUST
>>
>>51807822
same problem, the act of releasing the key takes up a good few ticks, looks like about 50
I figured out a way around it, not very stable but whatever
I can't get my head in to this OOP stuff, I don't know when or how that keyboard listener code works

I'm mainly asking anyone has had this problem and how they fixed it
>>
>>51807937
>updates kernel
>takes 5 minutes
genkernel pleb detected
>>
>>51807937
Are you dumb? As a long time Arch user, I was surprised by how simple and easy is upgrading your kernel on Gentoo last time I tried it. The kernel doesn't take all that long to build even on older hardware, and only the initial configuration takes some time (or you can go with default flags :^)). On the other hand building the system software with all its dependencies...
>>
>>51807958
When I upgrade my kernel it takes exactly 2:08 because that's consistently how long it takes to download and install linux-zen.

When I tried to install Gentoo (without genkernel, mind you) it took almost an entire day to compile the kernel and even then it broke and didn't install properly.
>>
File: dis nigga serious.jpg (16 KB, 132x167) Image search: [Google]
dis nigga serious.jpg
16 KB, 132x167
>>51806401
>no Gaben
>>
>>51807829
what do you mean nothing?
the program exits? the program crashes?
post a screenshot of the output

and also did you copy the file? is it possible that the version you are working on is different to the one you posted?
I've seen that a few times, try making a new folder, then make a new cpp file and copy the code you posted here in to it, then work on that file
>>
>>51807977
>>51807937
are you compiling gentoo on a toaster?
>>
>>51806537
Shots fired
>>
>>51807988
Gaben wasn't a particularly good programmer. He had a lot of cool ideas and he's a really skillful executive, but in terms of actual development he's pretty shit-tier. There's a reason Source games are always so buggy.
>>
>>51807977
>almost an entire day to compile the kernel without genkernel
oh, so you activated everything in the kernel as a module, how smart

it sounds like you aren't capable of doing "make install" "make install && make modules_install"
>>
>>51808008
Intel i5-3560K overclocked to 4.6GHz.
So no.
>>
I want to like to use Lua but I just can't seem to find a purpose for it.

LuaLaTeX isn't nearly as useful as I thought it would be.
So /dpt/ give me an idea of neat ways I can use Lua.
>>
>>51808032
sounds like you are doing something wrong. lemme teach you:
>get the default kernel config
>enable gpu, sound card, network, vfat (if you are in UEFI) and other filesystem drivers
>enable fuse
>look at the gentoo wiki for any extra shit you need to activate
>disable useless shit from default config like "Macintosh device drivers" shit
>???
>done
>>
>>51808012
>There's a reason Source games are always so buggy
At least they're not as bad as Bethesda's games in that regard.
>>
Fuck man, C++ is harder than expected.

And I just can't think of anything interesting or fun to do that doesn't involve shit I can't understand yet.
>>
>>51808089
Pick any game that has support for Lua scripting.
>>
>>51808113
Make a clock
>>
>>51808113
The first few years of programming are a grind. Stick with it.
>>
This is python 3.4.3

if user == 'A' or 'a':
choice1A = open('intro3choice1.txt').read()
print("_________________________________") # Troll Section
print()
print(choice1A)
print()

user2 = input("Please enter your answer: ") # Go through the woods
# Man in armor
if user2 == 'A' or 'a':
choice2A = open('intro3choice2A.txt').read()
print("_________________________________")
print()
print(choice2A)
print()

(imagine the elif statement is down here for if you say no)



Everytime I try an input for this adventure game it always defaults to A. The code is too long to post. Any suggestions?
>>
>>51808109
Well yeah, but they're nowhere near as stable as, say, a Carmack game. Now THAT guy was a genius.
>>
>>51808166

*****
(imagine the elif statement is down here for if you input B)
>>
>>51808124
Yeah I've made a few EU4 / CK2 mods and it's kinda fun but gets boring after awhile.
>>
>>51808166
damn your code is shitty
do if user.upper() == 'A' instead of if user == 'A' or 'a'
>>
>>51806542
just doesn't werk
>>
gfycat com/DearestOffensiveBlowfish
(apparently I can't directly link a gfycat upload for some reason)

How's this for a novice programmers first UI?

The layout isn't final and controls might change, but any suggestions on things I could do to improve usability?
>>
>>51808166
>using the snake language
>>
>>51808195
https://love2d.org/wiki/Main_Page
I've only heard of it, never used it myself.
>>
>>51808113
The worst part of C and C++ is dealing with dependencies.
>>
>30 years experience with C
>10 years experience with C++
>can't average 2 ints
>0 < -1
>C memory model
>told on all aspects of programming
i shyggy diggy /g/
>>
>>51808113
Make a program that converts normal time into microwave time.
>>
>>51808217
Python is the future dumbass.
>>
>>51808204
Haha well it's a beginner python course, had no experience in programming before.
>>
>>51808213
Offensive Blowfish sounds like a sweet name for a programming language.
On that note, who wants to get to work on the logo?
>>
>>51808206
k, test it.
>>
>>51808256
K L J A S D
L
J
A
S
D
>>
>>51808263
I like my logo.

I tried my best, I liked the muted white look, but I had no idea what fonts to pick or lay it out to make it look nice.

But I'm no designer so if someone would make a logo for me in a similar style, but you know better, I'd be very happy indeed.
>>
>>51808166
Can't make sense of your spaghetti from this code snippet only
>>
>>51808296
>>51808263
Oh.

I just understood what you meant with your post.

I've been sat here for about 10 hours doing this. I'm very tired.
>>
>>51808296
>gfycat com/DearestOffensiveBlowfish
I didn't look at the vid till just now, I only saw "offensive blowfish"
No problem. I also like the look, pretty modern looking. Especially good for a beginner imo tbqh
>>
File: openbsd_logo.jpg (22 KB, 352x342) Image search: [Google]
openbsd_logo.jpg
22 KB, 352x342
>>51808263
already been done
>>
How do I texture standard DirectX Mesh? Fags from google use meshes that already textured in .X
>>
>>51808331
That is a homosexual sea porcupine.
Ours needs to look offensive.
>>
File: 1444150462804-4.jpg (120 KB, 528x720) Image search: [Google]
1444150462804-4.jpg
120 KB, 528x720
>>51808089
Lua is primarily used to confuse unsuspecting programmers by indexing arrays from 1.

>>51807456
#include <stdio.h>
#include <ctype.h>

const char murckey[] = "MURCIELAGO\n";
const char murcval[] = "1234567890\n";

char
murcenc(char c) {
for (size_t i = 0; i < sizeof murckey; ++i)
if (toupper(c) == murckey[i])
return murcval[i];
return c;
}

void
murcinput(void) {
int c;
while ((c = getchar()) != EOF)
putchar(murcenc(c));
}

int
main(void) {
murcinput();
return 0;
}
>>
>>51808166
maybe the problem is located where you asing user.

can you post that?

also, use a print to know what you have in user before entering the if
>>
Name a language more verbose than Java
>>
>>51808372
cobol
>>
File: cnt.png (76 KB, 1031x525) Image search: [Google]
cnt.png
76 KB, 1031x525
>>51807434
Thanks, this program does not have any documentation but I referred to some training material and managed to make it count. I just needed to have an INT variable as a preset value.
>>
>>51808358
It'd be honestly easier if I just sent you the code, it's alot of text since it's a choose your own adventure game. I could upload the .py file if that'd help
>>
>>51808235
1. isn't averaging 2 ints as simple as: avg = (a + b)/2?
2. how is 0 < -1
>>
>>51808314
>>51808358
http://www.fast-files.com/getfile.aspx?file=102896
>>
>>51808372
cobol
>>
>>51808446
a+b can cause an overflow
>>
>>51808483
well, how to then? i feel like an idiot
>>
>>51808329
Thanks, the behind the scenes stuff was a lot more complex but a lot easier to figure out.

WPF stuff (especially with a third party package installed to provide graphical content) has been quite tough indeed.
>>
>>51808372
Depends. Languages like Pascal and Ada prefer words over symbols, so the code can be considered more verbose.
>>
//Simple Chronometer
//V0.1 "It doesn't work, shit" edition

#include<iostream>

using namespace std;

int main()
{

//Variables are self-explanatory
int hour = 0;
int minute = 0;
int second = 0;

while(true)
{
++second; //Add one to second each loop
if(second > 60)
{
++minute; //Add one to minute each time 60 seconds is reached
second = 0; //Reset seconds
}
if(minute > 60)
{
++hour; //Same thing done with minutes but with hours
minute = 0; //Reset minutes
}
break;
}

cout << "The time elapsed is: " << hour << ":" << minute << ":" << second << endl; //Print out the time elapsed. I want this to update at the same time as the while loop, but without spamming the screen with it every second. Basically keep it static except for the variables, which should change.

return 0;
}


Hey guys, I'm just started with C++ and I have a question.

How can I do this? (Check the last commentary). Disregard the fact that it's not a real chronometer yet (It doesn't count seconds), I'm going to add the whole chronometer thing later, so far I'm just testing stuff.
>>
File: 1445175706996-0.jpg (96 KB, 425x567) Image search: [Google]
1445175706996-0.jpg
96 KB, 425x567
>>51808446
Ints in C can only hold a certain number of bits. If you average some pretty big ints, (a + b) can be greater than INT_MAX meaning they will overflow the max, which leads to undefined (bad) behavior.

The second thing is about comparing signed to unsigned integers (which can be tricky in C). Both of these should print true (1) due to C faggotry:
#include <stdio.h>

int main(void) {
unsigned zero = 0;
signed negone = -1;
printf("%d\n", zero < negone);

/* or directly: */
printf("%d\n", 0u < -1);
}
>>
>>51808349
So I did google again. There's simply no answers for such questions.
>>
>>51806401
Seems all has abandoned.

Reposting with the user input before the mutlple paths.


# ADVENTURE STARTS HERE

intro1 = open('intro#1.txt').read()
print(intro1)
print()
input("Press enter to continue...")
print("_________________________________") # intro
intro2 = open('intro#2.txt').read()
print(intro2)
print()
user = input("Please enter your answer: ")
print()


# THIS IS WHERE THE MULTIPLE PATH'S START
if user == 'A' or 'a':
choice1A = open('intro3choice1.txt').read()
print("_________________________________") # Troll Section
print()
print(choice1A)
print()

user2 = input("Please enter your answer: ") # Go through the woods
# Man in armor
if user2 == 'A' or 'a':
choice2A = open('intro3choice2A.txt').read()
print("_________________________________")
print()
print(choice2A)
print()

>>
>>51808256
As much as I enjoy Python, I'm not sure I can agree. It's excellent for simple commandline utilities and automation scripts, but its lack of compile-time type checking and interface validation makes it a pain to deal with more complex applications.
>>
Ded
>>
>>51808470
you have to replace
if user == 'A' or 'a'

with
if user.upper() == 'A'

as >>51808204 said

what's happening is that the logical comparison is out of order.
it's checkin whether if (user == 'A' ) or if ('a') is declared, and that's always true.
another (worse) solution would be something like
if user in ("A", "a")
>>
>>51808561
Since I don't know your environment, google "clear terminal X C++" where X is your OS.
>>
>>51808733
>>51808470
also, use pastebin the next time.
>>
>>51808565
thanks.
>>
>>51808535
((bigger-smaller)/2)+smaller
>>
>>51808825
Unexpected
>>
>>51808733
>>51808204
>>51808759

Much appreciated all of your for the help, thanks for the tips. Thank you.
>>
Fugg, how does nanosleep() work? I can't understand the stuff I find in google.

Any kind anon willing to explain how to use it in C++ to a coding illiterate?
>>
>>51808966
http://www.tutorialspoint.com/unix_system_calls/nanosleep.htm
>>
>>51808966
What's unclear about the manpage?
Fill in the struct timespec with the amount of time you wanna sleep and call the function, nothing more to it.
>>
#define SZ 1000
typedef enum { off, on } STATE;
...
STATE lights[SZ][SZ] = { { off } };
STATE (*arr)[SZ][SZ] = &lights;
...
printf("%u\n", count_lights(arr));
...
unsigned count_lights(STATE (*arr)[SZ][SZ])
{


is this the correct way to pass a 2 dimensional array by reference in C?
>>
>>51808608
>if user == 'A' or 'a':
Are you fucking serious?
>>
File: 1449673715848-3.jpg (87 KB, 720x1078) Image search: [Google]
1449673715848-3.jpg
87 KB, 720x1078
>>51808561
>>51808561
#include <stdio.h>
#include <time.h>
#include <errno.h>

struct timer {
unsigned seconds, minutes, hours, days;
};

void
addsecond(struct timer *t) {
++t->seconds;
if (t->seconds >= 60) {
++t->minutes;
t->seconds = 0;
}
if (t->minutes >= 60) {
++t->hours;
t->minutes = 0;
}
if (t->hours >= 24) {
++t->days;
t->hours = 0;
}
}

void
showtimer(struct timer *t) {
printf("%02u:%02u:%02u:%04u", t->seconds, t->minutes, t->hours, t->days);
fflush(stdout);
}

void
printtimer(struct timer *t) {
showtimer(t);
putchar('\n');
}

void
reshowtimer(struct timer *t) {
putchar('\r');
showtimer(t);
}

void
runtimer(void) {
const struct timespec second = {
.tv_sec = 1,
.tv_nsec = 0,
};
struct timespec rem;
struct timer t_ = {0, 0, 0, 0}, *t = &t_;
printf("ss mm hh dddd\n");
for (;;) {
reshowtimer(t);
int nanoret;
if ((nanoret = nanosleep(&second, &rem)) != 0) {
; /* No error handling for now */
}
addsecond(t);
}
}

int
main(void) {
runtimer();
}
>>
>>51809140
the second dimension needs to be a constant size, otherwise, it's like function (arr[][size])
>>
>>51809174
>anon asks for C++
>post C

10/10
>>
>>51808608
there's gotta be a way to refactor all the repeated code.
>>
>>51809188
If I take out the first SZ i get an error
day06p01.c:86:4: error: invalid use of array with unspecified bounds
printf("%d ", *(arr)[i][j]);
>>
>>51809140
I don't see the point of the extra indirection, why doesn't count_lights just take a STATE a[SZ][SZ]?
Pointers to arrays are completely useless since you can't do anything with that indirection, can't reassign an array label since they aren't lvalues to begin with.

But to answer ouir question, yes, that is how you would do it.
>>
>>51809237
arr[i][j]
pass as arr[][SZ]
>>
>>51809198
>Implicating
>>
>>51809257
>falling for the bait
Anon, learn to identify shitposters and ignore them
>>
>>51809237
>>51809140
Are you sure that this works?

STATE lights[SZ][SZ] = { { off } };
STATE (*arr)[SZ][SZ] = &lights;


I think your goal was to have two copies of the array. Look into memcpy or just initialize the array like normal instead of the random dereference.
>>
>>51806401
Hey guys I come for one more shred of your help.

http://pastebin.com/gSG89jC3

This is the final solution, it works just fine but after a few inputs no matter what input I put in it doesn't open the file. I think it's indentation problems. Thanks a ton.
>>
>>51809257
font?
>>
>>51809317
python 3.4.3 btw
>>
>>51809257
Still not valid C++.
>>
>>51809370
Yes it is you tard
>>
>>51809300
I need to do work on this array, so I was hoping to pass a reference and not a copy of the array.

The whole point of the indirection is so I don't have to clutter up the function call with brackets.
adjust_lights(mode, arr, from, to);
...
void adjust_lights(P_MODE mode, STATE (*arr)[SZ][SZ], POINT from, POINT to)
>>
>>51809317
refactor all the excess print commands. I see the same 1) read file 2) print "___" line 2) print empty 3) print file 4) print empty

over & over

just make it a function and it will reduce the amount of code you have considerably and make it easy to debug
>>
>>51809381
[citation needed]
>>
File: 1444321921514-0.jpg (80 KB, 720x720) Image search: [Google]
1444321921514-0.jpg
80 KB, 720x720
>>51809280
After you've been here long enough you learn to happily coexist with shitposts and real content.

>>51809140
Strongly prefer something more like this:
enum {LSIZ = 1000};
typedef enum {ON, OFF} State;

State lights[LSIZ][LSIZ] = {{OFF}};
...
printf("%zd\n", count_lights(lights));
...
size_t
count_lights(State **lights) {
..
}
>>
>>51809408
>windows
>>
>>51809386
nigga
adjust_lights(mode, arr, from, to);
void adjust_lights(P_MODE mode, STATE ar[][SZ], POINT from, POINT to);
>>
>>51809403
>Strongly prefer something more like this:
That will not work, pointers are not arrays - especially not multidimensional arrays, completely different memory layouts.
>>
>>51808561
>//Print out the time elapsed. I want this to update at the same time as the while loop, but without spamming the screen with it every second. Basically keep it static except for the variables, which should change.
If you add a return character '\r' you will write over the current line and thus get the effect you are requesting.
You cannot go up several lines though, so a newline '\n' would break this.
If it doesn't always print (your buffer is too large) then use std::flush and it will flush your cout.

if you want the simple solution, just use sleep to sleep your thread.

If you want to make something better, you should use a timer or a seperate thread to keep track of timing and then update the thread with the clock when one second has elapsed
>>
Is it just me or is UML a joke?
>>
>>51809403
if you really want to pass your array like a normal single-dimensional array, you can just flatten your 2d array.

create function to just parse every 2 elements and this effectively simulates a 2d array without all the hassle

if you really, REALLY want a 2d array without all the mumbo, jumbo, you can get into an array that holds 2d arrays. but this requires more memory/more allocation on top
>>
>>51809493
it's one of those enterprise jokes yeah
>>
>Try to make calculator
>SUCCESS!
>Try to make simple cipher encoder/decoder
>failed
>Try to make chronometer
>failed

S-should I keep trying? I mean, I don't want to give up and I want to be a programmer so fucking much, but I'm starting to lose hope.
>>
>>51809564
how is an anonymous enum preferable to const int SIZ = 4?
>>
>>51809564
no, he's right. arrays decay into pointers, but aren't really pointers. if arrays were just pointers, then the whole huff-n-puff about 2d arrays in C wouldn't be in this thread

references:
https://lkml.org/lkml/2015/9/3/428 (never use an array notation as a function parameter)

http://stackoverflow.com/questions/1461432/what-is-array-decaying
>>
>>51809494
>>51809437
Yup these posters are correct, I deleted my post. Please avoid multidimensional arrays because they are shit and just use pointers instead.
>>
File: neat.png (21 KB, 923x763) Image search: [Google]
neat.png
21 KB, 923x763
Trying to draw a round cube with corners twice the size the side of the cube.
>>
>>51809493
If you use all of it, yes.
If you use the right parts in the right places, it is fine.
I mostly use it for documentation.

But a lot of companies use it as their primary development tool and have curry niggers turn it into code
>>
>>51809625
>Round cube
I think that's a sphere, anon.
>>
>>51809625
>a round cube
dude, what?
>>
>>51809625
Looks good.
cube/10
>>
>>51809611
You mean you're the same anon?
Please just get through a book, you'll end up much better.
>>
File: 1448815081009-4.jpg (94 KB, 640x960) Image search: [Google]
1448815081009-4.jpg
94 KB, 640x960
>>51809618
It used to be the case that you could not initialize an array with a const int like so:
const int SIZE = 4;
char somearray[SIZE];
 
With VLAs in C99 you can, but between #define and enum, go with enum. It preserves the symbol and makes debugging easier.
>>
typedef enum { male, female } Gender;


Will I get banned on github if I put this in my repos?
>>
>>51809681
nah
>>
>>51809669
Stop posting these testicle receptacles, I'm at work.
Also, stop nesting code tags.
Thread replies: 255
Thread images: 29

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.