ํƒœ๊ทธ ๋ณด๊ด€๋ฌผ: number

number

์ฃผ์–ด์ง„ ๋ฒ”์œ„ ๋‚ด์—์„œ ํ–‰์šด์˜ ํ‹ฐ์ผ“์„ ์„ธ์‹ญ์‹œ์˜ค. ์ž๋ฆฌ ์ˆซ์ž๋Š” ์šด์ด ์ข‹์€ ๊ฒƒ์œผ๋กœ ๊ฐ„์ฃผ๋ฉ๋‹ˆ๋‹ค . ์‚ฌ์ง„์˜

๋Ÿฌ์‹œ์•„์—๋Š” ์ „ํ†ต๊ณผ ๊ฐ™์€ ๊ฒƒ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ–‰์šด์˜ ํ‹ฐ์ผ“์„ ์ฐพ๋Š” ๊ฒƒ์„ ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค.

์ผ๋ฐ˜ ํ•ญ๊ณต๊ถŒ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

bus ticket

๋ณด์‹œ๋‹ค์‹œํ”ผ ํ‹ฐ์ผ“์—๋Š” 6 ์ž๋ฆฌ ์ˆซ์ž๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฒ˜์Œ ์„ธ ์ž๋ฆฌ์˜ ํ•ฉ์ด ๋งˆ์ง€๋ง‰ ์„ธ ์ž๋ฆฌ์˜ ํ•ฉ๊ณผ ๊ฐ™์€ ๊ฒฝ์šฐ 6 ์ž๋ฆฌ ์ˆซ์ž๋Š” ์šด์ด ์ข‹์€ ๊ฒƒ์œผ๋กœ ๊ฐ„์ฃผ๋ฉ๋‹ˆ๋‹ค .

์‚ฌ์ง„์˜ ์ˆซ์ž๋Š” ์šด์ด ์ข‹์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

038937
038 937
0 + 3 + 8 = 11
9 + 3 + 7 = 19
11 != 19

๋„์ „

๋ฒ”์œ„ ์ œํ•œ์„ ํฌํ•จํ•˜์—ฌ (๋ฒ”์œ„ ํฌํ•จ) ๊ทธ ์•ˆ์— ํฌํ•จ ๋œ ํ–‰์šด์˜ ํ‹ฐ์ผ“ ๋ฒˆํ˜ธ ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

๋งค๊ฐœ ๋ณ€์ˆ˜

  • ์ž…๋ ฅ : 2 ๊ฐœ์˜ ์ •์ˆ˜ : ๋ฒ”์œ„์˜ ์ฒซ ๋ฒˆ์งธ ์ •์ˆ˜์™€ ๋งˆ์ง€๋ง‰ ์ •์ˆ˜
  • ์ž…๋ ฅ ๊ฐ’์€ 0์—์„œ 999999 ์‚ฌ์ด์ž…๋‹ˆ๋‹ค.
  • ์ถœ๋ ฅ : 1 ์ •์ˆ˜ : ๋ฒ”์œ„์—์žˆ๋Š” ํ–‰์šด์˜ ์ˆซ์ž ์ˆ˜
  • ์ž…๋ ฅ์„ ๋ฐ›์•„ ํ—ˆ์šฉ๋˜๋Š” ํ˜•์‹์œผ๋กœ ์ถœ๋ ฅ์„ ๋ฐ˜ํ™˜ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
  • 100000๋ณด๋‹ค ์ž‘์€ ์ˆซ์ž์˜ ์•ž์— 0์„ ๊ฐ€์ •ํ•˜์‹ญ์‹œ์˜ค.

์˜ˆ

0, 1 => 1
100000, 200000 => 5280
123456, 654321 => 31607
0, 999999 => 55252

์ด๊ฒƒ์€ ์ด๋ฏ€๋กœ ๋ชจ๋“  ์–ธ์–ด์—์„œ ๊ฐ€์žฅ ์งง์€ ๋ฐ”์ดํŠธ ๋‹จ์œ„์˜ ๋Œ€๋‹ต์ด ์ด๊น๋‹ˆ๋‹ค.

์—…๋ฐ์ดํŠธ : ์—ฌ๊ธฐ ํ–‰์šด์˜ ๊ฒƒ์ด ์žˆ์Šต๋‹ˆ๋‹ค.



๋‹ต๋ณ€

05AB1E , 8 (๋˜๋Š” 10?) 11 (๋˜๋Š” 13?) ๋ฐ”์ดํŠธ

ลธส’โ‚„n+ยฆS3รดOร‹

