Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 0k
- # embedded perl to read line from stdin and push ASCII values of the characters
- { $_ = <>; chomp; return (map {ord} split //) } s?
- [q] sQ # quit loop
- [1+] s+ # increment
- 0 s1 # variable for storing result of part 1
- [ ln s1 ] sS # used for getting max, sets $1 to $n
- #
- # Macro to convert ASCII values on stack into seat number in $n
- #
- [
- z 0 =Q # break if stack empty
- 0r # put a zero under the top item to calculate bit on
- 8% 4 >+ # using that the bit we want is not of bit 3 in ASCII
- ln 2*+ sn # shift n and add bit to bottom
- lCx # loop
- ] sC
- #
- # Mainline
- #
- [
- l?x # grab input line as pushed ASCII values
- z 0 =Q # quit if we don't get any more
- 0 sn lCx # init $n, then call C to calculate seat in it
- ln d # push two copies of $n
- l1 <S # first: get max of $n and $1
- 1 r:a # second: used set a[$n] = 1
- lMx # loop
- ] sM
- lMx
- [Part 1: ]n l1p
- # Find seat for part 2 (assuming nice input where all seats contiguous but 1)
- 1- s2 # take answer from part 1, decrement and store in $2
- [
- l2 ;a 0 =Q # break if a[$2] = 0 (empty seat)
- l2 1- s2 # decrement $2
- lIx # loop
- ] sI
- lIx
- [Part 2: ]n l2p
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement