文章目录

    • @[toc]
  • 人工智能 AI Code 写代码测试
    • 用golang实现冒泡排序
    • 用golang实现计算环比函数
    • goroutine and channel
    • 用golang实现二叉树遍历代码
    • 用golang实现线程安全的HashMap操作代码
    • using C programming language write a tiny Operation System
    • use C language write a tiny compiler
    • 用golang实现B+树代码
    • 使用 golang 写一个开启10个协程请求rpc接口的代码
    • 用 C 语言实现一个HashMap 代码
    • use C language write a Collection Operation API

人工智能 AI Code 写代码测试

用golang实现冒泡排序

package mainimport "fmt"func main() {arr := []int{3,2,1,3,2,4,8,7,9,2,3}bubbleSort(arr) //冒泡排序fmt.Println("排序后:",arr)
}func bubbleSort(arr []int){for i:= 0; i < len(arr)-1; i++{for j:=0;j < len(arr)-1-i ;j++{if arr[j] > arr[j+1]{arr[j],arr[j+1] = arr[j+1],arr[j]}}}
}

用golang实现计算环比函数

package mainimport "fmt"func main() {fmt.Println(calcLinkRatio(5,3))
}//计算环比值(升、降)
func calcLinkRatio(a, b float64) float64 {//环比linkRatio := (b - a) / a * 100return linkRatio
}

goroutine and channel


package mainimport "fmt"// create a channel
var ch = make(chan int)// send data to channel
func sendData(nums ...int) {for _, n := range nums {ch <- n}
}// receive data from channel
func receiveData() {for {num := <-chfmt.Println("receive data from channel:", num)}
}// main function
func main() {// create go routinego sendData(1, 2, 3, 4, 5, 6)go receiveData()// wait for all routines to finishvar input stringfmt.Scanln(&input)fmt.Println("Done")
}

用golang实现二叉树遍历代码

type TreeNode struct
{Val intLeft *TreeNodeRight *TreeNode
}//先序遍历
func PreOrder(node *TreeNode) {if node == nil {return}//访问根节点fmt.Printf("%d ", node.Val)PreOrder(node.Left)PreOrder(node.Right)
}//中序遍历
func InOrder(node *TreeNode) {if node == nil {return}InOrder(node.Left)fmt.Printf("%d ", node.Val)InOrder(node.Right)
}//后序遍历
func PostOrder(node *TreeNode) {if node == nil {return}PostOrder(node.Left)PostOrder(node.Right)fmt.Printf("%d ", node.Val)
}

用golang实现线程安全的HashMap操作代码

go
package mainimport ("fmt""sync"
)type SafeHashMap struct {lock *sync.Mutexm    map[int]int
}// 创建一个新的 HashMap,并初始化 Mutex 锁
func NewSafeHashMap() *SafeHashMap {return &SafeHashMap{ lock: new(sync.Mutex), m : make(map[int]int)}
}// 根据键值对 kv 向 HashMap 中插入一项数据
// 返回 bool 值,若插入成功则返回 true,否则返回 false
func (shm *SafeHashMap) Put(k int, v int) bool {// 上锁shm.lock.Lock()defer shm.lock.Unlock()// 若 key 已经存在,则返回 false_, ok := shm.m[k]if ok {return false}// 插入 key-value 键值对shm.m[k] = vreturn true
}// 根据 key 从 HashMap 中取出一项 key-value 键值对,
// 若 key 存在则返回对应的 value 以及 true 值,
// 否则返回零值以及 false 值
func (shm *SafeHashMap) Get(k int) (int, bool) {// 上锁shm.lock.Lock()defer shm.lock.Unlock()// 根据 key 取出 valuev, ok := shm.m[k]return v, ok
}// 从 HashMap 中移除一项 key-value 键值对,
// 若 key 存在则移除该项并返回 true 值,
// 否则返回 false 值
func (shm *SafeHashMap) Remove(k int) bool {// 上锁shm.lock.Lock()defer shm.lock.Unlock()_, ok := shm.m[k]if ok {delete(shm.m, k)}return ok
}// 返回 HashMap 中 key-value 键值对的项数
func (shm *SafeHashMap) Size() int {return len(shm.m)
}func main() {// 创建一个空的安全的 HashMapshm := NewSafeHashMap()// 插入 key-value 键值对shm.Put(1, 10)v, ok := shm.Get(1)fmt.Println(v, ok)// 移除 keyok = shm.Remove(1)fmt.Println(ok)// 获取 key 的数量fmt.Println(shm.Size())
}