์˜จ๋ผ์ธ์œผ๋กœ ์‹œ๋„ ํ•˜๊ฑฐ๋‚˜ ๋” ๋งŽ์€ ํ…Œ์ŠคํŠธ ์‚ฌ๋ก€๋ฅผ ํ™•์ธ ํ•˜์‹ญ์‹œ์˜ค .

์ฐธ๊ณ  : 05AB1E์—์„œ ๋ฌธ์ž์—ด๊ณผ ์ •์ˆ˜๋Š” ์„œ๋กœ ๋ฐ”๊ฟ”์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์ถœ๋ ฅ ์ˆซ์ž์— ์„ ํ–‰ 0์ด ํฌํ•จ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ด๊ฒƒ์€ 1 ์ถ”๊ฐ€ ๋ฐ”์ดํŠธ ( 12 ๋ฐ”์ดํŠธ) ๋กœ ๊ณ ์ • ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค ) .

ลธโ‚„n+โ‚ฌยฆส’S3รดOร‹

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค ํ•˜๊ฑฐ๋‚˜ ๋” ๋งŽ์€ ํ…Œ์ŠคํŠธ ์‚ฌ๋ก€๋ฅผ ํ™•์ธ .

๊ธธ์ด๊ฐ€ 3 ์ดํ•˜์ธ ๋ฒ„๊ทธ ์ˆ˜์ • ๋ฒˆํ˜ธ์— +3 ๋ฐ”์ดํŠธ (๋ฒ”์œ„) [000000, 000999] ).

์„ค๋ช…:

ลธ          # Create an inclusive (on both sides) range from the two inputs
           #  i.e. 038920 and 038910 โ†’ 
           #   [38910,38911,38912,38913,38914,38915,38916,38917,38918,38919,38920]
 ส’         # Filter this list by:
  โ‚„n+      #  Add 1,000,000 to the number
     |     #  And remove the leading 1
           #   i.e. 38910 โ†’ 1038910 โ†’ '038910'
  S        #  Transform it to a list of digits
           #   i.e. '038910' โ†’ ['0','3','8','9','1','0']
   3รด      #  Split it into chunks of length 3
           #   i.e. ['0','3','8','9','1','0'] โ†’ [['0','3','8'],['9','1','0']]
     O     #  Sum the digits in both parts
           #   i.e. [['0','3','8'],['9','1','0']] โ†’ [11,10]
      ร‹    #  Check if they are equal (if they are, they remain in the filtered list)
           #   i.e. [11,10] โ†’ 0

ํŽธ์ง‘ : ๋‚˜ (๊ทธ๋ฆฌ๊ณ  ๋Œ€๋ถ€๋ถ„์˜ ๋‹ค๋ฅธ ๋‹ต๋ณ€)๊ฐ€ ๋„์ „์„ ์•ฝ๊ฐ„ ์ž˜๋ชป ์ฝ์€ ๊ฒƒ์œผ๋กœ ๋ณด์ด๋ฉฐ ๋ฒ”์œ„ ๋‚ด์˜ ์ˆซ์ž ์ž์ฒด ๋Œ€์‹  ์ˆซ์ž์˜ ์–‘์„ ๋ฌป๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด ๊ฒฝ์šฐ ํ›„ํ–‰ }g์„ ์ถ”๊ฐ€ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค (ํ•„ํ„ฐ๋ฅผ ๋‹ซ๊ณ  ํ•„ํ„ฐ๋ง ๋œ ๋ชฉ๋ก์— ๋‚จ์•„์žˆ๋Š” ์ˆซ์ž์˜ ์–‘์„ ์–ป์Œ). ๋Œ€์‹  10 13 ๋ฐ”์ดํŠธ์ž…๋‹ˆ๋‹ค .

ลธส’โ‚„n+ยฆS3รดOร‹}g

์˜จ๋ผ์ธ์œผ๋กœ ์‹œ๋„ ํ•˜๊ฑฐ๋‚˜ ๋” ๋งŽ์€ ํ…Œ์ŠคํŠธ ์‚ฌ๋ก€๋ฅผ ํ™•์ธ ํ•˜์‹ญ์‹œ์˜ค .


๋‹ต๋ณ€

C # (. NET ์ฝ”์–ด) , 93 + 18 = 111 ๋ฐ”์ดํŠธ

a=>b=>Enumerable.Range(a,b-a+1).Select(e=>$"{e:D6}").Count(e=>e[0]+e[1]+e[2]==e[3]+e[4]+e[5])

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!

