Bit Focus

Leap Year Determination

At Wikipedia we may see a straightforward way to tell whether a year is leap or not. Well here is a more "compact" way (pseudocode)
func is_leap_year(year)
    return (year MOD 4) XOR (year MOD 100) XOR (year MOD 400)
where MOD is modulo, and XOR is exclusive or.

Permanent Link: /p/1 Load full text

Post tags:


Circles Intersection

We are going to calculate points of intersections for 2 circels, given their centers and radiuses on a 2D plane. Say, we will implement the following C function
int intersect(struct circle_t const circles[], struct point_t intersections[]);
where point_t and circle_t are
struct point_t {
    double x;
    double y;

struct circle_t {
    point_t center;
    double r;
    The function intersect takes 2 circles as parameter, returns the number of points of intersection, and the details of the points will be put in parameter intersection. Since 2 circles may have up to 2 points of intersection, we may call that function in following way:

Permanent Link: /p/0 Load full text

Post tags:


. Back to Bit Focus
NijiPress - Copyright (C) Neuron Teckid @ Bit Focus
About this site