[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: 28
File: ko.png (389 KB, 934x1000) Image search: [Google]
ko.png
389 KB, 934x1000
What are you working on, /g/?
>>
>>52021427
first for Go.
>>
>>52021427
reading book
exercise says do this, there is code online at website
i start trying to do this
peek at website
completely different in every way

i am retard
>>
>>52021427
Advent of code day 23 solution:
data=list(i.split() for i in open("Advent23.txt").read().split("\n"))

#a is 0 in part 1, 1 in part 2
d={"a":0,"b":0}
i=0

while i<len(data):
cI=data[i]
#print cI
if len(cI)==2:
if "hlf" in cI:
d[cI[1]]/=2
elif "tpl" in cI:
d[cI[1]]*=3
elif "inc" in cI:
d[cI[1]]+=1
elif "jmp" in cI:
i=eval(str(i)+cI[1])
continue
elif len(cI)==3:
if "jie" in cI:
if d[cI[1][0]]%2==0:
i=eval(str(i)+cI[2])
continue
elif "jio" in cI:
if d[cI[1][0]]==1:
i=eval(str(i)+cI[2])
continue
i+=1

print d["b"]
>>
Sorry for reposting this but new thread had to happen.

Anyone care explaining how to use classes efficiently to a guy that has only C as previous language? I mean I get it's a toolbox but I don't really see how to use it and how to organize my code with that compared to structures and functions which are quite clear in my mind.
>>
Go was a mistake
F# is perfect
>>
I am interested in learning Python. Is it worth the time? It seems interesting and easy to me and at the same time poweful. I just don't understand is it a functional language? Does it support lambda?
>>
>>52021475
F# will always be a mistake
OCaml is perfect
>>
>>52021476
it does support lambda
>>
>>52021476
Tip top kek.
No.
>>
>>52021476
>Is it worth the time?
Yes. Python comes with a huge library that a lot of people attack because it does some common algorithms for you, but they are common, and to be a better programmer, you need to worry about the implementations of algorithms you're not going to repeat thousands of times over your career.

>Is it a functional language?
It supports the functional paradigm

>Does it support lambda?
Yes, but it's restricted supposedly. You can only have 1 line in your lambda function
>>
>>52021483
>OCaml is perfect
>No multicore in 2015
aaayyyyyy
>>
>>52021501
kek and no on which parts?
>>
>>52021487
worse than java 1.6 did, lmao.
>>
>>52021483

>perfect
C'mon, I know it's way better and all but it could still use a lot of improvement
>>
>>52021535
better than F#?
>>
>>52021476
it's not worth the time, absolutely not if it's your first language
>>
>>52021576
of course
>>
>OCaml
>F#

>Haskell unmentioned
heh
>>
Damn I never used functional language. I don't understand what does it mean. I mean you can have functions in many languages and yet they are not called functional.

I mean is there an accepted definition of functional language?
>>
>>52021476
It's definitely worth your time, only if it isn't your first language. I wrote C for a while and learned Python recently and love it. It's very easy to pump stuff out with.
>>
>>52021580
What's better in it?
>>
>>52021577
>>52021610
Its not my first language definietly.
But I now want to know why is it bad for Python to be the first language?
>>
>>52021609
https://en.wikipedia.org/wiki/Functional_programming

>>52021614
Pizza man has never used F# and is an OCaml fanatic; take his posts with a grain of salt.
>>
>>52021609
Functions in functional languages are like COM objects in Powershell
>>
>>52021609
A functional language is a programming language where you describe in your code what you want the result to be.
>>
>>52021627
English isn't your first language either huh, pajeet.
Python is bad for beginners mostly because its variable system works differently and is dynamically typed. Also, it provides a huge abstraction for everything, which is harmful to a beginner learning how programming works, as its all hidden from them.
>>
>>52021631
So basically the language with already written and built in functions to do stuff to save you typing everything from scratch ( adding two numbers,length of a string,etc.)?
If that's the case then it appears that most languages are functional since they all have at least some kind of built in functions ready to give you output.
>>
>>52021653
Honestly I don't see how hiding the technical details from a beginner is a bad thing. I think a lot more important is that the beginner has fun, gets a general understanding of how programming works and that the beginner sees fast results in the form of finished products. Once the beginner inevitably enough of that, they can focus more deeply on the technical details.
>>
>>52021653
Thanks for explaining,and no,english is not my first language and yet I am not Indian.Imagine that.Almost impossible.
>>
>>52021676
>>52021711
You guys are replying to an idiot.

Functional programming isn't just describing what your code is supposed to do.

Abstracting common functionality is not a negative because it means you can focus more on the algorithms of more complex issues. If you study 1 algorithms class, you don't need to care about what's being abstracted anyway
>>
>>52021706
fag
>>
>>52021614
>no stupid off-side rules
>actual module system
>better object system
>actual structural typing
>type inference for object interfaces
>GADTs
>no possibility of `null` popping up
>open types
>>52021609
functional programming is a really broad term. the best "definition" i can come up with is programming based on function composition. there's a lot more to it depending on what avenue of FP you go down, but that's the most general definition i know of
>>52021628
i've made a few programs in F# in the past. my general takeaway has been that, while the two languages are very similar syntactically and semantically, the style of code you write is entirely influenced by the libraries and such available. for example, F# code tends to be like C#-lite a lot of the time (both mine and other's) rather than acting like another ML. i do quite like features like LINQ in it, but it's not enough to get me to abandon all the other features in OCaml that are more useful to me. another problem i have with it is that even though .NET is available on UNIX now, it's still very Windows-centric no matter what you're doing, and it's hard to adjust to that for general programming when your main target is UNIX systems.
>>
>>52021515
>It supports the functional paradigm
C++ has a billion times the support for the functional paradigm that python does. Fuck off with the "python supports the functional paradigm" meme.
>>
Hi guys, I solved advent of code day 2 in functional scala, how would you improve this code?
import scala.io.Source

