Skip to content

Instantly share code, notes, and snippets.

View musoftware's full-sized avatar
🌏
Working from home

Musoftware musoftware

🌏
Working from home
View GitHub Profile
using System;
using System.Collections.Generic;
using System.Text;
namespace Largest_prime_factor
{
class Program
{
static void Main(string[] args)
{
@musoftware
musoftware / euler_3.cpp
Last active August 29, 2015 13:56
Largest prime factor
#include "stdafx.h"
#include <iostream>
using namespace std;
void main()
{
long int factor = 600851475143;
for (long int divider = 2; divider < factor; divider++)
{
(factor % divider == 0) ? factor /= divider, divider = 2 : NULL;
}
@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();
@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_5.vb
Created February 16, 2014 07:35
Smallest multiple
' 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
' What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
Module eular_5
Function LCM(ByVal n1 As Long, ByVal n2 As Long) As Long
Dim tmp As Long, product As Long
product = n1 * n2
Do
If n1 < n2 Then
@musoftware
musoftware / eular_6.js
Created February 16, 2014 07:50
Sum square difference
function result() {
var i = 0;
var i2 = 0;
for (var z = 1; z <= 100; z++) {
i += z;
i2 += Math.pow(z, 2);
}
return Math.pow(i, 2) - i2;
}
@musoftware
musoftware / eular_53.cs
Created February 21, 2014 12:26
Combinatoric selections
using System;
using System.Collections.Generic;
using System.Text;
namespace eular_53
{
class Program
{
static void Main(string[] args)
{
long exeedsmilliom = 0;
<?php
/**
* Mobile Detect Library
* =====================
*
* Motto: "Every business should have a mobile detection script to detect mobile readers"
*
* Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets).
* It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.
*
@musoftware
musoftware / visitor_country.php
Created March 4, 2014 22:29
visitor_country
<?php
function visitor_country() {
$ip = $this->getRealIpAddr();
$ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip));
if ($ip_data && $ip_data->geoplugin_countryName != null) {
$result = $ip_data->geoplugin_countryName;
@musoftware
musoftware / timespan.php
Created March 22, 2014 14:48
show ago limit
if (!function_exists('timespan')) {
function timespan($seconds = 1, $time = '', $limit = -1) {
if ($limit == -1)
$limit = 99;
$CI = & get_instance();
$CI->lang->load('date');
if (!is_numeric($seconds)) {