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

/dpt/ - Daily Programming Thread

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

Thread replies: 333
Thread images: 33

File: yF1VCTm.jpg (89KB, 1366x768px) Image search: [Google]
yF1VCTm.jpg
89KB, 1366x768px
Old thread: >>56790078

What are you working on, /g/?
>>
first for prolog
>>
Need good resources on Windows Driver Framework.

Also, my VM is not working. I'll deal with that tomorrow maybe. Tonight, reading.
>>
why the fuck does fclose(NULL) segfault
who the fuck thought that this was a sane idea
fuck you
>>
>>56797351
Ok.... so I looked it over, and realized I've done everything it says at least several times.

Then I decided to fuck with the path.
It doesn't detect any folders deeper than the "/media/" folder.

Why not?
>>
>>56797540
It might not have the proper permissions.
>>
>>56797540
wait.... the path seems to be to the fucking root of my drive.... it does NOT seem to be to the site...

gimme a couple mins. I'm gonna try this....
>>
>>56797537
An extra null check is one wasted instruction which in 1978 was a really big deal.
>>
>>56797537

Because if you dereference a null pointer, you get a segfault. The standards developers could have said that fclose should simply return if passed a null pointer, but why would they do that? It would be faster to simply not check if the argument is null and assume that the programmer is smart enough to supply a valid argument. Why are you calling fclose(NULL) anyways?
>>
>>56797537
I quickly read SO, and it's because fclose doesn't check for programming errors, but instead for exceptional conditions. Honestly, I don't think it should have to check for NULL, since you're supposed to check for it yourself, and you can do that where you please
>>
>>56797580
that would make sense but then why does free(NULL) work fine?

>>56797608
just trying to reuse error stuff
i mean it's not that big of a deal i can just slap an if there, but it's still a pain

cleanup:
if (finput)
fclose(finput);
if (foutput)
fclose(foutput);
free(outputname);
exit(exit_code);
>>
>>56797537
if you open a file and use it, you have to check it for being NULL anyways, so the following colde will NEVER pass NULL to fclose.
FILE *fp = fopen(name, "r+");
if (fp == NULL)
return;

... do something with fp here ...

fclose(fp);

So it would be a waste to have fclose check for NULL again!
>>
File: here_then.jpg (99KB, 1600x900px) Image search: [Google]
here_then.jpg
99KB, 1600x900px
Which is the most fun to learn:
>C
>C++
>Lisp
>Assembly

My python and SQL are good, and they've helped me a lot at work, but I'd like to learn something more low-level
>>
>>56797672
but I can end up doing
goto cleanup;
after I fopen() finput but before I fopen() foutput. i guess i could add another
early_cleanup
label but i think more complexity than it's worth
>>
>>56797651
I'm not actually sure then. Maybe it was different people who made free and fclose.
>>
>>56796958
How formal does this have to be?
I would just argue from the form of the left-most derivations. This will have form of n S replacements giving a string of n T's then k1,k2, ...kn applications of T replacements corresponding to each of the n T's in turn starting from the left. So s[n]T1[k1]T2[k2]...Tn[kn].
It's kind of obvious it's unambiguous at this point. If you want to be more formal/fancy you could count the number of these derivations for n-length strengths and show it's equal to number of n-length strings in the language.
>>
>>56797537
Why the fuck you use C and low level API in 2016
Fuck you
>>
>>56797693
>C++
I don't know LISP and Assembly though.
But while more fun, C++ is also sometimes very annoying. C feels more natural. I can recommended C over C++
>>
>>56797716
Since goto labels are fall-through cou can just clean your resource in the opposite order you opened/created them.

int
file_read(struct File *file, uint16_t *data, size_t pos, size_t size)
{
FILE *fp;
uint8_t *temp;
size_t read;

if (file == NULL || data == NULL)
return -1;

fp = fopen(file->name, "r");
if (fp == NULL)
return -1;

temp = malloc(size);
if (temp == NULL)
goto err_fclose;

fseek(fp, pos, SEEK_SET);
read = fread(temp, 1, size, fp);
if (read == 0)
{
goto err_free;
}

fclose(fp);

for (size_t i=0; i<read; ++i)
{
/* set buffer byte and set visibility bit */
data[i] = (1<<8) | temp[i];
}

free(temp);

return 0;

err_free:
free(temp);

err_fclose:
fclose(fp);

return -1;
}
>>
>>56797744
Why the fuck you dig a hole with a shovel in 2016
Fuck you
>>
>>56797651

#define CLOSE_IF_VALID(FD) if (FD) { fclose(FD); }
>>
>>56797570
>>56797573
Ok, figured it out!

The path was fucked, and then the file type wasn't being checked properly.
I'll fix that last part later. Gotta go to the bathroom
>>
>>56797693
Lisp is the opposite of low-level, it's one of the highest level languages around (don't get me wrong, lisp is fun, but it's a different kind of fun). C is fun because it is relatively high-level, really old, portable, small, simple, and runs on pretty much anything that was made in the last 30 or so years. in different ways. ARM assembly and other RISC assemblies are fun, x86 assembly is a chore but you should still learn it, every programmer should be able to read some assembly. I personally dislike C++, I find it too complex and big and confusing and it scares me.
>>
>>56797467
I'm trying to make web metronome using JS.
>>
>>56797781
Learn C you twat
>>
>>56797768
i guess that could work, thanks
>>
>if you google "metronome" Google gives you a metronome in JS
neat
>>
>>56797804
Huh, I'd always associated Lisp with low-level languages, probably made the mistake of thinking older language = low-level.

What's the use case for Lisp over other high-level languages, in that case? I've seen that Stallman quote about how powerful it is, but I never really understood why
>>
>>56797869
Huh, never even thought of that. I'm gonna try taking it apart and see if i can learn some tricks. Thanks.

Mine will have the ability for more complex beat patterns, though.
>>
I honestly have no idea WTF to do here. Can someone please guide me in the right direction on how to do this:

Write a Java program that does the following:
1. Asks the user for the names of 3 cities, separated by spaces. It is assumed that a given city name won't have spaces in it. So assume you won't have a city name like "Santa Monica".
2. Your program then prints the 3 city names in alphabetical order. For example:
Altadena
Belfast
Covina
>>
>>56797945
You've asked this before
>>
File: getchar.png (602KB, 1920x1080px) Image search: [Google]
getchar.png
602KB, 1920x1080px
I am not understanding Getchar for the life of me. I don't understand it conceptually I guess. What are some practical examples of this? Conceptually, what is an EOF? Here are some questions at the end of this section that I have to complete but as I don't quite understand the material, I can't.
>>
>>56797716
if (f != null) fclose(f);