18 ๋ฐ”์ดํŠธ using System.Linq;. ์ž…๋ ฅ ๋ฐ ์ถœ๋ ฅ ํ˜•์‹์ด ์œ ์—ฐ ํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ๋‘ ๊ฐœ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅ์œผ๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค (๋ฒ”์œ„ ํฌํ•จ).

์ผ๋ถ€ ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ :

a=1000
b=1100

Lucky numbers = 3 [001001, 001010, 001100]

a=2000
b=2100

Lucky numbers = 3 [002002, 002011, 002020]

a=222000
b=222100

Lucky numbers = 7 [222006, 222015, 222024, 222033, 222042, 222051, 222060]

a=0
b=999999

Lucky numbers = 55252 (that's 5.5% of the total numbers)

๋‹ต๋ณ€

์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ (ES6), 66 ๋ฐ”์ดํŠธ

currying ๊ตฌ๋ฌธ์—์„œ ์ž…๋ ฅ์„ ๋ฐ›์Šต๋‹ˆ๋‹ค. (m)(n)์—ฌ๊ธฐ์„œ m ์€ ๋ฐฐํƒ€์  ์ƒํ•œ๊ฐ’์ด๊ณ  n ์€ ๋ฐฐํƒ€์  ์ธ ํ•˜ํ•œ๊ฐ’์ž…๋‹ˆ๋‹ค.

m=>g=n=>n<=m&&![...n+=''].reduce((t,d,i)=>t-=n[i+3]?d:-d,0)+g(-~n)

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!

์–ด๋–ป๊ฒŒ?

์šฐ๋ฆฌ ๋Š” ์ˆซ์ž d i ๋ฅผ ๊ฑท๊ณ  ์ด t๋ฅผ ์—…๋ฐ์ดํŠธํ•˜์—ฌ ๊ฐ ์ˆซ์ž ์„ ํ…Œ์ŠคํŠธํ•ฉ๋‹ˆ๋‹ค .

n

di

t
  • ์ด ๋’ค์— 3 ์ž๋ฆฌ ์ด์ƒ์˜ ์ˆซ์ž๊ฐ€ ๋‚จ์•„ ์žˆ์œผ๋ฉด
    tโ†tโˆ’di

  • ๋‹ฌ๋ฆฌ
    tโ†t+di

ํ”„๋กœ์„ธ์Šค์˜ ๋์— ์ด ์žˆ์œผ๋ฉด n ์€ ํ–‰์šด์˜ ์ˆซ์ž์ž…๋‹ˆ๋‹ค.

t=0

n

์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ (ES6), 67 ๋ฐ”์ดํŠธ

๋™์ผํ•œ ์ž…๋ ฅ ํ˜•์‹.

m=>g=n=>n<=m&&!eval([...n/1e3+''].join`+`.split`+.`.join`^`)+g(n+1)

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!

์–ด๋–ป๊ฒŒ?

๊ฐ ์ˆซ์ž :

n
  • ๋‚˜๋ˆ•๋‹ˆ๋‹ค : ์˜ˆ
    1000

    38937 --> 38.937
  • ์ค„๋กœ ๊ฐ•์ œํ•˜๊ณ  ๋ถ„์—ด : ['3','8','.','9','3','7']
  • ์™€ ํ•จ๊ป˜ +:"3+8+.+9+3+7"
  • ๋Œ€์ฒด +.์™€ ํ•จ๊ป˜ ^:"3+8^+9+3+7"
  • JS ์ฝ”๋“œ๋กœ ํ‰๊ฐ€ํ•˜๊ณ  ๊ฒฐ๊ณผ๊ฐ€ ์ธ์ง€ ํ…Œ์ŠคํŠธํ•˜์‹ญ์‹œ์˜ค . ( 11 XOR 19 )
    0

    24 11

    19

n โ‰ก 0 ์ธ ๊ฒฝ์šฐ ์ด๋ฉด ์†Œ์ˆ˜์ ์ด ์ƒ์„ฑ๋˜์ง€ ์•Š์œผ๋ฉฐ n = 0 (truthy)์ด์•„๋‹Œ ํ•œ ํ‰๊ฐ€ ๋œ ํ‘œํ˜„์‹์€ ์–‘์˜ ํ•ฉ(๊ฑฐ์ง“)์ž…๋‹ˆ๋‹ค. ๋‘ ๊ฒฝ์šฐ ๋ชจ๋‘ ์˜ˆ์ƒ๋˜๋Š” ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค.

nโ‰ก0(mod1000)

n=0

๋‹ต๋ณ€

๋ฃจ๋น„ , 56 54 ๋ฐ”์ดํŠธ

->a,b{(a..b).count{|i|j=i.digits;j[0,3].sum*2==j.sum}}

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!

๋ฐฉ๋ฒ•:

  1. ๋ชจ๋“  ์ˆซ์ž์— ๋Œ€ํ•ด ์ˆซ์ž์˜ ๋ฐฐ์—ด์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค (๋ฐ˜๋Œ€ ๋จ)
  2. ๋ฐฐ์—ด์˜ ์ฒ˜์Œ 3 ์ž๋ฆฌ ์ˆซ์ž (์ˆซ์ž์˜ ๋งˆ์ง€๋ง‰ 3)์— 2๋ฅผ ๊ณฑํ•œ ๊ฐ’์„ ์ „์ฒด ๋ฐฐ์—ด์˜ ํ•ฉ๊ณ„์™€ ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค.
  3. ๋‘ ํ•ฉ์ด ๊ฐ™์€ ์ˆ˜๋ฅผ ์„ผ๋‹ค

๋‹ต๋ณ€

apt , 38 15 ๋ฐ”์ดํŠธ

รตV ร‹รฌ รฒ3n)mx rยฅ

