Skip to content

Instantly share code, notes, and snippets.

public class t {
public static void main(String[] args) {
int current_val = 0, counter = 0;
for (int i = 1; i < 10000000; i++) {
current_val = i;
while (current_val != 1) {
current_val = calculateSquares(current_val);
if (current_val == 89) {
@mahmoufadel
mahmoufadel / GetSquareDigitChains
Created March 6, 2014 22:33
GetSquareDigitChains
int resualt=GetSquareDigitChains(2,10000000);
static int GetSquareDigitChains(int strt, int end)
{
int i = 0;
for (; strt < end; strt++)
{
int nextstrt = 0;
int strtTemp = strt;
#!/usr/bin/env ruby
#Pre-requisite: gem install mail (https://github.com/mikel/mail)
require 'mail'
mysql_username = 'root'
mysql_password = '123456'
mysql_database = 'your database' # consider use of ARGV
file_suffix = Time.new.strftime('%Y%m%d_%H%M%S')
mysql_backup_file = "backup-#{mysql_database}-#{file_suffix}.sql.gz"
def counts_of_files_by_extension(dir)
Dir["#{dir}/**/*"].reduce(Hash.new(0)) do |extension_counts, filepath|
extension_counts[File.extname(filepath)] += 1
extension_counts
end
end
directory = ARGV.shift || Dir.pwd
counts = counts_of_files_by_extension(directory)
@l0gicpath
l0gicpath / screensharing.rb
Created February 22, 2014 22:00
Streaming your screen over http using screenshots. Uses 'screencapture' for mac systems, you'll need to find another screen capturing utility to be used from the terminal on your system of choice. An enhanced code over https://gist.github.com/blazeeboy/9151757
#! /usr/bin/env ruby
require 'socket' # needed for creating tcp servers
require 'base64' # we'll use base64 for encoding images and embedding them in the response
require 'cgi' # has a lovely helper method for generating rfc1123 compliant dates for http headers
refresh_rate = 1 # in seconds, interval between each screen capture
server = TCPServer.open 3005 # start our server at port 3005
# the html page template we'll be sending over to the browser
page_tmpl = %Q[
#! /usr/bin/env python3
from math import factorial
#from functools import lru_cache
MAXN = 100
MAXNCR = 1000000
import time
before = time.time()
#! /usr/bin/env python
import heapq
from itertools import imap, ifilter
import time
before = time.time()
class Pair(object):
def __init__(self, f1, f2):
self.f1, self.f2 = f1, f2
self.total = f1 + f2
@musoftware
musoftware / eular_4.fs
Created February 15, 2014 21:13
Largest palindrome product
open System;
let sw = System.Diagnostics.Stopwatch()
sw.Start()
let ispalindrom (x):bool =
let s = x.ToString().ToCharArray() |> Array.rev
(new string(s) = x.ToString())
printfn "%d" (seq {
for x in 899..999 do
for y in x..999 do
if ispalindrom (x*y) then yield (x*y)
@musoftware
musoftware / eular_4.cpp
Last active August 29, 2015 13:56
Largest palindrome product
#include "stdafx.h"
#include <time.h>
#include <iostream>
using namespace std;
int reverse(int number);
int is_palindromic(int n);
int main()
{
int biggest = 0;
clock_t begin = clock();
function is_palindrome(int number){
word = Int.to_string(number)
word == String.reverse(word)
}
function pair_with(int elem, it){
Iter.map(function(el){ (elem, el) }, it)
}
function pairs(seq){