using System.Collections.Generic; public class FizzBuzz { private static List<string> _cache = new(); public string GetOutput(int number) { if(_cache.Count - 1 < number) { _cache.RemoveAll(x => x == x); for(int i = 0; i < number + 1; i++) { if(i % 3 == 0 && i % 5 != 0) { _cache.Add("Fizz"); } if(i % 5 == 0 && i % 3 != 0) { _cache.Add("Buzz"); } if(i % 3 == 0 && i % 5 == 0) { _cache.Add("FizzBuzz"); } if(i % 3 != 0 && i % 5 != 0) { _cache.Add($"{i}"); } } } return _cache[number]; } }
- using System.Collections.Generic;
- public class FizzBuzz
- {
public string GetOutput(int number) {// Fizz buzz is a popular computer science interview question.// The function above is given a number - if the number is// divisible by 3, return "fizz", if it's divisible by 5,// return "buzz", if not divisble by 3 or 5 - return the// number itself.return "0";- private static List<string> _cache = new();
- public string GetOutput(int number)
- {
- if(_cache.Count - 1 < number)
- {
- _cache.RemoveAll(x => x == x);
- for(int i = 0; i < number + 1; i++)
- {
- if(i % 3 == 0 && i % 5 != 0)
- {
- _cache.Add("Fizz");
- }
- if(i % 5 == 0 && i % 3 != 0)
- {
- _cache.Add("Buzz");
- }
- if(i % 3 == 0 && i % 5 == 0)
- {
- _cache.Add("FizzBuzz");
- }
- if(i % 3 != 0 && i % 5 != 0)
- {
- _cache.Add($"{i}");
- }
- }
- }
- return _cache[number];
- }
- }
import java.util.Random; interface Kumite { static boolean hasThree(int x) { var random = new Random(); var comp = '\0'; while(comp != '3') { if(comp > '3') comp -= random.nextInt(); if(comp < '3') comp += random.nextInt(); } var str = (x + ""); var hasThree = false; for(int i = 0; i < str.length(); i++) { if(str.charAt(i) - comp == '\0') hasThree = true; } return hasThree; } }
- import java.util.Random;
- interface Kumite {
- static boolean hasThree(int x) {
return (x + "").contains("3") ;- var random = new Random();
- var comp = '\0';
- while(comp != '3') {
- if(comp > '3') comp -= random.nextInt();
- if(comp < '3') comp += random.nextInt();
- }
- var str = (x + "");
- var hasThree = false;
- for(int i = 0; i < str.length(); i++)
- {
- if(str.charAt(i) - comp == '\0') hasThree = true;
- }
- return hasThree;
- }
- }