using C programming language write a tiny Operation System

哈哈,让 AI 写一个操作系统,估计有点难为它了。目前来看,还达不到MOSS的水平,自动生成操作系统。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>/******************** Function declarations ********************/
void clear(void); // clears the console
void print_welcome_message (void);  // prints an introductory message
void command_input(void); // get an input from the user
int run_command (char *inp); // runs the command which is given by the user/******************** Main code ********************/
int main(void)
{clear();print_welcome_message();command_input();return 0;
}/******************** Function definitions ********************/
void clear()
{#ifdef WINDOWSsystem("cls");#elsesystem("clear");#endif
}void print_welcome_message()
{printf("Welcome to our Tiny OS!\n");printf("Start typing the commands:\n\n");
}void command_input()
{char input_str[20];while(1){printf("> ");scanf("%s", input_str);if(run_command(input_str) == -1){break;}}
}int run_command(char *inp)
{if(strcmp(inp, "exit") == 0){printf("\nbye!\n\n");return -1;}else{printf("Invalid Command.\nType \"exit\" to Exit.\n\n");return 0;}}

用 C 语言实现操作系统的自举启动的代码。

#include "boot.h"// 加载操作系统
void boot_load_os()
{    // 这里是一大堆代码// ...// 执行操作系统execute_os();
}

use C language write a tiny compiler

写个编译器看看。

#include <stdio.h>
#include <string.h>const int MAX_SIZE = 1000;// creating a structure to store the tokens.
struct tokens {char* type;char* value;
};//function to lex the program
struct tokens lex(char* input)
{struct tokens token;int i = 0;int startIndex = 0;while(input[i] != '\0'){char currentChar = input[i];if (currentChar == ' '){char* str = malloc(i - startIndex);memcpy(str, &input[startIndex], i - startIndex);token.type = str;token.value = NULL;break;}else if (currentChar == '+' || currentChar == '-'){token.type = "op";token.value = malloc(1);token.value[1] = '\0';token.value = currentChar;break;}i++;}return token;
}int main() {char input[MAX_SIZE];printf("Enter a simple expression:\t");scanf("%s", input);struct tokens token = lex(input);printf("Type: %s, Value: %s\n", token.type, token.value);return 0;
}

用golang实现B+树代码

