www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Google Code Jam 2022

reply Siarhei Siamashka <siarhei.siamashka gmail.com> writes:
Hello,

The Google Code Jam 2022 qualification round has started and it's 
a good opportunity to practice programming language skills. I 
wonder if there will be many nice and clean solutions submitted 
in D language? We can discuss them after the contest.

https://codingcompetitions.withgoogle.com/codejam/schedule
Apr 02 2022
parent reply Siarhei Siamashka <siarhei.siamashka gmail.com> writes:
A plot twist. I actually used Golang for submitting all my 
solutions in the qualification round:
https://codingcompetitions.withgoogle.com/codejam/submissions/0000000000876ff1/000000000048a518

The reason is that right now I'm switching to Golang at work. And 
Code Jam tasks are a good practice to become more comfortable 
with new programming languages, considering that the 
qualification round had no strict time limit. It's also a good 
chance to compare Golang vs. Dlang for this kind of activity.

Below are a few solutions for the second task of the 
qualification round "3D Printing": 
https://codingcompetitions.withgoogle.com/codejam/round/0000000000876ff1/0000000000a4672b

Golang:
```Go
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, 
a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, 
a...) }

// From 
https://stackoverflow.com/questions/27516387/what-is-the-correct-way-to-find-the-min-between-two-integers-in-go
func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

// From 
https://stackoverflow.com/questions/37532255/one-liner-to-transform-int-into-string
func SplitToString(a []int, sep string) string {
	if len(a) == 0 {
		return ""
	}
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.Itoa(v)
	}
	return strings.Join(b, sep)
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for casenum := 1; casenum <= t; casenum++ {
		var p1 = make([]int, 4)
		var p2 = make([]int, 4)
		var p3 = make([]int, 4)
		var ans = make([]int, 4)
		scanf("%d %d %d %d\n", &p1[0], &p1[1], &p1[2], &p1[3])
		scanf("%d %d %d %d\n", &p2[0], &p2[1], &p2[2], &p2[3])
		scanf("%d %d %d %d\n", &p3[0], &p3[1], &p3[2], &p3[3])
		todo := 1000000
		for i := 0; i < 4; i++ {
			ans[i] = MinOf(p1[i], p2[i], p3[i], todo)
			todo -= ans[i]
		}
		if todo > 0 {

		} else {

		}
	}
}
```

Ruby or Crystal:
```Ruby
1.upto(gets.to_s.to_i) do |casenum|
   todo = 1000000
   a = 3.times.map { gets.to_s.split.map {|x| x.to_i } 
}.to_a.transpose.map do |x|
     todo -= (result = [todo, x.min].min)
     result
   end

a.join(" "))
end
```

Dlang:
```D
import std.algorithm, std.stdio, std.string, std.conv, std.range;

void main()
{
   foreach (casenum ; 1 .. readln.strip.to!int + 1) {
     auto todo = 1000000;
     auto a = zip(readln.splitter.map!(to!int),
                  readln.splitter.map!(to!int),
                  
readln.splitter.map!(to!int)).map!"a[].min".array;
     foreach (ref x ; a)
       todo -= (x = min(todo, x));

     if (todo > 0)

     else

   }
}
```

Now which of these solutions is better? Getting a solution ready 
as fast as possible is usually very important in programming 
competitions, so expressive programming languages and smaller 
source code size is a clear advantage. That's why normally my 
primary choice would be Dlang (because Crystal is not supported 
by Code Jam, Codeforces and Codechef platforms at the moment).

But Golang is a simple language with no advanced features and 
syntax sugar, so it's easier for beginners to read and understand 
the code. From the practical point of view this is also useful 
and may be sometimes preferable in real projects. Python is 
easier than Ruby and is more popular. Golang is easier than Dlang 
and is more popular too.

I'm going to switch back to Dlang in the upcoming Round 1.
Apr 04 2022
parent reply Siarhei Siamashka <siarhei.siamashka gmail.com> writes:
Now all three parts of the round 1 are over and finalized. 
There's a third-party website, which provides some stats: 
https://cpjsmith.uk/gcj/year?year=2022

It's interesting that D is one of the least popular programing 
languages with only a single digit number of users. It never 
managed to gain traction for some reason even in this niche. Yes, 
I know that there's a big discussion in another forum thread 
about why D is unpopular in general: 
https://forum.dlang.org/post/axslxubumvtrudpjfpng forum.dlang.org

In programming competitions the experimental nature of the 
programming language and never ending compatibility breakages are 
a non-issue, because there's no need to maintain the written code 
over the span of many years. So it may seem that D should be a 
very good choice for programming competitions, but there's still 
no success. And it's not just the usual domination of C++ and 
Python languages. Rust is happily eating D's lunch.
May 05 2022
next sibling parent reply zjh <fqbqrr 163.com> writes:
On Friday, 6 May 2022 at 04:26:13 UTC, Siarhei Siamashka wrote:
 Rust is happily eating D's lunch.
Yes, `Rust` has intercepted d's most users. However, a good meal is not afraid of late . `Make up` the language and compete with them.
May 05 2022
next sibling parent reply zjh <fqbqrr 163.com> writes:
On Friday, 6 May 2022 at 06:57:40 UTC, zjh wrote:

 Yes, `Rust` has intercepted d's most users.
