Skip to content

Instantly share code, notes, and snippets.

Even Fibonacci Numbers

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

A Pen by Vlad Bezden on CodePen.

Project Euler. Problem 3

Largest prime factor

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

A Pen by Vlad Bezden on CodePen.

@vlad-bezden
vlad-bezden / Reverse Words In-Place.markdown
Last active June 12, 2016 09:49
Interview Cake Task on Reverse Words in-place

This is an exercise from Interview Cake web site

You're working on a secret team solving coded transmissions. Your team is scrambling to decipher a recent message, worried it's a plot to break into a major European National Cake Vault. The message has been mostly deciphered, but all the words are backwards! Your colleagues have handed off the last step to you.

Write a function reverse_words() that takes a string message and reverses the order of the words in-place

For example:

message = 'find you will pain only go you recordings security the into if'

@vlad-bezden
vlad-bezden / if_member_in_group.py
Last active April 29, 2016 20:18
Python example to check if user is in a group
#
# Code example to check if user is part of the group
#
import win32net
def if_user_in_group(group, member):
members = win32net.NetLocalGroupGetMembers(None, group, 1)
return member.lower() in list(map(lambda d: d['name'].lower(), members[0]))
@vlad-bezden
vlad-bezden / add_user_to_group.py
Created April 29, 2016 20:50
Example on how to add user to the group in Windows using Python
#
# Example on how to add user to the group in Python
#
import win32net
def add_user_to_group(domain, group, user):
user_group_info = {
@vlad-bezden
vlad-bezden / fibonacci.py
Created May 27, 2016 20:07
Fibonacci number generator in Python
def fibonacci(i):
"""Return all fibonacci numbers up to N. """
a, b = 0, 1
while a <= i:
yield a
a, b = b, a + b
@vlad-bezden
vlad-bezden / clicker.py
Last active June 18, 2016 13:35
Programs triggers mouse click every x number of seconds that can be passed via command line. If nothing passed via command line default click time will be 60 seconds. For more help use: python clicker.py -h
#
# Program triggers mouse click every 60 seconds
#
import pyautogui
import time
import threading
import argparse
@vlad-bezden
vlad-bezden / time_calc.py
Created June 6, 2016 00:42
Program calculates time such as 5:5 + 22:16 + 1:23:45 in hh:mm:ss format. It allows to enter time with '.' or with ':' as a time separator
import sys
import datetime
from time import strptime
def process_input(user_input):
"""Parses user input and returns parsed time. """
time_separator = '.'
time_tokens = 3
@vlad-bezden
vlad-bezden / admin.py
Created June 6, 2016 00:46
Program adds user to the ADMINISTRATORS group every 60 seconds
import win32net
import sys
import time
USER = 'some_user_name'
GROUP = 'ADMINISTRATORS'
DOMAIN = 'some_domain'
CHECK_TIME = 60 # delay for 60 seconds
USER_PART_OF_THE_GROUP_ERROR_NUMBER = 1378
user_group_info = {
@vlad-bezden
vlad-bezden / tuple.js
Last active July 27, 2016 13:59
Tuple
'use strict'
class Tuple {
constructor(...args) {
this._args = args
args.forEach((val, index) => {
Object.defineProperty(this, `item${index}`, {
get: () => val
})
})