Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from astera/master
more solutions
- Loading branch information
Showing
11 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
|
||
bool modzero(int num) | ||
{ | ||
int j = 1; | ||
for (j = 1; j <= 20; j++) { | ||
if (num % j) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
int main() { | ||
int i = 1; | ||
while (true) { | ||
if (modzero(i)) { | ||
printf ("The number is %d\n", i); | ||
break; | ||
} | ||
i++; | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <stdio.h> | ||
|
||
int funct1(int count) { | ||
int i = 1; | ||
int sum1 = 0; | ||
for (i = 1; i <= count; i++) { | ||
sum1 += i*i; | ||
} | ||
return sum1; | ||
} | ||
|
||
int funct2(int count) { | ||
int sum2 = count / 2 * (1 + count); | ||
return sum2*sum2; | ||
} | ||
|
||
void main() { | ||
int count = 100; | ||
int diff = funct2(count) - funct1(count); | ||
printf ("%d\n", diff); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
def funct1(): | ||
sum1 = 0 | ||
for i in xrange(1,101): | ||
sum1 += i**2 | ||
return sum1 | ||
|
||
def funct2(): | ||
sum2 = sum (xrange(1,101)) | ||
return sum2**2 | ||
|
||
diff = abs(funct1() - funct2()) | ||
print diff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
def funct1 | ||
sum1 = 0 | ||
for i in (1..100) | ||
sum1 += i**2 | ||
end | ||
return sum1 | ||
end | ||
|
||
def funct2 | ||
sum2 = (1..100).inject {|sum, i| sum + i} | ||
return sum2**2 | ||
end | ||
|
||
diff = (funct1 - funct2).abs | ||
puts diff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'mathn' | ||
|
||
a = Array.new | ||
|
||
Prime.each(120000) do |prime| | ||
a << prime | ||
end | ||
|
||
puts "The 10,001st prime number is #{a[10000]}." |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <stdio.h> | ||
|
||
int main() { | ||
int a, b, c; | ||
int num = 1000; | ||
int result; | ||
|
||
for(a = 1; a < num; a++) { | ||
for(b = a; b < num; b++) { | ||
if((a*a + b*b) == ((num - a - b)*(num - a - b))) { | ||
c = (num - a - b); | ||
result = a*b*c; | ||
printf("%d\n", result); | ||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
num = 1000 | ||
|
||
for a in xrange(1, num): | ||
b = ((num*a - ((num**2)/2))/(a - num)) | ||
c = num - a - b | ||
|
||
if ((a**2 + b**2) == c**2) and a < b: | ||
result = a * b * c | ||
print result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
num = 1000 | ||
|
||
for a in (1..num) | ||
for b in (a..num) | ||
if a*a + b*b == (num - a - b)*(num - a - b) | ||
c = num - a - b | ||
puts "a = #{a}, b = #{b}, c = #{c} -- result = #{a*b*c}" | ||
end | ||
end | ||
end |