Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

problem 36

  • Loading branch information...
commit fce6964018069a0b4e8c48fb63779bc0121c5357 1 parent 6d1fa03
@yyyc514 authored
Showing with 35 additions and 0 deletions.
  1. +35 −0 problem36.go
View
35 problem36.go
@@ -0,0 +1,35 @@
+// Problem 36 - http://projecteuler.net/
+//
+// Find the sum of all numbers, less than one million,
+// which are palindromic in base 10 and base 2.
+
+package main
+
+import (
+ "fmt";
+ "strconv";
+ "strings";
+)
+
+func palidrome(s string) bool { return reverse(s) == s }
+
+func reverse(s string) string {
+ orig := strings.Bytes(s);
+ len := len(s);
+ n := make([]byte, len);
+ for i := 0; i < len; i++ {
+ n[len-i-1] = orig[i]
+ }
+ return string(n);
+}
+
+func main() {
+ sum := 0;
+ for i := 1; i < 1000000; i++ {
+ if palidrome(strconv.Itoa(i)) &&
+ palidrome(strconv.Itob(i, 2)) {
+ sum += i;
+ }
+ }
+ fmt.Printf("%d\n", sum);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.