태그 보관물: code-golf

code-golf

새로 발견 된 수 : 비인! 구분 된 숫자 범위

“Nobel 수학상은 새로운 수를 발견 한 캘리포니아 교수에게 수여되었습니다!이 수는 6 명에서 7 명 사이입니다.” -조지 칼린

이 과제에서는 주어진 입력 범위 내에서 모든 정수를 포함하여 인쇄합니다. 입력 순서에 따라 오름차순 또는 내림차순으로 숫자를 인쇄합니다. 즉, 입력의 경우 오름차순 if , 내림차순 if [n1, n2]인쇄 합니다 .n1 < n2n1 > n2

이후는 bleen이제 입력으로 사용될 수있는 정수이다. 또한 사이의 출력에 포함되어야 6하고 7해당되는 경우. 또한 -bleen-7과 -6 사이 에 존재합니다.

입력

[n1, n2]프로그래밍 언어의 선택 입력을 통한 [-10, 10] 범위의 정수 2 개 .

(입력에 bleen-bleen! 도 포함될 수 있습니다 .)

산출

6에서 7 사이에 새로 발견 된 것을 포함하여로 시작 n1하고로 끝나는 모든 정수를 인쇄하십시오 . 출력은 언어가 지원하는 일부 형식 (쉼표 또는 공백으로 구분)으로 문자로 구분 된 숫자 범위 일 수 있습니다. 출력의 후행 공간은 괜찮습니다.n2bleen

Input:  1 10
Output: 1 2 3 4 5 6 bleen 7 8 9 10

Input:  -9 -4
Output: -9 -8 -7 -bleen -6 -5 -4

Input:  -8 bleen
Output: -8 -7 -bleen -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 bleen

Input:  9 1
Output: 9 8 7 bleen 6 5 4 3 2 1

Input:  2 -bleen
Output: 2 1 0 -1 -2 -3 -4 -5 -6 -bleen

Input:  -bleen 0
Output: -bleen -6 -5 -4 -3 -2 -1 0

Input:  bleen bleen
Output: bleen

Input:  2 2
Output: 2

추가 사항

프로그램이나 함수를 작성하고 입력을 받고 출력을 제공하는 표준 방법 을 사용할 수 있습니다 .

프로그래밍 언어를 사용할 수 있지만 표준 허점 은 허용되지 않습니다.

이것은 이므로 바이트 단위로 측정 된 가장 짧은 유효한 답변이 이깁니다.



답변

파이썬 3, 132130 바이트

r=round
bleen=6.1
m=1.08
a,b=eval(input())
d=1-2*(a>b)
print(*[[r(i/m),"-bleen"[i>0:]][i*i==49]for i in range(r(m*a),d+r(m*b),d)])

다음 예제 형식으로 입력을받습니다.

-8, bleen


답변

루비, 114 (100) 98 바이트

입력은로 구성된 배열입니다 [n1, n2]. (이 두 개의 별도 인수해야하는 경우에서 함수 인수를 변경 한 바이트 g에이 *g. Bleen 문자열이어야 "bleen". 출력 범위. 자신 (?)의 초기 버전 부여 -7 바이트 @Jordan 제안들의 어레이 그 후에도 7 골을 더 떨어 뜨 렸습니다.

온라인으로 사용해보십시오.

->g{a=*-10..-7,?-+b='bleen',*-6..6,b,*7..10;x,y=g.map{|v|a.index v}
y<x ?a[y..x].reverse: a[x..y]}

다음에서 입력을 읽는 원본 전체 프로그램 버전 ARGV:

b='bleen'
a=[*-10..-7,?-+b,*-6..6,b,*7..10].map &:to_s
x,y=$*.map{|v|a.index v}
puts y<x ?a[y..x].reverse: a[x..y]


답변

Pyth , 35 바이트

K++L\-P_J++`M7"bleen"`M}7TJ@LK}FxLK

테스트 스위트.

첫 번째 부분, 즉 K++L\-P_J++`M7"bleen"`M}7TJ이 배열을 생성합니다.

['-10', '-9', '-8', '-7', '-bleen', '-6', '-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5', '6', 'bleen', '7', '8', '9', '10']

그런 다음에 저장합니다 K.

두 번째 부분, 즉 @LK}FxLK, 입력으로 표시된 하위 목록을 찾습니다.


답변

파이썬 3 157 145 123 108 115 139 161 158 153 바이트

