Skip to content

Instantly share code, notes, and snippets.

View jishnujayakumar's full-sized avatar
😎
Diving into Robotics...

Jishnu P jishnujayakumar

😎
Diving into Robotics...
View GitHub Profile
#!/bin/python3
import os, sys, math
def reflectionComponent(pcomp, qcomp):
if pcomp > qcomp:
return qcomp - abs(qcomp - pcomp)
elif pcomp < qcomp:
return qcomp + abs(qcomp - pcomp)
else:
def is_leap_year(year):
if year < 1918:
return year%4 == 0
elif year > 1918:
return (year%400==0) or ((year%4==0) and (year%100 != 0))
def day_of_programmer(year):
if year == 1918:
return f"26.09.{year}"
else:
@jishnujayakumar
jishnujayakumar / migratory-birds.py
Last active March 4, 2021 10:24
Given an array of bird sightings where every element represents a bird type id, determine the id of the most frequently sighted type. If more than 1 type has been spotted that maximum amount, return the smallest of their ids.
def migratory_birds(arr):
index = dict()
max_sight_count, min_ids = 0, 6
for bird_id in arr:
if bird_id not in index:
index[bird_id] = 0
index[bird_id] += 1
max_sight_count = max(index[bird_id], max_sight_count)
@jishnujayakumar
jishnujayakumar / rotate-array.py
Created February 26, 2021 12:42
Naive in-place array rotation
def rotate_array(arr, k):
element_at_secondary_index = None
primary_index = 0
steps = 0
n = len(arr)
while steps < n:
secondary_index = (primary_index+k) % n