You are way overthinking this man.
>>
>>56797945
So a sample input would be:
Covina Altadena Belfast
And the output for that would be:
Altadena
Belfast
Covina
>>
>>56797945
Where do you get stuck?
>>
>>56797945
This takes less than 5 minutes.
Google it.
>>
>>56797966
>Conceptually, what is an EOF?
It's just a special value that signifies the end of a file. You know how '\n' signifies the end of a line? It's like that. But with files. Getchar just reads the next character from a file, that's all there is. Their example loop reads every character until it hits the EOF character, at that point it knows it has read the entire file, so it stops reading.
>>
>>56797945
s => 
s.split(" ")
.sort()
.forEach(c =>
console.log(c))
>>
>>56797905
Lisp has a regular, sexp-based syntax, thus making it easy to parse, and therefore stuff like code generation and metaprogramming (code that edits itself) becomes easier. It also has the whole set of functional programming tools (closures, map, first-class functions, anonymous functions), meaning it's easy to do stuff that lends itself to functional code, such as AI programming or finite-state machines. And then there's call/cc which is just a whole 'nother beast, it's kinda like cooperative multithreading except more flexible, you can pass off whole program states as arguments which can then be resumed at will. It's a different way of thinking, and one that makes a bunch of stuff surprisingly easy.
>>
>>56797966
EOF is just a character that is used by convention to signal that it's the end of the file.

Files can be thought of as text streams, split into lines, words, and characters. The null character, \0, signals the end of a string in a char array. Similarly, the the EOF character, literally EOF, signals the end of the file.

You can use getchar() to read in a char at a time from STDIN (standard input) and create conditions. In K&R chapter 1, you use it to check to see if you have read in the entire file yet in most of those early exercises.
>>
>>56798105
What if I write an EOF character to a file? What if I'm writing a binary file. Is it just impossible to write one kind of character?
>>
>>56798092
>the whole set of functional programming tools (closures, map, first-class functions, anonymous functions)


Where are the types?
>>
>>56797966
getchar() gets a character from the standard input(keyboard)
ill edit the example so its more helpful
int main()
{
int c; //getchar returns an integer, which is 0 - 128 depending on what character you entered(ASCII code.)
while ((c = getchar()) != EOF) //EOF means END OF FILE. This is similar to a \n except that instead of signaling the end of the line it signals the end of a file or input stream
putchar(c); //putchar prints the char version of the ASCII integer from getchar()
}
>>
>>56798072
looking at the example loop though, there hasn't been anything assigned to an EOF. I assume a program wouldn't just randomly assign a character to be an EOF?
>>
>>56797945
download and use the jquery bubblesort function
>>
File: v4yo1.jpg (41KB, 500x500px) Image search: [Google]
v4yo1.jpg
41KB, 500x500px
>>56798079
s => s.split(/\s+/).sort().forEach(console.log)

>cmon step it up bro
>>
For languages A and B, let the perfect shuffle of A and B be the language {w | w = a1b1 ... akbk, where a1... ak is in A and b1 ... bk is in B, each ai,bi is in the alphabet}.

Show that the class of regular languages is closed under the perfect shuffle
>>
>>56798147
Well, technically speaking EOF isn't a char that's just sitting there at the end of your file. It's just what the operating system gives you when you reach the end of a file. The problems you mention, like what about binary files, are up to the OS to solve.
>>
>>56797945

