From fc2202bec293b66548c7f0a34222d6944748ecf4 Mon Sep 17 00:00:00 2001 From: Pyon Date: Wed, 17 Jan 2018 18:53:09 +0900 Subject: [PATCH 1/3] skelton --- project/euler/pe0026-0050.go | 6 ++++++ project/euler/pe0026-0050_test.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/project/euler/pe0026-0050.go b/project/euler/pe0026-0050.go index 5d9395c..c015b6d 100644 --- a/project/euler/pe0026-0050.go +++ b/project/euler/pe0026-0050.go @@ -373,3 +373,9 @@ func PE0033() int { // 約分する return pD / Gcm(pN, pD) } + +// PE0035 1,000,000以下の巡回素数の個数を計算 +// +// https://projecteuler.net/problem=35 +func PE0035() { +} diff --git a/project/euler/pe0026-0050_test.go b/project/euler/pe0026-0050_test.go index ecc36c3..e2c140c 100644 --- a/project/euler/pe0026-0050_test.go +++ b/project/euler/pe0026-0050_test.go @@ -216,4 +216,10 @@ func TestPE0033(t *testing.T) { // }}} +// PE0035 {{{ +func TestPE0035(t *testing.T) { +} + +// }}} + // vim:set foldmethod=marker: From 03dc411593570b2d339691537ed45fd5586ee65a Mon Sep 17 00:00:00 2001 From: Pyon Date: Thu, 18 Jan 2018 02:00:57 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E6=A1=81=E3=81=AB=E9=97=9C=E3=81=99?= =?UTF-8?q?=E3=82=8B=E5=87=BE=E6=95=B8=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/euler/digit.go | 38 ++++++++++++++++++++++++ project/euler/digit_test.go | 58 +++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 project/euler/digit.go create mode 100644 project/euler/digit_test.go diff --git a/project/euler/digit.go b/project/euler/digit.go new file mode 100644 index 0000000..8e7cde7 --- /dev/null +++ b/project/euler/digit.go @@ -0,0 +1,38 @@ +package euler + +// CalculateDigitNumber 桁数を計算する +func CalculateDigitNumber(n int) int { + if n == 0 { + return 1 + } + if n < 0 { + n *= -1 + } + m := 0 + for i := 1; n/i > 0; i *= 10 { + m++ + } + return m +} + +// CirculateDigit 末尾の桁の數字を先頭に移動する +func CirculateDigit(n int) int { + minus := false + if n < 0 { + minus = true + n *= -1 + } + + m := 1 + for n/(10*m) > 0 { + m *= 10 + } + h := n / 10 + t := n % 10 + + l := t*m + h + if minus { + return -1 * l + } + return l +} diff --git a/project/euler/digit_test.go b/project/euler/digit_test.go new file mode 100644 index 0000000..71289b8 --- /dev/null +++ b/project/euler/digit_test.go @@ -0,0 +1,58 @@ +package euler + +import "testing" + +func TestCalculateDigitNumber(t *testing.T) { + cases := []struct { + Input int + Expected int + }{ + {-10, 2}, + {-1, 1}, + {0, 1}, + {1, 1}, + {3, 1}, + {10, 2}, + {41, 2}, + {100, 3}, + {213, 3}, + } + for _, tc := range cases { + if actual := CalculateDigitNumber(tc.Input); actual != tc.Expected { + t.Errorf( + "Input:%v\nExpected:%v\nActual:%v", + tc.Input, + tc.Expected, + actual, + ) + } + } +} + +func TestCirculateDigit(t *testing.T) { + cases := []struct { + Input int + Expected int + }{ + // 負數 + {-1, -1}, {-10, -1}, {-12, -21}, + // 0 + {0, 0}, + // 正數 + {1, 1}, {2, 2}, + {10, 1}, {12, 21}, + {100, 10}, {102, 210}, {120, 12}, {123, 312}, + {1000, 100}, {1002, 2100}, {1020, 102}, {1200, 120}, + {1023, 3102}, {1203, 3120}, {1230, 123}, {1234, 4123}, + } + for _, tc := range cases { + if actual := CirculateDigit(tc.Input); actual != tc.Expected { + t.Errorf( + "Input:%v\nExpected:%v\nActual:%v", + tc.Input, + tc.Expected, + actual, + ) + } + } +} From f264b3e93ae0988b656b1607034650462596ca02 Mon Sep 17 00:00:00 2001 From: Pyon Date: Mon, 5 Feb 2018 11:47:52 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=201000000=E4=BB=A5=E4=B8=8B=E3=81=AE?= =?UTF-8?q?=E7=B4=A0=E6=95=B0=E3=82=92=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/euler/pe0026-0050.go | 10 +++++++++- project/euler/pe0026-0050_test.go | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/project/euler/pe0026-0050.go b/project/euler/pe0026-0050.go index 0db9ed2..586822c 100644 --- a/project/euler/pe0026-0050.go +++ b/project/euler/pe0026-0050.go @@ -408,5 +408,13 @@ func PE0034() int { // PE0035 1,000,000以下の巡回素数の個数を計算 // // https://projecteuler.net/problem=35 -func PE0035() { +func PE0035(n int) int { + // n以下の素数列 + ps := []int{} + pg := NewPrimeGenerator() + for p := pg.Next(); p <= n; p = pg.Next() { + ps = append(ps, p) + } + + return 0 } diff --git a/project/euler/pe0026-0050_test.go b/project/euler/pe0026-0050_test.go index dfb40ea..202a098 100644 --- a/project/euler/pe0026-0050_test.go +++ b/project/euler/pe0026-0050_test.go @@ -238,6 +238,22 @@ func TestPE0034(t *testing.T) { // PE0035 {{{ func TestPE0035(t *testing.T) { + cases := []struct { + Input int + Expected int + }{ + {1000000, 0}, + } + for _, tc := range cases { + if actual := PE0035(tc.Input); actual != tc.Expected { + t.Errorf( + "Input:%v\nExpected:%v\nActual:%v", + tc.Input, + tc.Expected, + actual, + ) + } + } } // }}}