Task: Matrix digital rain

C: 
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>


#define ROW_DELAY 40000


int get_rand_in_range(int min, int max)
{
  return (rand() % ((max + 1) - min) + min);
}

int main(void)
{
  
  srand(time(NULL));

  
  char chars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

  int total_chars = sizeof(chars);

  
  initscr();
  noecho();
  curs_set(FALSE);

  start_color();
  init_pair(1, COLOR_GREEN, COLOR_BLACK);
  attron(COLOR_PAIR(1));

  int max_x = 0, max_y = 0;

  getmaxyx(stdscr, max_y, max_x);

  

  
  int columns_row[max_x];

  
  int columns_active[max_x];

  int i;

  
  for (i = 0; i < max_x; i++)
  {
    columns_row[i] = -1;
    columns_active[i] = 0;
  }

  while (1)
  {
    for (i = 0; i < max_x; i++)
    {
      if (columns_row[i] == -1)
      {
        
        columns_row[i] = get_rand_in_range(0, max_y);
        columns_active[i] = get_rand_in_range(0, 1);
      }
    }

    
    for (i = 0; i < max_x; i++)
    {
      if (columns_active[i] == 1)
      {
        
        int char_index = get_rand_in_range(0, total_chars);
        mvprintw(columns_row[i], i, "%c", chars[char_index]);
      }
      else
      {
        
        mvprintw(columns_row[i], i, " ");
      }

      columns_row[i]++;

      
      if (columns_row[i] >= max_y)
      {
        columns_row[i] = -1;
      }

      
      if (get_rand_in_range(0, 1000) == 0)
      {
        columns_active[i] = (columns_active[i] == 0) ? 1 : 0;
      }
    }

    usleep(ROW_DELAY);
    refresh();
  }

  endwin();
  return 0;
}







Python: import curses
import random
import time





ROW_DELAY=.0001

def get_rand_in_range(min, max):
    return random.randrange(min,max+1)

try:
    
    chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    
    total_chars = len(chars)
        
    stdscr = curses.initscr()
    curses.noecho()
    curses.curs_set(False)
        
    curses.start_color()
    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    stdscr.attron(curses.color_pair(1))
    
    max_x = curses.COLS - 1
    max_y = curses.LINES - 1
    
         
    
    
    
    
    columns_row = []
    
    
    
    
    columns_active = []
    
    for i in range(max_x+1):
        columns_row.append(-1)
        columns_active.append(0)
        
    while(True):
        for i in range(max_x):
            if columns_row[i] == -1:
                
                
                columns_row[i] = get_rand_in_range(0, max_y)
                columns_active[i] = get_rand_in_range(0, 1)
     
        
        
        for i in range(max_x):
            if columns_active[i] == 1:
                
                char_index = get_rand_in_range(0, total_chars-1)
                
                stdscr.addstr(columns_row[i], i, chars[char_index])
            else:
                
                
                stdscr.addstr(columns_row[i], i, " ");
                
     
            columns_row[i]+=1
     
            
            if columns_row[i] >= max_y:
                columns_row[i] = -1
    
            
            if get_rand_in_range(0, 1000) == 0:
                if columns_active[i] == 0:      
                    columns_active[i] = 1
                else:
                    columns_active[i] = 0
     
            time.sleep(ROW_DELAY)
            stdscr.refresh()
    
except KeyboardInterrupt as err:
    curses.endwin()