[Jprogramming] advent of code, days 36bl 25
Moon S
moon.aka.sun at gmail.com
Fri Dec 25 23:52:51 UTC 2015
I had nearly the same for the last day. Then remembered that J has modular
exponentiation optimized. And I have 64-bit J, so no need for extended
numbers.
3 timex '(33554393&|@*&252533)^:(2947(<.&-:@(*:@+-3&*@[+]))3029)20151125'
5.12972
3 timex
'33554393|20151125*(33554393&|@^&(2947(<.&-:@(*:@+-3&*@[+]))3029))252533'
1.38599e_5
On Sat, Dec 26, 2015 at 1:28 AM, David Lambert <b49p23tivg at gmail.com> wrote:
> NB. Christmas
> NB. To continue, please consult the code grid in the manual. Enter the
> code at row 2978, column 3083.
>
>
> n=:]+[:-:[:*/_2 _1++ NB. ROW n COL
>
> REPEATS=: 2978 n 3083
>
>
> START=: 20151125
>
> PART1=: (33554393x|252533x*])^:(REPEATS-1)x:START
>
>
> PART2=: 'finish the other 5!'
>
>
>
>
>
> NB. Day 21
>
> Note 'information'
>
> hero
>
> Weapons: Cost Damage Armor
> Dagger 8 4 0
> Shortsword 10 5 0
> Warhammer 25 6 0
> Longsword 40 7 0
> Greataxe 74 8 0
>
> Armor: Cost Damage Armor
> Leather 13 0 1
> Chainmail 31 0 2
> Splintmail 53 0 3
> Bandedmail 75 0 4
> Platemail 102 0 5
>
> Rings: Cost Damage Armor
> Damage +1 25 1 0
> Damage +2 50 2 0
> Damage +3 100 3 0
> Defense +1 20 0 1
> Defense +2 40 0 2
> Defense +3 80 0 3
>
>
> 100 hit points.
>
>
>
> BOSS
> Hit Points: 103
> Damage: 9
> Armor: 2
> )
>
> read=: 1!:1@:boxopen
> Until=: 2 :'u^:(0-:v)^:_'
> odd=: 1&(2b10001 b.)
> even=: -.@:odd
>
> NAMES=: 'HERODAMAGE HEROARMOR HEROHP BOSSDAMAGE BOSSARMOR BOSSHP MELEE'
> (NAMES)=: i.#;:NAMES
>
> battle=: fight Until death
> play=: cleanup@:battle@:prepare
>
> melee=: MELEE&{
> next=: MELEE >:@:{`[`]} ]
> fight=: next@:turn
> turn=: (hero)`(boss)@.(odd@:melee)
> hero=: BOSSHP&(((BOSSHP{])-(1>.(HERODAMAGE{])-(BOSSARMOR{])))`[`]})
> boss=: HEROHP&(((HEROHP{])-(1>.(BOSSDAMAGE{])-(HEROARMOR{])))`[`]})
> death=: 1 e.1>(HEROHP,BOSSHP)&{
> cleanup=: ]
>
> prepare=: 3 : 0 NB. prepare HERODAMAGE,HEROARMOR
>
> NB. 100 hit points.
>
> NB. BOSS
> NB. Hit Points: 103
> NB. Damage: 9
> NB. Armor: 2
>
> A=. 0#~#;:NAMES
> A=. HEROHP (100"_)`[`]} A
> A=. HERODAMAGE (({.y)"_)`[`]} A
> A=. HEROARMOR (({:y)"_)`[`]} A
> A=. BOSSHP (103"_)`[`]}A
> A=. BOSSDAMAGE (9"_)`[`]}A
> A=. BOSSARMOR (2"_)`[`]}A
> )
>
> test_prepare=: 3 : 0 NB. prepare HERODAMAGE,HEROARMOR
>
> NB.For example, suppose you have 8 hit points, 5 damage, and 5 armor, and
> that the boss has 12 hit points, 7 damage, and 2 armor:
>
> A=. 0#~#;:NAMES
> A=. HEROHP (8"_)`[`]} A
> A=. HERODAMAGE (({.y)"_)`[`]} A
> A=. HEROARMOR (({:y)"_)`[`]} A
> A=. BOSSHP (12"_)`[`]}A
> A=. BOSSDAMAGE (7"_)`[`]}A
> A=. BOSSARMOR (2"_)`[`]}A
> )
>
> WEAPON=: _3[\ 8 4 0 10 5 0 25 6 0 40 7 0 74 8 0
> ARMOR=: 0,_3[\ 13 0 1 31 0 2 53 0 3 75 0 4 102 0 5
> RINGS=: 0,_3[\ 25 1 0 50 2 0 100 3 0 20 0 1 40 0 2 80 0 3
> A=:{<"1 L:0 WEAPON;ARMOR;RINGS;RINGS
> B=:(~.L:1),A
> C=: +/&:>&>B NB. C is an N by 3 array of cost, damage, armor
> D=:(#~ 0 < ([: play }.)"1)C
>
> PART1=: {.{./:~D
>
>
> PART2=: {.{.\:~(#~ 1 > ([: play }.)"1)C
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
More information about the Programming
mailing list