Skip to content

Instantly share code, notes, and snippets.

View bragboy's full-sized avatar
🧘
Inner peace

Bragadeesh bragboy

🧘
Inner peace
View GitHub Profile
ONES = ["zero","one","two","three","four","five","six","seven","eight","nine"]
ELEVENS = ["eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
TEN,AND = ["ten","and"]
TENS = ["twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
HUNDRED, THOUSAND = ["hundred","thousand"]
def nums_upto_99(n)
return ONES[n] if n < 10
return TEN if n==10
return "#{ELEVENS[n-11]}" if n < 20
def divisors_sum(n)
return 1 if n==1
sum = 0
1.upto(Math.sqrt(n)) {|x| sum+= (x + n/x) if n%x == 0}
sum-=Math.sqrt(n).to_i if (Math.sqrt(n) - Math.sqrt(n).to_i) == 0
return sum-=n
end
sum = 0
1.upto(9999) do |n|
b = divisors_sum(n)
max = []
1.upto(99) { |x| 1.upto(99){|y| max << (x**y).to_s.split(//).inject(0){|b,i| b+=i.to_i}} }
puts "The maximum sum is #{max.max}"
#include <iostream>
using namespace std;
#define STACKSIZE 10
class stack
{
private:
int arr[STACKSIZE+1];
int tos;
public:
stack();
def is_prime(n)
return false if n <= 1
2.upto(Math.sqrt(n).to_i) do |x|
return false if n%x == 0
end
true
end
@bragboy
bragboy / prime3.cpp
Last active November 12, 2015 10:41
bool is_prime(int x)
{
if(x <= 1)
return false;
int s = (int) sqrt(x);
for(int i = 2; i <= s; i++)
if(x%i == 0)
return false;
return true;
}
@bragboy
bragboy / prime2.cpp
Last active November 12, 2015 10:41
bool is_prime(int x)
{
if(x <= 1)
return false;
for(int i = 2; i <= x/2; i++)
if(x%i == 0)
return false;
return true;
}
@bragboy
bragboy / prime.cpp
Last active November 12, 2015 10:41
bool is_prime(int x)
{
if(x <= 1)
return false;
for(int i = 2; i < x; i++)
if(x%i == 0)
return false;
return true;
}
package boxgame;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
public class BoxPuzzle extends JFrame{
#include <iostream>
using namespace std;
#define MAX 5
int main(){
int a[MAX][MAX] =
{{ 1, 2, 3, 4, 5},
{ 6, 7, 8, 9,10},
{11,12,13,14,15},