Post a program

#include
#include
#include
#include
#include
#include
#include
struct parameters
{
char prgrmnme[5];
char prgrmmde[7];
char flepth[100];
char addrss[32];
char prt[5];
};
int sendmode(struct parameters ar);
int receivemode(struct parameters ap);
/*main()*/
int main(int argc, char *argv[])
{
int result = 0;
void help(void);
char programmodesend[] = "SEND";
char programmodereceive[] = "RECEIVE";
char programhelp[] = "HELP";
struct parameters arguments;
/*the program begins by determining what operation
*mode the user specified in the command-line parameters*/
if (argc < 5)
{
fprintf(stderr, "ERROR: too few arguments\n");
return -20;
}
else if (strcmp(argv[1], programmodesend) == 0)
{
result = 1;
}
else if (strcmp(argv[1], programmodereceive) == 0)
{
result = 2;
}
else
{
result = 3;
}
switch (result)
{
case 1:
strcpy(arguments.prgrmnme, argv[0]);
strcpy(arguments.prgrmmde, argv[1]);
strcpy(arguments.flepth, argv[2]);
strcpy(arguments.addrss, argv[3]);
strcpy(arguments.prt, argv[4]);
return (result = sendmode(arguments));
case 2:
strcpy(arguments.prgrmnme, argv[0]);
strcpy(arguments.prgrmmde, argv[1]);
strcpy(arguments.flepth, argv[2]);
strcpy(arguments.addrss, "127.0.0.1");
strcpy(arguments.prt, argv[3]);
return (result = receivemode(arguments));
case 3:
fprintf(stderr, "INVALID MODE\n");
help();
return -1;
}
}/*main()*/

Attached: robot.png (580x715, 76K)

Other urls found in this thread:

en.wikipedia.org/wiki/Sieve_of_Eratosthenes
pastebin.com/XwFZYuAp
twitter.com/SFWRedditVideos

wow that's ugly, maybe check some getopt examples and use enum or array of anonymous struct instead of result variable end standalone literals, then each action in it's own function
this is also riddled with stack overflow attack surface as you just write anything user gives you on stack without bound checking
this wouldn't pass any code review ever, hang yourself or git gud

the pattern is pretty comfy
when using getopt and flags:
enum {
NONE,
SEND,
RECIEVE,
HELP
} verb = NONE;

and changing verb with keyword instead of magic numbers

combine it with anonymous struct with char *keyword and int flag for string maching:
const struct verblist {
const char *keyword;
int value;
} *t, verblist[] = {
{"SEND", SEND},
{"RECIEVE", RECIEVE},
{"HELP". HELP},
{NULL. -1},
}

for (t = verblist; t->keyword != NULL; t++) {
if (strcmp(argv[0], t->keyword) == 0) {
verb = t->value;
break;
}
}

whoops typos, mistyped . instead of , in the verblist and there should be semicolon at the end of verblist array

this is excellent, i appreciate this thanks

Attached: 1531418207669.gif (498x372, 663K)

# This program will solve the 10th question on project Euler:
# The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
# Find the sum of all the primes below two million.

# This list contains the first four prime numbers and will hold the rest until 2,000,000.
primes_list = [2, 3, 5, 7]
# var is the candidate for being prime and x iterates through prime_list.
var = 11
x = 0

# This while loop repeats we get all primes below 2,000,000.
while var < 2000001:
# This for loop will iterate through the entire primes list to see if the current number is a prime number.
for i in primes_list:
# For the sake of optimization, the remainder of the number and a prime is taken once and compared twice.
var2 = (var % primes_list[x])
# If the prime is not a factor...
if var2 != 0:
# ... and the number is larger than all the primes in the list, thus not divisible by any of them...
if primes_list[x] >= (var * 0.25):
print(var)
# ... then it must be the next prime! It is added to the list.
primes_list.append(var)
x = 0
i = 0
# Numbers terminating in 5 cannot be prime, so we skip them.
if (var % 10) == 3:
var += 4
else:
var += 2
else:
# ... and the number is smaller than the largest prime in the list, then go on the next prime
# in the list.
x += 1
# If the prime is a factor...
if var2 == 0:
# ... then the number is not prime, on to the next candidate, and reset the list to 2.
x = 0
i = 0
# Same as above, we skip numbers clearly divisible by 5.
if (var % 10) == 3:
var += 4
else:
var += 2

# Finally print the answer.
print(sum(primes_list))

Do I use too many comments?

looks like girl's code

Its not. I've seen girls code with 0 comments and just use variables that are meaningless are huge programs.

Also, I just realized that I could check numbers less than the square root of a candidate prime to check primality rather than those less than 1/4 of the candidate prime.

Yes

you could also just sieve it

I just looked that up. This is my first foray into computational mathematics.

int sum = 0, add;
for (int i = 2; i < 1000000; ++i)
{
add = 1;

for (int j = 2; j < i; ++j)
if (i % j == 0)
add = 0;

if (add)
sum += i;
}

printf("Sum: %u", sum);


couldn't think of any way to make it even less efficient

en.wikipedia.org/wiki/Sieve_of_Eratosthenes
the naive sieve implementation is:
sieve = list(range(2, limit+1))
for i in range(len(sieve)):
if sieve[i] != 0: # is prime
for j in range(i + sieve[i], len(sieve), sieve[i]):
sieve[j] = 0 # set all multiples of this prime to 0

now all non-zero numbers in the sieve list are primes