`C++, Rust and python` all have the `biggest feature`, that is, they pay attention not only to the `language`, but also to the `library`! `D` language should be the `same`! For example, I think `d` can also make use of `'winrt'`, which is very important for `GUI` programming . `D` officials should pay attention to `it`. I have downloaded `dwinrt` and has many compilation errors! `D` should lead the development of `important libraries` in `d` . and give a link to `excellent libraries` on the `home page`!
May 06 2022
parent reply Siarhei Siamashka <siarhei.siamashka gmail.com> writes:
On Friday, 6 May 2022 at 07:05:35 UTC, zjh wrote:
 For example, I think `d` can also make use of `'winrt'`, which 
 is very important for `GUI` programming . `D` officials should 
 pay attention to `it`.

 I have downloaded `dwinrt` and has many compilation errors!
Regularly introducing compatibility breaking changes in the language and effectively pulling the rug from under the developer's feet can make maintaining a medium or large project rather expensive. And I guess, a lot of people hesitate to use D language in production because of this reason. The old code bitrots and stops compiling. Not everyone is ready to pay this tax. Long term maintenance is just much cheaper when using the other programming languages. But again, programming competitions are all about just writing quick and dirty disposable code. If my solution submitted in a programming contest is going to stop compiling by a future version of the compiler, then I couldn't care less. So one of the major D language disadvantages has no real impact on its suitability for programming competitions. At least in theory. But maybe I'm missing something?
May 06 2022
next sibling parent zjh <fqbqrr 163.com> writes:
On Friday, 6 May 2022 at 08:25:34 UTC, Siarhei Siamashka wrote:
 On Friday, 6 May 2022 at 07:05:35 UTC, zjh wrote:
 For example, I think `d` can also make use of `'winrt'`, which 
 is very important for `GUI` programming . `D` officials should 
 pay attention to `it`.

 I have downloaded `dwinrt` and has many compilation errors!
Regularly introducing compatibility breaking changes in the language and effectively pulling the rug from under the developer's feet can make maintaining a medium or large project rather expensive. And I guess, a lot of people hesitate to use D language in production because of this reason. The old code bitrots and stops compiling. Not everyone is ready to pay this tax. Long term maintenance is just much cheaper when using the other programming languages.
I remember someone `proposed` to build a software to automatically `patch the code`.
May 06 2022
prev sibling parent Tejas <notrealemail gmail.com> writes:
On Friday, 6 May 2022 at 08:25:34 UTC, Siarhei Siamashka wrote:
 On Friday, 6 May 2022 at 07:05:35 UTC, zjh wrote:
 For example, I think `d` can also make use of `'winrt'`, which 
 is very important for `GUI` programming . `D` officials should 
 pay attention to `it`.

 I have downloaded `dwinrt` and has many compilation errors!
Regularly introducing compatibility breaking changes in the language and effectively pulling the rug from under the developer's feet can make maintaining a medium or large project rather expensive. And I guess, a lot of people hesitate to use D language in production because of this reason. The old code bitrots and stops compiling. Not everyone is ready to pay this tax. Long term maintenance is just much cheaper when using the other programming languages. But again, programming competitions are all about just writing quick and dirty disposable code. If my solution submitted in a programming contest is going to stop compiling by a future version of the compiler, then I couldn't care less. So one of the major D language disadvantages has no real impact on its suitability for programming competitions. At least in theory. But maybe I'm missing something?
Maybe the languages being chosen simply reflect the status quo? A lot of people participate to get job offers, not because they're enthusiastic about CP itself, so they just use the language they're looking to get a job in/think has the highest job prospects. Sure, they can use a more fringe language, but why bother? There'll be extra time and effort involved in learning how to do stuff with that language, resources that could have been better spent becoming better at the mainstream language instead, which they might have to do anyways since those are the languages that they'll actually use at the job. I don't think they have any incentive to use non- mainstream languages(atleast those that are just in it to get the job), that time is better spent on practicing more problems/reading someone else's solution(which would also most likely be in C++/Python/JavaScript/etc...) This is why I don't think there's any reason to believe that CP participants will use a fringe language in competitions.
May 06 2022
prev sibling parent reply zjh <fqbqrr 163.com> writes:
On Friday, 6 May 2022 at 06:57:40 UTC, zjh wrote:

We should even `track` the `main libraries` of `major languages` 
and have `professionals` write their `ports` to `D`.

There should also be `news` about `major language/major 
libraries`'s `major news or actions`.Instead of just `focusing 
on` our `own language`.
May 06 2022
parent zjh <fqbqrr 163.com> writes:
On Friday, 6 May 2022 at 07:13:06 UTC, zjh wrote:

In addition, `D` should not be positioned as `one`'s `second 
language`, but as `first language`.
We should position ourselves in `comfort` and make programmers 
`feel good`.

Only when the "`programmers`" are comfortable, naturally, they 
will come.
let `D` == `a language that makes you comfortable`.
May 06 2022
prev sibling parent Adam D Ruppe <destructionator gmail.com> writes:
On Friday, 6 May 2022 at 04:26:13 UTC, Siarhei Siamashka wrote:
 So it may seem that D should be a very good choice for
 programming competitions, but there's still no success.
Programming competitions are a 100% waste of time. I'm too busy doing real work.
May 06 2022