Anonymous avatar Anonymous committed b9a9a3f

added euler-004 and st config

Comments (0)

Files changed (3)

config/st/config.h

+#define TAB 8
+#define TNAME "st-256color"
+#define FONT "-*-fixed-medium-r-*-*-*-120-75-75-*-60-*-*"
+#define BOLDFONT "-*-fixed-bold-r-*-*-*-120-75-75-*-60-*-*"
+#define BORDER 2
+#define SHELL "/bin/sh"
+
+/* Terminal colors */
+static const char *colorname[] = {
+	"black",
+	"red3",
+	"green3",
+	"yellow3",
+	"blue2",
+	"magenta3",
+	"cyan3",
+	"gray90",
+	"gray50",
+	"red",
+	"green",
+	"yellow",
+	"#5c5cff",
+	"magenta",
+	"cyan",
+	"white"
+};
+
+/* Default colors (colorname index) */
+/* foreground, background, cursor */
+#define DefaultFG 7
+#define DefaultBG 0
+#define DefaultCS 1
+
+/* Special keys */
+static Key key[] = {
+	{ XK_BackSpace, "\177" },
+	{ XK_Insert,    "\033[2~" },
+	{ XK_Delete,    "\033[3~" },
+	{ XK_Home,      "\033[1~" },
+	{ XK_End,       "\033[4~" },
+	{ XK_Prior,     "\033[5~" },
+	{ XK_Next,      "\033[6~" },
+	{ XK_F1,        "\033OP"   },
+	{ XK_F2,        "\033OQ"   },
+	{ XK_F3,        "\033OR"   },
+	{ XK_F4,        "\033OS"   },
+	{ XK_F5,        "\033[15~" },
+	{ XK_F6,        "\033[17~" },
+	{ XK_F7,        "\033[18~" },
+	{ XK_F8,        "\033[19~" },
+	{ XK_F9,        "\033[20~" },
+	{ XK_F10,       "\033[21~" },
+	{ XK_F11,       "\033[23~" },
+	{ XK_F12,       "\033[24~" },
+};
+
+/* Line drawing characters (sometime specific to each font...) */
+static char gfx[] = {
+	['f'] = 'o',
+	['g'] = '+',
+	['i'] = '#',
+	[255] = 0,
+};

euler/004-palindrome-product.c

+/* project euler problem 004
+ * -------------------------
+ * find the largest palindrome that is a factor of two
+ * three digit numbers. */
+
+#include <stdio.h>
+#include <math.h>
+
+int
+main() {
+	int has_three_digit_factors(int num);
+	int is_palindrome(int num);
+	int result = 0;
+	int i;
+
+	int a, b, c;
+	for(a = 999; a >= 100; a--) {
+		for(b = 999; b >=100; b--) {
+			if(is_palindrome(a * b) && ((a * b) > result)) {
+				result = a * b;
+			}
+		}
+	}
+
+	if(result)
+		printf("%i\n",result);
+	else
+		printf("no result found\n");
+
+	return 0;
+}
+
+
+int
+is_palindrome(int num) {
+	int reverse (int num);
+	return num == reverse(num);
+}
+
+int reverse (int num) {
+	int reversed = 0;
+	while(num > 0) {
+		reversed = (reversed * 10) + (num % 10);
+		num /= 10;
+	}
+	return reversed;
+}

euler/004-palindrome-product.c.orig

+/* project euler problem 003
+ * -------------------------
+ * find the largest palindrome that is a factor of two
+ * three digit numbers. */
+
+#include <stdio.h>
+#include <math.h>
+
+int
+main() {
+	int has_three_digit_factors(int num);
+	int is_palindrome(int num);
+	int result = 0;
+	int i;
+
+	for(i=998001; i >= 10000; i--) {
+		if(has_three_digit_factors(i) && is_palindrome(i)) {
+			result = i;
+			break;
+		}
+	}
+
+	if(result)
+		printf("%i\n",result);
+	else
+		printf("no result found\n");
+
+	return 0;
+}
+
+
+int
+has_three_digit_factors(int num) {
+	int i;
+	for(i=999; i >= 100; i--) {
+		if(!(num % i) && ((num/i) >= 100) && (num/i) <= 999) {
+			return 1;
+		}
+	}
+	return 0;
+}
+
+int
+is_palindrome(int num) {
+	int num_digits(int num);
+	int get_digit(int num, int digit);
+	int digits = num_digits(num);
+	int i;
+
+	for(i=digits; i > (digits - (digits / 2)); i--) {
+		if(get_digit(num,i) != get_digit(num, digits - i + 1)) {
+			return 0;
+		}
+	}
+	
+	return 1;
+}
+
+int
+num_digits(int num) {
+	int count = 0;
+
+	while(num != 0) {
+		num /= 10;
+		count++;
+	}
+
+	return count;
+}
+
+int
+get_digit(int num, int digit) {
+	return ((num / (int)pow(10,(digit-1))) % 10);
+}
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.