This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| 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}" |
This file contains hidden or 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
| #include <iostream> | |
| using namespace std; | |
| #define STACKSIZE 10 | |
| class stack | |
| { | |
| private: | |
| int arr[STACKSIZE+1]; | |
| int tos; | |
| public: | |
| stack(); |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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; | |
| } |
This file contains hidden or 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
| 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; | |
| } |
This file contains hidden or 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
| 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; | |
| } |
This file contains hidden or 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
| 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{ |
This file contains hidden or 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
| #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}, |