Lynn 덕분에 22를 저장했습니다. shooqie 덕분에 17 명이 저장되었습니다. ljeabmreosn 덕분에 3 명이 저장되었습니다. Geoff Reedy 덕분에 5 명이 저장되었습니다.

a,b=eval(input())
s='-'
c='bleen'
d=a<b
l=list(map(str,range(-10,11)))[::[-1,1][d]]
x=l.insert
y=l.index
x(4,d*s+c)
x(18,(1^d)*s+c)
print(l[y(a):y(b)+1])

처럼 입력하십시오 '-10', '8'. 초보자를위한 팁을 환영합니다.

계정에 7을 추가했습니다 -bleen. 와 같이 반전 된 입력을 설명하기 위해 15가 추가되었습니다 '8','-10'. bleenvs 에 대한 반전 된 입력 부호를 설명하기 위해 큰 21을 추가했습니다 -bleen.


답변

루비, 141 바이트

->*a{
l="bleen"
s=13
a,b=a.map{|n|2*n rescue s*(n<=>?b)}
b,a,r=a,b,1if b<a
o=(a..b).map{|n|n==s ?l:n==-s ??-+l:n/2}.uniq
puts r ?o.reverse: o}

언 골프

lambda do |*args|
  bleen = "bleen"
  subst = 13 # This will stand in for "bleen"

  a, b = args.map {|arg|
    begin
      # Double the number
      2 * arg
    rescue
      # It wasn't a number, so it's "bleen" or "-bleen"; replace it with 13 or -13
      subst * (arg <=> "b")
    end
  }

  if b < a
    # If the range isn't ascending, reverse it and remember that we did
    b, a, reverse = a, b, 1
  end

  # Step through the range, replacing 13 and -13 with "bleen" and "-bleen" and
  # halving everything else
  result = (a..b).map {|n|
    if n == subst
      bleen
    elsif n == -subst
      "-" + bleen
    else
      n / 2
    end
  }.uniq # Drop duplicates

  # Reverse the result if the range was descending
  puts reverse ? result.reverse : result
end


답변

배치, 239186 바이트

@set/ableen=1431655772,a=%1*3,b=%2*3,c=b-a^>^>31^|1
@for /l %%i in (%a%,%c%,%b%)do @((if %%i==20 echo bleen)&(if %%i==-20 echo -bleen)&set/aj=%%i%%3,k=%%i/3&cmd/cif %%j%%==0 echo %%k%%)

에서 루프의 작품 3*%13*%3그러나 설정 한 다음 세 가지로 나누어없이 나머지 숫자를 인쇄하는 bleen마법의 숫자는 오버 플로우 정수가 발생하고 값이 20대신 사용됩니다. 그런 다음 루프의 해당 지점에 인쇄됩니다.


답변

자바 스크립트 (ES6), 158

골프하기 어려운 도전. 아마도 파이썬과 루비 답변에 사용되는 범위 메소드는 JS에서도 점수가 더 높을 수 있습니다.

(a,b)=>(c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,a=c(a),b=c(b),d=b>a?1:-1,a-=d,e=x=>x-7?x-(x>7):'bleen',[...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x)))

덜 골프

(a,b)=>(
  c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,
  a=c(a),b=c(b),
  d=b>a?1:-1,
  a-=d,
  e=x=>x-7?x-(x>7):'bleen',
  [...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x))
)

테스트

f=(a,b)=>(c=x=>x<-6?x-1:x>6?x+1:1/x?x:x<'b'?-7:7,a=c(a),b=c(b),d=b>a?1:-1,a-=d,e=x=>x-7?x-(x>7):'bleen',[...Array(d*(b-a))].map((x=a+=d)=>x<0?'-'+e(-x):e(x)))

function go(){
  var a=A.value,b=B.value
  // make them numeric if possible
  a=isNaN(a)?a:+a
  b=isNaN(b)?b:+b

  O.textContent=f(a,b)
}
go()
A <select id=A onchange='go()'>
<option>-10<option>-9<option>-8<option>-7<option>-bleen<option>-6<option>-5<option>-4<option>-3<option>-2<option>-1<option>0
<option>1<option>2<option>3<option>4<option>5<option>6<option>bleen<option>7<option>8<option>9<option>10
</select>
B <select id=B onchange='go()'>
<option>-10<option>-9<option>-8<option>-7<option>-bleen<option>-6<option>-5<option>-4<option>-3<option>-2<option>-1<option>0
<option>1<option>2<option>3<option>4<option>5<option>6<option>bleen<option>7<option>8<option>9<option selected>10
</select>
<pre id=O></pre>