sort . words <$> getLine >>= mapM putStrLn
>>
>>56798147
getchar() returns an int which is important, since EOF does not fit into a single char.
So writing EOF to a file is impossible.
>>
>>56798199
You said it was a character first and now you're saying it's not? So then what is it? (Hint: I already know what it is, but there's problems with your explanation.)
>>56798207
Correct.
>>
>>56798189
>needless regexp
>prints an array
>>
>>56798201
withWords f = unwords . f . words
withLine f = putStrLn . f =<< getLine

main = withLine (withWords L.sort)
>>
>>56798179
>jQuery
>Java
>>
>>56798229
>>prints an array
Are you sure?
>>
>>56798163
EOF is a macro defined by some C library. You could say it's "random", but it is that way by convention.
>>
>>56798154
True, I guess saying "the whole set" is too strong. What lisp does provide is just a solid, mature implementation of untyped lambda calculus.
>>
What are you reading /dpt/?
>>
>>56798252
No, wait. It doesn't.
>>
>>56798247
java is short for javascript, guess they havent taught you that yet in your intro to cs class kid
>>
>>56798262
>some C library
I don't think you should call the C standard library "some library".
>>
>>56798247
Java is just a subset of JavaScript.
>>
>tfw can't figure out how to create a program to solve a problem that has to have linear runtime complexity
I feel retarded that other people were able to do it easily.
>>
>>56798262
It's a bit more than just random. What if it was < CHAR_MAX?
>>
>>56798245
That prints em all on a single line.
>>
>>56798315
Yes, it's better that way
>>
>>56798221
>You said it was a character first and now you're saying it's not? So then what is it? (Hint: I already know what it is, but there's problems with your explanation.)
Fair point, but initially he specifically asked what EOF is, conceptually speaking. Conceptually it's easy to imagine that it's a special character that signifies the end of the file.
>>
>>56798315
>>56798326
And you could always use unlines if you really wanted them line seperated
>>
File: linus.jpg (655KB, 2200x1238px) Image search: [Google]
linus.jpg
655KB, 2200x1238px
Is your code tasty, /dpt/?
>>
>>56798294
Well, what's the problem?
>>
>>56798331
The issue I find with that is that it implies that there's a character reserved for EOF, which isn't true.
>>
>>56798201
isn't it great when compositional operators are randomly left and right precendent
(((sort . words) <$> getLine) >>= (mapM putStrLn))

why?
why can't haskell just either stick with left to right or right to left?
>>
>>56797816

I already know C, you fucking retard.
>>
>>56798367
too bad u'll never C ur penis hue hue
>>
EOF is -1
>>
>>56798344
let cities = readLine().components(seperatedBy: " ")
for city in cities.sorted() {
print(city)
}
>>
>>56798345
I'm passing in a string of coordinates of knights on an nxn chessboard, where n=Integer.MAX_VALUE, and have to return true if all the knights aren't attacking each other, return false if a knight attacks another knight.
Professor said a HashSet would work to solve it but I'm retarded and can't figure out exactly how to keep the runtime linear.
Doing this in Java by the way.
>>
>>56798359
Well, I would assume if you were reading and confused about chapter 1 of K&R that you wouldn't really be nitpicking over what constitutes a char vs a symbolic constant.

If you want to know really why it works, it's because getchar doesn't typecheck and EOF is by convention -1 which isn't a valid integer corresponding to the conventional size of a char.

Does that help? No, not really. Because you wade out into why arbitrary design decisions were made instead of doing the exercises.
>>
>>56798190
Interleave the automata.
>>
>>56798361

(((sort . words) <$> getLine) >>= (mapM putStrLn))
sort (the) words (from) getLine (andThen) (runTheResultsThrough) putStrLn
>>
>>56798389

>projecting
>>
>>56798397

^D
>>
>>56798361
scroll down a bit
https://www.haskell.org/onlinereport/decls.html#nested

generally I use parentheses and then remove if lint lets me and if it's not competely unclear
>>
>>56798424
I never asked the original question about EOF. But I thought your explanation could be misinterpreted, which is why I started asking questions.
>>
>>56798432
yes, I'm projecting my inability to see ur penis, hand me a microscope
>>
>>56798410
More functional version
let cities = readLine().components(seperatedBy: " ")
cities.sorted().forEach(print)
>>
>>56798416
This should be sufficient:
for each knight in input:
if this knight's square has been attacked:
return false
else:
mark the knight's square
mark any square the knight is attacking
>>
>>56798416
This can't be done in time linear in n.
>>
>>56798435
or ^Z on linux
>>
>>56798426
if you do epsilon transitions from each A state to a B state, you need to remember what A state you left off from to go back to it
>>
>>56798272
Mythical Man Month.
And a little Code Complete to help me improve my code.
>>
>>56798460
I would have gone with something about needing a projector to see it.
>>
>>56798444
Sure, and half of those responses were made by someone else besides me too.

If you want to know why, it's because the explanation is framed that way and then later elucidated in the book itself, so I gave an explanation that wasn't completely correct in the interest of being suitable for the person asking it in the context, since it's explained that EOF is a symbolic constant anyway when you do the exercise to find the value that getchar returns for it.
>>
>>56798473
O(10n) so it's O(n), right?
Hashset add/lookup is O(1), you have a max of 1 lookup and 9 adds per knight.
>>
>>56798460

You're projecting your inability to see your own penis. Buzz off, virgin.
>>
>>56797781
>FD
>VALID
0 is a valid file descriptor, you know.
>>
>>56798520
Yeah O(10n) is still O(n).
Are you >>56798464? Because that looks like O(n^2) to me, unless I'm wrong.
>>
>>56797905
Literally don't bother with Lisp unless you're going into AI.
>>
>>56798521
Fizz
>>
>>56798431
a . b composes b into a
a >>= b pipes a into b
is confusing to me when used in a bulk of code because randomly mixing
a $ b applies the result of b on a
a |> b applies to the result of a on b
would be confusing too

i remember haskellers arguing in favor of $ vs |> to be consistent with the mathematical "right to left" notation, why not for >>=?
>>
>>56798520
The number of knights may be O(n^2) so you can't do it in O(n).
>>
>>56798551
No I'm not, but n^2 would imply looping through the knights twice & I don't see that.
>>
>>56798573
that's what =<< is for
>>
>>56798551
No he's not me, I'm me. And I'm pretty certain this is O(n): >>56798464

for // O(n)
if // O(1)
return false; // O(1)
else // O(1)
mark squares // O(1)


I don't see how it would be O(n^2).
>>
>>56798512
Sure, but the asker may not necessarily be reading K&R, so they'll miss that example. Anyways in the beginning they seemed to be confused at what EOF itself was, and although that example may have been fine in K&R, where the book is structured to redefine the explanation, here, the asker may just leave with a misconception.
>>
>>56798577
Oh, well I was thinking linear wrt the number knights, not the width of the board. Forgot board was described as n x n.
>>
>>56798579
Yeah, same.
n^2 would have to loop knights once for each knight, something like this:
for attacker in knights:
for target in knights:
if can_attack(attacker, target):
return false
>>
>>56798586
yeah but >>= is generally used, no?
>>
>>56798612
It IS linear wrt the number of knights.
>>
>>56798605
So, you think you're better than K&R?
>>
File: how very eggy of you.png (36KB, 473x329px) Image search: [Google]
how very eggy of you.png
36KB, 473x329px
Alright, finished the database/manager/everything else for this class

Recommend me more class names available to students/professors in the database

Currently I have
"Unethical hacking", "Numerology for fun and Prophet", "Phrenology basics", "Ancient Sexology", "Physiognomy for active profiling", "Slam poetry 101", and "Social engineering for profit and profit",
>>
>>56798634
but >>= is naturally sequential like *>

m >>= f >>= g >>= h
h =<< (f =<< (g =<< m))
does not look very natural
>>
>>56798521
Not being virgin on the behind isn't something to brag about
>>
>>56798590
I see what you mean, but how would I mark the coordinate being attacked? Wouldn't I have to check each knight against those squares?
>>
>>56798672
but why not keep that idea for . and $?
i've found code using |> to be somewhat more readable than using code $ personally, but mixing orders like that just makes it way more annoying
>>
Why not social engineering for ??? and profit?
>>
>>56798663
Modern Dairy Science
Intro to Formalities
Tattoo Shapes
College Algebra
Big Pyramids
>>
>>56798693
. and $ are pure
>>
>>56798682
You mark a spot by inserting it into your hash set.
>>
>>56798682
Nope. Have you heard of prime sieves? This exercise looks like a warmup for a sieve of eratosthenes implementation.
https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

Anyway, marking a square is simply setting board[x][y] = true or 1 or whatever

// again, pseudocode because i'm too lazy for correct syntax
// these default to false
bool board[][] = new bool[8][8];

// get each new knight as an x, y tuple
foreach ( (x, y) in knights ) {
if (board[x][y] == true) return false;

board[x][y] = true;
board[x+1][y+2] = true;
// ... etc for all attacked square, make sure to do bounds checking so you're not attacking outside the board
}


You mentioned a hashmap which works just as well as an array in this case, use whatever you were taught in class.
>>
File: 1470710265808.jpg (25KB, 600x399px) Image search: [Google]
1470710265808.jpg
25KB, 600x399px
>>56798344
import java.net.InetSocketAddress

import akka.NotUsed
import akka.stream._
import akka.stream.scaladsl.{Flow, Framing}
import akka.stream.stage.{GraphStage, GraphStageLogic}
import akka.util.ByteString


private object PortLine {
def unapply(line: String): Option[Int] = for {
portLine ← Option(line)
Array(port, _) ← Some(portLine.split("/tcp\\s+open", 2))
} yield port.toInt
}

private object IpLine {
def unapply(line: String): Option[String] = for {
ipLine ← Option(line) if line.contains("Nmap scan report for ")
Array(_, ip) ← Some(ipLine.split("Nmap scan report for ", 2))
} yield ip
}

private final class NmapLogParseStage extends GraphStage[FlowShape[String, InetSocketAddress]] {
val input = Inlet[String]("nmap-log-parser.input")
val output = Outlet[InetSocketAddress]("nmap-log-parser.output")

val shape = FlowShape(input, output)

def createLogic(inheritedAttributes: Attributes) = new GraphStageLogic(shape) {
override def preStart() = {
super.preStart()
nextLine()
}

def processLine(ip: Option[String] = None)(line: String): Unit = line match {
case IpLine(foundIp) ⇒
nextLine(Some(foundIp))

case line @ PortLine(foundPort) if ip.nonEmpty ⇒
emit(output, InetSocketAddress.createUnresolved(ip.get, foundPort), () ⇒ nextLine(ip))

case _ ⇒
nextLine(ip)
}

def nextLine(ip: Option[String] = None): Unit = {
read(input)(processLine(ip)(_), completeStage)
}

setHandler(output, eagerTerminateOutput)
setHandler(input, eagerTerminateInput)
}
}

object NmapLogParser {
def apply(lineSeparator: String = System.getProperty("line.separator"), maxLineLength: Int = 10000): Flow[ByteString, InetSocketAddress, NotUsed] = {
Framing.delimiter(ByteString(lineSeparator), maxLineLength, allowTruncation = true)
.map(_.utf8String)
.via(new NmapLogParseStage)
}
}
>>
>>56798768
JUST
>>
>>56798663
Underwater Basketweaving
Sex and Gender in Third Wave Jihad
>>
>>56798730
>>56798760
I see. I think I can go on from this. I just wasn't seeing it. Thanks anons who helped me.
>>
>>56797966
alright so I get the concept of getchar and EOF (somewhat) but these questions still elude me. Heres what I've tried to do so far. I've also thought of putting "int EOF" under int c or a for statement like:

for(c, EOF = c)
putchar(c);
>>
>>56798849
>Heres what I've tried to do so far.
Let's start with why. What are you trying to accomplish? The book shows you the correct way to read a file character by character. Are you trying to do something else instead?
>>
>>56798760
A 2D array isn't technically linear so he needs to use a hash table.
>>
>>56798760
>>56798878
*or a 2D array with lazy initialization.
>>
File: 1409286721653.jpg (12KB, 251x242px) Image search: [Google]
1409286721653.jpg
12KB, 251x242px
>mfw microkernel morons think there's nothing wrong with running the memory manager as a user-level daemon

lmao where do these retards even come from
>>
>>56798760
Not the same anon, but wouldn't you have to separate the loop into two, first one for marking, and then one for the checking, since as it is now, the first knight won't have the second's, third's, etc marks.
I mean, its still O(n), but the pseudocode is bugging me...
>>
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Please input 3 city names separated by spaces in one line and press Enter.");
String city1 = input.next();
String city2 = input.next();
String city3 = input.next();

System.out.println(city1);
System.out.println(city2);
System.out.println(city3);

}


bls how do I sort the strings

I can enter with spaces and each string gets a single value, but how do I make em print out in alphabetical order
>>
>>56798904
You won't miss anything because knights can always attach each other.
>>
>>56798872
I'm trying to solve the second question, which is to print the value of EOF.
>>
>>56798927
Oh yeah, my bad.
>>
>>56798901
Stupid frogposter
>>
>>56798878
Technically as long as it's O (n) or lower it's fine.
>>56798904
I don't think so. Your initializing all values on the 2D array to false, and you're only checking certain coordinates for each knight, not the entire 2D array. So it would be O(kn) runtime.
>>
>>56798878
>>56798893
>A 2D array isn't technically linear so he needs to use a hash table.
It's linear in terms of time complexity (notice we never iterate through the entire board). It could potentially be non-linear in terms of space complexity. However we are talking about linearity with respect to the input, which in this case is just knight positions. The space complexity is O(1) because we're always working with a standard size chess board (in the context of OP's assignment anyway). If it had to take an arbitrary size chessboard as an input as well you would be correct to say the array doesn't have linear space complexity wrt the input.
>>
>>56798605
They posted a screenshot of them reading K&R with their original question. That's why it was relevant.

You can double-check if you don't believe me. It's not like I was just assuming they were working through it for no reason.
>>
I always wanted to make a library. Make something useful for other people to use.
And then have people use it. But everything has already been done.

Even when trying hard to think of ways to be productive and helpful I draw a blank.

Programming sucks.
>>
>>56798940

microkernel micropenis detected
>>
>>56798464
>>56798760
I.. don't think this solves the problem. Although admittedly i didn't quite understand the problem.

But if you just loop once over the knights like that you will evaluate if the earlier knights are being attacked before evaluating if the later knights are attacking, giving you false negatives.
>>
>>56798929
Why don't you just print EOF?
>>
>>56798971
You could always just make a better library than the existing one in that category.
>>
>>56798916
this is honestly pretty cute, you're making good progress

you're really close now, just google how to sort in java
>>
>>56798971
Then help maintain an existing library? There's plenty of backend projects out there that could use some help.
>>
>>56798929
Oh the exercises, my bad.
EOF is just a constant that's defined somewhere in the standard library. To print it, simply do:
printf("%d\n", EOF);
Note that it's %d because EOF is defined as an int.
>>
File: what I got.png (241KB, 1920x1080px) Image search: [Google]
what I got.png
241KB, 1920x1080px
>>56798997
this is what I get.
>>
>>56798978
>But if you just loop once over the knights like that you will evaluate if the earlier knights are being attacked before evaluating if the later knights are attacking, giving you false negatives.
Not true, because if knight A is attacking knight B then knight B is also attacking knight A. Therefore order doesn't matter.
>>
>>56799024
Why are you printing it multiple times? And why aren't you using printf?
>>
>>56798971
Don't make a library for other people to use. Make a library for you to use.

If you can't think of a library you have a use for that doesn't already exist then congratulations, you have everything you need to be in a position to be very productive. Libraries only exist to help people be more productive.
>>
So... I'm trying to get into neural networks...
Is using an adjacency matrix with the usual bool values replaced with weight values a good way to store the graphs?
>>
>>56799024
Oh, and you can use ^D for EOF.
>>
>>56799024
The problem is that you are printing the value of EOF instead of the value of c.

That's basically the code for the copy program in chapter 1 with EOF being passed to putchar instead of the variable being used for getchar.

That code is saying to put EOF for each character in STDIN until EOF is reached in STDIN.
>>
File: besto girl.gif (748KB, 500x482px) Image search: [Google]
besto girl.gif
748KB, 500x482px
>>56799008
F-FUG don't say that kind of stuff
>>
>>56798964
>>56798967
I forgot it wasn't for general n.
I'd still use a hash table or explicitly describe lazy initialization if this is a homework assignment just to make sure you don't lose points.
Initializing a MAX_VALUE x MAX_VALUE array is a bit much.
>>
>>56799039
Clever. I didn't think of that. I wonder if the professor also missed that?
>>
>>56798967
>>56799080
>If it had to take an arbitrary size chessboard as an input as well you would be correct to say the array doesn't have linear space complexity wrt the input.
The time complexity would also go to O(n^2) unless you do lazy initialization.
>>
Is there a better way to do this? No flame plz anon
http://ix.io/1qJ8
>>
>>56799062
I don't know much about neural networks, but that sounds about right for networks with a fixed number of nodes.

If you want to add a node to the network (in any layer), then you will have to re-allocate the entire structure.

Similarly, removing a node would also be a pain.
>>
>>56799101
>Is there a better way to do this?
Don't use C++.
>>
>>56799101
stl already has a for_each, doesn't it?
>>
>>56799101
>>56799140
http://en.cppreference.com/w/cpp/algorithm/for_each
>>
>>56799140
>>56799150
Word up.
>>
File: 1462541619347.png (283KB, 714x574px) Image search: [Google]
1462541619347.png
283KB, 714x574px
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Please input 3 city names separated by spaces in one line and press Enter.");

String city1 = input.next();
String city2 = input.next();
String city3 = input.next();

String[] cities = {city1, city2, city3};


Arrays.sort(cities);

System.out.println(cities[0]);
System.out.println(cities[1]);
System.out.println(cities[2]);

}


OH FUG, I DID IT OH!!!!!!!!!!!!!!!!!!!!!!!!

Please input 3 city names separated by spaces in one line and press Enter.
gayguyville cuckville pajeettown
cuckville
gayguyville
pajeettown


FUG
>>
File: 1474687087768.gif (2MB, 319x249px) Image search: [Google]
1474687087768.gif
2MB, 319x249px
How can I make this reverse shell bettter
>inb4 don't use python
I don't feel like writing 4000 lines of code so I used python.
heres the server.py
http://pastebin.com/JpaaxBAW

client.py
http://pastebin.com/MEAtHVcY
>>
>>56799179
Now do it for a variable amount of cities.
>>
>>56799186
>I don't feel like writing 4000 lines of code so I used python.
Why not use Haskell instead?
>>
I'm trying to learn haskell and I made a list of the dividers of n, only problem is that I get this error:

* Non type-variable argument in the constraint: Num [t]
(Use FlexibleContexts to permit this)
* When checking the inferred type
dividers :: forall t. (Num [t], Integral t) => t -> [t]

the code being

dividers 1 = 1
dividers 2 = 2
dividers n = [a | a <- [3..n], n `mod` a == 0]

Now, if I just take [a | a <- [3..n], n `mod` a == 0] and replace n with a number and run it the thing actually works and It gives out a list of all the dividers of that number but it won't compile with the n in there. Do I need to pun constraints on n as well?
>>
Alright, I think I'm just about done

Sample random student:

////////////////////////////////////////////////////////////////////////////////////////////////////
/Name: His Excellency Huang /
/Date of Birth: 8/6/81 /
/Age: 35 years /
/Home Address: 1086 Atlantic Ave., United Kingdom /
/Local Address: 65 Atlantic Pass, United States /
/Visa class: f /
/Visa permissions: Permits the holder to follow courses as long as the holder is paying their fees./
/Expiry date: Thu Jun 26 16:48:23 PDT 1986 (expires in 31 days) /
/Position: Student /
/ID: -834071953 /
/Balance: 2.3116493 /
/Classes: /
/Modern Dairy Science /
/Screaming (Lecture) /
/Screaming (Workshop) /
////////////////////////////////////////////////////////////////////////////////////////////////////
>>
>>56799191
Never tried it, I have no clue how I would do this in haskell.
>>
>>56799195
dividers 1 = [1]
dividers 2 = [2]
>>
File: 1459834124491.webm (330KB, 1280x720px) Image search: [Google]
1459834124491.webm
330KB, 1280x720px
vim or emacs?
>>
>>56799189
what does that mean?

more then 3 cities?
>>
>>56799211
ed
>>
>>56799211
http://spacemacs.org/
Why not both?
>>
File: 1455627844909.png (581KB, 438x897px) Image search: [Google]
1455627844909.png
581KB, 438x897px
Still working on akari-bbs!

I didn't like how I implemented code tags, so I'm rewriting it so I could use it for other things as well.
>>
>>56799220
Any amount of cities.
>>
>>56799211
Try them both and see which you like more.

The only cost there is time.
>>
>>56799234

Is it that bad? If you had to make spoiler tags with that part of the code, would it be horrible?
>>
>>56799209
>mfw
Am I retarded or is the haskell error that stupid to not point me at the right place?
>>
>>56799234
you are my favourite anon
>>
>>56799211
If you're a newbie, vim is easier to get into.
Emacs is really nice if you're working with a Lisp though.
>>
>>56799211

uemacs
>>
>>56799247
The type error is there because it's possible to unify those two types, but because you don't have an extension enabled that would unify them it doesn't.

Numeric literals have type
forall a. (Num a) => a

i.e., a numeric literal can be any type that instantiates Num such as Integer, Float, Double, etc.

It's possible to define a Num instance for lists, so it's possible to unify those equations.
>>
File: C.jpg (114KB, 575x502px) Image search: [Google]
C.jpg
114KB, 575x502px
I need a break from web shit, does anyone know a quick and fun C book?
>>
>>56799234
Why are you writing it in C?
Was this a design choice or you just like the language?
And how does writing web stuff in C compare to things like Java or Python?
>>
>>56799320
>fun C
>>
>>56797672
and then that C programmer is dropped into C++ land (because there are no C jobs anymore), calls a function in the "do something" space that throws an exception and he ends up never getting to fclose(fp) and now has a resource leak.

when will the C meme end?
>>
>>56799320
K&R, alternatively Expert C.
>>
>>56799320
K&R.
It's actually pretty short and to the point.
>>
>>56799357
>>56799345

Aside from K&R
>>
>>56799338
C++ is the memiest of memes, mate.
C is here to stay, and there is no indication that it's going to go away any time soon.
>exception
Kill yourself.
>>
File: carlos.png (272KB, 560x560px) Image search: [Google]
carlos.png
272KB, 560x560px
I guess you could say >>56799391 took exception to that
>>
>>56799345

this one?
>http://www.electroons.com/8051/ebooks/expert%20C%20programming.pdf
>>
File: stoopid.jpg (64KB, 789x785px) Image search: [Google]
stoopid.jpg
64KB, 789x785px
>>56799406
>>
>>56799391
no, the memiest of memes is anything with ".js" at the end.
>>
>>56799338
>using stdio.h in c++
Don't you guys have streams for file io now?
Isn't stdio.h just backwards compatability anyways?

So why do you apply my informative answer into a surrounding it was never intended to be used in?
>>
>>56799429
did my joke catch (you off guard) { ... }
>>
>>56799433
C++ iostreams are an absolute joke.
I can understand why some sepplesfag would want to use the much more sane stdio.
>>
>>56799454
stdio is apparently much faster than iostream too
>>
sepples allows you to
throw 22;

but it doesn't allow you to
catch(22)
>>
>>56797467
She's cute. What anime?
>>
>>56799418
Ye, the fish book.
It has a ton of tips, challenges, real life stories, etc.
It's one of the few technical books I had fun reading through.
>>
>>56799328
>or you just like the language?
It's mostly because I only know C and I wanted to try webdev.
I really do like C tho.

When writing CGI in C, you pretty much have to roll your own everything.

Other languages probably have import do_everything in their standard library for the basic stuff like GET/POST data, input validation, etc.
>>
File: us three.png (1MB, 1047x517px) Image search: [Google]
us three.png
1MB, 1047x517px
C++ might be getting a second standard library.

Who #hype here?
>>
>>56799617
link: https://youtu.be/j84pZM840eI?t=15m17s
>>
>>56799617
it will be shit
>>
>>56799560
>When writing CGI in C, you pretty much have to roll your own everything.
That's part of the charm.
>>
I am expecting to get shat on a bit for posting this, but if I don't like programming, should I get my bachelor's in Informatics? Or should I just do something that isn't related to IT at all.

I am currently in an Associates program for Computer Information Technology, and while I passed the classes with excellent grades that had programming, it was really very basic-tier shit, as I'm sure all of you can figure since its at the junior college level.

I didn't really care for it though. Do understand, this isn't about me coming here and saying "I don't like thing that you like", this is me realizing that if something is not for me, I would be a fool to stick my nose deeper into it.

tl;dr
I don't care for programming. Is a bachelor's degree in Informatics a viable option, or should I seek to obtain a degree unrelated to IT?
>>
>>56799617
Andrei looks so cute~
>>
>>56799617
>C++ might be getting a second standard library.
That sounds terrible.
>>
>>56799627
The mod sounds like he just hit puberty.
>>
>>56799674
Don't mistake your vocation
Select the right location
Avoid debt
Persevere
Whatever you do, do it with all your might
Depend upon your own personal exertions
Use the best tools
Don't get above your business
Learn something useful
Let hope predominate but be not too visionary
Do not scatter your powers
Be systematic
Read the newspapers
Beware of "outside operations"
Don't endorse without security
Advertise your business
Be polite and kind to your customers
Be charitable
Don't blab
Preserve your integrity
>>
>>56799679
Andrei > Scott > Herb imho
>>
>>56799712
He looks like he just hit puberty
>>
>>56799674
There are a ton of other IT degrees that involve less programming. Anything from UX design to networking (i.e. configuring routers) to business management with a tech focus. You don't have to give up on all of IT just because you don't like programming. It could also be that you'd enjoy more of a tech support role, which you can probably go to trade school for (it'll depend on where you live). Tech support is generally seen as low on the IT totem pole, but even tech support comes in all kinds of different forms, sometimes overlapping with system administrator stuff.
>>
I've started learning Perl.
How much of a mistake am I making and what are the most often used cases for it?
>>
Why is programming so shit?
>>
>>56799784
>use cases for perl
>>
>>56799784
no one seems to want it anymore
it's kinda fun
>>
>>56799784
you will be a 1337 hacker
>>
File: 1.webm (229KB, 700x500px) Image search: [Google]
1.webm
229KB, 700x500px
Can you do this on Windows?

