# Happy Christmas Eve! 🎄

**URL:** <https://fortran-lang.discourse.group/t/happy-christmas-eve/519>\
**Category:** Uncategorized\
**Created:** [December 24, 2020, 5:02pm UTC](https://fortran-lang.discourse.group/t/happy-christmas-eve/519 "2020-12-24T17:02:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [December 24, 2020, 5:02pm UTC](https://fortran-lang.discourse.group/t/happy-christmas-eve/519/1 "2020-12-24T17:02:36Z")

</div>

Merry Christmas Eve, all!

Run the code below to produce some Christmas trees:

```auto
do i=3,9
do k=1,i
print*,repeat(' ',i-k)//repeat('*',2*k-1)
enddo
print*,repeat(' ',i-1)//'*'
if (i<9) write(*,*)
enddo
end

```

(This is my [code golf](https://code.golf/christmas-trees#fortran) solution with 123 characters. Apparently, it is possible to do it with less than 70 characters!)

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [December 24, 2020, 10:49pm UTC](https://fortran-lang.discourse.group/t/happy-christmas-eve/519/2 "2020-12-24T22:49:35Z")

</div>

Reminds me of the old obfustication challenges:

```auto
write(*,'(*(a/),a/)')([(repeat(' ',i-k)//repeat('*',2*k-1),k=1,i),repeat(' ',i-1)//'*'],i=3,9)
end

```

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [December 24, 2020, 10:54pm UTC](https://fortran-lang.discourse.group/t/happy-christmas-eve/519/3 "2020-12-24T22:54:44Z")

</div>

Your code works with `ifort`, but with `gfortran` I get:

```nohighlight
Fortran runtime error: Argument NCOPIES of REPEAT intrinsic is negative (its value is -1)

```

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [December 24, 2020, 11:16pm UTC](https://fortran-lang.discourse.group/t/happy-christmas-eve/519/4 "2020-12-24T23:16:27Z")

</div>

```auto
write(*,'(*(a/),a/)')([(repeat(' ',i-k)//repeat('*',2*k-1),k=1,i),repeat(' ',i-1)//'*'],i=3,9)

```

Just having fun, but it shows how hard you can make something be to debug, doesn’t it? But …

```auto
do i=3,9
do k=1,i
write(*,*)i-k,2*k-1
enddo
write(*,*)i-1
enddo
end

```

should see what it does to nvfortran! The description I have on hand doesn’t say zero is disallowed, do not see a negative. Now I actually have to think about it:\>

---

<div class="post-metadata">

**Author:** ![nshaffer](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/nshaffer/32/161_2.png) [@nshaffer](https://fortran-lang.discourse.group/u/nshaffer)\
**Post date:** [December 24, 2020, 11:23pm UTC](https://fortran-lang.discourse.group/t/happy-christmas-eve/519/5 "2020-12-24T23:23:31Z")

</div>

```auto
use iso_fortran_env
open(output_unit,encoding="UTF-8")
write(*,*)char(127876,selected_char_kind("ISO_10646"))
end

```

114 characters 😁

---

<div class="post-metadata">

**Author:** ![jeremie.vandenplas](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@jeremie.vandenplas](https://fortran-lang.discourse.group/u/jeremie.vandenplas)\
**Post date:** [December 25, 2020, 12:46am UTC](https://fortran-lang.discourse.group/t/happy-christmas-eve/519/6 "2020-12-25T00:46:40Z")

</div>

Starting from your proposition, in 93 characters:

```auto
print'(*(a/))',((repeat(' ',i-k+1)//repeat('*',2*k-1),k=1,i),repeat(' ',i)//'*','',i=3,9)
end

```

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [December 25, 2020, 1:39am UTC](https://fortran-lang.discourse.group/t/happy-christmas-eve/519/7 "2020-12-25T01:39:16Z")

</div>

All nice!

No one run the obfuscation version with gfortran unless you are curious whether you will get a bus error or fill /var/crash first. Does not seem right to give or receive a bug report this time of year, so some other time – but a real doozie.

Assuming your terminal emulator handles ANSI in-line control sequences, this one should be safe to run with gfortran

```auto
!write(*,'(*(a,/),a,/)')([(repeat(' ',i-k)//repeat('*',2*k-1),k=1,i),repeat(' ',i-1)//'*'],i=3,9)
!write(*,'(*(i0,/),i0/)')([(i-k,2*k-1,k=1,i),i-1],i=3,9)
implicit none
integer, allocatable :: seed(:)
integer,parameter :: first=1,last=8
integer :: i,k,n,r
real :: rand_val
   call random_seed(size = n)
   allocate(seed(n))
   call random_seed(get=seed)
   write(*,'(a,a,*(a,/),a,/)')char(27)//'[H'//char(27)//'[J'
   do
      call random_number(rand_val)
      r=first+floor((last+1-first)*rand_val)
      write(*,'(a,*(a,/),a,/)')char(27)//'[H',([&
      &( repeat(' ',min(8,max(0,i-k)))//repeat(char(33+r+k),min(17,max(0,2*k-1))) ,k=1,i),&
      &repeat(' ',min(max(0,i-1),9) )//'*'],i=8,9)
   enddo
end

```

Merry Christmas!

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [December 25, 2020, 9:41am UTC](https://fortran-lang.discourse.group/t/happy-christmas-eve/519/8 "2020-12-25T09:41:52Z")

</div>

> [@nshaffer](#):
>
> ```auto
> use iso_fortran_env
> open(output_unit,encoding="UTF-8")
> write(*,*)char(127876,selected_char_kind("ISO_10646"))
> end
> 
> ```

An “improved” version (53 characters):

```fortran
open(unit=6,encoding="UTF-8")
print*,char(127876,4)
end

```

```auto
$ gfortran -std=f2018 -Wall -Wextra -pedantic essai2.f90 && ./a.out
 🎄

```
