You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.8 KiB

Exercises

Here let be listed exercises for the readers of the wiki. You can allow yourself to as many helpers and resources as you find challenging: with each problem you should either find out you know the solution or learn something new while solving it.

Problems in each category should follow from easiest to most difficult. The listed solutions may not be the only possible solutions, just one of them.

General Knowledge

  1. What is the difference between free software and open source?

Solutions

  1. The free software and open source movements are technically very similar but extremely different in spirit, i.e. while most free software licenses are also open source and vice versa (with small exceptions such as CC0), free software is fundamentally about pursuing user freedom and ethics while open source is a later capitalist fork of free software that removes talk about ethics, aims to exploit free licenses for the benefit of business and is therefore unethical.

Programming

  1. Write a C program that prints out all prime numbers under 1000 as well as the total count of these prime numbers.

Solutions

1:

// Sieve of Eratosthenes algorithm, one possible way to generate prime numbers
#include <stdio.h>
#define N 1000

char primeMap[N];

int main(void)
{
  int primeCount = 0;

  for (int i = 0; i < N; ++i)
    primeMap[i] = 1;

  for (int i = 2; i < N; ++i)
  {
    if (primeMap[i])
    {
      primeCount++;
      printf("%d\n",i);
    }

    int j = i;

    while (1) // mark all multiples of i non-primes
    {
      j += i;

      if (j >= N)
        break;

      primeMap[j] = 0; // can't be a prime
    }
  }

  printf("prime count under %d: %d\n",N,primeCount);

  return 0;
}

Math

Solutions