Shaggy์—๊ฒŒ -23 ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

๋‚˜์˜ ์ฒซ๋ฒˆ์งธ Japt ์ œ์ถœ; ๋ชจ๋“  ๋„์›€์„ ์ฃผ์‹  Shaggy์—๊ฒŒ ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค!

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!


๋‹ต๋ณ€

ํŒŒ์ด์ฌ 3 117 113 106 135 ๋ฐ”์ดํŠธ

์ด๊ฒƒ์€ ๋‚˜์˜ ์ฒซ ๋ฒˆ์งธ ๋Œ€๋‹ต์ด๋ฏ€๋กœ ๊ฐœ์„ ์˜ ์—ฌ์ง€๊ฐ€ ์žˆ๋‹ค๊ณ  ํ™•์‹ ํ•ฉ๋‹ˆ๋‹ค.

def x(a,b):
    n=0
    for i in range(a,b+1):
        if sum(map(int,str(i//1000)))==sum(map(int,str(i%1000))):n+=1
    print(n)
  • WW ๋•๋ถ„์— -4 ๋ฐ”์ดํŠธ
  • Asone Tuhid ๋•๋ถ„์— -7 ๋ฐ”์ดํŠธ
  • ํ•จ์ˆ˜๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ์œ„ํ•œ +29 ๋ฐ”์ดํŠธ

์ •์ˆ˜ ๋‚˜๋ˆ„๊ธฐ๋ฅผ ํ†ตํ•ด ์ฒ˜์Œ ์„ธ ์ž๋ฆฌ๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ  ๋งˆ์ง€๋ง‰ ์„ธ ์ž๋ฆฌ๋ฅผ ๋ชจ๋“ˆ๋กœ ํ†ตํ•ด ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค. ๋ฒ”์œ„์˜ ์ฒซ ๋ฒˆ์งธ ์ •์ˆ˜์™€ ๋งˆ์ง€๋ง‰ ์ •์ˆ˜๋Š” ๊ฐ๊ฐ xas a๋ฐ ๋กœ ํ•จ์ˆ˜์˜ ์ธ์ˆ˜๋กœ ์ž…๋ ฅ๋ฉ๋‹ˆ๋‹ค b. ์ถœ๋ ฅ์ด n์ธ์‡„๋ฉ๋‹ˆ๋‹ค.

์–ธ ๊ณจํ”„ ๋“œ :

def x(a, b):
    n = 0
    for i in range(a, b + 1):
        if sum(map(int, str(i // 1000))) == sum(map(int, str(i % 1000))):
            n += 1
    print(n)

๋‹ต๋ณ€

R , 93 86 ๋ฐ”์ดํŠธ

@ Giuseppe /์˜ ์ตœ์ข… ์นญ์ฐฌ์— ๋” ์งง์€ ๋…ผ๋ฆฌ

function(a,b){for(i in sprintf("%06d",a:b)){x=utf8ToInt(i);F=F+!sum(x[1:3]-x[4:6])}
F}

์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด์‹ญ์‹œ์˜ค!

์ •์ˆ˜ ์ž…๋ ฅ. ๋กœ ์ฑ„ ์›๋‹ˆ๋‹ค 0. 6 ๊ฐœ์˜ ASCII ์ฝ”๋“œ ํฌ์ธํŠธ๋กœ ๋ณ€ํ™˜ํ•˜์‹ญ์‹œ์˜ค. F๋‚ด์žฅ์„ ๋‚จ์šฉํ•˜์‹ญ์‹œ์˜ค .