Skip to content

Instantly share code, notes, and snippets.

@souravdatta
souravdatta / numbers.pas
Created March 1, 2022 14:32
A simple pascal program to generate random numbers
program numbers;
uses sysutils, math;
procedure delay(n : integer);
var
i, j : integer;
begin
for i := 1 to n do
for j := 1 to n do
@souravdatta
souravdatta / mrain.c
Created February 13, 2022 20:24
Matrix rain - a very simple implementation with ncurses
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <ncurses.h>
#include <unistd.h>
#include <string.h>
#define N 100
int usleep(unsigned usec);
@souravdatta
souravdatta / temp.f90
Last active August 9, 2021 15:59
Temparature calculation using Fortran
program temp
implicit none
integer, parameter :: NX = 3, NY = 3
integer :: i, j, oiter, numiter = 100
real, dimension(0:nx+1, 0:ny+1) :: t
t = 0.0
t(:,0) = 100.
t(0,:) = 100.
@souravdatta
souravdatta / DistChoco.java
Created July 27, 2021 12:30
Distribute chocolates in max square sizes
import java.util.Scanner;
public class ChocoDist {
private static int distributeOneChocolate(int x, int y) {
int count = 0;
if (x == y) return 1;
while (x > 0 && y > 0) {
// The minimum of width (x) and height (y) is
@souravdatta
souravdatta / BrideGroom.java
Last active July 27, 2021 12:21
Matching brides and grooms in Java
package com.solutions;
import java.util.Scanner;
public class BrideGroom {
private static void rotate(char[] arr, int atIndex) {
char head = arr[atIndex];
for (int i = atIndex + 1; i < arr.length; i++) {
arr[i - 1] = arr[i];
@souravdatta
souravdatta / Bitscore.java
Created July 27, 2021 11:52
Bit score calculation in Java
import java.util.Arrays;
import java.util.Scanner;
public class Bitscore {
private static String calculateScore(int number) {
String n = number + "";
char[] digits = n.toCharArray();
if (digits.length < 2) return "";
@souravdatta
souravdatta / bitscore.py
Created July 27, 2021 10:53
Calculate bit score
def calc_score(n):
s = sorted([x for x in str(n)])
if len(s) >= 2:
maxn = int(s[-1])
minn = int(s[0])
score = str(maxn * 11 + minn * 7)
if len(score) >= 2:
return score[len(score) - 2:]
return 0
@souravdatta
souravdatta / bridegrooms.py
Created July 26, 2021 20:52
Match bride grooms
def match(brides, grooms, n=0):
if len(brides) == 0:
return 0
if n == len(grooms) + 1:
return len(grooms)
if brides[0] == grooms[0]:
return match(brides[1:], grooms[1:])
@souravdatta
souravdatta / distchoco.py
Last active July 26, 2021 17:54
Distribute chocolate of square sizes
def dist_one(x, y):
count = 0
if x == y:
return 1
while x > 0 and y > 0:
cut = min(x, y)
count = count + 1
if x > cut:
@souravdatta
souravdatta / conv.c
Last active July 26, 2021 20:54
A number converter program in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int value(char c)
{
switch (c) {
case 'A':