#!/bin/bash

for image in "$@" ; do
filename="$(shuf -i 1400000000000-1469999999999 -n 1)"
extension=$(echo ${image##*.})
mv "$image" "$filename.$extension"
done
>>
>>56799806
It seems like it would be very pleasurable to write in overall
>no one wants it anymore
:(

>>56799827
You would probably have to do some registry tomfuckery but there's no reason you couldn't add in a "scripts" context menu and then have that point to a folder with said scripts in them.
>>
>>56799827
Can I do this in OSX?
>>
If hell freezes over and orange Hitler wins the debate, I'll spend the night programming in a one piece
>>
>>56799857
Yes
>>
>>56798544

My choice of variable names was poor. It's a FILE pointer.
>>
>>56799872
Post pics.
>>
File: 1468815458659.png (598KB, 720x720px) Image search: [Google]
1468815458659.png
598KB, 720x720px
>>56799857
The bash script would work at least. Also I realized there is a mistake, useless use of echo.

extension=${image##*.}


>>56799872
Is that a celebration or because you don't like Trump?

If you don't like Trump please escort yourself back to tumblr.
>>
>>56799906
duh
>>
What's a good place to learn about various media encoding algorithms like HEVC?
>>
>>56799872
We'll be waiting! :3
>>
>>56799827

Well, aside from the fact that Bash is supported on Windows through MSYS2, Cygwin, and the Linux Subsystem for Windows, I am pretty sure all of those are features that are available in Powershell (although the syntax would be different).
>>
>>56799923
Trump pledged to aggressively enforce federal obscenity law which applies to lolis.
>>
>>56799926
Just so we're clear, which one is orange Hitler?
>>
>>56799988
Linus Torvalds
>>
>>56799971
Doubt you could get bash scripts integrated and working with a file manager like that on Windows though.

Do you even have a terminal emulator available on Windows that supports copy and paste?

Windows doesn't even support newlines, I would have to backspace it all and then re-create the newlines in Notepad because Windows can't into newlines.

>>56799978
Nothing compared to the civilization-ending leftist ideals that Hillary further pushes.
>>
facebook servers choking
gonna be some job openings over there tomorrow
>>
File: 1474923343763.png (37KB, 248x288px) Image search: [Google]
1474923343763.png
37KB, 248x288px
>>56800092
>every time a website crashes, a web dev loses his job
>>
File: 1470814242711.png (13KB, 640x400px) Image search: [Google]
1470814242711.png
13KB, 640x400px
I need something like this
a single particle in the middle that repels all others

my professor asked me to do this but I have no idea where should I start
any help? I'm thinking about coloumb's law
>>
>>56799827
Make it so it can't overwrite another image.
>>
>>56800049

ofc windows DOES support newlines, anything that does ascii has a newline character, but pressing enter in windows is a /r or a /r/n for some archaic backwards compatibility reason.

I have no idea how this really relates to your conversation, but I am sure you could do a simple find & replace to fix em all in vim. I think its ":s *string*"
>>
Currently working through project euler problems, im relatively new to programming so i've only been able to do the first three on my own (」゚ロ゚)」
>>
http://blog.cleancoder.com/uncle-bob/2016/05/01/TypeWars.html
>>
>>56800115
its usually ops / IT fault

dev mistakes are generally more subtle than causing the entire website to choke.
>>
>>56800169
don't ruin my dreams anon
>>
>>56800164
>OOP and procedural fags arguing about types
Hilarious
>>
>>56800139
Use a repelling inverse square law and the Euler-Cromer method.
What language?
>>
>>56797467
Implementing an Extended Kalman Filter off of my old basic Kalman Filter implementation :D
>>
>>56800164
> You don't need static type checking if you have 100% unit test coverage.
Oh jeez. It's like they don't realize how easy it is to get 100% unit test
coverage if you constrain the types a function will accept/return -_-
>>
>>56800150
not that guy, but if you check the range he's working in is in the range of a short cryptographic hash. unless he is doing this often, with every picture in a folder of thousands of pictures, the chance of a single collision is diminishingly (but not unreasonably) small.

but if someone wants to do the probabilities on that collision and drop some objectivity in here, go for it.
>>
>>56800231

thanks, I'll take a look
C++
>>
>>56800231
>What language?
How is that even relevant?
>>
>>56800317
Just curious.
>>
>>56800317
maybe he wants to help?

how are you even relevant...
>>
>>56800252
Will it happen, probably not but for such a simple script might as well make it impossible imo. I'd be paranoid about being unlucky or having a weird non-default random seed or something.
I think all it would take is something like
while [ -f "$filename.$extension"]
do
filename="$(shuf -i 1400000000000-1469999999999 -n 1)"
done
mv "$image" "$filename.$extension"
>>
>>56800326
>>56800339
It's just stupid how much /dpt/ cares about language.
>>
>>56800486
This is when I say I love writing functional javascript and slip out the back.

bon nuit amigos
>>
File: 1445711577073.jpg (20KB, 255x256px) Image search: [Google]
1445711577073.jpg
20KB, 255x256px
>>56800486
I wasn't going to mock his language choice or anything.
I've just seen those sorts of exercises using different languages and was curious.
>>
Donald Trump imagines the average hacker as "someone sitting on their bed who weighs 400 lbs". Welp.
>>
>>56800543
I'm pretty sure that the average American isn't a hacker.
>>
>>56800515
>javascript
>functional
>in any sense
>>
>>56800551
But if the average hacker is american...
>>
File: ENOUGH.jpg (29KB, 412x430px) Image search: [Google]
ENOUGH.jpg
29KB, 412x430px
QUICK, MAKE A PROGRAM THAT OUTPUTS A STAR OF DAVID WITH A GIVEN SIZE FROM THE COMMAND LINE

OR I WILL FUCKING STAB YOU BITCH
>>
>>56799784
Perl is the only scripting language in the OpenBSD base install. Therefore, the OpenBSD packaging system is 100% pure perl, and so are many of its modules. That's something, right?

Perl is dead on Linux, though. And on the other platforms it was never even alive.

>>56800486
People like to be fanboys and argue about shit like that. See: Windows vs. Linux, Firefox vs. Chrome, GNOME vs. KDE, VIM vs. Emacs, GPL vs. BSD, systemd vs. sysvinit. They're all tools, people. You don't see people arguing screwdriver vs. drill, do you?
>>
>>56800595
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
if (argc != 2)
return 1;

int n = atoi(argv[1]);

while (n--)
printf("\u2721");
putchar('\n');
}
>>
>>56800610
>owning a drill
>>
>>56800633
>int main
>char *argv[]
>>
>>56800682
That is the proper type signature for main in C.
>>
>>56800633
does char *argv[] make a copy of the cli args
does char **argv point to the actual cli args?
>>
>>56800610
>You don't see people arguing screwdriver vs. drill, do you?
Those do different things. More apt comparison would be people arguing about screw drives.
>>
>>56800711
[] is just syntatic sugar for * afaik
>>
>>56800711
In C, they are both exactly equivalent, and are valid to put as main's second argument.
The first just seems a littler for "obvious", as it's an array of char pointers.
>>
>>56800720
>a littler for "obvious"
Jesus, I really need to read my own shit before I post, especially after I change a sentence. That didn't come out right at all.
a little more obvious*
>>
File: really.png (108KB, 400x381px) Image search: [Google]
really.png
108KB, 400x381px
>compiler for compressor's language isn't compiling
>normies just use nomachine to connect to the linux machine on campus that has it installed and working
>i have linux on my computer and nomachine doesn't work on it
http://www.cs.ecu.edu/karl/cinnameg/8-2/lin/Misc/get.html
this is it if you want to try and tell me how to do it. i ran into a couple blocks that i managed to get past by untar'ing it into a directory in my home directory, then doing the configure, and then touching t_parser.c before sudo make install. also i had to create some directory for make install when it gave an error for the directory not existing. i have to run make install as sudo because otherwise it tells me i don't have permission and has an error because of it.

past all that now, and it does literally thousands of make commands for like idk how long, and then tells me there was an error. i didn't note down the error and i dont want to do it again because it took ages and i couldn't barely use my computer while it was doing all of them

please send help
>>
>>56800690
Proper type sig is
int main(int argc, char *argv[argc])
>>
>>56800736
Stupid frogposter
>>
>>56800736
*compiler for professor's language isn't compiling
>>
>>56800595
do it yourself you lazy cunt
>>
>>56800738
>not
>int
>main(int ac, char **av)

pls
>>
>>56800738
>char *argv[argc]
It would be argc + 1 though, since argv[argc] is guaranteed to be the null pointer. You also missed the opportunity to use 'static' there.
However, that is not what the standard states, so it's not important.
>>
>>56800749
>not
>public static void main(String[] args)
wew
>>
>>56800633
>while "subtract 1 from n", print some character
>add a line break

What kind of nigger bullshit is this? First of all, planning for a variable to overflow to end a loop is the programming equivalent of crashing a plane into a car to make the car stop. Secondly, this just prints a string of stars of David. You are asked to draw a star of David.

Nice code camp skills.
>>
>>56800749
>Not
main(argc, argv)
char *argv[];
{
}


Please
>>
>>56800765
why are you declaring argv between the function constructor and its definition? Does that even compile?
>>
>>56800762
>planning for a variable to overflow to end a loop is the programming equivalent of crashing a plane into a car to make the car stop
n being greater than or equal to zero is a precondition of my program.
>>
>>56800781
Yes, but you subtract 1 every iteration, and the loop ends when subtracting 1 doesn't work anymore because it reached 0.

You're counting on the fact that your exception will be handled as a simple "false", but it's an exception. Just because it works doesn't mean it's not stupid.
>>
>>56800765
>not
int
main(int c, char **v)
{
code here
}

pls
>>
>>56800810
>code here
nice job fag lmao, that's not even going to compile haha I win
>>
>>56800760
publicstaticvoidmainstringargs
>>
>>56800780
>Does that even compile?
Yes. Although I forgot to put the return 0 in the function body.
It's the old style function declaration, as well as implicit int.

>>56800804
>when subtracting 1 doesn't work anymore
int is signed, you know.
>You're counting on the fact that your exception will be handled as a simple "false", but it's an exception.
What are you even talking about? n is guaranteed to be zero at some point, and when that happens, the loop will fail.
After the loop finished, n will be -1.
>>
>>56800810
>not
global int c; global char *v[];
int main(int argc, char *argv[])
{
c = argc;
v = argv;
actual_main();
}
actual_main()
{
code
}
>>
>>56800840
global is not a keyword in C.
>>
>>56800837
If n is signed, then why would the loop fail? As long as the subtraction wields the expected result, the expression is true.
>>
File: go.png (69KB, 600x600px) Image search: [Google]
go.png
69KB, 600x600px
Finally started to learn Go. And damn, what a fun and sexy language. I can't wait to start a few pet projects with it. All the hate towards Google kept me off it for so long. What a waste.
>>
File: bc78020b8.jpg (38KB, 405x343px) Image search: [Google]
bc78020b8.jpg
38KB, 405x343px
>>56800762
>>56800804
Nice try b8er.
>>
>>56800855
In C, zero is false, and non-zero is true.
When n reaches zero, the loop will terminate.
>>
>>56800865
while(n--) does not evaluate n, it evaluates the expression n--
>>
>>56800870
n-- evaluates to n, with the side-effect of decrementing n.
>>
>>56799872
Alright faggot

Time to deliver
>>
>>56800877
well that's fucking retarded
>>
>>56800884
Do you seriously not know any C-like languages?
>>
>>56800888
This is what happens when you people keep pushing the haskell meme.
>>
>>56800857
i started playing with it today. it's fun but i'm not sure why
what are you going to write?
>>
>>56800888
he means it's fucking retarded to do it like that instead of just using a for loop, which it is

nice trips btw
>>
File: 1471681836299.jpg (66KB, 470x555px) Image search: [Google]
1471681836299.jpg
66KB, 470x555px
>>56800901
>a countdown while loop is now "fucking retarded"
Also uses one less variable.
>>
>>56800901
>he means
Sure you do buddy.
>>
>>56800911
why would you not just use a for loop like everyone else?

nice dubs btw
>>
>>56800882
You watched the debate, right?

Trump was destroyed for 75% of that debate.
>>
>>56800888
>>56800901
No, it's retarded that the expression is not what is evaluated for the loop.

while(n--) should equate while(n = n - 1)

Otherwise it's a very arbitrary shortcut and it just gives pajeets opportunities to make their code confusing.

What does while(n-- && m--) evaluate? n * m? Come on!

Also, not >>56800898
>>
Why don't more languages support swap syntax like Python?
>>
>>56800901
Why introduce another variable for absolutely no reason?
I'm not using n to index anything or need its original value later.

The only real problem with my code is that it doesn't handle negative numbers.
>>
>>56800911
How about just putting n-- inside the loop, where the subtraction is actually occurring.
>>
>>56800927
>why make your code easy to read?
>>
>>56800246
what for?
>>
>>56800924
>>56800938
>>56800948
It's not confusing or hard to read if you use C at all.
>>
>>56800927
>>56800911
Where are you getting this "another variable" from?
for (n = atoi(argv[1]); n > 0; n--) doesn't need any other variables.
>>
>>56800924
>Otherwise it's a very arbitrary shortcut
Yes, that's the whole point of the prefix/postfix increment/decrement operators.

>What does while(n-- && m--) evaluate? n * m? Come on!
0 if either n or m is zero, 1 otherwise. There is also the side effect of decrementing n, and decrementing m is n is non-zero.

>>56800938
>where the subtraction is actually occurring
The subtraction IS actually occurring. Any expression is allowed to have side effects in C (and most non purely function languages).
>>
>>56800898
I'll probably use it on the backend of a new web project.
>>
>>56800956
>why should I write my program on separate lines, it's not hard to just read between the semicolons!
>>
>>56800925
What do you mean swap syntax?
>>
>>56800977
It's a simple decrement in a while loop.
>>
New thread:
>>56800999
>>56800999
>>56800999

Trips and no traps edition.
>>
>>56800994
>why can't these plebs understand my poorly written code? why must my intellect be so superior?
>>
File: autism girl.png (1MB, 1920x1080px) Image search: [Google]
autism girl.png
1MB, 1920x1080px
>>56800408
>>56800150
I believe this would do it.

#!/bin/bash

for image in "$@" ; do
while true ; do
timestamp="$(shuf -i 1400000000000-1469999999999 -n 1)"
extension=${image##*.}
filename="$timestamp.$extension"
[[ ! -f "filename" ]] && break
done
mv "$image" "$filename"
done
>>
>>56801069
Chi-chan is not autistic, you dumbshit.
>>
>>56801069
>
[[ ! -f "filename" ]]

>
"filename"
>>
>>56800924
>while(n--) should equate while(n = n - 1)
It does
n = n - 1 also returns n
>>
File: vid.webm (3MB, 1758x1010px) Image search: [Google]
vid.webm
3MB, 1758x1010px
Beautiful

>>56801266
Assburgers at least.

>>56801363
Maybe some crazy person has their images named like "image. _ jpeg"

Better safe than sorry.
>>
>>56801611
What is $@?
>>
>>56801676
All arguments. In a bash script "$1" and "$2" would be the first and second arguments respectively.

So if you ran a script like

./script.sh arg1 arg2

Then "$1" would be arg1, and "$2" would be arg2.

If you use "$@" that means ALL arguments. So if you ran

./script.sh arg1 arg2 arg3 arg4 ...

It would collect all arguments into $@.
for x in "$@"
is a way to loop through all of them.
>>
>>56801763
I see, thanks.
>>
>>56801363
Woops, just realized there was no $

Holy shit I'm stupid.
Thread posts: 333
Thread images: 33


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

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


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