def primemaker(x): primes = [] if x < 2 : return [] else: primes.append(2) for possibleprimes in range(3,(x+1), 2): # only odd numbers isprime = True for n in range(2,possibleprimes//2+1): if possibleprimes % n == 0: isprime = False break # stop after first non prime number found if isprime: primes.append(possibleprimes) return primes
- def primemaker(x):
- primes = []
- if x < 2 : return []
- else:
for possibleprimes in range(2,(x+1)):- primes.append(2)
- for possibleprimes in range(3,(x+1), 2): # only odd numbers
- isprime = True
- for n in range(2,possibleprimes//2+1):
- if possibleprimes % n == 0:
- isprime = False
- break # stop after first non prime number found
- if isprime:
- primes.append(possibleprimes)
- return primes
import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; class Solution { public static String numberOfNumbers(int value) { String delimiter = getDelimiterFor(value); return IntStream.rangeClosed(1, Math.abs(value)) .mapToObj(Solution::repeatByItself) .collect(Collectors.joining(delimiter)); } private static String getDelimiterFor(int value){ return value > 0 ? "-" : "+"; } private static String repeatByItself(int i){ return String.valueOf(i).repeat(i); } }
- import java.util.stream.Collectors;
- import java.util.stream.IntStream;
- import java.util.stream.Stream;
- class Solution {
- public static String numberOfNumbers(int value) {
- String delimiter = getDelimiterFor(value);
return IntStream.rangeClosed(0, Math.abs(value))- return IntStream.rangeClosed(1, Math.abs(value))
- .mapToObj(Solution::repeatByItself)
.filter(Solution::notBlank)- .collect(Collectors.joining(delimiter));
- }
- private static String getDelimiterFor(int value){
- return value > 0 ? "-" : "+";
- }
- private static String repeatByItself(int i){
- return String.valueOf(i).repeat(i);
- }
private static boolean notBlank(String s){return !s.isBlank();}- }
import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; class Solution { public static String numberOfNumbers(int value) { String delimiter = value > 0 ? "-" : "+"; String result = ""; for (int i = 1; i <= Math.abs(value); i++) { result += String.valueOf(i).repeat(i) + ((i + 1 <= Math.abs(value)) ? delimiter : ""); } return result; } }
- import java.util.stream.Collectors;
- import java.util.stream.IntStream;
- import java.util.stream.Stream;
- class Solution {
- public static String numberOfNumbers(int value) {
String delimiter = getDelimiterFor(value);return IntStream.rangeClosed(0, Math.abs(value)).mapToObj(Solution::repeatByItself).filter(Solution::notBlank).collect(Collectors.joining(delimiter));}private static String getDelimiterFor(int value){return value > 0 ? "-" : "+";}private static String repeatByItself(int i){return String.valueOf(i).repeat(i);}private static boolean notBlank(String s){return !s.isBlank();- String delimiter = value > 0 ? "-" : "+";
- String result = "";
- for (int i = 1; i <= Math.abs(value); i++) {
- result += String.valueOf(i).repeat(i) + ((i + 1 <= Math.abs(value)) ? delimiter : "");
- }
- return result;
- }
- }