1,2,5,6,9,10,13,14,17,18一组,3,4,7,8,11,12,15,16,19,20一组,在jsscript中给出公式从1到20中找出这两组数据
时间: 2023-10-08 20:14:19 浏览: 34
这两组数据可以通过以下公式来筛选出来:
```javascript
const group1 = [];
const group2 = [];
for (let i = 1; i <= 20; i++) {
if (i % 4 === 1 || i % 4 === 2) {
group1.push(i);
} else {
group2.push(i);
}
}
console.log("Group 1:", group1);
console.log("Group 2:", group2);
```
这段代码将1到20的数字按照要求分成了两组,结果如下:
```
Group 1: [1, 2, 5,6, 9, 10, 13, 14, 17, 18]
Group 2: [3, 4, 7, 8, 11, 12, 15, 16, 19, 20]
```
相关问题
进料开始时间(s) 料的序号 中间过程所需时间(s) 进入的固化机序号 进入时间 0 1 1 1 1 3.6 2 4 2 7.6 7.2 3 7 3 14.2 10.8 4 10 4 20.8 14.4 5 13 5 27.4 18 6 16 6 34 21.6 7 19 7 40.6 25.2 8 22 8 47.2 28.8 9 1 1 29.8 32.4 10 4 2 36.4 36 11 7 3 43 39.6 12 10 4 49.6 43.2 13 13 5 56.2 46.8 14 16 6 62.8 50.4 15 19 7 69.4 54 16 22 8 76 57.6 17 1 1 58.6 61.2 18 4 2 65.2 64.8 19 7 3 71.8 68.4 20 10 4 78.4 72 21 13 5 85 75.6 22 16 6 91.6 79.2 23 19 7 98.2 82.8 24 22 8 104.8 这个表格每8个算一组,再处理125组时的数据是多少
如果要处理前 125 组数据,那么需要处理前 125 * 8 = 1000 条数据。具体的数据如下:
进料开始时间(s) 料的序号 中间过程所需时间(s) 进入的固化机序号 进入时间
0 1 1 1 1
3.6 2 4 2 7.6
7.2 3 7 3 14.2
10.8 4 10 4 20.8
14.4 5 13 5 27.4
18 6 16 6 34
21.6 7 19 7 40.6
25.2 8 22 8 47.2
28.8 9 1 1 29.8
32.4 10 4 2 36.4
36 11 7 3 43
39.6 12 10 4 49.6
43.2 13 13 5 56.2
46.8 14 16 6 62.8
50.4 15 19 7 69.4
54 16 22 8 76
57.6 17 1 1 58.6
61.2 18 4 2 65.2
64.8 19 7 3 71.8
68.4 20 10 4 78.4
72 21 13 5 85
75.6 22 16 6 91.6
79.2 23 19 7 98.2
82.8 24 22 8 104.8
0 1 1 1 1
3.6 2 4 2 7.6
7.2 3 7 3 14.2
10.8 4 10 4 20.8
14.4 5 13 5 27.4
18 6 16 6 34
21.6 7 19 7 40.6
25.2 8 22 8 47.2
28.8 9 1 1 29.8
32.4 10 4 2 36.4
36 11 7 3 43
39.6 12 10 4 49.6
43.2 13 13 5 56.2
46.8 14 16 6 62.8
50.4 15 19 7 69.4
54 16 22 8 76
57.6 17 1 1 58.6
61.2 18 4 2 65.2
64.8 19 7 3 71.8
68.4 20 10 4 78.4
72 21 13 5 85
75.6 22 16 6 91.6
79.2 23 19 7 98.2
82.8 24 22 8 104.8
0 1 1 1 1
3.6 2 4 2 7.6
7.2 3 7 3 14.2
10.8 4 10 4 20.8
14.4 5 13 5 27.4
18 6 16 6 34
21.6 7 19 7 40.6
25.2 8 22 8 47.2
28.8 9 1 1 29.8
32.4 10 4 2 36.4
36 11 7 3 43
39.6 12 10 4 49.6
43.2 13 13 5 56.2
46.8 14 16 6 62.8
50.4 15 19 7 69.4
54 16 22 8 76
57.6 17 1 1 58.6
61.2 18 4 2 65.2
64.8 19 7 3 71.8
68.4 20 10 4 78.4
72 21 13 5 85
75.6 22 16 6 91.6
79.2 23 19 7 98.2
82.8 24 22 8 104.8
...(共1000条数据)
用java实现,{1、2、3、4、5、6、7、8、9、10、11、12、13、14、15、16、17、18}集合中有共18个元素,每3个组合在一起列出全部的组合
可以使用递归的方式来实现这个问题。首先,定义一个递归函数,函数的输入参数包括原始集合、当前组合、起始索引和目标组合长度。然后,在每一层递归中,遍历起始索引到原始集合的长度减去目标组合长度,依次将当前索引对应的元素添加到当前组合中,并将起始索引加一,然后递归调用函数。如果当前组合的长度等于目标组合长度,说明已经找到一个符合条件的组合,将其输出。最后,调用这个递归函数,并传入初始参数。
下面是用Java实现这个算法的代码:
```java
import java.util.ArrayList;
import java.util.List;
public class Combination {
public static void main(String[] args) {
List<Integer> nums = new ArrayList<>();
for (int i = 1; i <= 18; i++) {
nums.add(i);
}
List<List<Integer>> combinations = getCombinations(nums, 3);
for (List<Integer> combination : combinations) {
System.out.println(combination);
}
}
public static List<List<Integer>> getCombinations(List<Integer> nums, int targetLength) {
List<List<Integer>> combinations = new ArrayList<>();
List<Integer> currentCombination = new ArrayList<>();
combine(nums, currentCombination, 0, targetLength, combinations);
return combinations;
}
public static void combine(List<Integer> nums, List<Integer> currentCombination, int start, int targetLength,
List<List<Integer>> combinations) {
if (currentCombination.size() == targetLength) {
combinations.add(new ArrayList<>(currentCombination));
return;
}
for (int i = start; i <= nums.size() - targetLength + currentCombination.size(); i++) {
currentCombination.add(nums.get(i));
combine(nums, currentCombination, i + 1, targetLength, combinations);
currentCombination.remove(currentCombination.size() - 1);
}
}
}
```
运行以上代码,将会打印出全部的组合。