goto goes to incorrect line?

12 views
Skip to first unread message

Viktor Grigorov

unread,
May 3, 2024, 10:47:49 AMMay 3
to J Mailing List J
Hey, all,

I was solving 2021's Advent of Code's 8. problem, and I stumbled into an oddity. The below code, on my system at least, results in the whole block being repeated rather than it sans first line. Am I missing something or is this, say, an optimization from the C compiler, even though the 'as if' rule is violated?


{{'digits one seven four eight'=._1;'';'';'';''[r=.0[y=.,}.<;._2 LF,y
for_words.{:"1(2&}.)L:0 ([:<;.1'|',])S:0 y do.
  while.0<+/_1=digits do.
    echo digits=._1#~(1++/' '&=;words) NB. this echo showed the fault in my case 
    label_q.
    for_word.([:<;._1])' ',;words do.
      length=.#word=.>word
      echo word;word_index;digits
      select.length
      case.7 do.digits=.8(word_index)}digits[eight=.word
      case.4 do.digits=.4(word_index)}digits[four=.word
      case.3 do.digits=.7(word_index)}digits[seven=.word
      case.2 do.digits=.1(word_index)}digits[one=.word
      case.5 do.
        if.(four&(2=[:+/e.))word do.digits=.2(word_index)}digits
        elseif.(four&(4=[:+/e.)+.one&(2=[:+/e.)+.seven&(3=[:+/e.))word do.digits=.3(word_index)}digits
        elseif.(four&(3=[:+/e.)+.seven&(2=[:+/e.))word do.digits=.5(word_index)}digits
        end.
      case.6 do.
        if.(one&(1=[:+/e.)+.seven&(2=[:+/e.))word do.digits=.6(word_index)}digits
        elseif.(one&(2=[:+/e.)+.four&(4=[:+/e.)+.seven&(3=[:+/e.))word do.digits=.9(word_index)}digits
        elseif.(one&(2=[:+/e.)+.seven&(3=[:+/e.))word do.digits=.0(word_index)}digits
        else.digits=.0(word_index)}digits
        end.
      end.
    end.
    if.0<_1=digits do.goto_q.end.
  end.
  r=.r+number=.10#.;digits
  echo '---';digits;number
  'digits one four seven'=._1;'';'';''
end.
r
}}0 :0
be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc
fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg
fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb
aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea
fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb
dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe
bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef
egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb
gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce
)

Viktor Grigorov

unread,
May 3, 2024, 10:57:31 AMMay 3
to 'Viktor Grigorov' via forum
Addendum. the condition for going to the top should have a +/ before the =. This changes nothing however.

May 3, 2024, 17:47 by fo...@jsoftware.com:
> To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
>

Viktor Grigorov

unread,
May 3, 2024, 11:05:28 AMMay 3
to 'Viktor Grigorov' via forum
Never mind. I'm purblind it'd seem. Pardon the spam.

May 3, 2024, 17:57 by fo...@jsoftware.com:

> Addendum. the condition for going to the top should have a +/ before the =. This changes nothing however.
>
> May 3, 2024, 17:47 by fo...@jsoftware.com:
>
Reply all
Reply to author
Forward
0 new messages