Games
Arrays
Data Types
Algorithms
Logic
fn required_energy(heights: Vec<i64>) -> i64 { heights .iter() .skip(1) .zip(heights.iter()) .map(|(y2, y1)| (y2 - y1).abs()) .sum::<i64>() }
using System;public static class Kata{public static int CalculatingTheAmountEnergy(int[] coordinates){// here's your code}- fn required_energy(heights: Vec<i64>) -> i64 {
- heights
- .iter()
- .skip(1)
- .zip(heights.iter())
- .map(|(y2, y1)| (y2 - y1).abs())
- .sum::<i64>()
- }
#[test] fn test() { assert_eq!(required_energy(vec![1, 5, 10]), 9); assert_eq!(required_energy(vec![1, 5, 10, 3, 20]), 33); assert_eq!(required_energy(vec![0, 0, 1]), 1); }
using NUnit.Framework;using System;[TestFixture]public class SolutionTest{[TestCase(new int[] { 1, 5, 10}, ExpectedResult = 9)][TestCase(new int[] { 1, 5, 10, 3, 20}, ExpectedResult = 33)][TestCase(new int[] { 0, 0, 1}, ExpectedResult = 1)]public int Tests(int[] values) => Kata.CalculatingTheAmountEnergy(values);}- #[test]
- fn test() {
- assert_eq!(required_energy(vec![1, 5, 10]), 9);
- assert_eq!(required_energy(vec![1, 5, 10, 3, 20]), 33);
- assert_eq!(required_energy(vec![0, 0, 1]), 1);
- }