Skip to content

Instantly share code, notes, and snippets.

View goyuninfo's full-sized avatar

goyun.info goyuninfo

View GitHub Profile
package com.mycompany.mavenproject3;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
s=0
for i in range(1000):
if i % 3 == 0 or i % 5 == 0:
s+=i
print s
def sumDivisibleBy(n):
p=int(999/n)
return n * (p * (p + 1)) / 2
s=int(sumDivisibleBy(3) + sumDivisibleBy(5) - sumDivisibleBy(15))
print(s)
/**
*
* @author i88.ca
*/
public class ProjectEuler1 {
public static void main(String[] args) {
int s = sumDivisibleBy(3) + sumDivisibleBy(5) - sumDivisibleBy(15);
System.out.println(s);
@goyuninfo
goyuninfo / projecteuler2.py
Created May 15, 2014 20:43
project eluler problem 2 Even Fibonacci numbers
p,c=0,1
s=0
print s
while c<4000000:
print c
if c%2 ==0:
s=s+c
print s
p,c=c,p+c
print s
@goyuninfo
goyuninfo / mysql.example.py
Created May 15, 2014 22:01
Example of Python Script to deal with MySQL
#!/usr/bin/python
import MySQLdb
conn = MySQLdb.connect (host = "host",
user = "us",
passwd = "pass",
db = "yourDB")
cursor = conn.cursor (MySQLdb.cursors.DictCursor )
cursor.execute ("SELECT * from yourTable")
@goyuninfo
goyuninfo / projecteuler2.java
Last active August 29, 2015 14:01
Project eluler problem 2 Even Fibonacci numbers
package euler;
/**
* @author <a href="http://i88.ca">http://i88.ca</a>
*
*/
public class P2 {
public static void main(String[] args) {
int a = 1;
@goyuninfo
goyuninfo / Project-Euler-4.java
Last active August 29, 2015 14:01
Project Euler Problem 4 Largest palindrome product
package euler;
/**
* @author i88.ca
*
*/
public class P4 {
public static int reverse(int number) {
// reverse function of String is applicable too.
@goyuninfo
goyuninfo / Project-Euler-4.py
Created May 19, 2014 19:36
Project Euler Problem 4 Largest palindrome product
def is_palindrome(n):
"""Return True if n is a palindrome; False otherwise."""
s = str(n)
return s == s[::-1]
from itertools import product
print max(x * y for x, y in product(range(1000), repeat=2) if is_palindrome(x * y))
@goyuninfo
goyuninfo / Project-Euler-5.py
Created May 19, 2014 23:41
Project Euler Smallest multiple
i=19
while 1:
i=i+19
if i%17 !=0:
continue
if i%16 !=0:
continue
if i%15 !=0:
continue
if i%14 !=0: