Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
43
Task/Hailstone-sequence/Bracmat/hailstone-sequence.bracmat
Normal file
43
Task/Hailstone-sequence/Bracmat/hailstone-sequence.bracmat
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
(
|
||||
( hailstone
|
||||
= L len
|
||||
. !arg:?L
|
||||
& whl
|
||||
' ( !arg:~1
|
||||
& (!arg*1/2:~/|3*!arg+1):?arg
|
||||
& !arg !L:?L
|
||||
)
|
||||
& (!L:? [?len&!len.!L)
|
||||
)
|
||||
& ( reverse
|
||||
= L e
|
||||
. :?L
|
||||
& whl'(!arg:%?e ?arg&!e !L:?L)
|
||||
& !L
|
||||
)
|
||||
& hailstone$27:(?len.?list)
|
||||
& reverse$!list:?first4 [4 ? [-5 ?last4
|
||||
& put$"Hailstone sequence starting with "
|
||||
& put$!first4
|
||||
& put$(str$(" has " !len " elements and ends with "))
|
||||
& put$(!last4 \n)
|
||||
& 1:?N
|
||||
& 0:?max:?Nmax
|
||||
& whl
|
||||
' ( !N+1:<100000:?N
|
||||
& hailstone$!N
|
||||
: ( >!max:?max&!N:?Nmax
|
||||
| ?
|
||||
. ?
|
||||
)
|
||||
)
|
||||
& out
|
||||
$ ( str
|
||||
$ ( "The number <100000 with the longest hailstone sequence is "
|
||||
!Nmax
|
||||
" with "
|
||||
!max
|
||||
" elements."
|
||||
)
|
||||
)
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue