Skip to content

Instantly share code, notes, and snippets.

@CodeMaster7000
CodeMaster7000 / H.C.F. Finder.r
Created January 22, 2022 22:22
A program in R to find the H.C.F. of any 2 integers.
hcf <- function(x, y) {
if(x > y) {
smaller = y
} else {
smaller = x
}
for(i in 1:smaller) {
if((x %% i == 0) && (y %% i == 0)) {
hcf = i
}
@CodeMaster7000
CodeMaster7000 / Fibonacci Series (R).r
Created January 22, 2022 22:24
A program in R that prints the Fibonacci series for as long as you want!
nterms = as.integer(readline(prompt="How many terms should I print? "))
n1 = 0
n2 = 1
count = 2
if(nterms <= 0) {
print("Plese enter a positive integer")
} else {
if(nterms == 1) {
print("Fibonacci sequence:")
print(n1)
@CodeMaster7000
CodeMaster7000 / Leap Year Checker.r
Created January 22, 2022 22:25
A program in R which checks in the input year is a leap year or not.
year = as.integer(readline(prompt="Enter a year: "))
if((year %% 4) == 0) {
if((year %% 100) == 0) {
if((year %% 400) == 0) {
print(paste(year,"is a leap year"))
} else {
print(paste(year,"is not a leap year"))
}
} else {
print(paste(year,"is a leap year"))
@CodeMaster7000
CodeMaster7000 / Factorial Finder.r
Created January 29, 2022 09:47
A program in R to find the factorial of a number using recursion.
recur_factorial <- function(n) {
if(n <= 1) {
return(1)
} else {
return(n * recur_factorial(n-1))
}
}
@CodeMaster7000
CodeMaster7000 / Decimal to Binary.r
Created January 29, 2022 09:49
A program in R to convert a decimal number into binary using recursion.
convert_to_binary <- function(n) {
if(n > 1) {
convert_to_binary(as.integer(n/2))
}
cat(n %% 2)
}
@CodeMaster7000
CodeMaster7000 / Bar Chart.r
Created January 29, 2022 10:10
A program in R which plots a bar graph. The information used to plot this bar graph is from sample data regarding the temperature in a location during the week.
max.temp <- c(22, 27, 26, 24, 23, 26, 28)
barplot(max.temp,
main = "Maximum Temperatures in a Week",
xlab = "Degrees Celsius",
ylab = "Day",
names.arg = c("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"),
col = "red",
horiz = TRUE)
@CodeMaster7000
CodeMaster7000 / Mountain Range Curves.py
Created February 10, 2022 20:21
A short programme coded in Python 3 with turtle that draws the curves of mountain peaks.
import turtle
import math
import random
screen = turtle.Screen()
screen.setup(700,600)
screen.title("Testing Mountain Curves")
turtle.hideturtle()
turtle.speed(0)
@CodeMaster7000
CodeMaster7000 / Conversation Starter.sh
Last active February 11, 2022 21:29
A basic conversation starter coded in Shell, which uses a name input to start a simple conversation.
clear
read -p "May I know your name, please? " name
echo "Hello $name, let us be friends!"
echo ""
@CodeMaster7000
CodeMaster7000 / File Creator.sh
Last active February 11, 2022 21:54
A program in Shell which generates a file. Enjoy putting it to the test!
echo "What is the name of your file?"
read FILE
echo "This file will be created as ${FILE}_file."
touch ${FILE}_file
@CodeMaster7000
CodeMaster7000 / Most Populous Countries 3D Pie Chart.r
Created February 11, 2022 21:53
A 3D pie chart coded in R, displaying the 4 most populous countries in the world.
library(plotrix)
x <- c(21, 62, 10,53)
lbl <- c("USA","China","Indonesia","India")
pie3D(x,labels = lbl,explode = 0.1, main = "Pie Chart of Most Populous Countries ")