This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Necessary imports | |
from math import pow | |
# List to store the values | |
happylist = [] | |
# Function to check if the number 'n' ia a happy number | |
def is_happy(n): | |
m = int(n) | |
if m == 4: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A very simple snake game | |
# By aceking007 | |
# Imports | |
import turtle | |
import time | |
import random | |
# Score and delay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame as pg | |
# Colors | |
red = pg.Color(255, 0, 0) | |
green = pg.Color(0, 255, 0) | |
black = pg.Color(0, 0, 0) | |
white = pg.Color(255, 255, 255) | |
brown = pg.Color(165, 42, 42) | |
# Variables | |
screen_width = 400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The class for food object | |
class Food(): | |
# Initialization | |
def __init__(self): | |
self.x = screen_width/2 | |
self.y = screen_height/4 | |
self.color = red | |
self.width = 10 | |
self.height = 10 | |
# Makes the food visible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The snake object | |
class Player(): | |
# Initialization | |
def __init__(self): | |
self.x = screen_width/2 | |
self.y = screen_height/2 | |
self.width = 10 | |
self.height = 10 | |
self.velocity = 10 | |
self.direction = 'stop' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
score, high_score = (0,0) | |
# Draw the score on the screen | |
def draw_score(surface): | |
global high_score | |
font_name = pg.font.match_font('arial') | |
if score > high_score: | |
high_score = score | |
# writing the score | |
font = pg.font.Font(font_name, 18) | |
text_surface = font.render('Score: {} High Score: {}'.format(score, high_score), True, white) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyModule | |
using PyCall | |
function __init__() | |
py """ | |
import numpy as np | |
def one(x): | |
return np.sin(x) ** 2 + np.cos(x) ** 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def binarySearch (arr, l, r, x): | |
if r >= l: | |
mid = l + (r - l)/2 | |
if arr[mid] == x: | |
return mid | |
elif arr[mid] > x: | |
return binarySearch(arr, l, mid-1, x) | |
else: | |
return binarySearch(arr, mid+1, r, x) | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function binarysearch(lst::Vector{T}, value::T, low=1, high=length(lst)) where T | |
if isempty(lst) return 0 end | |
if low ≥ high | |
if low > high || lst[low] != value | |
return 0 | |
else | |
return low | |
end | |
end | |
mid = (low + high) ÷ 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import sys | |
generations = 5000 | |
pop_size = 1000 | |
gamete_no = 1000 | |
pop = [] | |
n = len(sys.argv) | |
if n == 2: |
OlderNewer