程序员不好好写代码,就只能回去当总理了!

新加坡总理李显龙之子李浩毅不仅是技术博主,还是Scala社区的主要贡献者,拥有MIT计算机科学学位。他的开源项目在GitHub上获得了超10,000星,每月下载超过700万次。

来源 | 程序员的那些事(ID:iProgrammer)

封面图 | 优快云下载自视觉中国

平常关注的技术博主,居然是新加坡总理的儿子!

最近,《Hands-on Scala Programming》的作者李浩毅在程序员圈子引发热议。原来他就是新加坡总理李显龙的儿子。

(格子衫衬衣是不是很眼熟?)

据公开信息显示,李浩毅出于 1989 年,毕业于 MIT,计算机科学和工程学位。他是 Scala 社区的主要贡献者。

李浩毅的个人网站上自称,其开源项目在 Github 上有超过 10,000 Star,每个月的下载次数超过 7,000,000 次。自称擅长用 Scala 来构建分布式后端系统、高性能web 应用程序等。

有网友感叹,他一直关注的技术博主,原来是这样的身份背景。「这是我人生接触的第二个家里比我有权家里黄金遍地智商比我强还比我努力的人!」

还有网友调侃说,要是李浩毅不好好写代码,就只有回去当坡县县长了。

新加坡总理也是会编程的!

其实现任总理李显龙,也是有计算机科学文凭的。

他在英国剑桥大学三一学院修读数学,1973 年拿过数学尖子生「Senior Wrangler」头衔,1974 年荣获数学一等荣誉及计算机科学文凭(优异)。

2015 年 5 月,李显龙曾经在一次创业者论坛上透露,他最后编写的程序是一个解决数独问题的程序。

在帖子中,李显龙除了解释程序之外,还公开了数独程序的完整源码。有兴趣的童鞋,请看:

#include "stdio.h"
int InBlock[81], InRow[81], InCol[81];
const int BLANK = 0;const int ONES = 0x3fe;   // Binary 1111111110
int Entry[81];  // Records entries 1-9 in the grid, as the corresponding bit set to 1int Block[9], Row[9], Col[9];  // Each int is a 9-bit array
int SeqPtr = 0;int Sequence[81];
int Count = 0;int LevelCount[81];

void SwapSeqEntries(int S1, int S2){     int temp = Sequence[S2];     Sequence[S2] = Sequence[S1];     Sequence[S1] = temp;}

void InitEntry(int i, int j, int val){   int Square = 9 * i + j;   int valbit = 1 << val;     int SeqPtr2;
     // add suitable checks for data consistency        Entry[Square] = valbit;   Block[InBlock[Square]] &= ~valbit;   Col[InCol[Square]] &= ~valbit; // Simpler Col[j] &= ~valbit;   Row[InRow[Square]] &= ~valbit; // Simpler Row[i] &= ~valbit;
     SeqPtr2 = SeqPtr;     while (SeqPtr2 < 81 && Sequence[SeqPtr2] != Square)           SeqPtr2++ ;
     SwapSeqEntries(SeqPtr, SeqPtr2);     SeqPtr++;}

void PrintArray(){     int i, j, valbit, val, Square;     char ch;          Square = 0;
     for (i = 0; i < 9; i++) {         if (i % 3 == 0) putc('\n', stdout);         for (j = 0; j < 9; j++) {             if (j % 3 == 0) putc(' ', stdout);             valbit = Entry[Square++];             if (valbit == 0) ch = '-';             else {                 for (val = 1; val <= 9; val++)                     if (valbit == (1 << val)) {                        ch = '0' + val;                        break;                     }             }             putc(ch,stdout);         }         putc ('\n', stdout);     }}

void ConsoleInput(){     int i, j;     char InputString[80];
     for (i = 0; i < 9; i++) {         printf("Row[%d] : ", i + 1);         scanf("%s", InputString);
         for (j = 0; j < 9; j++) {             char ch = InputString[j];             if (ch >= '1' && ch <= '9')                InitEntry(i, j, ch - '0');         }     }
     PrintArray();}

void PrintStats(){    int i, j, S;
    printf("\nLevel Counts:\n\n");
    S = 0;    while (LevelCount[S] == 0) S++;
    i = 0;
    while (S < 81) {          int Seq = Sequence[S];          printf("(%d, %d):%4d ", Seq / 9 + 1, Seq % 9 + 1, LevelCount[S]);          if (i++ > 4){             printf("\n");             i = 0;          }          S++;    }
    printf("\n\nCount = %d\n", Count);}

void Succeed(){     PrintArray();     PrintStats();}

int NextSeq(int S){    int S2, Square, Possibles, BitCount;    int T, MinBitCount = 100;
    for (T = S; T < 81; T++) {        Square = Sequence[T];        Possibles = Block[InBlock[Square]] & Row[InRow[Square]] & Col[InCol[Square]];        BitCount = 0;        while (Possibles) {           Possibles &= ~(Possibles & -Possibles);           BitCount++;        }
        if (BitCount < MinBitCount) {           MinBitCount = BitCount;           S2 = T;        }    }
    return S2;}

void Place(int S){    LevelCount[S]++;    Count++;
    if (S >= 81) {       Succeed();       return;    }
    int S2 = NextSeq(S);    SwapSeqEntries(S, S2);
    int Square = Sequence[S];
    int   BlockIndex = InBlock[Square],      RowIndex = InRow[Square],      ColIndex = InCol[Square];
    int   Possibles = Block[BlockIndex] & Row[RowIndex] & Col[ColIndex];    while (Possibles) {          int valbit = Possibles & (-Possibles); // Lowest 1 bit in Possibles          Possibles &= ~valbit;          Entry[Square] = valbit;          Block[BlockIndex] &= ~valbit;          Row[RowIndex] &= ~valbit;          Col[ColIndex] &= ~valbit;                  Place(S + 1);
          Entry[Square] = BLANK; // Could be moved out of the loop          Block[BlockIndex] |= valbit;          Row[RowIndex] |= valbit;          Col[ColIndex] |= valbit;  }
    SwapSeqEntries(S, S2);}

int main(int argc, char* argv[]){  int i, j, Square;
  for (i = 0; i < 9; i++)    for (j = 0; j < 9; j++) {      Square = 9 * i + j;      InRow[Square] = i;      InCol[Square] = j;      InBlock[Square] = (i / 3) * 3 + ( j / 3);    }

  for (Square = 0; Square < 81; Square++) {        Sequence[Square] = Square;    Entry[Square] = BLANK;        LevelCount[Square] = 0;    }
  for (i = 0; i < 9; i++)    Block[i] = Row[i] = Col[i] = ONES;
    ConsoleInput();    Place(SeqPtr);    printf("\n\nTotal Count = %d\n", Count);
  return 0;}

更多精彩推荐

☞蒋凡“罚酒三杯”,这些被价值观干掉的阿里人表示不服
☞你还在为 TCP 重传、滑动窗口、流量控制、拥塞控制发愁吗?看完图解就不愁了
☞阿里部门主管回应 P8 工程师“在内网质疑蒋凡事件”被辞退;李国庆向当当员工致歉;VS Code 五周年| 极客头条
☞用 Python 实现手机自动答题,这下百万答题游戏谁也玩不过我!
☞IDEA 惊天 bug:进程已结束,退出代码 1073741819
☞当 DeFi 遇上 Rollup,将擦出怎样的火花?
你点的每个“在看”,我都认真当成了喜欢
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值