回答編集履歴

6

コード修正

2015/07/25 14:17

投稿

hirohiro
hirohiro

スコア2068

test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  total=0
10
10
 
11
- for n in i..j
11
+ for n in i..(j+1)
12
12
 
13
13
  total += str[n,1].to_i
14
14
 

5

コード修正

2015/07/25 14:17

投稿

hirohiro
hirohiro

スコア2068

test CHANGED
@@ -44,13 +44,13 @@
44
44
 
45
45
  for num in 1..j do
46
46
 
47
- b = (amari*10)/7
47
+ b = (amari*10)/n
48
48
 
49
49
  if num >= i then total += b end
50
50
 
51
51
  if b then print(b) else print(0) end
52
52
 
53
- amari = ((amari*10)%7)
53
+ amari = ((amari*10)%n)
54
54
 
55
55
  end
56
56
 
@@ -58,11 +58,9 @@
58
58
 
59
59
  end
60
60
 
61
+ print("1.")
61
62
 
62
-
63
- p sum(97,2,96)
63
+ print("\n",sum(97,2,96))
64
-
65
-
66
64
 
67
65
  ```
68
66
 

4

内容修正

2015/07/25 14:16

投稿

hirohiro
hirohiro

スコア2068

test CHANGED
@@ -1,3 +1,75 @@
1
+ ###strを使うパターン
2
+
3
+ ```Ruby
4
+
5
+ def sum(str,i,j)
6
+
7
+ i +=1
8
+
9
+ total=0
10
+
11
+ for n in i..j
12
+
13
+ total += str[n,1].to_i
14
+
15
+ end
16
+
17
+ total
18
+
19
+ end
20
+
21
+
22
+
23
+ str =
24
+
25
+ "0.010309278350515463917525773195876288659793814432989690721649484536082474226804123711340206185567"
26
+
27
+ p sum(str, 2, 96)
28
+
29
+ ```
30
+
31
+
32
+
33
+ ###jが無制限なパターン
34
+
35
+ 検証のしようが無いのですが、多分無制限なはず
36
+
37
+ ```Ruby
38
+
39
+ def sum(n,i,j)
40
+
41
+ total=0
42
+
43
+ amari=1
44
+
45
+ for num in 1..j do
46
+
47
+ b = (amari*10)/7
48
+
49
+ if num >= i then total += b end
50
+
51
+ if b then print(b) else print(0) end
52
+
53
+ amari = ((amari*10)%7)
54
+
55
+ end
56
+
57
+ total
58
+
59
+ end
60
+
61
+
62
+
63
+ p sum(97,2,96)
64
+
65
+
66
+
67
+ ```
68
+
69
+
70
+
71
+ ###最初に投稿したもの
72
+
1
73
  限界は14?
2
74
 
3
75
  ※ 15桁目以降の数値が1/nのほうと一致しませんし

3

コード修正

2015/07/25 14:13

投稿

hirohiro
hirohiro

スコア2068

test CHANGED
@@ -1,6 +1,8 @@
1
- ありますね。修正中
1
+ 界は14?
2
2
 
3
- //論理上上限無(ハードウェアリソース的な限界はあるかも)
3
+ ※ 15桁目以降の数値が1/nほうと一致ませんし
4
+
5
+ ※ それ以降は成否の検証方法が分からなかったため
4
6
 
5
7
  ```ruby
6
8
 
@@ -10,9 +12,9 @@
10
12
 
11
13
  for num in i..j do
12
14
 
13
- r += ((1.0*10**num/n)).floor % 10
15
+ r += ((1.0*10**num)/n).floor % 10
14
16
 
15
- print(((1.0*10**num/n)).floor % 10, " + ")
17
+ print(((1.0*10**num)/n).floor % 10, " + ")
16
18
 
17
19
  end
18
20
 
@@ -22,6 +24,10 @@
22
24
 
23
25
 
24
26
 
27
+ print(1.0/7, ": ")
28
+
25
- print("= ",c(7,1,5)) #1 + 4 + 2 + 8 + 5 + = 20
29
+ print("= ",c(7,1,16))
30
+
31
+ #0.142857142857143: 1 + 4 + 2 + 8 + 5 + 7 + 1 + 4 + 2 + 8 + 5 + 7 + 1 + 4 + 2 + 8 + = 69
26
32
 
27
33
  ```

2

修正中

2015/07/25 13:03

投稿

hirohiro
hirohiro

スコア2068

test CHANGED
@@ -1,4 +1,6 @@
1
+ 上限ありますね。修正中
2
+
1
- 論理上の上限無し(ハードウェアリソース的な限界はあるかも)
3
+ //論理上の上限無し(ハードウェアリソース的な限界はあるかも)
2
4
 
3
5
  ```ruby
4
6
 

1

コード修正

2015/07/25 12:48

投稿

hirohiro
hirohiro

スコア2068

test CHANGED
@@ -8,9 +8,9 @@
8
8
 
9
9
  for num in i..j do
10
10
 
11
- r += ((1.0/n)*10**num).floor % 10
11
+ r += ((1.0*10**num/n)).floor % 10
12
12
 
13
- print(((1.0/n)*10**num).floor % 10, " + ")
13
+ print(((1.0*10**num/n)).floor % 10, " + ")
14
14
 
15
15
  end
16
16