package bptree// B+树定义
type BPTree struct {Order    int                    // B+树的阶数Root     *Node                  // 根节点Height   int                    // 树的高度Size     int                    // 树的大小Sequence func(interface{}, int) // B+树键比较函数
}// B+树中的节点
type Node struct {IsLeaf   bool              // 标识该节点是否为叶子节点Entries  []*Entry          // 节点上的数据条目Next     *Node             // 指向右兄弟节点Children []*Node           // 不是叶子节点时有效,存放子节点指针Parent   *Node             // 指向父节点Items    map[interface{}]*Entry // 键值对
}// 数据条目
type Entry struct {Key   interface{} // B+树索引键Value interface{} // 数据值
}// 构造函数,构建一棵B+树
func NewTree(order int, sequence func(interface{}, int)) *BPTree {tree := &BPTree{Order:    order,Root:     nil,Height:   0,Size:     0,Sequence: sequence,}return tree
}// 搜索数据,返回搜索键的数据记录
func (tree *BPTree) Search(key interface{}) interface{} {node := tree._search(tree.Root, key)if node == nil {return nil}entry := node.Items[key]if entry == nil {return nil}return entry.Value
}// 内部搜索函数,返回搜索键所在节点
func (tree *BPTree) _search(node *Node, key interface{}) *Node {if node == nil {return nil}// 在节点上搜索键i, _ := tree._binarySearch(node, key)// 找到键if i >= 0 && node.Entries[i].Key == key {return node}// 不是叶子节点,从子节点继续搜索if !node.IsLeaf {return tree._search(node.Children[i], key)}// 未找到键return nil
}// 二分搜索函数,在节点上搜索键
func (tree *BPTree) _binarySearch(node *Node, key interface{}) (int, bool) {low := 0high := len(node.Entries) - 1for low <= high {mid := (low + high) / 2result := tree.cmpFunc(key, node.Entries[mid])if result == 0 {return mid, true // 搜索成功} else if result < 0 {high = mid - 1} else {low = mid + 1}}return low, false // 搜索失败
}

使用 golang 写一个开启10个协程请求rpc接口的代码

// 请求rpc
func RpcRequest(aid int, ch chan int) {resp := sendRpc(aid) // 发送rpcch <- resp
}func main() {ch := make(chan int, 10)for i := 0; i < 10; i++ {go RpcRequest(i, ch)}for i := 0; i < 10; i++ {resp := <- chfmt.Println("resp:", resp)}
}

用 C 语言实现一个HashMap 代码

/* 定义key-value字段 */
typedef struct
{void *key; //key void *value; //valuestruct ht_node *next; //单链表
} ht_node;/* 定义hashmap */
typedef struct
{int size; //字典的大小 ht_node **head;  //字典的头int count;   //元素的个数
}ht_hash_map;/*hash函数,计算键值*/
int hash_int_func(int key)
{key += ~(key << 15);key ^= (key >> 10);key += (key << 3);key ^= (key >> 6);key += ~(key << 11);key ^= (key >> 16);return (key & 0x7FFFFFFF);
}/* 创建hashmap */
ht_hash_map *ht_create(int size)
{ht_hash_map *ht = (ht_hash_map*)malloc(sizeof(ht_hash_map));ht->count = 0;ht->size = size;ht->head = (ht_node**)malloc(sizeof(ht_node*)*size);int i;for(i = 0; i < ht->size; i++){ht->head[i] = NULL;}return ht;
}/* 设置hashmap */
int ht_set(ht_hash_map *ht,void *key, void *value)
{int index = hash_int_func(*(int*)key) % ht->size;ht_node *tmp = ht->head[index];ht_node *last = NULL;while(tmp){if(*(int*)tmp->key == *(int*)key){tmp->value = value;return 0;}last = tmp;tmp = tmp->next;}// 没有重复映射ht_node *node = (ht_node*)malloc(sizeof(ht_node));node->key = key;node->value = value;node->next = NULL;// head为空if(ht->head[index] == NULL){ht->head[index] = node;}else{last->next = node;}ht->count++;return 1;
}/* 获取hashmap */
void *ht_get(ht_hash_map *ht, void *key)
{int index = hash_int_func(*(int*)key) % ht->size;ht_node *tmp = ht->head[index];while(tmp){if(*(int*)tmp->key == *(int*)key)return tmp->value;tmp = tmp->next;}return NULL;
}/* 删除hashmap */
int ht_remove(ht_hash_map *ht, void *key)
{int index = hash_int_func(*(int*)key) % ht->size;ht_node *tmp = ht->head[index];ht_node *last = NULL;while(tmp){if(*(int*)tmp->key == *(int*)key){if(last == NULL){//头节点ht->head[index] = tmp->next;}else{last->next = tmp->next;}free(tmp);return 0;}last = tmp;tmp = tmp->next;}return 1;
}/* 销毁hashmap */
void ht_destory(ht_hash_map *ht) {int i;for (i = 0; i < ht.size; i++) {item *cur_item, *cur_item_tmp;cur_item_tmp = ht->items[i];while (cur_item_tmp) {cur_item = cur_item_tmp;cur_item_tmp = cur_item_tmp->next;free(cur_item);}}free(ht);
}/* 查找hashmap中的key-value */
ht_item *ht_search(ht_hash_map *ht, const char *key) {int index;index = hash(key, ht->size);item *cur_item;cur_item = ht->items[index];while (cur_item) {if (strcmp(cur_item->key, key) == 0) { return cur_item; }cur_item = cur_item->next;}return NULL;
}

use C language write a Collection Operation API

#include <stdlib.h>typedef struct item {void *data;
} Item;typedef struct Collection{void* data;int size;
} Collection;// Create a new Collection
Collection* Collection_create() {Collection *collection = (Collection*)malloc(sizeof(Collection));if (collection == NULL) {return NULL;}collection->data = NULL;collection->size = 0;return collection;
}// Add an item to the Collection
int Collection_add(Collection *collection, void* item) {if (collection == NULL) return 0;// Increase the size of the collectionint newSize = collection->size + 1;Item *items = (Item*)realloc(collection->data, newSize*sizeof(Item));if (items == NULL) {return 0;}collection->data = items;// Add the itemItem *item_ptr = &items[collection->size];item_ptr->data = item;collection->size = newSize;return 1;
}// Remove an item from the Collection
int Collection_remove(Collection *collection, void* item) {if (collection == NULL || collection->size == 0) return 0;// Find the item to removeItem *items = (Item*)collection->data;int removeIndex = -1;int i;for (i = 0; i < collection->size; i++) {Item *item_ptr = &items[i];if (item_ptr->data == item) {removeIndex = i;break;}}if (removeIndex == -1) {return 0;}// Remove the itemint newSize = collection->size - 1;Item *newItems = (Item*)malloc(newSize*sizeof(Item));if (newItems == NULL) return 0;// Copy the elements before the removeIndexfor (i = 0; i < removeIndex; i++) {newItems[i] = items[i];}// Copy the elements after the removeIndexfor (i = removeIndex; i < newSize; i++) {newItems[i] = items[i+1];}free(collection->data);collection->data = newItems;collection->size = newSize;return 1;
}// Clear all items from the Collection
int Collection_clear(Collection *collection) {if (collection == NULL) return 0;free(collection->data);collection->data = NULL;collection->size = 0;return 1;
}// Delete the Collection
void Collection_delete(Collection *collection) {if (collection == NULL) return;free(collection->data);free(collection);
}

估计 csdn 封掉链接,不让贴,请私信我!

【人工智能 Open AI 】我们程序员真的要下岗了- 全能写Go / C / Java / C++ / Python / JS 人工智能机器人相关推荐

  1. 做Java程序员真的没有春天吗?写给正在求职的Java开发

    简介 HikariCP 是用于创建和管理连接,利用"池"的方式复用连接减少资源开销,和其他数据源一样,也具有连接数控制.连接可靠性测试.连接泄露控制.缓存语句等功能,另外,和 dr ...

  2. ai取代程序员_未来50%的工作都将被人工智能给取代,程序员会被机器人取代吗?...

    首先程序员这个行业和其他行业一样也是分等级的. 虽然非常不想用"底层从业者"这五个词来定义最低层次的程序员,但事实就是如此. 当行业的某个技术领域发展成熟到一定程度时,这个领域的大 ...

  3. AI抢程序员工作:2040年AI可能代替程序员

    原文链接:点击打开链接 摘要: 美国橡树岭国家实验室的一些专家预测,到2040年,AI技术将会强大到足以替代程序员.不过,即使机器能够完全代替今天程序员所做的工作,但这并不意味着它们不需要人类的帮助. ...

  4. 人工智能“上位”会让程序员消失吗?

    大脑以及二进制代码(图:Canva) 来源:Forbes 作者:Nisha Talagala 编译整理:科技行者 写代码已经成了许多工作的一项关键技能.一些国家和学校甚至认为,编程语言是一种可以接受的 ...

  5. 程序员真的是一个吃青春饭的行业吗?

    对于某一些程序员而言,的确是这样. 程序员行业的35岁危机真真切切的存在,不少企业或明或暗的要求一线的程序员的年龄不超过35岁. 首先程序员不是一个行业.程序员是一种职业.而且程序员这种职业不限于行业 ...

  6. 上海宝付解读10年后AI取代程序员

    上海宝付解读10年后AI取代程序员. 在AI技术的兴趣,人工智能将取代人工,司机将被自动驾驶取代,医生将被智能医疗取代等等,还有将要消失的10大职业.20类职业等等,在网络上一搜满屏都是,且不论只这些 ...

  7. 专访微软亚洲研究院首席研发经理邹欣:AI 时代程序员将往哪走?

    导读:6月21-23日,2019 GIAC全球互联网架构大会将于深圳举行.GIAC是面向架构师.技术负责人及高端技术从业人员的年度技术架构大会,是中国地区规模最大的技术会议之一.今年GIAC邀请到了众 ...

  8. 程序员真的是吃青春饭的吗?(献给即将进入职场的程序员们)

    又有学生问我:程序员真的是吃青春饭的吗?我是不是做到三十岁就该考虑转型了? 我告诉他们: 这是中国的记者们用统计数字造下的一个弥天大谎,当我们看到微软集团内的许多白发程序员在兢兢业业地工作的时候,我们 ...

  9. AI 帮程序员找 Bug,一键快速预测

    作者 | Jane 出品 | AI科技大本营(ID:rgznai100) 在程序开发中,程序员每天都要和 Bug 打交道,对新手程序员而言,Debug 是一件非常让人头疼的事情.好不容易写完一段代码, ...

最新文章

  1. ajax传递参数给springmvc
  2. pyecharts第九节、旭日图(现代饼图)
  3. 【Qt】Qt5.9连接MySQl5.7(亲自测试成功)
  4. HDU - 3374 String Problem(最小表示法+最大表示法+KMP的next数组)
  5. VS Code集成SandDance可视化分析数据
  6. 程序员像瞎子,产品经理像跛子
  7. 面试官系统精讲Java源码及大厂真题 - 05 ArrayList 源码解析和设计思路
  8. shortcut switch in terminal start pos end pos
  9. 算法模板java_我的Java设计模式-模板方法模式
  10. jQuery file upload测试
  11. eclipse部署Javaweb项目
  12. 影视剪辑,视频剪辑素材音效哪里找?超实用剪辑入门必备素材
  13. 杭州电子科技大学计算机非全日制,杭州电子科技大学非全日制研究生考试难吗?...
  14. 手机号码清洗的优势是什么
  15. 数据库语法整理及WAF绕过方式
  16. IAR报错could not find the following source file
  17. 使用unity时VS无报错
  18. 很多应用程序运行时会出现“若要运行此应用程序,您必须首先安装.NET Framework的以下版本之一”的解决方法
  19. 20175227张雪莹 2018-2019-2 《Java程序设计》第十一周学习总结
  20. Failed to load JavaHL Library问题

热门文章

  1. Webstorm设置自动保存
  2. html5本地点赞状态,javascript实现手动点赞效果
  3. PHP strtotime -1 month 获取上个月月份踩坑
  4. 实用 / 文艺 / 资深 的APP 《Yee》含全网VIP影视 / 影院热映电影 ----------------基于FusionApp制作
  5. 【python 爬虫】全国失信被执行人名单爬虫
  6. python-max函数
  7. 国际投行看好一家什么样的物流数据公司
  8. app怎么调起微信公众号_小程序_微信群_企业微信Html
  9. 页面缩放导致布局变乱
  10. 真正的成熟是怎样的?