there are obvious optimizations:
- you know multiples of 2 are non-primes, so start the list from 3 and step by two and save half of space
- similarly, each odd step while zeroing points on multiple of 2
- when zeroing, you can start from square of the prime as smaller multiples have been zeroed by smaller primes
- use boolean instead of numbers and deduce the number by index, this can also save space in memory

In college, I'm not a compsci kid, I'm a math-fag, and I'm familiar with the Sieve of Eratosthenes, but I'm just now learning how to code, and implementing math in computers. I'm very much a beginner at coding.

Tell me if I have this right.
> sieve = list(range(2, limit+1))
This creates a list of all numbers between 2 and the limit, which I assume is the square root of the number for which you are trying to get all primes underneath.
>for i in range(len(sieve)):
This is a for loop that iterates through the range of the list, or all numbers in the list.
>if sieve[i] != 0: # is prime
An if statement that finds the next non-zero number in the list.
>for j in range(i + sieve[i], len(sieve), sieve[i]):
I'm assuming this statement takes all numbers that are multiples of the prime we found with the previous if statement and with the next line sets them to zero, but i'm not sure how this syntax does that. Help pls.
>sieve[j] = 0 # set all multiples of this prime to 0When the for statement finds a multiple of the prime, it sets it equal to zero.

This makes sense, the only thing I am having trouble with is the particular syntax of line 4. Can someone exblain?

Attached: TooSmart.jpg (540x443, 29K)

Idk why the fuck it did that but the last line just says that I am having trouble with the syntax of line 4.

the limit is not square root
range(from, to, step) and if no step given it defaults to 1

Couldn't we make it more efficient by checking only numbers who are less than the square root of the max we are trying to get?

Like if we are trying to get all primes under 100, we only need to get rid of the multiples of the primes under 10.
All non-primes are a product of primes less than the square root of themselves.

#include
#include

void fc(char* vallue) {
value = malloc(sizeof(char*));
printf("Value: %s\n", value);
printf("Addr: %p\n", value);
free(value);
free(value);
printf("Address: %p\n", value);
}

int main() {
static char* vlr = "teste";
printf("Value: %s\n", vlr);
printf("Addr: %p\n", vlr);
fc(vlr);
return 0;
}

As it turns out, we can.
sieve = list(range(2, 2000000 + 1))
for i in range(round(math.sqrt(len(sieve)))):
if sieve[i] != 0:
for j in range(i + sieve[i], len(sieve), sieve[i]):
sieve[j] = 0


This runs in a fraction of the time and yields the same answer. This is what happens when math-fags and cs-fags work together.

.text
Addi $v0, $0, 0x69

don't get cocky, this is 3x faster
def sieve(limit):
length = (limit-1)//2
s = [True] * length
for i in range(int(length ** 0.5)+1):
if s[i]:
for j in range(2*i*i + 6*i + 3, length, 2*i+3):
s[j] = False
return [2] + [n*2+3 for n, p in enumerate(s) if p]

You only need to check i % j up to sqrt(i). Not i < j

exblain brogram :DDD?

Attached: spurdo.jpg (800x800, 52K)

I know. See
>couldn't think of any way to make it even less efficient

optimizations listed in s array only holds odd numbers from 3
on index i, value of the number is 2*i+3
cleans from square of prime, the arithmetic are so bloated because of ^
collect primes into array and prepend 2 to returned array

from mcpi.minecraft import Minecraft
mc = Minecraft.create()
pos = mc.player.getPos/()
x=pos.x
y=pos.y
z=pos.z
high=10
an=20
ex=5
block1=0
block2=4
setBlocks(x,y,z,z+high,y+ex,z+ex,block4)
setBlocks(x+1,y+1,z+1,z+high-1,y+an-1,z+ex-1,block1)

#include
int main(void) { for (;;) puts("op is a faggot"); }

hello david

set answer to the button returned of (display dialog "How old are you?" buttons {"9000 years or less", "9001 or more"} default button 2)
display dialog "You selected " & answer

Attached: 1250084942013.jpg (450x338, 55K)

Part 1:
#include
#include
#include
#include
#include


#define BLOCK_SIZE ((1 path, O_WRONLY);
if (diskFd == -1) {
die("couldn't open disk");
}

block = calloc(1, BLOCK_SIZE);
if (block == NULL) {
die("couldn't allocate block");
}

randomFd = open("/dev/urandom", O_RDONLY);
if (randomFd == -1) {
die("couldn't open /dev/urandom");
}

position = work->start;

while (position + BLOCK_SIZE < work->stop) {
if (read(randomFd, block, BLOCK_SIZE) == -1) {
die("read fail from /dev/urandom");
}

if (write(diskFd, block, BLOCK_SIZE) == -1) {
die("failed write to disk");
}

position += BLOCK_SIZE;

if (position > work->stop) {
break;
}

if (lseek(diskFd, position, SEEK_SET) != position) {
die("lseek failed in thread");
}
}

if (position < work->stop) {
if (read(randomFd, block, BLOCK_SIZE) == -1) {
die("read from /dev/urandom failed");
}

if (write(diskFd, block, work->stop - position) == -1) {
die("write failed in thread");
}
}

close(diskFd);
close(randomFd);

free(block);
free(work);

return NULL;
}

Can't reply with part 2 for some reason...

Certain keywords are banned from posts. Use pastebin, my nig.

yeah maybe it said "die" too much and thought it was mean

pastebin.com/XwFZYuAp

>blocks your typechecker

Attached: 2018-04-03-190254_350x221_scrot.png (350x221, 17K)

i hope this is a joke