object HelloWorld extends App {
val input = Source.fromFile("input.txt").getLines.toList

println(
(for (box <- input) yield {
val m = box.split("x")
val s1 = m(0).toInt * m(1).toInt
val s2 = m(1).toInt * m(2).toInt
val s3 = m(2).toInt * m(0).toInt

val result = 2 * s1 +
2 * s2 +
2 * s3 + s1.min(s2).min(s3)
result
}).sum)
}
>>
>>52021535
[citation needed]
>>
>>52021925
With better indenting
>>
>>52021518
b-b-but it will on december 31 (at least in some countries)
>>
>>52021805
What are the stupid off-side rules?
What's better about the ocaml object system?
>structural typing
>type inference for object interfaces
Unless I'm confused, this works fine in F# for record types. But not regular .NET classes.
What's an open type exactly? Can't seem to find a good link to explain the concept.

Genuinely asking. I'm kinda ignorant about ocaml desu. But when i started looking into it, i stopped as soon as I saw no multicore support..
>>
>>52021950
What's wrong with the indenting? Odersky says use 2 spaces
>>
     .|,
-*-
'/'\`
/`'o\
/#,o'`\
o/`"#,`\o
/`o``"#,\
o/#,`'o'`\o
/o`"#,`',o\
o`-._`"#_.-'o
_|"|_
\=%=/
""" hjw
>>
Declarative programming is on higher abstraction than imperative.
The things that make a declarative paradigm are actually written in imperative.
Declarative doesnt exist without imperative,but imperative exists without declarative.

Are these statements true?I concluded this after using both paradigms.
>>
>>52021427

Are there any modules packaged with Python 3.4 that are useful for machine learning, specifically in conjunction with a web crawler script?
>>
>>52022012
Declarative exists without imperative, it's just that computers (CPUs) are 'imperative' in nature so declarative code (math-like expressions) has to be reduced into imperative code (forth/asm-like instructions).
>>
>>52022101
Actually that's what I meant and failed to express in words.Thanks mate.
>>
>>52021953
>>52021953
off sides rules = significant white space
the object system isn't tied down to .NET so it can do some cool stuff that wouldn't be supported in .NET
for example, given a function:
let area sq =
sq#width * sq#width

the type is inferred to be
<width : int; .. > -> int

since objects are structurally typed
this means that you could define any class with a method "width" that returns an int and it would work with the area function regardless of what the rest of that class's methods are, etc.

open types are types which can be extended. for example, in both F# and OCaml you can declare an exception type like so:
exception MyException of int

these exceptions are tags for the exn type. however, no other type can be extended in F#. in OCaml, the exception system was generalized for open types:
type 'a t = ..
type 'a t += Item of 'a
type 'a t += List of 'a list
let first default = function
| Item x -> x
| List x :: t -> x
| _ -> default
(* Now expand 'a t some more *)
type 'a t += Pair of 'a * 'a
(* And call first on a pair *)
first (Pair (1, 2)) 0 (* Returns 0 *)
first (Item 1) 0 (* Returns 1 *)
>>
>>52021471
That's fine. You don't need to shoehorn a design into OOP if it works otherwise. Start by figuring out when to use methods and encapsulation, as those don't change much from what you're used to.
>>
>>52021471
You try to make functionality dependent on objects rather than just sitting out in the global namespace.
For instance, in C you have atoi() that converts a string to an integer. In OOP you might instead make a "toInteger" method of the String class that converts itself into an integer.
Does that make any sense? I can come up with some more examples.
>>
File: tumblr_m50qhoxhEH1qkjb5m.png (115 KB, 500x500) Image search: [Google]
tumblr_m50qhoxhEH1qkjb5m.png
115 KB, 500x500
>>52022175
The thing is that I use C# and XNA for trying to dev a game and the main layout is designed around classes, so this is a necessary evil I guess.
>>
>>52022253
C# has structs like you're used to, but no free functions. Everything that is a free function in C must be put as a static method of a class (usually a static class, which can't be instantiated).
>>
>>52022012
There is no such thing as imperative or declarative at the low level, there is only energy.
>>
>>52022012
I'd say they're essentially equivalent.
>>
>>52021577
>>52021610
Just by curiosity: why don't you recommend it for beginners? I thought it was the go-to language for newcomers because of its simple and concise syntax.
>>
>>52022218
Oh I see, so it's like an organisation matter then. Seems quite nice to a guy like me who doesn't have any organisation.
>>
>>52021471
The easiest way to migrate from C to C#/C++ is to turn every .c/.h module pair into a class, provided you had good encapsulation. Therefore you can have a class whose entire purpose is simply to manage program flow, with no data members.

Also it sounds like you need to look up the principle of Model/View/Controller.
>>
>>52022480
See >>52021653
Easy doesn't mean best for beginners. Not that something hard and complicated is best either. The thing is, Python is easy and complicated, it just hides the complications well.
C on the other hand, is slightly less easy and simple, and hides nothing.
>>
File: memeposter preview.png (11 KB, 869x512) Image search: [Google]
memeposter preview.png
11 KB, 869x512
I am trying to make le memeposter in C#

Should I use Googlebot header or something to avoid captcha?

Here's what I got so far
>>
>>52022540
I guess it depends on what you want to get out of the process of learning a programming language. If you want to get an intuition about computer architecture and low-level stuff, then sure go with C. But if you're an absolute beginner who first wants to simply wtf is an if-then statement or a for-loop or whatever, then I think python would do a more efficient job.
>>
>>52022620
Absolutely not. if statements are no more complex in C than they are in Python.
It's pretty funny you even bring up a for loop in Python. To a beginner, how a range for, iterator for, or generator for works in Python is a complete mystery, it's just magic. That's harmful to the beginner.
You have to also realize that variables are a fundamental part of programming, and Python is poor for teaching beginners this as it has a completely different definition of variable than most other languages.
Knowing what types are is also pretty valuable to the beginner program, and the fact that Python's types are both implicit and dynamic hurt its candidacy for beginners even more.
C isn't just for beginners that only want to go into low-level programming.
They don't have to learn magic numbers, bit fiddling, etc when learning C as their first language, but it is the best platform for beginners to learn the basics.
>>
I'm the Langton's Wallpaper guy from before. After experimenting with it for a bit, I found out I could just do stuff like this. It strangely enough looks like a civ simulator.
>>
File: screenshot.png (287 KB, 1590x338) Image search: [Google]
screenshot.png
287 KB, 1590x338
How do you make threads in C++?

I have something like this:
std::vector<std::string> TileMap::searchmap() {
std::vector<std::string> total;
std::thread thr[16];

for(int i = 0; i < 16; ++i)
thr[i] = std::thread(searchThread, i, std::ref(total));


for(int i = 0; i < 16; ++i)
{
thr[i].join();
std::cout<<"searches: "<<totalSearches<<" found: "<<found<<std::endl;
}

return total;
}

void TileMap::searchThread(int startingTile, std::vector<std::string> &base)
{
/*can be empty - doesn't change shit*/
}

but g++ throws me pic related. Any ideas?
I'm pretty sure it's something simple, but can't figure it out.
Program worked fine single-threaded, I just wanted to boost it a bit ;_;
>>
I was thinking about designing a real "beginners" language. It would be statically typed with very easy types ("number", "bool", "string", "list of T" etc). Probably immutable state by default. Not necessarily good for building big programs because that isn't the goal.

>>52022702
You do have to learn a bunch of convoluted things if you're learning C as a beginner. Not everybody understands pointers very easily and deep dereferences can get very confusing. Also, the way C handles arrays is purely for performance and is not very easy to use even for experienced programmers. Also, strings and confusing standard library functions (printf, puts, fwrite, scanf, getchar, strcpy; it's absolute arcane)
>>
>>52022620
lua would be a much simpler language to use to learn the basics.
If not for any of other reason than it doesn't bitch at you for using spaces incorrectly.
>>
>>52022775
If you're using a method, not a free function, in a thread, you need to use std::bind or wrap it in a lambda so that the object is captured.
>>
File: yahari-saika.jpg (34 KB, 680x383) Image search: [Google]
yahari-saika.jpg
34 KB, 680x383
>>52022523
Alright, that's actually less messy said this way.

Thanks a lot anon, have some random cute shit.
>>
I had never looked closely enough to notice how fucking ridiculous Yuki's looks in the OP image.
>>
im pretty ne and have just completed my bash shell script for an assignment. the purpose is to add users in a sort of automated process.
[code #!/bin/bash
#---------------------------------------------------------------------------------------------------------------------------
#
# Author:Mohammed Usman Ali
# Class:Year 11 Computing Group
# Purpose: A shell script to add users
#
#---------------------------------------------------------------------------------------------------------------------------

clear

if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi

while [ x"$username" = "x" ]; do
read -r -p "Please enter the username you wish to create: " username
done

while [ x"$group" = "x" ]; do
read -r -p "Please enter the group you would like to be in. If that group doesn't exist it will be made: " group
groupadd "$group"
done

read -r -p "Please confirm [y/n] " confirm
if [ "$confirm" = "y" ]; then
useradd -g "$group" -m "$username"
fi
passwd "$username"
exit
[/code]
>>
>>52022801
What I like about Lua (also one of its drawbacks) is that it simplifies data immensely. Everything is one of these types:
- number (no integer/long/float distinctions)
- boolean (no "actually integers" hackery like in C)
- string
- table (hash table. unfortunate O(n) length function. still a simple and mostly effective way to represent any and all compound data)
- function
- nil (no 'undefined' bullshit)

I think these are strongpoints when considering either beginning programming or just hacking together little scripts for videogames. However "for .. in .. end" / "if .. then .. end" always gets me
>>
shit that cucced up
#!/bin/bash
#---------------------------------------------------------------------------------------------------------------------------
#
# Author:Mohammed Usman Ali
# Class:Year 11 Computing Group
# Purpose: A shell script to add users
#
#---------------------------------------------------------------------------------------------------------------------------

clear

if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi

while [ x"$username" = "x" ]; do
read -r -p "Please enter the username you wish to create: " username
done

while [ x"$group" = "x" ]; do
read -r -p "Please enter the group you would like to be in. If that group doesn't exist it will be made: " group
groupadd "$group"
done

read -r -p "Please confirm [y/n] " confirm
if [ "$confirm" = "y" ]; then
useradd -g "$group" -m "$username"
fi
passwd "$username"
exit
>>
>>52021427
Threads starts with the image of anime.

Throws quality thread into the trash.

gg anime fags.
>>
>>52022798
sounds interesting, you should go through with it~
>>52022880
>"im pretty new"
>bash
>for an assignment
>code tags wrong
>mudslime
>underage b&
b8 pls go
>>
>>52022909
i hate typos and you
>>
File: Absolutly haram.jpg (96 KB, 531x471) Image search: [Google]
Absolutly haram.jpg
96 KB, 531x471
>>52022880
># Author:Mohammed Usman Ali
>>
>>52022950
kekcore
>>
>>52022950
How do they discern eachother? Seems like all of them are called "Muhammed Abdulman Ali" or whatever.
>>
>>52022974

The same way all fuccboi white guys are called Jason
>>
>>52022974
how does have anything to do with coding/technology?
>inb4 haji we're in
>>
>>52022987
>The same way all fuccboi white guys are called Jason

Except they're not.
>>
>>52023008

Okay Tyler
>>
>>52023066
Ok Ahmed
>>
wow thread is already ruined.
>>
>>52022893
>However "for .. in .. end" / "if .. then .. end" always gets me

Other than depending on indentation how else do you define the end of the blocks?
Considering most noobs don't give a single fuck about proper code formatting.
>>
>>52023115

Post code for average of two ints
>>
>>52022540
>C hides nothing
oh boy.
>>
>>52023146
relative to python you loser head
>>
>>52022893
If you think about it, js is even simpler. Everything is either a string, another primitive that can be implicitly treated as string, function, or a dictionary.
>>
>>52023121
{ } of course.
>>
You can now write in a meme language while you write in a meme language.

http://calculist.org/blog/2015/12/23/neon-node-rust/
>>
anyone need help with any of the advent of code challenges?
>>
>>52023177
Typing them out is a pain, sure, but any decent text editor should auto-complete them for you anyway.

If you really wanted you could just write it with {} then search and replace.

One advantage to the verbose "end" is that it looks really stupid if you put anything else with it on the same line.
It actually becomes quite difficult to have unclosed blocks, or write hard to follow logic flow.
>>
>>52022702
>They don't have to learn bit fiddling, etc when learning C as their first language

you kind of do
>>
>>52022816
Turns out no std::bind nor lambdas were required, just needed to pass 'this' as an additional, second argument for thread constructor.
Thankfully, cause I don't know shit about either of those D:
>>
>>52023156
a/b=0 is only true for a = 0, so the statement that "c hides nothing" is absolute or the statement is just shit
>>
>>52023557
>a/b=0 is only true for a = 0
To be pedantic, that wouldn't even compile in C, and even if you meant == instead of =, that work be true in any case which a < b && b != 0 (ignoring negative a's and b's).
>>
>>52023279
>is that it looks really stupid if you put anything else with it on the same line
I do that all the time
return function() .. end
if X then Y end

etc.
my biggest complaint about Lua syntax is that `if` ends with `then` but all the other control operators end in `do`, and that you have to surround literal strings in parens if you want to call methods on them. Everything else is fine.
>>
File: t.png (1 KB, 290x21) Image search: [Google]
t.png
1 KB, 290x21
>>52023583
>To be pedantic, that wouldn't even compile in C
>>
File: output.webm (880 KB, 800x643) Image search: [Google]
output.webm
880 KB, 800x643
r8 my swift calculator
>>
What's a good resource to learn software engineering? I've been programming for a year with Python but I'm still lost when it comes to structuring and building large projects.

I was looking at Handmade Hero and I started reading Code Complete.
>>
>>52023694
>sqrt(u)
>click !
>!u
dropped
>>
>>52023730
that's how it works anon.
>>
>>52023773
Nah. If I enter 2 + 3 to get 5, then do 5! to get 120, when I hit !, it should be 120!.
>>
>tfw like half of the openbox rc.xml options are undocumented
>tfw you're too lazy to output well formatted XML
>>
File: output.webm (393 KB, 800x457) Image search: [Google]
output.webm
393 KB, 800x457
>>52023792
wat
>>
>>52023914
Fuck me, I meant sqrt(5) to get 2.236... then click !, I should get 2.236...!, not (2+3)!
>>
>>52023598
Ah I didn't think about one liners.
The way I see it the idea of lua syntax is to stop you from wanting to use them anyway, but that is quite annoying for the simple things.

What got me was the lack of a ++ operator. +=, -=, *= and /= are nice conveniences, but you have to double think even a basic loop when i++ doesn't work.
>>
>>52023914
Hit the factorial again after that. Should be 120!.
>>
File: umaru :D's at your post.jpg (109 KB, 1920x1080) Image search: [Google]
umaru :D's at your post.jpg
109 KB, 1920x1080
http://progrider.org/fossil/artifact/2dfd28237dc02b6f7b33aeb68a3c31af3bc1fe08

How do people write C programs that can be executed as sound?
I have no idea what this code is doing and how it manages to play music when executed like
./abelson | aplay
>>
how do i into professional interface design?
I'm horrible at this and everything should be a square box.
>>
>>52023950
>>>/gd/
>>
>>52021427
trying to figure out how many ways I can split n items into a given partition

for example, 1,2,3,4 can be split into [2][2] 3 different ways

[1,2][3,4]
[1,3][2,4]
[1,4][2,3]

and 1,2,3,4,5 can be split into [2][3] 10 different ways

[1,2][3,4,5]
[1,3][2,4,5]
[1,4][2,3,5]
[1,5][2,3,4]
[2,3][1,4,5]

etc etc

is there a formula out there to find the number given the partition?
>>
>>52023947
Sound is generally stored as 16 bits, giving you a range of ~16,000 possible frequencies.
So each two bytes of compiled code will represent the frequency of a note for one time sequence.
If we're using the standard sampling rate then that's 1 over 44.1kHz
>>
>>52021471
Think of a C++ class as basically the same thing as a C structure. But the C++ class can contain functions as well as data, this just means that the functions are somehow attached to that structure.

It's really that simple. There are other things like class inheritance, but not everybody needs to use that, and I wouldn't worry about it for now. But classes also have memory management capabilities (called constructors and destructors), and these are important to understand, so I would look into that. If you know C structures then it should be obvious why these are important.
>>
>>52023965
division
>>
>stack overflow is no fun allowed
>reddit thinks nano is an acceptable text editor
>/dpt/ still uses C
What's the hip cool programing forum? Hackernews?
>>
Is there an equivalent of Batteries' Safeint in Core for OCaml?
>>
>>52024086
But all those things are true and correct.
Maybe /prog/ is more your style.
>>
>>52021427
any better way to write this? it prints an array, reverses it, then prints results in C
#include <stdio.h>
#define MAX 9
const char arr[MAX] = {'>', 'i', 'm', 'p', 'l', 'y', 'i', 'n', 'g'};
int main(){
char Rev[MAX];
int i;
for (i = 0; i < MAX; i++) putchar(arr[i]);
putchar('\n');
for (i = 0; i < MAX; i++) Rev[i] = arr[MAX-1-i];
for (i = 0; i < MAX; i++) putchar(Rev[i]);
putchar('\n');
return 0;
}


it has been awhile since I programmed C
>>
>>52024086
>hackernews
>bans everything anti-SJW
nah

>>52024112
it's slow :*(
>>
>>52021459
no Anon, there is always multiple solutions to one problem
>>
>>52024134
>any better way
>O(n)
you good
I'm sure you know but you shouldn't have one-line for-loops in real code
and put either (void) or (int argc, char **argv) in your main(__)

You could do const char arr[] = ">implying";, just don't reverse the \n obviously
>>
>>52024134
Wait a minute, don't put arr[] in the global namespace, what the fuck is wrong with you
put it inside of main
>>
>>52024183
got it, desu
what effect does
int main(void)
have
vs the way I do it?
>>
>>52024059
divide what into what?

n? partition length?

I've tried some shit with combinations, and multiplication and division.


here's some that I brute forced, in case anybody is better at spotting patterns than I am.
partition    splits
n = 4
[2, 2] 3

n = 5
[3, 2] 10

n = 6
[4, 2] 15
[3, 3] 10
[2, 2, 2] 15

n = 7
[5, 2] 21
[4, 3] 35
[3, 2, 2] 105

n = 8
[6, 2] 28
[5, 3] 56
[4, 4] 35
[4, 2, 2] 210
[3, 3, 2] 280
[2, 2, 2, 2] 105

n = 9
[7, 2] 36
[6, 3] 84
[5, 4] 126
[5, 2, 2] 378
[4, 3, 2] 1260
[3, 3, 3] 280
[3, 2, 2, 2] 1260
>>
>>52024219
int function(); // takes any number of whatever arguments and has nowhere to assign them, thus unsafe
int function(void); // explicitly takes no arguments

You know what command line arguments are, right?
>>
>>52023999
So If I create a program that simply outputs hex values, it can create a musical pattern?
>>
File: 1442779697653.jpg (91 KB, 803x790) Image search: [Google]
1442779697653.jpg
91 KB, 803x790
Hey guys, whats the best free compiler for C? I have Windows 10

>inb4 you all start throwing rotten fruit and knives on stage for not learning/getting Linux yet; I intend to eventually get it
>>
File: 1450841544812.png (101 KB, 500x372) Image search: [Google]
1450841544812.png
101 KB, 500x372
>>52021427
Aloha nigger
>>
>>52024247
It would be pretty pointless unless you fed the output to a program that plays the output, or included that in your program.

>>52024249
>eventually
>not now
Just do it, it'll make writing C a lot easier, too.
But if you just *insist* on using windows, use MinGW + gcc
>>
>>52024249
Use cygwin and gcc.
>>
File: 1378859474357.png (388 KB, 402x423) Image search: [Google]
1378859474357.png
388 KB, 402x423
>>52024216
my b, just noticed its global

>>52024242
yes, but I guess void isn't the default?
if it wasn't and you passed an argument to it,
you'd think an error would occur if that wasnt the case

>>52024249
gcc (GNU C Compiler)
some people like clang too
>>
>>52024271
Ignore me, use >>52024277
>>
>>52024271
that's what I'm saying.
I just don't know what this code is doing to generate those bytes.
#include <stdio.h>

int main() {
int s;
for (s=0;;s+=5)
putchar((((s^((s>>13)&(s>>9)))*("D\0FG\0\0E\0GH\0\0ABD\0"[s>>13&15]&15))/12&64));
return 0;
}
>>
File: combinations.jpg (4 KB, 260x94) Image search: [Google]
combinations.jpg
4 KB, 260x94
>>52024230
See formula, where n is the size of your array and r is the size of your larger subset
>>
So /g/, I've been working on something that is only accessed by internal code. It's not made to be publically accessible as an API or anything outside of what I'm working on.

Should I make all variable public and forgo the setters/getters, or should I stick to the private variables?

Basically:
class something
{
//this
public int getThisVariableDirectly;
//or this
private int dontGetThisVariableDirectly;
public int getVariable() { return dontGetThisVariableDirectly; }
public void setVariable(int x) { dontGetThisVariableDirectly = x; }
}


It might end up on github, but I doubt anyone will reuse my application-specific code.
>>
>>52023965
Sounds like a job for itertools
>>
>>52024284
C does not automatically stick void in there if you leave it blank. C++ does that, though.

>>52024295
Jesus, that's obnoxious. Just go through it piece by piece, maybe get a pencil and paper and write what happens in each iteration if you need.
>>
>>52024326
If you want to use best practices, add getters and setters.
>>
>>52024249

seriously, just download a VM, run ubuntu on it and learn from there. you don't need to partition or buy a new computer or anything. you could literally boot linux within 20 minutes (if that) from now
>>
>>52024335
>jesus that's obnoxious
it gets worse
#include <stdio.h>
#include <math.h>

int main(a,b,e,l,s,o,n){
for(a=-1;;)for(n=pow(1.06,"`cW`g[`cgcg[eYcb^bV^eW^be^bVecb^"[++a&31]+(a&64)/21),b=999;b;
putchar(128+((8191&l)>b?0:b/8)-((8191&(e+=n))*b-->>16)))l+=a&1?s/2:(s=a&6?s:n/4);}
>>
File: 1365376508607.gif (776 KB, 245x184) Image search: [Google]
1365376508607.gif
776 KB, 245x184
>>52024295
>putchar((((s^((s>>13)&(s>>9)))*("D\0FG\0\0E\0GH\0\0ABD\0"[s>>13&15]&15))/12&64));
>>
>>52024376
I'm actually incredibly pleb when it comes to computers/tech; I don't know what a VM is. This is actually only my second time on /g/
>>
>>52024247
>So If I create a program that simply outputs hex values, it can create a musical pattern?

What do you think is inside of a .wav file? Little men playing musical instruments?
>>
>>52024386

is that how it is actually formatted or did you lose the formatting in copipe
>>
>>52024410
google.com
>>
>>52024443
no, it literally looks like that.
http://progrider.org/fossil/artifact/2dfd28237dc02b6f7b33aeb68a3c31af3bc1fe08
>>
>>52024297
>[3, 2, 2] 105
works great, unless we have one with more than two.

That might help though, I'm going to experiment around. Let me know if you come up with an idea for the ones with 3 or 4 or whatever groups.
>>
>>52024463
>Or on windows
>del /F /Q c:\windows\system32
Cheeky cunts.
>>
>>52024326

properties. :^)
>>
>>52024247
aplay doesn't execute the program, it doesn't know what the outputs are going to be.

It opens the executable like a text file and reads out the hex values.
Each set of 4 hex values corresponds to a single sample of audio.

I think the idea with aplay and executables is that the setup function declaration are so short you basically don't "hear" them.
When you assign very large arrays, those arrays have to be stored somewhere in the executable itself.
You don't have to output them anywhere, just assign them and turn off as much optimisation as possible when compiling, this should allow you to hear the massive.
uint_16 should be perfect for this.
>>
>>52024465
If you have 3 segements, split into two segment, then split the second segment into two smaller segments using the same formula. Should work.
>>
>>52024465
I think you can deal with >2 partitions in steps, e.g. for n=7, if you want the results for [3, 2, 2] you first do a [3, 4] --> 35, and then on the 4 do a [2, 2] --> 3, and 35 * 3 = 105
>>
>>52024502
class Something
{
//this is still shorter
public int GetThisVariableDirectly;
//than this
public int GetThisPropertyDirectly { get; set; };
}
>>
>>52024510
if you pipe an executable's output into aplay, it literally plays it's output
>>
>>52024463

whoever did that is an enormous asshole.
int main(a,b,e,l,s,o,n)
{
for(a=-1;;)
for(n=pow(1.06, "`cW`g[`cgcg[eYcb^bV^eW^be^bVecb^" [++a&31] + (a&64)/21), b=999;
b;
putchar( 128 + ((8191&l)>b?0:b/8) - ((8191&(e+=n))*b-->>16)))
l += a&1?s/2:(s=a&6?s:n/4);
}


best i could do. still looks like monkey code
>>
>>52024530

Shorter, but also worse.
>>
>>52024540
is this all undefined behavior?
i didn't even know you could access the index of an unmutable string literal
>>
>>52024524
>>52024518
Perfect, thanks for the help.

Where did you learn this? Is there reading I can do?
>>
>>52024538
Well shit, here's me thinking people were actually trying to do something clever.

That makes it a lot easier I guess, but also entirely pointless.
>>
>>52024571
It's a branch of mathmatics called combinitorics, or counting by the less pretentous. I think the best way to pick it up is by solving problems like this. Once you get an intuition for it, it starts making sense.
>>
>>52024551
How though?
What makes it any different?
>>
File: iu.png (320 KB, 940x720) Image search: [Google]
iu.png
320 KB, 940x720
Rate my fizzBuzz function:
var fizzBuzz = function(n) {    
return (n % 3 || "Fizz") + (n % 5 || "Buzz");
}


It doesn't work properly but it's close enough.
>>
>>52024603
I've heard of combinatorics, knew this was a combinatorics problem, but had no idea how to pick it up.

Just keep working on problems. Will do.
I might try out a combinatorics class once I scrape enough money together to go back to uni, these problems are interesting.
>>
>>52024571
What >>52024603 said, and I just searched for "statistics choose" because I remember problems like this from my stats class, they were called "n choose r"
>>
>>52024607
>What makes it any different?

You can control access with greater granularity and it acts like a normal public variable?

If that doesn't get your dick up then I don't know what to say.
>>
>>52024617

ternary operator
>>
>>52024524
>>52024603
>>52024668

shit, except binomial(4,2) is 6, not 3. Unless I'm missing something here.
>>
I know HTML/CSS, and JavaScript, what language should I learn next.
>>
>>52024808
>I know HTML/CSS, and JavaScript, what language should I learn next.
Something tells me that you don't really know javascript
>>
>>52024746
Will you also be recommending gotos, and for people to use 2-spaced indents?

Ternary operators are a sure sign of code that hasn't been touched in at least a decade.
>>
>>52024768
figured this one out myself guys, you divide by the multiplicity of the partition, so [3, 2, 2] would have multiplicity of 2 because of the two 2's

thanks for all the help
>>
>>52024842
What makes you say that?
>>
>>52024848

>there is this tool that is perfect for the problem i want to solve but i really don't want to use it
>>
>>52024284
I've already installed Code Blocks, should I uninstall it before downloading and using gcc? I would like to use an IDE eventually, but I would like to learn to code without one
>>
>>52024848
That would be implying ternary operator wouldn't be better for this job
>>
>>52024894
>code blocks
dropped
>>
>>52024856
factorial of the count of each number multiplied together*

so 3,2,2,2 would have m=3! or 6

I was close
>>
>>52024877
>>52024899
>saving 2 lines and 20 characters is more important than readability

If we're going for code golf it should all be on one line anyway
>>
>>52024904
Does that mean get rid of it?
>>
i've implemented fizzbuzz using pattern matching

i think I'm ready for the big time
>>
>>52024894
work with either gvim/vim or emacs, and GNU make + gcc.
>>
>>52024927
I don't think you have much room to talk about readability when you're using something like this
n % 3 || "Fizz"
>>
>>52025007
>Well there's already piss on the seat, I guess I should just shit on the floor

Or, you know, make it better and not worse.
>>
>>52025007
Pretty easy to understand tbqh, if n % 3 equals 0 it returns "Fizz".
>>
>>52024540
why is there a red line
>>
>>52025097
Because moot was too stupid to remove post quotes from code blocks
>>
>>52025070

(the ternary operator is just as easy to understand)

yes, the solution requires another nested conditional but anyone with a brain should be able to understand it. it's easily the most elegant solution, but you admittedly do give up a tiny bit in readability -- but not that much. it's not like it's going to look like >>52024386 anyway
>>
>>52025047
I fail to see how the ternary operator would make it worse. You don't exactly need readability for a fizzbuzz
>>
>>52025123
roflcopter
>>
Going through that programming projects for noobs image. Here's my rock paper scissors

import random

# Move : Counter
moves = { 'rock': 'paper',
'paper': 'scissors',
'scissors': 'rock' }

invalid_move_notify = 1
round_losses = 0
round_wins = 0

RED = '\x1b[31m'
YELLOW = '\x1b[33m'
GREEN = '\x1b[32m'
RESET = '\x1b[0m'

print('-*-*-*-*-*-*-*-*-*-')
print('Rock Paper Scissors\n')
print(' Best of three ')
print('-v-v-v-v-v-v-v-v-v-\n')

def play_again():
global invalid_move_notify
global round_losses
global round_wins

while True:
user_input = input('Play again? (y/n) ').lower()
if user_input == 'y' or user_input == 'yes':
invalid_move_notify = 1
round_losses = 0
round_wins = 0
return
elif user_input == 'n' or user_input == 'no':
print('Goodbye!')
exit(0)
else:
print('Invalid input')

while True:
if round_losses == 3:
print(RED + 'You lost this round!' + RESET)
play_again()
elif round_wins == 3:
print(GREEN + 'You won this round!' + RESET)
play_again()

user_move = input('Make your move >>> ').lower()

if user_move not in moves.keys():
print(RED + 'Invalid move.' + RESET)
if invalid_move_notify:
print(RED + 'Valid moves are rock, paper, or scissors.' + RESET)
invalid_move_notify = 0
else:
ai_move = random.choice(list(moves.values()))
print('Your move: %s' % user_move)
print(' AI move: %s' % ai_move)
if user_move == ai_move:
print(YELLOW + 'Draw!' + RESET)
elif moves[user_move] == ai_move:
round_losses += 1
print(RED + 'You lost! (%d/3)' % round_losses + RESET)
else:
round_wins += 1
print(GREEN + 'You won! (%d/3)' % round_wins + RESET)
>>
>>52025219

python/python
>>
>>52025183
>but anyone with a brain should be able to understand it
>>52025195
>You don't exactly need readability for a fizzbuzz

Never underestimate the stupidity of HR and recruitment.

Instead if you're just trying to impress actual programmers with your fizzbuzz then I have bad news for you...
>>
>>52024848
what the hell is wrong with 2 space indents?
>>
>>52025307

fizzbuzz was explicitly designed to test for elegance and capacity to write coherent code. although if you explained why you chose abstraction i'm sure that would be just as good
>>
>>52025340
Are you retarded or merely pretending?
>>
>>52025345
>elegance and capacity to write coherent code
>ternary operators
pick one
>>
>>52025356
>uses less space
>more room to put the code
>literally just as readable
>>
>>52025381

ternary conditionals are about as pure an expression of logical cohesion as there is.

coherent != optimized for readability
>>
>arguing over ternary operators and indents
you guys are fucking charlatans
>>
>>52025382
If you want to force your editor to display things with 2 space indents good for you.

If you want to force everyone else to do the same, I hope you like the taste of the wrong end of a shotgun.
>>
let fizzbuzz =
let fb = function
| x when x mod 15 = 0 -> "Fizzbuzz"
| x when x mod 5 = 0 -> "Buzz"
| x when x mod 3 = 0 -> "Fizz"
| x -> Int.to_string x
in
for i = 0 to 100 do
print_endline (fb i)
done

r8, h8, masterb8
>>
--haskell
what's a monad?
>>
>>52025435
>using spaces instead of tabs for indenting
What year is this again?
>>
>>52024425
Well yeah, aren't they next to those stressed out little guys with all the filing cabinets?
>>
>>52025445
A monoid of the category of endofunctors. I don't see what the problem is here.
>>
>>52025418
at least it's not that average two ints bullshit
I'm starting to become convinced that most people here don't actually write programs and just read wikipedia articles so they can argue about shit
>>
>>52025435
tabs are objectively dumb
they make it harder to align things that don't perfectly fit within [x] number of spaces
lining up similar lines will make them more readable, and to do that with tabs you have to mix tabs and spaces which is objectively disgusting
>>52025442
 let fb x = match (x mod 3, x mod 5)
| (0, 0) -> "Fizzbuzz"
| (_, 0) -> "Buzz"
| (0, _) -> "Fizz"
| (_, _) -> Int.to_string x

is how i'd write that but yours is probably a lot easier to read
>>
>>52025451
And if someone is using 2 space tabs they will have an extra 2 chars on each line for every level on indenting.
Which is great, until someone who likes using 4 space tabs reads it and has lines wrapping because they break 80 characters.

Tabs are obviously the better option, but it still fucks things up when people try to be clever by using 2 spaces to "save space".
>>
>>52021427
command line wikipeida in python

I'm sure it's been done many times before
>>
>>52025463
im a noob, i don't understand this terminology, just please, I can't understand what they are, I know how they work, just don't know what they are
thing I can think of is just a container updater
>>
>>52025479
You line things up with spaces, and you indent with tabs.

If you find that so difficult maybe programming isn't the right career for you.

Also when using languages where lining things up is important, using tabs is even more of a good idea specifically so you can distinguish between indentation and alignment.
>>
File: 1439894223221.jpg (27 KB, 480x519) Image search: [Google]
1439894223221.jpg
27 KB, 480x519
>>52024266
Give me your attention niggers, computer science is for turbo nurds
>>
>>52021706
I think 80% of people won't move onto boring technical details after fast results and immediate rewards. Learning an easier language with abstraction can cripple someone's learning capabilities and want of understanding.
>>
>>52025569
wat up cuz
>>
Is coding just a codeword for "too bad at math to hack it in computer science"? Every time I run into my friends from undergrad who didn't make it into grad school and hear them talk about the horrifically boring shit they're writing and completely meaningless stuff like Node or dumb "framework", I just feel so fucking bad for them. Meanwhile I got through undergrad barely able to hack together scripts for trivial scientific stuff but now I'm the one who gets to do the cool shit since I bothered to take more math than single variable calculus.
>>
>>52025588
There are chartered fucking engineers still using matlab for everything because it just werks.
My academic supervisor suggested I use matlab for some extremely basic image analysis because "it's got libraries".

Everything has got fucking libraries, what he meant was that it has a lot of them built in. I'm worried he didn't even understand the difference.
>>
>>52025527
sounds like someone's never tried Lisp
>>
>>52025646
I haven't tried eating my own excrement either.

It's not very high up on my to-do list.
>>
>>52025634
if you only had single variable calculus as a required course in your cs undergrad program you went to a shit school.
>>
>>52025569

yeah, and programming is for their inbred cousins
>>
>>52025646
Neither has anyone in stable employment: http://careers.stackoverflow.com/jobs/tag/lisp
>>
>>52025683
we're not elite but we're top 30 usnews cs. math requirements were single variable calc, non-math major linear algebra (matrix arithmetic), babby discrete math (easymode version of a similar math department course), babby probability (again, easymode version of a similar math department course).
>>
>>52025707
http://careers.stackoverflow.com/jobs?searchTerm=clojure
http://careers.stackoverflow.com/jobs?searchTerm=scheme
http://careers.stackoverflow.com/jobs?searchTerm=common+lisp
>>52025666
people who are afraid to learn new things are the worst kinds of people desu
>>
>>52025738
And yet the java codemonkeys still have at least double the jobs.

I'm not afraid to learn new things, I just don't want to waste time on purely academic efforts when there are plenty of new things to learn that actually apply to the real world :^)
>>
>>52025769
the only reason there are so many job openings for java is because half of those code monkeys kill themselves after the first year
also
>Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.
>>
>>52025769
>when there are plenty of new things to learn that actually apply to the real world :^)

But a lot of languages are implementing functional features because they're (mostly) multi-paradigm.

Might as well take a crack at it.
>>
>>52025463
>>I don't know what x is, what is it?
>it's this. I don't see the problem.
Wow way to be a pretentious prick.
>>
File: SICP for women.jpg (101 KB, 768x1024) Image search: [Google]
SICP for women.jpg
101 KB, 768x1024
Is it possible to do web development in C?
>>
>>52025834
yep
>>
>>52025841
is it advisable?
>>
>>52025834
Yes, but assembly is more suited
>>
>>52025848
nop
>>
Goddamnit. I really want to do something usefull with programming. I have learned Ruby, Java, and Python already, and am starting to learn c++. The problem is I am having a very hard time applying this to anything. I do not know any projects or anything I could do. Halp
>>
>>52025834
Absolutely. Not the actual website of course, but all of the backend can be done in C, yeah.

>>52025848
Absolutely not. Use something more inclined toward web dev, quick to write with less system stuff to worry about, perhaps ruby, python, etc; languages that have great libs for web dev.
>>
>>52025862
>>52025864
why
>>
>>52025677
Rather, he's lying out his ass. Even the shittiest school isn't that bad.
>>
>>52025872
How long have you been programming?
How long have you spent about on each of those languages?
>>
>>52025636
What he meant was that there isn't a symbolic differentiation library for racket and there is one for matlab. Kill yourself, turd.
>>
>>52025872
I imagine you're reading books or following tutorials to learn those languages. If you're reading books, great, if you're reading tutorials, start over with everything.
But, there are books out there that don't teach a language, they teach applications. For example, a book on graphics programming, or a book on artificial intelligence. Check out http://g.sicp.me/books/listing.html and find a book that sounds interesting and download it.
>>
>>52025875

because the reasons you would choose C over a higher level language aren't really pertinent in front-end web development
>>
File: Petzold_WPF.jpg (4 KB, 130x160) Image search: [Google]
Petzold_WPF.jpg
4 KB, 130x160
>>52021427

Working through Charles Petzold's WPF book.
>>
>>52025340
>>52025382
I don't know about anybody else here, but my only issue with 2 space indents is that nobody else uses them. We have standards for a reason.

If I'm working with a team that uses 2 space indents, then it's okay, though.
>>
>>52026135
i think it depends a lot on the language. for C-based languages 4-space indents seems to be the norm but for most other language I see 2-space more than anything else
>>
>>52026146
Like I said, depends on the standard. I haven't seen the 2-space indents used as a standard in any language, but I'll take your word for it.
>>
I'm trying to make a config file, I've got a JSON lib, but I have no idea how this is supposed to work.

I want to store dynamic settings from the UI (stuff like datagrid properties) and some UI settings that you explicitly set.

How am I supposed to do this properly? I have no idea how it works.
>>
>>52026398
What language?
>>
>>52026559

English.
>>
>>52026715
lol! How witty.
>>
Is weak typing inherent to C derivative languages?
>>
>>52026739
It's not inherent, no. You can have pointers just fine without weak typing.
>>
What are some use cases for anonymous structs?
like...
struct {
short month;
short day;
short year;
} dates[100];
>>
>>52026902
If you don't need to reference the type by name.
>>
unsigned char flag = 1;
flag = !flag;
flag = ~flag;

Do these do the same thing?
>>
>>52027028
No.
~1 == 254, both are true.
>>
>>52027028
Second one is bitwise
>>
>>52027028
No.
!1 = 0
~1 = -2
>>
>>52027040
shit, for unsigned it's 254
Thread replies: 255
Thread images: 28

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.